-
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.
feat(prometheus): allow to rename names of the metrics
- Loading branch information
Showing
9 changed files
with
585 additions
and
120 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/plugin-prometheus': minor | ||
'@graphql-mesh/types': minor | ||
--- | ||
|
||
Now you can customize the names of the metrics |
137 changes: 96 additions & 41 deletions
137
examples/openapi-orbit/tests/__snapshots__/orbit.test.js.snap
Large diffs are not rendered by default.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
packages/plugins/prometheus/src/createHistogramForEnvelop.ts
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,37 @@ | ||
import { Histogram, Registry } from 'prom-client'; | ||
|
||
export const commonLabelsForEnvelop = ['operationType', 'operationName'] as const; | ||
|
||
export function commonFillLabelsFnForEnvelop(params: { | ||
operationName?: string; | ||
operationType?: string; | ||
}) { | ||
return { | ||
operationName: params.operationName!, | ||
operationType: params.operationType!, | ||
}; | ||
} | ||
|
||
interface CreateHistogramContainerForEnvelop { | ||
defaultName: string; | ||
help: string; | ||
valueFromConfig: string | boolean; | ||
registry: Registry; | ||
} | ||
|
||
export function createHistogramForEnvelop({ | ||
defaultName, | ||
help, | ||
valueFromConfig, | ||
registry, | ||
}: CreateHistogramContainerForEnvelop) { | ||
return { | ||
histogram: new Histogram({ | ||
name: typeof valueFromConfig === 'string' ? valueFromConfig : defaultName, | ||
help, | ||
labelNames: commonLabelsForEnvelop, | ||
registers: [registry], | ||
}), | ||
fillLabelsFn: commonFillLabelsFnForEnvelop, | ||
}; | ||
} |
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
Oops, something went wrong.