Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Prometheus metrics refactor #8484

Merged
merged 8 commits into from
Oct 22, 2024
Merged

Conversation

gastonfournier
Copy link
Contributor

Migrate some prometheus metrics to use the new and sequential metric updater

Copy link

vercel bot commented Oct 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 22, 2024 10:49am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Oct 22, 2024 10:49am

Copy link
Contributor

github-actions bot commented Oct 18, 2024

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

Comment on lines 40 to 60
private async fetch<T, L extends string>(
definition: GaugeDefinition<T, L>,
): Promise<MetricValue<L>[]> {
const result = await definition.query();
if (
result !== undefined &&
result !== null &&
(!Array.isArray(result) || result.length > 0)
) {
const resultArray = this.asArray(definition.map(result));
resultArray
.filter((r) => !Number.isInteger(r.value))
.forEach((r) => {
this.log.warn(
`Invalid value for ${definition.name}: ${r.value}. Value must be an integer.`,
);
});
return resultArray.filter((r) => Number.isInteger(r.value));
}
return [];
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Encapsulate transformation from the query result (which can either be a single result or an array), into an array of valid metrics for prometheus

@@ -14,7 +14,7 @@ type MapResult<R, L extends string> = (
type GaugeDefinition<T, L extends string> = {
name: string;
help: string;
labelNames: L[];
labelNames?: L[];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Support gauges without labels

Copy link
Member

@chriswk chriswk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@gastonfournier gastonfournier merged commit 15f55c7 into main Oct 22, 2024
11 checks passed
@gastonfournier gastonfournier deleted the prometheus-metrics-refactor branch October 22, 2024 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants