Skip to content

Commit

Permalink
Add PARKED, INTERRUPTED and DELAYED to the Metric types #258
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcGiffing committed Mar 12, 2024
1 parent 7ce02df commit 4543e20
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ This section is meant to help you migrate your application to new version of thi
==== Spring Boot Starter Bucket4j 0.12

* Removed deprecated expression property
* three new metric counter are added per default (PARKED, INTERRUPTED and DELAYED)

==== Spring Boot Starter Bucket4j 0.9

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import java.util.List;

import io.github.bucket4j.BucketListener;
import lombok.Getter;

/**
* Marker Interface
*
*/
public class MetricBucketListener implements BucketListener {

private final String name;
@Getter
private final String name;
private final List<MetricTagResult> tags;
private final List<MetricHandler> metricHandlers;
private final List<MetricType> allowedTypes;
Expand All @@ -36,26 +38,26 @@ public void onRejected(long tokens) {
}
}

public String getName() {
return name;
}

@Override
public void onParked(long nanos) {
// TODO check if we should provide this information

if(allowedTypes.contains(MetricType.PARKED_COUNTER)) {
metricHandlers.forEach(metricHandler -> metricHandler.handle(MetricType.PARKED_COUNTER, name, 1, tags));
}
}

@Override
public void onInterrupted(InterruptedException e) {
// TODO check if we should provide this information
if(allowedTypes.contains(MetricType.INTERRUPTED_COUNTER)) {
metricHandlers.forEach(metricHandler -> metricHandler.handle(MetricType.INTERRUPTED_COUNTER, name, 1, tags));
}

}

@Override
public void onDelayed(long nanos) {
// TODO check if we should provide this information

if(allowedTypes.contains(MetricType.DELAYED_COUNTER)) {
metricHandlers.forEach(metricHandler -> metricHandler.handle(MetricType.DELAYED_COUNTER, name, 1, tags));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

public interface MetricHandler {

void handle(MetricType type, String name, long tokens, List<MetricTagResult> tags);
void handle(MetricType type, String name, long counterIncrement, List<MetricTagResult> tags);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
public enum MetricType {

CONSUMED_COUNTER,
REJECTED_COUNTER
REJECTED_COUNTER,
PARKED_COUNTER,
INTERRUPTED_COUNTER,
DELAYED_COUNTER
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class Bucket4jMetricHandler implements MetricHandler {

@Override
public void handle(MetricType type, String name, long tokens, List<MetricTagResult> tags) {
public void handle(MetricType type, String name, long counterIncrement, List<MetricTagResult> tags) {

List<String> extendedTags = new ArrayList<>();
extendedTags.add("name");
Expand All @@ -34,12 +34,27 @@ public void handle(MetricType type, String name, long tokens, List<MetricTagResu
case CONSUMED_COUNTER:
Metrics
.counter("bucket4j_summary_consumed", extendedTagsArray)
.increment(tokens);
.increment(counterIncrement);
break;
case REJECTED_COUNTER:
Metrics
.counter("bucket4j_summary_rejected", extendedTagsArray)
.increment(tokens);
.increment(counterIncrement);
break;
case PARKED_COUNTER:
Metrics
.counter("bucket4j_summary_parked", extendedTagsArray)
.increment(counterIncrement);
break;
case INTERRUPTED_COUNTER:
Metrics
.counter("bucket4j_summary_interrupted", extendedTagsArray)
.increment(counterIncrement);
break;
case DELAYED_COUNTER:
Metrics
.counter("bucket4j_summary_delayed", extendedTagsArray)
.increment(counterIncrement);
break;
default:
throw new IllegalStateException("Unsupported metric type: " + type);
Expand Down

0 comments on commit 4543e20

Please sign in to comment.