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

Add metric to track how many times is each key requested #24

Merged
merged 3 commits into from
Jun 24, 2024

Conversation

lbaquerofierro
Copy link
Contributor

No description provided.

src/index.ts Outdated Show resolved Hide resolved
@thibmeu thibmeu changed the title PXY-673: Add metric to track how many times is each key requested Add metric to track how many times is each key requested Jun 21, 2024
@fisherdarling
Copy link

I have a concern with cardinality here. We usually try not to add prometheus labels with unbounded cardinality, due to each unique label creating a unique prometheus timeseries. I guess the kids will be short-lived ~1 week, so this might be fine.

@thibmeu
Copy link
Contributor

thibmeu commented Jun 21, 2024

@fisherdarling cardinality of key_id is 256 (from 0 to 255). I agree this is large.
The number of values then depends on the prometheus server retention time, speed of the rotation, and numbers of keys to retain in parallel.
If rotation is once a day and retention of two weeks, the upperbound is 14 (for 14 days).

@thibmeu
Copy link
Contributor

thibmeu commented Jun 21, 2024

@lbaquerofierro I've posted a change proposal to your repo lbaquerofierro#1

It does not create an additional metric, and allows to set default labels.

@thibmeu thibmeu self-requested a review June 21, 2024 08:11
src/errors.ts Outdated
@@ -11,7 +11,7 @@ function shouldSendToSentry(error: Error): boolean {
export async function handleError(ctx: Context, error: Error) {
console.error(error.stack);

ctx.metrics.erroredRequestsTotal.inc({ env: ctx.env.ENVIRONMENT });
ctx.metrics.erroredRequestsTotal.inc({ env: ctx.env.ENVIRONMENT, servcice: ctx.env.SERVICE });
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ctx.metrics.erroredRequestsTotal.inc({ env: ctx.env.ENVIRONMENT, servcice: ctx.env.SERVICE });
ctx.metrics.erroredRequestsTotal.inc({ env: ctx.env.ENVIRONMENT, service: ctx.env.SERVICE });

src/index.ts Outdated
Comment on lines 82 to 89
ctx.metrics.signedTokenTotal.inc({ env: ctx.env.ENVIRONMENT, service: ctx.env.SERVICE });

const keyId = tokenRequest.truncatedTokenKeyId.toString();
ctx.metrics.keyRequestTotal.inc({
env: ctx.env.ENVIRONMENT,
service: ctx.env.SERVICE,
key_id: keyId,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

only use this metric

Suggested change
ctx.metrics.signedTokenTotal.inc({ env: ctx.env.ENVIRONMENT, service: ctx.env.SERVICE });
const keyId = tokenRequest.truncatedTokenKeyId.toString();
ctx.metrics.keyRequestTotal.inc({
env: ctx.env.ENVIRONMENT,
service: ctx.env.SERVICE,
key_id: keyId,
});
const keyId = keyId = tokenRequest.truncatedTokenKeyId.toString();
ctx.metrics.signedTokenTotal.inc({ env: ctx.env.ENVIRONMENT, service: ctx.env.SERVICE, key_id: keyId });

@fisherdarling
Copy link

@fisherdarling cardinality of key_id is 256 (from 0 to 255). I agree this is large. The number of values then depends on the prometheus server retention time, speed of the rotation, and numbers of keys to retain in parallel. If rotation is once a day and retention of two weeks, the upperbound is 14 (for 14 days).

Great! Thanks for walking through the true cardinality. 14 is perfectly fine.

Copy link
Contributor

@thibmeu thibmeu left a comment

Choose a reason for hiding this comment

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

change looks ok.
once you've addressed the nit, can you squash your changes, and rebase your branch on origin/main

package.json Outdated
@@ -40,7 +40,7 @@
"@typescript-eslint/parser": "6.21.0",
"commander": "12.1.0",
"dotenv": "16.4.0",
"esbuild": "0.19.12",
"esbuild": "^0.21.5",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: fix the version

@lbaquerofierro lbaquerofierro force-pushed the lina/add-metrics/PXY-673 branch 2 times, most recently from 968eecd to 59de7f2 Compare June 24, 2024 14:48
Copy link
Contributor

@thibmeu thibmeu left a comment

Choose a reason for hiding this comment

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

I proposed one additional commit lbaquerofierro#2 that you should be able to merge.
Once done, we can rebase and merge this branch

@thibmeu thibmeu merged commit 6b496e8 into cloudflare:main Jun 24, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants