Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sliding time window array reservoir #376

Merged
merged 2 commits into from
Sep 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion micro-event-metrics/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,14 @@ Number of active jobs to cache in memory

```text
com.aol.micro.server.event.metrics.MetricsCatcher.requests-started
com.aol.micro.server.event.metrics.MetricsCatcher.requests-started-interval-count
com.aol.micro.server.event.metrics.MetricsCatcher.request-start-<TYPE>
com.aol.micro.server.event.metrics.MetricsCatcher.request-start-<TYPE>-interval-count
com.aol.micro.server.event.metrics.MetricsCatcher.requests-completed
com.aol.micro.server.event.metrics.MetricsCatcher.requests-completed-interval-type
com.aol.micro.server.event.metrics.MetricsCatcher.request-completed-<TYPE>
com.aol.micro.server.event.metrics.MetricsCatcher.request-completed-<TYPE>-interval-count

```

#### Timers :
Expand Down Expand Up @@ -172,6 +177,8 @@ event.metrics.capture.jobs.by.type=true # jobsByType,
event.metrics.capture.number.of.queries=10000 # numQueries,
event.metrics.capture.queries.minutes=180 # holdQueriesForMinutes,
event.metrics.capture.number.of.jobs=10000 # numJobs,
event.metrics.capture.jobs.minutes=180
event.metrics.capture.jobs.minutes=180,
event.metrics.capture.timer.interval.seconds=10
event.metrics.capture.jobs.prefix=null
```

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Configuration {

private final int numJobs;
private final int holdJobsForMinutes;
private final int timerIntervalSeconds;
private final String prefix;

@Autowired
Expand All @@ -35,6 +36,7 @@ public Configuration(@Value("${event.metrics.capture.errors.by.type:true}") bool
@Value("${event.metrics.capture.queries.minutes:180}") int holdQueriesForMinutes,
@Value("${event.metrics.capture.number.of.jobs:10000}") int numJobs,
@Value("${event.metrics.capture.jobs.minutes:180}") int holdJobsForMinutes,
@Value("${event.metrics.capture.timer.interval.seconds:10}") int timerIntervalSeconds,
@Value("${event.metrics.capture.jobs.prefix:#{null}}") String prefix) {
super();
this.errorsByType = errorsByType;
Expand All @@ -45,6 +47,7 @@ public Configuration(@Value("${event.metrics.capture.errors.by.type:true}") bool
this.holdQueriesForMinutes = holdQueriesForMinutes;
this.numJobs = numJobs;
this.holdJobsForMinutes = holdJobsForMinutes;
this.timerIntervalSeconds = timerIntervalSeconds;
this.prefix = Optional.ofNullable(prefix)
.orElseGet(() -> MetricsCatcher.class.getTypeName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.aol.micro.server.events.GenericEvent;
import com.aol.micro.server.spring.metrics.InstantGauge;
import com.codahale.metrics.SlidingTimeWindowArrayReservoir;
import com.codahale.metrics.Timer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -20,6 +22,7 @@
import com.google.common.eventbus.Subscribe;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

@Component
public class MetricsCatcher<T> {
Expand Down Expand Up @@ -59,8 +62,7 @@ public void requestStart(AddQuery<T> data) {
registry.meter(queryStartName(rd) + "-meter")
.mark();

queries.start(rd.getCorrelationId(), registry.timer(queryEndName(rd) + "-timer")
.time());
queries.start(rd.getCorrelationId(), timer(queryEndName(rd) + "-timer").time());
registry.counter(prefix + ".requests-active-" + rd.getType() + "-count")
.inc();
((InstantGauge) registry.gauge(prefix + ".requests-started-" + rd.getType() + "-interval-count",
Expand Down Expand Up @@ -135,8 +137,7 @@ public void jobStarted(JobStartEvent data) {
registry.meter(prefix + ".job-meter-" + data.getType())
.mark();

jobs.start(data.getCorrelationId(), registry.timer(prefix + ".job-timer-" + data.getType())
.time());
jobs.start(data.getCorrelationId(), timer(prefix + ".job-timer-" + data.getType()).time());
registry.counter(prefix + ".jobs-active-" + data.getType() + "-count")
.inc();
}
Expand Down Expand Up @@ -223,4 +224,8 @@ public void genericEvent(GenericEvent event) {
private String name(ErrorCode c) {
return prefix + ".error-" + c.getSeverity() + "-" + c.getErrorId();
}

private Timer timer (String name) {
return registry.timer(name, () -> new Timer(new SlidingTimeWindowArrayReservoir(configuration.getTimerIntervalSeconds(), TimeUnit.SECONDS)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void setup() {
registry = new MetricRegistry();
bus = new EventBus();
config = new Configuration(
false, false, false, false, 5, 6, 7, 8, "bob");
false, false, false, false, 5, 6, 7, 8, 10, "bob");
catcher = new MetricsCatcher<>(
registry, bus, config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void setup() {
registry = new MetricRegistry();
bus = new EventBus();
config = new Configuration(
true, true, true, true, 5, 6, 7, 8, "bob");
true, true, true, true, 5, 6, 7, 8, 10,"bob");
catcher = new MetricsCatcher<>(
registry, bus, config);
}
Expand Down