@koala42/redis-highway 0.2.10 → 0.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/keys.d.ts CHANGED
@@ -14,8 +14,9 @@ export declare class KeyManager {
14
14
  getDlqStreamKey(): string;
15
15
  /**
16
16
  * Metrics for storing throughput
17
+ * @param current - if true, takes throughput in the running minute, if false, takes -1 minute for closed throughput bucket
17
18
  */
18
- getThroughputKey(groupName: string, timestamp: number): string;
19
+ getThroughputKey(groupName: string, timestamp: number, current?: boolean): string;
19
20
  /**
20
21
  * Metrics - retries key
21
22
  */
package/dist/keys.js CHANGED
@@ -24,10 +24,11 @@ class KeyManager {
24
24
  }
25
25
  /**
26
26
  * Metrics for storing throughput
27
+ * @param current - if true, takes throughput in the running minute, if false, takes -1 minute for closed throughput bucket
27
28
  */
28
- getThroughputKey(groupName, timestamp) {
29
+ getThroughputKey(groupName, timestamp, current = true) {
29
30
  const minute = Math.floor(timestamp / 60000) * 60000;
30
- return `metrics:throughput:${this.streamName}:${groupName}:${minute}`;
31
+ return `metrics:throughput:${this.streamName}:${groupName}:${current ? minute : minute - 60000}`;
31
32
  }
32
33
  /**
33
34
  * Metrics - retries key
package/dist/metrics.d.ts CHANGED
@@ -13,12 +13,12 @@ export declare class Metrics {
13
13
  * Get current metrics for the queue
14
14
  * @param groupNames - List of consumer groups to fetch throughput for
15
15
  */
16
- getMetrics(groupNames: string[]): Promise<QueueMetrics>;
16
+ getMetrics(groupNames: string[], current?: boolean): Promise<QueueMetrics>;
17
17
  /**
18
18
  * Get prometheus compatible metrics
19
19
  * @param groupNames target group names for throughput metrics
20
20
  * @param prefix - export prefix
21
21
  * @returns metrics as string
22
22
  */
23
- getPrometheusMetrics(groupNames: string[], prefix?: string): Promise<string>;
23
+ getPrometheusMetrics(groupNames: string[], prefix?: string, current?: boolean): Promise<string>;
24
24
  }
package/dist/metrics.js CHANGED
@@ -12,13 +12,13 @@ class Metrics {
12
12
  * Get current metrics for the queue
13
13
  * @param groupNames - List of consumer groups to fetch throughput for
14
14
  */
15
- async getMetrics(groupNames) {
15
+ async getMetrics(groupNames, current = false) {
16
16
  const pipeline = this.redis.pipeline();
17
17
  pipeline.xlen(this.streamName);
18
18
  pipeline.xlen(this.keys.getDlqStreamKey());
19
19
  const timestamp = Date.now();
20
20
  groupNames.forEach(group => {
21
- pipeline.get(this.keys.getThroughputKey(group, timestamp));
21
+ pipeline.get(this.keys.getThroughputKey(group, timestamp, current));
22
22
  });
23
23
  const results = await pipeline.exec();
24
24
  if (!results) {
@@ -49,13 +49,13 @@ class Metrics {
49
49
  * @param prefix - export prefix
50
50
  * @returns metrics as string
51
51
  */
52
- async getPrometheusMetrics(groupNames, prefix = 'redis_highway_queue') {
52
+ async getPrometheusMetrics(groupNames, prefix = 'redis_highway_queue', current = false) {
53
53
  const pipeline = this.redis.pipeline();
54
54
  pipeline.xlen(this.streamName);
55
55
  pipeline.xlen(this.keys.getDlqStreamKey());
56
56
  const timestamp = Date.now();
57
57
  groupNames.forEach(group => {
58
- pipeline.get(this.keys.getThroughputKey(group, timestamp));
58
+ pipeline.get(this.keys.getThroughputKey(group, timestamp, current));
59
59
  pipeline.get(this.keys.getTotalKey(group));
60
60
  pipeline.get(this.keys.getRetriesKey(group, timestamp));
61
61
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koala42/redis-highway",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "description": "High performance redis queue",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -40,4 +40,4 @@
40
40
  "typescript": "^5.9.3",
41
41
  "vitest": "^4.0.16"
42
42
  }
43
- }
43
+ }