Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
chore(redis): add redis connection and error metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Sep 9, 2024
1 parent 844de23 commit edf25d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/cache/redis-kv-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { RedisClientType, commandOptions, createClient } from 'redis';
import winston from 'winston';

import * as config from '../config.js';
import * as metrics from '../metrics.js';
import { KVBufferStore } from '../types.js';

export class RedisKvStore implements KVBufferStore {
Expand All @@ -45,14 +46,14 @@ export class RedisKvStore implements KVBufferStore {
message: error.message,
stack: error.stack,
});
// TODO: add prometheus metric for redis error
metrics.redisErrors.inc({ error: error.message });
});
this.client.connect().catch((error: any) => {
this.log.error(`Redis connection error`, {
message: error.message,
stack: error.stack,
});
// TODO: add prometheus metric for redis connection error
metrics.redisConnectionError.inc();
});
}

Expand Down
13 changes: 13 additions & 0 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as promClient from 'prom-client';

export const metrics = new promClient.Registry();

// ARNS cache metrics
export const arnsCacheHit = new promClient.Counter({
name: 'arns_cache_hit',
help: 'Number of times the ARNS cache was hit',
Expand All @@ -30,3 +31,15 @@ export const arnsCacheMiss = new promClient.Counter({
help: 'Number of times the ARNS cache was missed',
labelNames: ['cache_type'],
});

// Redis metrics
export const redisConnectionError = new promClient.Gauge({
name: 'redis_connection_error',
help: 'Redis connection error',
});

export const redisErrors = new promClient.Counter({
name: 'redis_errors',
help: 'Redis errors',
labelNames: ['error'],
});

0 comments on commit edf25d6

Please sign in to comment.