Skip to content

Commit

Permalink
Add retry count metric (#178)
Browse files Browse the repository at this point in the history
* Add retry count metric

* Rename metric

* Update metric before sending request
  • Loading branch information
mosmeh authored Dec 16, 2022
1 parent c9d786b commit f7febfe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.linecorp.decaton.processor.metrics.internal.AvailableTags;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.DistributionSummary;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.Meter.Id;
Expand Down Expand Up @@ -261,6 +262,12 @@ public class RetryMetrics extends AbstractMetrics {
.description("The number of tasks failed to enqueue in retry topic")
.tags(availableTags.subscriptionScope())
.register(registry));

public final DistributionSummary retryTaskRetries =
meter(() -> DistributionSummary.builder("retry.task.retries")
.description("The number of times a task was retried")
.tags(availableTags.subscriptionScope())
.register(registry));
}

public static Metrics withTags(String... keyValues) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,19 @@ public DecatonTaskRetryQueueingProcessor(SubscriptionScope scope, DecatonTaskPro
public void process(ProcessingContext<byte[]> context, byte[] serializedTask)
throws InterruptedException {
TaskMetadata originalMeta = context.metadata();
long nextRetryCount = originalMeta.retryCount() + 1;
long nextTryTimeMillis = System.currentTimeMillis() + backoff.toMillis();
TaskMetadataProto taskMetadata =
TaskMetadataProto.newBuilder(originalMeta.toProto())
.setRetryCount(originalMeta.retryCount() + 1)
.setRetryCount(nextRetryCount)
.setScheduledTimeMillis(nextTryTimeMillis)
.build();
DecatonTaskRequest request =
DecatonTaskRequest.newBuilder()
.setMetadata(taskMetadata)
.setSerializedTask(ByteString.copyFrom(serializedTask))
.build();
metrics.retryTaskRetries.record(nextRetryCount);

CompletableFuture<PutTaskResult> future = producer.sendRequest(context.key(), request);
future.whenComplete((r, e) -> {
Expand Down

0 comments on commit f7febfe

Please sign in to comment.