Skip to content

Commit 583538d

Browse files
sonus21Admin
andauthored
add metrix prefix: #271 (#272)
Co-authored-by: Admin <example@example.com>
1 parent 030c17e commit 583538d

File tree

4 files changed

+31
-23
lines changed

4 files changed

+31
-23
lines changed

rqueue-core/src/main/java/com/github/sonus21/rqueue/config/MetricsProperties.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019-2023 Sonu Kumar
2+
* Copyright (c) 2019-2025 Sonu Kumar
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* You may not use this file except in compliance with the License.
@@ -18,11 +18,14 @@
1818

1919
import io.micrometer.core.instrument.Tag;
2020
import io.micrometer.core.instrument.Tags;
21+
2122
import java.util.LinkedHashMap;
2223
import java.util.Map;
2324
import java.util.Map.Entry;
25+
2426
import lombok.Getter;
2527
import lombok.Setter;
28+
import org.apache.commons.lang3.StringUtils;
2629

2730
/**
2831
* RqueueMetrics provides all possible configurations available in Rqueue library for metrics.
@@ -46,6 +49,11 @@ public abstract class MetricsProperties {
4649

4750
private Tags metricTags = Tags.empty();
4851

52+
/*
53+
* Prefix to be used while publishing metrics.
54+
*/
55+
private String prefix = "";
56+
4957
/**
5058
* Get Tags object that can be used in metric. Tags can be either configured manually or using
5159
* properties or XML file.
@@ -74,6 +82,13 @@ public boolean countFailure() {
7482
return count.isFailure();
7583
}
7684

85+
public String getMetricName(String name) {
86+
if (StringUtils.isEmpty(prefix)) {
87+
return name;
88+
}
89+
return prefix + name;
90+
}
91+
7792
@Getter
7893
@Setter
7994
public static class Count {

rqueue-core/src/main/java/com/github/sonus21/rqueue/metrics/QueueCounter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019-2023 Sonu Kumar
2+
* Copyright (c) 2019-2025 Sonu Kumar
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* You may not use this file except in compliance with the License.
@@ -60,15 +60,15 @@ void registerQueue(
6060
QueueDetail queueDetail) {
6161
if (metricsProperties.countFailure()) {
6262
Counter.Builder builder =
63-
Counter.builder(FAILURE_COUNT)
63+
Counter.builder(metricsProperties.getMetricName(FAILURE_COUNT))
6464
.tags(queueTags.and(QUEUE_KEY, queueDetail.getQueueName()))
6565
.description("Failure count");
6666
Counter counter = builder.register(registry);
6767
queueNameToFailureCounter.put(queueDetail.getName(), counter);
6868
}
6969
if (metricsProperties.countExecution()) {
7070
Counter.Builder builder =
71-
Counter.builder(EXECUTION_COUNT)
71+
Counter.builder(metricsProperties.getMetricName(EXECUTION_COUNT))
7272
.tags(queueTags.and(QUEUE_KEY, queueDetail.getQueueName()))
7373
.description("Task execution count");
7474
Counter counter = builder.register(registry);

rqueue-core/src/main/java/com/github/sonus21/rqueue/metrics/RqueueMetrics.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,32 +67,25 @@ private long size(String name, boolean isZset) {
6767

6868
private void monitor() {
6969
for (QueueDetail queueDetail : EndpointRegistry.getActiveQueueDetails()) {
70-
Tags queueTags =
71-
Tags.concat(metricsProperties.getMetricTags(), "queue", queueDetail.getName());
72-
Gauge.builder(QUEUE_SIZE, queueDetail, c -> size(queueDetail.getQueueName(), false))
70+
Tags queueTags = Tags.concat(metricsProperties.getMetricTags(), "queue",
71+
queueDetail.getName());
72+
Gauge.builder(metricsProperties.getMetricName(QUEUE_SIZE), queueDetail,
73+
c -> size(queueDetail.getQueueName(), false))
7374
.tags(queueTags.and(QUEUE_KEY, queueDetail.getQueueName()))
74-
.description("The number of entries in this queue")
75-
.register(meterRegistry);
76-
Gauge.builder(
77-
PROCESSING_QUEUE_SIZE,
78-
queueDetail,
75+
.description("The number of entries in this queue").register(meterRegistry);
76+
Gauge.builder(metricsProperties.getMetricName(PROCESSING_QUEUE_SIZE), queueDetail,
7977
c -> size(queueDetail.getProcessingQueueName(), true))
8078
.tags(queueTags.and(QUEUE_KEY, queueDetail.getProcessingQueueName()))
81-
.description("The number of entries in the processing queue")
82-
.register(meterRegistry);
83-
Gauge.builder(
84-
SCHEDULED_QUEUE_SIZE,
85-
queueDetail,
79+
.description("The number of entries in the processing queue").register(meterRegistry);
80+
Gauge.builder(metricsProperties.getMetricName(SCHEDULED_QUEUE_SIZE), queueDetail,
8681
c -> size(queueDetail.getScheduledQueueName(), true))
8782
.tags(queueTags.and(QUEUE_KEY, queueDetail.getScheduledQueueName()))
8883
.description("The number of entries waiting in the scheduled queue")
8984
.register(meterRegistry);
9085
if (queueDetail.isDlqSet()) {
91-
Builder<QueueDetail> builder =
92-
Gauge.builder(
93-
DEAD_LETTER_QUEUE_SIZE,
94-
queueDetail,
95-
c -> size(queueDetail.getDeadLetterQueueName(), false));
86+
Builder<QueueDetail> builder = Gauge.builder(
87+
metricsProperties.getMetricName(DEAD_LETTER_QUEUE_SIZE), queueDetail,
88+
c -> size(queueDetail.getDeadLetterQueueName(), false));
9689
builder.tags(queueTags);
9790
builder.description("The number of entries in the dead letter queue");
9891
builder.register(meterRegistry);

rqueue-spring-boot-reactive-example/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
id "war"
55
}
66
dependencies {
7-
implementation project(":rqueue-spring-boot-starter")
7+
implementation "com.github.sonus21:rqueue-spring-boot-starter:3.3.0-RELEASE"
88
implementation "org.springframework.boot:spring-boot-starter-data-redis-reactive"
99
implementation "org.springframework.boot:spring-boot-starter-webflux"
1010
implementation "io.lettuce:lettuce-core"

0 commit comments

Comments
 (0)