Add prom gauge for partitions latest fetched block - #383
Merged
Conversation
JonoPrest
commented
Dec 11, 2024
Comment on lines
+74
to
+138
| } | ||
|
|
||
| let metricNames: Utils.Set.t<string> = Utils.Set.make() | ||
|
|
||
| module MakeSafePromMetric = ( | ||
| M: { | ||
| type t | ||
| let make: {"name": string, "help": string, "labelNames": array<string>} => t | ||
| let labels: (t, 'a) => t | ||
| let handleFloat: (t, float) => unit | ||
| let handleInt: (t, int) => unit | ||
| }, | ||
| ): { | ||
| type t<'a> | ||
| let makeOrThrow: (~name: string, ~help: string, ~labelSchema: S.t<'a>) => t<'a> | ||
| let handleInt: (t<'a>, ~labels: 'a, ~value: int) => unit | ||
| let handleFloat: (t<'a>, ~labels: 'a, ~value: float) => unit | ||
| } => { | ||
| type t<'a> = {metric: M.t, labelSchema: S.t<'a>} | ||
|
|
||
| let makeOrThrow = (~name, ~help, ~labelSchema: S.t<'a>): t<'a> => | ||
| switch labelSchema->getLabelNames { | ||
| switch labelSchema->Labels.getLabelNames { | ||
| | Ok(labelNames) => | ||
| PromClient.Gauge.makeGauge({ | ||
| "name": name, | ||
| "help": help, | ||
| "labelNames": labelNames, | ||
| }) | ||
| if metricNames->Utils.Set.has(name) { | ||
| Js.Exn.raiseError("Duplicate prometheus metric name: " ++ name) | ||
| } else { | ||
| metricNames->Utils.Set.add(name)->ignore | ||
| let metric = M.make({ | ||
| "name": name, | ||
| "help": help, | ||
| "labelNames": labelNames, | ||
| }) | ||
|
|
||
| {metric, labelSchema} | ||
| } | ||
|
|
||
| | Error(error) => Js.Exn.raiseError(error) | ||
| } | ||
|
|
||
| let makeLabels = (self: t<'a>, ~labels: 'a): t<'a> => self->PromClient.Gauge.labels(labels) | ||
|
|
||
| let setFloat = (self: t<'a>, ~labels: 'a, ~value) => | ||
| self | ||
| ->makeLabels(~labels) | ||
| ->PromClient.Gauge.setFloat(value) | ||
| let handleFloat = ({metric, labelSchema}: t<'a>, ~labels: 'a, ~value) => | ||
| metric | ||
| ->M.labels(labels->S.serializeOrRaiseWith(labelSchema)) | ||
| ->M.handleFloat(value) | ||
|
|
||
| let setInt = (self: t<'a>, ~labels: 'a, ~value) => | ||
| self | ||
| ->makeLabels(~labels) | ||
| ->PromClient.Gauge.set(value) | ||
| let handleInt = ({metric, labelSchema}: t<'a>, ~labels: 'a, ~value) => | ||
| metric | ||
| ->M.labels(labels->S.serializeOrRaiseWith(labelSchema)) | ||
| ->M.handleInt(value) | ||
| } | ||
|
|
||
| module SafeCounter = MakeSafePromMetric({ | ||
| type t = PromClient.Counter.counter | ||
| let make = PromClient.Counter.makeCounter | ||
| let labels = PromClient.Counter.labels | ||
| let handleInt = PromClient.Counter.incMany | ||
| let handleFloat = PromClient.Counter.incMany->Utils.magic | ||
| }) | ||
|
|
||
| module SafeGauge = MakeSafePromMetric({ | ||
| type t = PromClient.Gauge.gauge | ||
| let make = PromClient.Gauge.makeGauge | ||
| let labels = PromClient.Gauge.labels | ||
| let handleInt = PromClient.Gauge.set | ||
| let handleFloat = PromClient.Gauge.setFloat | ||
| }) |
Collaborator
Author
There was a problem hiding this comment.
TBH this refactor was not necessary because I didn't end up using the safe counter anyways
JonoPrest
commented
Dec 11, 2024
| ->PromClient.Gauge.setFloat(value) | ||
| let handleFloat = ({metric, labelSchema}: t<'a>, ~labels: 'a, ~value) => | ||
| metric | ||
| ->M.labels(labels->S.serializeOrRaiseWith(labelSchema)) |
Collaborator
Author
There was a problem hiding this comment.
But I kept it here because it actually runs the serializer on the labels schema
JonoPrest
commented
Dec 11, 2024
Comment on lines
+97
to
+100
| if metricNames->Utils.Set.has(name) { | ||
| Js.Exn.raiseError("Duplicate prometheus metric name: " ++ name) | ||
| } else { | ||
| metricNames->Utils.Set.add(name)->ignore |
Collaborator
Author
There was a problem hiding this comment.
And has a check that you don't register the same name multiple times
DZakh
approved these changes
Dec 11, 2024
JonoPrest
enabled auto-merge (rebase)
December 11, 2024 15:10
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.