docs: fix prometheus documentation (#5645)

This commit is contained in:
Valentin Cocaud 2024-10-08 12:47:44 +02:00 committed by GitHub
parent e52caa90e7
commit 3d5829b753
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1173,7 +1173,7 @@ curl -v http://localhost:4000/metrics
### Customizations
<Tabs items={["Introspection Queries", "Metric Name", "Metric Config", "Registry"]}>
<Tabs items={["Introspection Queries", "Labels", "Metric Name", "Metric Config", "Registry"]}>
<Tabs.Tab>
@ -1183,6 +1183,23 @@ ignore introspection queries for all metrics prefixed by `graphql_envelop_` by s
</Tabs.Tab>
<Tabs.Tab>
By default, all labels are enabled, but each one can be disabled to reduce cardinality:
```ts filename="gateway.confing.ts"
import { defineConfig } from '@graphql-hive/gateway'
export const gatewayConfig = defineConfig({
prometheus: {
labels: {
url: false // remove `url` labels from all relevant metrics
}
}
})
```
</Tabs.Tab>
<Tabs.Tab>
By providing a string, you can change the name of the metric. For example, to change the name of the
@ -1193,7 +1210,9 @@ import { defineConfig } from '@graphql-hive/gateway'
export const gatewayConfig = defineConfig({
prometheus: {
graphql_yoga_http_duration: 'http_request_duration'
metrics: {
graphql_yoga_http_duration: 'http_request_duration'
}
}
})
```
@ -1226,23 +1245,25 @@ import { register as registry } from 'prom-client'
export const gatewayConfig = defineConfig({
prometheus: {
graphql_yoga_http_duration: createHistogram({
registry,
histogram: {
name: 'graphql_yoga_http_duration',
help: 'Time spent on HTTP connection',
labels: ['method', 'statusCode', 'operationName', 'operationType'],
buckets: [0.1, 5, 15, 50, 100, 500],
}
fillLabelsFn(params, { request, response }) {
return {
method: request.method,
statusCode: response.status,
operationType: params.operationType,
operationName: params.operationName || 'Anonymous',
};
}
})
metrics: {
graphql_yoga_http_duration: createHistogram({
registry,
histogram: {
name: 'graphql_yoga_http_duration',
help: 'Time spent on HTTP connection',
labels: ['method', 'statusCode', 'operationName', 'operationType'],
buckets: [0.1, 5, 15, 50, 100, 500],
}
fillLabelsFn(params, { request, response }) {
return {
method: request.method,
statusCode: response.status,
operationType: params.operationType,
operationName: params.operationName || 'Anonymous',
};
}
})
}
}
})
```