-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds an infinite number of bundles Also the /graphql sticks in the first commit, which is undesired. There are also some debugging messages that need to be cleaned up. * special middleware to serve /graphql * add new bundles to cache, with ttl The ttl is not currently enforced (no cache invalidation yet). Additionally some methods have been fixed in order to obtain data from the latest bundles. * invalidate cache and print cache info * remove unnecessary lines * Fix reloading problems. Requires version updates. * rename existing tests * remove unnecessary lines * add multisha tests * refactor bundle removal logic * lint * bump qontract-server version * add new cache and router metrics * refactor metrics * typo * support redirecting GET /graphql to POST /graphql * renamed metrics * typo * typo in default BUNDLE_SHA_TTL * implements bad bundle reload test * rename metrics * update README.md * enable yarn lint test in travis * fix linting
- Loading branch information
Showing
15 changed files
with
1,097 additions
and
442 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ node_js: | |
- "10" | ||
notifications: | ||
email: false | ||
script: | ||
- "yarn run lint" | ||
- "yarn test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "qontract-server", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "qontract graphql server", | ||
"author": "Red Hat App SREs <[email protected]>", | ||
"license": "Apache-2.0", | ||
|
@@ -16,7 +16,7 @@ | |
"update-graphql-schema": "scripts/update-graphql-schema.js test/graphql_schema.json $(find test -name '*.data.json')" | ||
}, | ||
"dependencies": { | ||
"apollo-server-express": "^2.2.0", | ||
"apollo-server-express": "^2.18.0", | ||
"aws-sdk": "^2.364.0", | ||
"bufferutil": "^4.0.1", | ||
"dotenv": "^8.2.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import * as express from 'express'; | ||
import * as db from './db'; | ||
|
||
import promClient = require('prom-client'); | ||
const promBundle = require('express-prom-bundle'); | ||
|
||
interface IAcct { | ||
[key: string]: number; | ||
} | ||
|
||
// metrics middleware for express-prom-bundle | ||
export const metricsMiddleware = promBundle({ | ||
includeMethod: true, | ||
includePath: true, | ||
normalizePath: [ | ||
['^/graphqlsha/.*', '/graphqlsha/#sha'], | ||
], | ||
buckets: [.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10], | ||
formatStatusCode: (res: express.Response) => `${Math.floor(res.statusCode / 100)}xx`, | ||
}); | ||
|
||
// enable prom-client to expose default application metrics | ||
promClient.collectDefaultMetrics({ prefix: 'qontract_server_' }); | ||
|
||
// Create metric stores | ||
const reloadCounter = new promClient.Counter({ | ||
name: 'qontract_server_reloads_total', | ||
help: 'Number of reloads for qontract server', | ||
}); | ||
|
||
const datafilesGauge = new promClient.Gauge({ | ||
name: 'qontract_server_datafiles', | ||
help: 'Number of datafiles for a specific schema', | ||
labelNames: ['schema'], | ||
}); | ||
|
||
const routerStackGauge = new promClient.Gauge({ | ||
name: 'qontract_server_router_stack_layers', | ||
help: 'Number of layers in the router stack', | ||
}); | ||
|
||
const bundleGauge = new promClient.Gauge({ | ||
name: 'qontract_server_bundle_object_shas', | ||
help: 'Number of shas cached by the application in the bundle object', | ||
}); | ||
|
||
const bundleCacheGauge = new promClient.Gauge({ | ||
name: 'qontract_server_bundle_cache_object_shas', | ||
help: 'Number of shas cached by the application in the bundleCache object', | ||
}); | ||
|
||
export const updateCacheMetrics = (app: express.Express) => { | ||
routerStackGauge.set(app._router.stack.length); | ||
bundleGauge.set(Object.keys(app.get('bundles')).length); | ||
bundleCacheGauge.set(Object.keys(app.get('bundleCache')).length); | ||
}; | ||
|
||
export const updateResourceMetrics = (bundle: db.Bundle) => { | ||
// Count number of files for each schema type | ||
const reducer = (acc: IAcct, d: any) => { | ||
if (!(d.$schema in acc)) { | ||
acc[d.$schema] = 0; | ||
} | ||
acc[d.$schema] += 1; | ||
return acc; | ||
}; | ||
const schemaCount: IAcct = bundle.datafiles.reduce(reducer, {}); | ||
|
||
// Set the Gauge based on counted metrics | ||
Object.keys(schemaCount).map(schemaName => | ||
datafilesGauge.set({ schema: schemaName }, schemaCount[schemaName]), | ||
); | ||
|
||
reloadCounter.inc(1); | ||
}; |
Oops, something went wrong.