-
Notifications
You must be signed in to change notification settings - Fork 612
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISPN-15029 Create metrics for latency between nodes
Other side changes included in this PR are * Publish percentiles for histograms * Added remaining Micrometer meters (Counter, FunctionTimer, DistributionSummary) * Extract logic from MetricsCollector to a new class MetricsRegistry
- Loading branch information
Showing
48 changed files
with
2,007 additions
and
598 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
commons/all/src/main/java/org/infinispan/commons/stat/BaseMetricInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.infinispan.commons.stat; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Base implementation of {@link MetricInfo} with all the required information. | ||
* | ||
* @since 15.0 | ||
*/ | ||
abstract class BaseMetricInfo implements MetricInfo { | ||
|
||
private final String name; | ||
private final String description; | ||
private final Map<String, String> map; | ||
|
||
BaseMetricInfo(String name, String description, Map<String, String> map) { | ||
this.name = Objects.requireNonNull(name); | ||
this.description = Objects.requireNonNull(description); | ||
this.map = map == null || map.isEmpty() ? Collections.emptyMap() : Map.copyOf(map); | ||
} | ||
|
||
@Override | ||
public final String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public final String getDescription() { | ||
return description; | ||
} | ||
|
||
@Override | ||
public final Map<String, String> getTags() { | ||
return map; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + "{" + | ||
"name='" + getName() + '\'' + | ||
", description='" + getDescription() + '\'' + | ||
", tags=" + getTags() + | ||
'}'; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
commons/all/src/main/java/org/infinispan/commons/stat/BaseSetterMetricInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.infinispan.commons.stat; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.function.BiConsumer; | ||
|
||
/** | ||
* Extends {@link BaseMetricInfo} with a consumer, usually a target instance and the tracker to set. | ||
* | ||
* @since 15.0 | ||
*/ | ||
abstract class BaseSetterMetricInfo<O, M> extends BaseMetricInfo { | ||
|
||
private final BiConsumer<O, M> setter; | ||
|
||
BaseSetterMetricInfo(String name, String description, Map<String, String> map, BiConsumer<O, M> setter) { | ||
super(name, description, map); | ||
this.setter = Objects.requireNonNull(setter); | ||
} | ||
|
||
public final void accept(O targetInstance, M metricTracker) { | ||
setter.accept(targetInstance, metricTracker); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
commons/all/src/main/java/org/infinispan/commons/stat/CounterMetricInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.infinispan.commons.stat; | ||
|
||
import java.util.Map; | ||
import java.util.function.BiConsumer; | ||
|
||
/** | ||
* Represents a counter. It sets {@link CounterTracker} into the target instance. | ||
* <p> | ||
* A counter tracks a monotonically increasing values and never resets to a lesser value. | ||
* | ||
* @since 15.0 | ||
*/ | ||
public final class CounterMetricInfo<T> extends BaseSetterMetricInfo<T, CounterTracker> { | ||
|
||
public CounterMetricInfo(String name, String description, Map<String, String> map, BiConsumer<T, CounterTracker> setter) { | ||
super(name, description, map, setter); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
commons/all/src/main/java/org/infinispan/commons/stat/CounterTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.infinispan.commons.stat; | ||
|
||
/** | ||
* Tracks a monotonically increasing values. | ||
* <p> | ||
* The counters may never be reset to a lesser value. | ||
*/ | ||
public interface CounterTracker { | ||
|
||
/** | ||
* Update the counter by one. | ||
*/ | ||
void increment(); | ||
|
||
/** | ||
* Update the counter by {@code amount}. | ||
* | ||
* @param amount The amount to add to the counter. | ||
*/ | ||
void increment(double amount); | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
commons/all/src/main/java/org/infinispan/commons/stat/DistributionSummaryMetricInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.infinispan.commons.stat; | ||
|
||
import java.util.Map; | ||
import java.util.function.BiConsumer; | ||
|
||
/** | ||
* Represents a distribution summary (histogram). It sets {@link DistributionSummaryTracker} into the target instance. | ||
* <p> | ||
* A distribution summary tracks the sample distribution of events. | ||
* | ||
* @since 15.0 | ||
*/ | ||
public final class DistributionSummaryMetricInfo<T> extends BaseSetterMetricInfo<T, DistributionSummaryTracker> { | ||
|
||
public DistributionSummaryMetricInfo(String name, String description, Map<String, String> map, BiConsumer<T, DistributionSummaryTracker> setter) { | ||
super(name, description, map, setter); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
commons/all/src/main/java/org/infinispan/commons/stat/DistributionSummaryTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.infinispan.commons.stat; | ||
|
||
/** | ||
* Track the sample distribution of events. | ||
*/ | ||
public interface DistributionSummaryTracker { | ||
|
||
/** | ||
* Updates the statistics kept by the summary with the specified amount. | ||
* | ||
* @param amount Amount for an event being tracked. | ||
*/ | ||
void record(double amount); | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
commons/all/src/main/java/org/infinispan/commons/stat/FunctionTimerMetricInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.infinispan.commons.stat; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.BiConsumer; | ||
|
||
/** | ||
* Represents a duration metric. It sets {@link TimerTracker} into the target instance. | ||
* <p> | ||
* A distribution summary tracks a duration. | ||
* | ||
* @since 15.0 | ||
*/ | ||
public final class FunctionTimerMetricInfo<T> extends BaseSetterMetricInfo<T, TimerTracker> { | ||
|
||
private final TimeUnit timeUnit; | ||
|
||
public FunctionTimerMetricInfo(String name, String description, Map<String, String> map, BiConsumer<T, TimerTracker> setter, TimeUnit timeUnit) { | ||
super(name, description, map, setter); | ||
this.timeUnit = Objects.requireNonNull(timeUnit); | ||
} | ||
|
||
/** | ||
* @return The {@link TimeUnit} of the time tracked by the event. | ||
*/ | ||
public TimeUnit getTimeUnit() { | ||
return timeUnit; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "FunctionTimerMetricInfo{" + | ||
"name='" + getName() + '\'' + | ||
", timeUnit=" + timeUnit + | ||
", description='" + getDescription() + '\'' + | ||
", tags=" + getTags() + | ||
'}'; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
commons/all/src/main/java/org/infinispan/commons/stat/GaugeMetricInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.infinispan.commons.stat; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Represents a gauge metric. | ||
* <p> | ||
* A gauge tracks a specific value, like a queue size. | ||
* | ||
* @since 15.0 | ||
*/ | ||
public final class GaugeMetricInfo<T> extends BaseMetricInfo { | ||
|
||
private final Function<T, Number> function; | ||
|
||
public GaugeMetricInfo(String name, String description, Map<String, String> map, Function<T, Number> function) { | ||
super(name, description, map); | ||
this.function = Objects.requireNonNull(function); | ||
} | ||
|
||
/** | ||
* @return The {@link Supplier} to be invoked to fetch the value from {@code instance}. | ||
*/ | ||
public Supplier<Number> getGauge(T instance) { | ||
return () -> function.apply(instance); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
commons/all/src/main/java/org/infinispan/commons/stat/MetricInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.infinispan.commons.stat; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
/** | ||
* Class that represent the information about a metrics. | ||
* <p> | ||
* Includes the metrics's name, description and tags. Subclasses can add more information about it. | ||
* | ||
* @since 15.0 | ||
*/ | ||
public interface MetricInfo { | ||
|
||
/** | ||
* @return The metrics name. | ||
*/ | ||
String getName(); | ||
|
||
/** | ||
* @return The metrics description/help message. | ||
*/ | ||
String getDescription(); | ||
|
||
/** | ||
* @return The tags to be used. Must be non-null. | ||
*/ | ||
default Map<String, String> getTags() { | ||
return Collections.emptyMap(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
commons/all/src/main/java/org/infinispan/commons/stat/TimeGaugeMetricInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.infinispan.commons.stat; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Same as {@link GaugeMetricInfo} but the tracked value is a time or duration. | ||
* | ||
* @since 15.0 | ||
*/ | ||
public final class TimeGaugeMetricInfo<T> extends BaseMetricInfo { | ||
|
||
private final Function<T, Number> function; | ||
private final TimeUnit timeUnit; | ||
|
||
public TimeGaugeMetricInfo(String name, String description, Map<String, String> map, Function<T, Number> function, TimeUnit timeUnit) { | ||
super(name, description, map); | ||
this.function = Objects.requireNonNull(function); | ||
this.timeUnit = Objects.requireNonNull(timeUnit); | ||
} | ||
|
||
/** | ||
* @return The {@link Supplier} to invoke to return the current value of the metric. | ||
*/ | ||
public Supplier<Number> getGauge(T instance) { | ||
return () -> function.apply(instance); | ||
} | ||
|
||
/** | ||
* @return The {@link TimeUnit} of the tracked value. | ||
*/ | ||
public TimeUnit getTimeUnit() { | ||
return timeUnit; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
commons/all/src/main/java/org/infinispan/commons/stat/TimerMetricInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.infinispan.commons.stat; | ||
|
||
import java.util.Map; | ||
import java.util.function.BiConsumer; | ||
|
||
/** | ||
* Represents a duration event (histogram). It sets {@link TimerTracker} into the target instance. | ||
* | ||
* @since 15.0 | ||
*/ | ||
public final class TimerMetricInfo<T> extends BaseSetterMetricInfo<T, TimerTracker> { | ||
|
||
public TimerMetricInfo(String name, String description, Map<String, String> map, BiConsumer<T, TimerTracker> setter) { | ||
super(name, description, map, setter); | ||
} | ||
} |
Oops, something went wrong.