Skip to content

Commit 2316bdd

Browse files
author
decobot
committed
feat(cache): add cache_error metric for Redis operation failures
1 parent 6ab0762 commit 2316bdd

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

runtime/caches/redis.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@ import {
55
NOT_IMPLEMENTED,
66
withCacheNamespace,
77
} from "./utils.ts";
8+
import { ValueType } from "../../deps.ts";
9+
import { meter } from "../../observability/otel/metrics.ts";
810
import { Redis } from "npm:ioredis@^5.10.1";
911

12+
const cacheError = meter.createCounter("cache_error", {
13+
description: "Number of Redis cache operation errors",
14+
unit: "1",
15+
valueType: ValueType.INT,
16+
});
17+
1018
const CONNECTION_TIMEOUT = parseInt(
1119
Deno.env.get("LOADER_CACHE_REDIS_CONNECTION_TIMEOUT_MS") || "2000",
1220
);
@@ -107,7 +115,10 @@ export function create(redis: RedisConnection | null, namespace: string) {
107115
COMMAND_TIMEOUT,
108116
)
109117
)
110-
.catch(() => 0);
118+
.catch(() => {
119+
cacheError.add(1, { engine: "REDIS", operation: "delete" });
120+
return 0;
121+
});
111122

112123
return result > 0;
113124
},
@@ -131,7 +142,10 @@ export function create(redis: RedisConnection | null, namespace: string) {
131142

132143
return deserialize(result);
133144
})
134-
.catch(() => undefined);
145+
.catch(() => {
146+
cacheError.add(1, { engine: "REDIS", operation: "match" });
147+
return undefined;
148+
});
135149

136150
return result;
137151
},
@@ -155,7 +169,9 @@ export function create(redis: RedisConnection | null, namespace: string) {
155169
COMMAND_TIMEOUT,
156170
)
157171
)
158-
.catch(() => {});
172+
.catch(() => {
173+
cacheError.add(1, { engine: "REDIS", operation: "put" });
174+
});
159175
},
160176
};
161177
}

0 commit comments

Comments
 (0)