Skip to content

Commit

Permalink
chore: instrument the cache engine (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e authored Mar 25, 2024
1 parent 4b69310 commit 61a39b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/lib/cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IStorage } from './storage/types';
import { cacheHitCount } from './metrics';

export default class Cache {
id: string;
Expand All @@ -17,8 +18,12 @@ export default class Cache {
return '';
}

getCache() {
return this.storage.get(this.filename);
async getCache() {
const cache = await this.storage.get(this.filename);

cacheHitCount.inc({ status: !cache ? 'MISS' : 'HIT', type: this.constructor.name });

return cache;
}

async isCacheable() {
Expand Down
6 changes: 6 additions & 0 deletions src/lib/metrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ try {
}
}

export const cacheHitCount = new client.Counter({
name: 'cache_hit_count',
help: 'Number of hit/miss of the cache engine',
labelNames: ['status', 'type']
});

const providersResponseCode = new client.Gauge({
name: 'provider_response_code',
help: 'Response code of each provider request',
Expand Down

0 comments on commit 61a39b5

Please sign in to comment.