-
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.
New StatsD plugin and Documentation about Tracing/Monitoring (#4422)
* New StatsD plugin & Documentation about Tracing & Monitoring * Fix website * Go * Fix * Docs * Fix typo * ..
- Loading branch information
Showing
22 changed files
with
687 additions
and
379 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,10 @@ | ||
--- | ||
'@graphql-mesh/plugin-newrelic': patch | ||
'@graphql-mesh/types': patch | ||
'@graphql-mesh/plugin-statsd': patch | ||
--- | ||
|
||
🚀🚀🚀 **New StatsD plugin** 🚀🚀🚀 | ||
|
||
You can learn more about tracing and monitoring in GraphQL with different plugins (StatsD, Prometheus, NewRelic and more) in our documentation. | ||
[Tracing and Monitoring in GraphQL Mesh](http://www.graphql-mesh.com/docs/guides/monitoring-and-tracing) |
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
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-statsd", | ||
"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/statsd" | ||
}, | ||
"peerDependencies": { | ||
"graphql": "*", | ||
"hot-shots": "^8.0.0 || ^9.0.0" | ||
}, | ||
"dependencies": { | ||
"@envelop/statsd": "2.6.0", | ||
"@graphql-mesh/utils": "0.41.1", | ||
"@graphql-mesh/types": "0.82.0", | ||
"tslib": "^2.4.0" | ||
}, | ||
"devDependencies": { | ||
"hot-shots": "9.0.0" | ||
}, | ||
"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,67 @@ | ||
import { MeshPlugin, MeshPluginOptions, YamlConfig } from '@graphql-mesh/types'; | ||
import StatsD, { Tags } from 'hot-shots'; | ||
import { useStatsD } from '@envelop/statsd'; | ||
import { getHeadersObj } from '@graphql-mesh/utils'; | ||
|
||
const metricNames = { | ||
delegationCount: 'delegations.count', | ||
delegationErrorCount: 'delegations.error.count', | ||
delegationLatency: 'delegations.latency', | ||
fetchCount: 'fetch.count', | ||
fetchErrorCount: 'fetch.error.count', | ||
fetchLatency: 'fetch.latency', | ||
}; | ||
|
||
export default function useMeshStatsd(pluginOptions: MeshPluginOptions<YamlConfig.StatsdPlugin>): MeshPlugin<any> { | ||
const client = new StatsD(pluginOptions.client); | ||
const prefix = pluginOptions.prefix || 'graphql'; | ||
return { | ||
onPluginInit({ addPlugin }) { | ||
addPlugin( | ||
useStatsD({ | ||
...pluginOptions, | ||
client, | ||
}) | ||
); | ||
}, | ||
onFetch({ url, options, info }) { | ||
const tags: Tags = { | ||
url, | ||
method: options.method, | ||
sourceName: (info as any)?.sourceName, | ||
fieldName: info?.fieldName, | ||
requestHeaders: JSON.stringify(options.headers), | ||
}; | ||
const start = Date.now(); | ||
return ({ response }) => { | ||
tags.statusCode = response.status.toString(); | ||
tags.statusText = response.statusText; | ||
const responseHeadersObj = getHeadersObj(response.headers); | ||
tags.responseHeaders = JSON.stringify(responseHeadersObj); | ||
client.increment(`${prefix}.${metricNames.fetchCount}`, tags); | ||
const end = Date.now(); | ||
if (!response.ok) { | ||
client.increment(`${prefix}.${metricNames.fetchErrorCount}`, tags); | ||
} | ||
client.histogram(`${prefix}.${metricNames.fetchLatency}`, end - start, tags); | ||
}; | ||
}, | ||
onDelegate({ sourceName, fieldName, args, key }) { | ||
const tags: Tags = { | ||
sourceName, | ||
fieldName, | ||
args: JSON.stringify(args), | ||
key, | ||
}; | ||
const start = Date.now(); | ||
return ({ result }) => { | ||
if (result instanceof Error) { | ||
client.increment(`${prefix}.${metricNames.delegationErrorCount}`, tags); | ||
} | ||
client.increment(`${prefix}.${metricNames.delegationCount}`, tags); | ||
const end = Date.now(); | ||
client.histogram(`${prefix}.${metricNames.delegationLatency}`, end - start, tags); | ||
}; | ||
}, | ||
}; | ||
} |
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,57 @@ | ||
extend type Plugin { | ||
statsd: StatsdPlugin | ||
} | ||
|
||
type StatsdPlugin @md { | ||
""" | ||
If you wish to disable introspection for logging (default: false) | ||
""" | ||
skipIntrospection: Boolean | ||
""" | ||
prefix.operations.count (default: graphql) | ||
""" | ||
prefix: String | ||
|
||
""" | ||
Client Configuration | ||
""" | ||
client: StatsdClientConfiguration | ||
} | ||
|
||
type StatsdClientConfiguration { | ||
bufferFlushInterval: Int | ||
bufferHolder: StatsdClientBufferHolder | ||
cacheDns: Boolean | ||
cacheDnsTtl: Int | ||
globalTags: JSON | ||
globalize: Boolean | ||
host: String | ||
isChild: Boolean | ||
maxBufferSize: Int | ||
mock: Boolean | ||
path: String | ||
port: Int | ||
protocol: StatsdClientProtocol | ||
sampleRate: Float | ||
suffix: String | ||
telegraf: Boolean | ||
useDefaultRoute: Boolean | ||
tagPrefix: String | ||
tagSeperator: String | ||
tcpGracefulErrorHandling: Boolean | ||
tcpGracefulRestartRateLimit: Int | ||
udsGracefulErrorHandling: Boolean | ||
udsGracefulRestartRateLimit: Int | ||
closingFlushInterval: Int | ||
} | ||
|
||
enum StatsdClientProtocol { | ||
tcp | ||
udp | ||
uds | ||
stream | ||
} | ||
|
||
type StatsdClientBufferHolder { | ||
buffer: String! | ||
} |
Oops, something went wrong.
3165827
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-git-master-theguild.vercel.app
graphql-mesh.com
graphql-mesh-theguild.vercel.app
www.graphql-mesh.com