-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Prometheus Plugin * Better names * Go * Improve plugin DX
- Loading branch information
Showing
13 changed files
with
343 additions
and
31 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@graphql-mesh/types': minor | ||
'@graphql-mesh/plugin-prometheus': minor | ||
--- | ||
|
||
New Prometheus Plugin |
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,7 @@ | ||
--- | ||
'@graphql-mesh/config': minor | ||
'@graphql-mesh/plugin-prometheus': minor | ||
'@graphql-mesh/types': minor | ||
--- | ||
|
||
Plugin factories now can return promises |
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 |
---|---|---|
|
@@ -14,3 +14,5 @@ additionalResolvers: | |
documents: | ||
- example-queries/*.graphql | ||
|
||
plugins: | ||
- newrelic: {} |
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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "@graphql-mesh/plugin-prometheus", | ||
"version": "0.0.0", | ||
"sideEffects": false, | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"typings": "dist/index.d.ts", | ||
"typescript": { | ||
"definition": "dist/index.d.ts" | ||
}, | ||
"exports": { | ||
".": { | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" | ||
}, | ||
"./*": { | ||
"require": "./dist/*.js", | ||
"import": "./dist/*.mjs" | ||
} | ||
}, | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "Urigo/graphql-mesh", | ||
"directory": "packages/plugins/prometheus" | ||
}, | ||
"peerDependencies": { | ||
"graphql": "*", | ||
"prom-client": "^13 || ^14.0.0" | ||
}, | ||
"dependencies": { | ||
"@envelop/prometheus": "6.6.0", | ||
"@graphql-mesh/utils": "0.41.0", | ||
"@graphql-mesh/types": "0.81.0", | ||
"tslib": "^2.4.0" | ||
}, | ||
"devDependencies": { | ||
"prom-client": "14.0.1" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"directory": "dist" | ||
} | ||
} |
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,79 @@ | ||
import { usePrometheus } from '@envelop/prometheus'; | ||
import { MeshPlugin, MeshPluginOptions, YamlConfig } from '@graphql-mesh/types'; | ||
import { getHeadersObj, loadFromModuleExportExpression } from '@graphql-mesh/utils'; | ||
import { Histogram, register as defaultRegistry, Registry } from 'prom-client'; | ||
|
||
export default async function useMeshPrometheus( | ||
pluginOptions: MeshPluginOptions<YamlConfig.PrometheusConfig> | ||
): Promise<MeshPlugin<any>> { | ||
const registry = pluginOptions.registry | ||
? await loadFromModuleExportExpression<Registry>(pluginOptions.registry, { | ||
cwd: pluginOptions.baseDir, | ||
importFn: pluginOptions.importFn, | ||
defaultExportName: 'default', | ||
}) | ||
: defaultRegistry; | ||
const fetchHistogram = new Histogram({ | ||
name: 'graphql_mesh_fetch_duration', | ||
help: 'Time spent on outgoing HTTP calls', | ||
labelNames: ['url', 'method', 'requestHeaders', 'statusCode', 'statusText', 'responseHeaders'], | ||
registers: [registry], | ||
}); | ||
const delegateHistogram = new Histogram({ | ||
name: 'graphql_mesh_delegate_duration', | ||
help: 'Time spent on delegate execution', | ||
labelNames: ['sourceName', 'typeName', 'fieldName', 'args', 'key'], | ||
registers: [registry], | ||
}); | ||
return { | ||
onPluginInit({ addPlugin }) { | ||
addPlugin( | ||
usePrometheus({ | ||
...pluginOptions, | ||
registry, | ||
}) | ||
); | ||
}, | ||
onDelegate({ sourceName, typeName, fieldName, args, key }) { | ||
if (pluginOptions.delegation !== false) { | ||
const start = Date.now(); | ||
return () => { | ||
const end = Date.now(); | ||
const duration = end - start; | ||
delegateHistogram.observe( | ||
{ | ||
sourceName, | ||
typeName, | ||
fieldName, | ||
args: JSON.stringify(args), | ||
key: JSON.stringify(key), | ||
}, | ||
duration | ||
); | ||
}; | ||
} | ||
return undefined; | ||
}, | ||
onFetch({ url, options }) { | ||
if (pluginOptions.fetch !== false) { | ||
const start = Date.now(); | ||
return ({ response }) => { | ||
const end = Date.now(); | ||
const duration = end - start; | ||
fetchHistogram.observe( | ||
{ | ||
url, | ||
method: options.method, | ||
requestHeaders: JSON.stringify(options.headers), | ||
statusCode: response.status, | ||
statusText: response.statusText, | ||
responseHeaders: JSON.stringify(getHeadersObj(response.headers)), | ||
}, | ||
duration | ||
); | ||
}; | ||
} | ||
return undefined; | ||
}, | ||
}; | ||
} |
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,21 @@ | ||
extend type Plugin { | ||
prometheus: PrometheusConfig | ||
} | ||
|
||
type PrometheusConfig @md { | ||
requestCount: Boolean | ||
requestTotalDuration: Boolean | ||
requestSummary: Boolean | ||
parse: Boolean | ||
validate: Boolean | ||
contextBuilding: Boolean | ||
execute: Boolean | ||
errors: Boolean | ||
resolvers: Boolean | ||
resolversWhiteList: [String] | ||
deprecatedFields: Boolean | ||
delegation: Boolean | ||
fetch: Boolean | ||
skipIntrospection: Boolean | ||
registry: String | ||
} |
Oops, something went wrong.
ca7994f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
graphql-mesh – ./
graphql-mesh-azure.vercel.app
graphql-mesh-theguild.vercel.app
graphql-mesh-git-master-theguild.vercel.app
graphql-mesh.com
www.graphql-mesh.com