Skip to content

Commit

Permalink
Add time histogram for getting OBO tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
cskrov committed Jul 10, 2024
1 parent 959c541 commit 7cf503f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 8 additions & 1 deletion server/src/auth/cache-gauge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { proxyRegister } from '@app/prometheus/types';
import { Counter, Gauge } from 'prom-client';
import { Counter, Gauge, Histogram } from 'prom-client';

const labelNames = ['hit'] as const;

Expand All @@ -15,3 +15,10 @@ export const cacheSizeGauge = new Gauge({
help: 'Number of OBO tokens in the cache.',
registers: [proxyRegister],
});

export const oboRequestDuration = new Histogram({
name: 'obo_request_duration',
help: 'Duration of OBO token requests in milliseconds.',
buckets: [0, 10, 100, 200, 300, 400, 500, 600, 800, 900, 1_000],
registers: [proxyRegister],
});
6 changes: 5 additions & 1 deletion server/src/plugins/obo-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getLogger } from '@app/logger';
import { getOnBehalfOfAccessToken } from '@app/auth/on-behalf-of';
import fastifyPlugin from 'fastify-plugin';
import { isDeployed } from '@app/config/env';
import { oboRequestDuration } from '@app/auth/cache-gauge';

const log = getLogger('obo-token-plugin');

Expand Down Expand Up @@ -75,7 +76,10 @@ const getOboToken: GetOboToken = async (appName, req, reply) => {
trace_id,
span_id,
);
reply.addServerTiming('obo_token_middleware', getDuration(oboStart), 'OBO Token Middleware');

const duration = getDuration(oboStart);
oboRequestDuration.observe(duration);
reply.addServerTiming('obo_token_middleware', duration, 'OBO Token Middleware');

return oboAccessToken;
} catch (error) {
Expand Down

0 comments on commit 7cf503f

Please sign in to comment.