Skip to content

Commit

Permalink
changes requested by comment, batch two, tck
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-confino committed Apr 18, 2024
1 parent fc27902 commit 5f97f23
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
*/
public class CounterMetric {

private MetricRegistryProxy registry;
private MetricID metricId;
private long baseline;

Expand All @@ -43,7 +42,7 @@ public CounterMetric(MetricID metricId) {
* Get the counter value, or zero if the metric doesn't exist
* <p>
* This method will not create the metric if it does not exist.
*
*
* @param startTime
* a start time as a unix epoch, all metrics from before this time will be ignored
* @param endTime
Expand All @@ -65,7 +64,7 @@ public void baseline() {

/**
* Return the difference between the current value of the metric and the value when {@link #baseline} was called.
*
*
* @return the difference between the metric value and the baseline
*/
public long delta() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public class InMemoryMetricReader implements MetricReader {

private CollectionRegistration collectionRegistration;
boolean isShutdown = false;
private boolean isShutdown = false;

public static InMemoryMetricReader current() {
return CDI.current().select(InMemoryMetricReader.class).get();
Expand All @@ -60,8 +60,7 @@ public void register(CollectionRegistration registration) {

@Override
public CompletableResultCode forceFlush() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'forceFlush'");
return CompletableResultCode.ofSuccess();
}

@Override
Expand Down Expand Up @@ -107,7 +106,8 @@ public Optional<LongPointData> getGaugueMetricLatestValue(MetricID id) {
.allMatch(key -> point.getAttributes().asMap().containsKey(key)
&& id.attributes.asMap().get(key)
.equals(point.getAttributes().asMap().get(key))))
.sorted((pointOne, pointTwo) -> Long.compare(pointOne.getEpochNanos(), pointTwo.getEpochNanos()))
// feeding the points into Long.compare in reverse order will return the largest first.
.sorted((pointOne, pointTwo) -> Long.compare(pointTwo.getEpochNanos(), pointOne.getEpochNanos()))
.findFirst();

return gague;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

package org.eclipse.microprofile.fault.tolerance.tck.telemetryMetrics.util;

import java.util.Set;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.LongCounter;
Expand Down Expand Up @@ -49,44 +47,44 @@
* {@link BulkheadResult#ACCEPTED} and {@link BulkheadResult#REJECTED}.
*/
public enum MetricDefinition {
INVOCATIONS("ft.invocations.total", Set.of(LongCounter.class), InvocationResult.class, InvocationFallback.class),
RETRY_CALLS("ft.retry.calls.total", Set.of(LongCounter.class), RetryRetried.class, RetryResult.class),
RETRY_RETRIES("ft.retry.retries.total", Set.of(LongCounter.class)),
TIMEOUT_CALLS("ft.timeout.calls.total", Set.of(LongCounter.class), TimeoutTimedOut.class),
TIMEOUT_EXECUTION_DURATION("ft.timeout.executionDuration", Set.of(LongHistogram.class), "nanoseconds"),
CIRCUITBREAKER_CALLS("ft.circuitbreaker.calls.total", Set.of(LongCounter.class), CircuitBreakerResult.class),
CIRCUITBREAKER_STATE("ft.circuitbreaker.state.total", Set.of(ObservableLongGauge.class), "nanoseconds",
INVOCATIONS("ft.invocations.total", LongCounter.class, InvocationResult.class, InvocationFallback.class),
RETRY_CALLS("ft.retry.calls.total", LongCounter.class, RetryRetried.class, RetryResult.class),
RETRY_RETRIES("ft.retry.retries.total", LongCounter.class),
TIMEOUT_CALLS("ft.timeout.calls.total", LongCounter.class, TimeoutTimedOut.class),
TIMEOUT_EXECUTION_DURATION("ft.timeout.executionDuration", LongHistogram.class, "nanoseconds"),
CIRCUITBREAKER_CALLS("ft.circuitbreaker.calls.total", LongCounter.class, CircuitBreakerResult.class),
CIRCUITBREAKER_STATE("ft.circuitbreaker.state.total", ObservableLongGauge.class, "nanoseconds",
CircuitBreakerState.class),
CIRCUITBREAKER_OPENED("ft.circuitbreaker.opened.total", Set.of(LongCounter.class)),
BULKHEAD_CALLS("ft.bulkhead.calls.total", Set.of(LongCounter.class), BulkheadResult.class),
BULKHEAD_EXECUTIONS_RUNNING("ft.bulkhead.executionsRunning", Set.of(ObservableLongGauge.class)),
BULKHEAD_EXECUTIONS_WAITING("ft.bulkhead.executionsWaiting", Set.of(ObservableLongGauge.class)),
BULKHEAD_RUNNING_DURATION("ft.bulkhead.runningDuration", Set.of(LongHistogram.class), "nanoseconds"),
BULKHEAD_WAITING_DURATION("ft.bulkhead.waitingDuration", Set.of(LongHistogram.class), "nanoseconds");
CIRCUITBREAKER_OPENED("ft.circuitbreaker.opened.total", LongCounter.class),
BULKHEAD_CALLS("ft.bulkhead.calls.total", LongCounter.class, BulkheadResult.class),
BULKHEAD_EXECUTIONS_RUNNING("ft.bulkhead.executionsRunning", ObservableLongGauge.class),
BULKHEAD_EXECUTIONS_WAITING("ft.bulkhead.executionsWaiting", ObservableLongGauge.class),
BULKHEAD_RUNNING_DURATION("ft.bulkhead.runningDuration", LongHistogram.class, "nanoseconds"),
BULKHEAD_WAITING_DURATION("ft.bulkhead.waitingDuration", LongHistogram.class, "nanoseconds");

private String name;
private String unit;
private Set<Class> metricClassses;
private Class<?> metricClass;
private Class<? extends AttributeValue>[] getAttributeClasses;

@SafeVarargs
private MetricDefinition(String name, Set<Class> metricClassses, String unit,
private MetricDefinition(String name, Class<?> metricClass, String unit,
Class<? extends AttributeValue>... tagClasses) {
this.name = name;
this.unit = unit;
this.metricClassses = metricClassses;
this.metricClass = metricClass;
this.getAttributeClasses = tagClasses;
}

@SafeVarargs
private MetricDefinition(String name, Set<Class> metricClassses,
private MetricDefinition(String name, Class<?> metricClasss,
Class<? extends AttributeValue>... tagClasses) {
this(name, metricClassses, null, tagClasses);
this(name, metricClasss, null, tagClasses);
}

/**
* The metric name
*
*
* @return the name
*/
public String getName() {
Expand All @@ -95,7 +93,7 @@ public String getName() {

/**
* The metric unit
*
*
* @return the unit
*/
public String getUnit() {
Expand All @@ -104,18 +102,18 @@ public String getUnit() {

/**
* The subclass of {@link Metric} used by this metric
*
*
* @return the metric class
*/
public Set<Class> getMetricClasses() {
return metricClassses;
public Class<?> getMetricClass() {
return metricClass;
}

/**
* The tags which are applied to this metric
* <p>
* The classes returned from this method will be enums which implement {@link AttributeValue}
*
*
* @return the tags which are applied to this metric
*/
public Class<? extends AttributeValue>[] getAttributeClasses() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,14 @@ public HistogramMetric getBulkheadWaitingDuration() {
* This allows us to check how they've changed later in the test using the {@code CounterMetric.delta()} or
* {@code GaugeMetric.delta()} methods, without having to explicitly baseline every metric ourselves up front.
*/
@Deprecated
public void baselineMetrics() {
for (MetricDefinition definition : MetricDefinition.values()) {
for (AttributeValue[] tags : getTagCombinations(definition.getAttributeClasses())) {
MetricID id = getMetricId(definition, tags);
if (definition.getMetricClasses().contains(LongCounter.class)) {
if (definition.getMetricClass() == LongCounter.class) {
getCounterMetric(id).baseline();
}
if (definition.getMetricClasses().contains(ObservableLongGauge.class)) {
if (definition.getMetricClass() == ObservableLongGauge.class) {
getGaugeMetric(id).baseline();
}
}
Expand All @@ -152,7 +151,7 @@ public void baselineMetrics() {
* Given an array of TagValue enums, this method find every combination of values from across this set of tags.
* <p>
* For example, if we had two tags {@code foo=[a|b]} and {@code bar=[x|y]}, this method would return
*
*
* <pre>
* [[foo=a, bar=x],
* [foo=a, bar=y],
Expand All @@ -165,7 +164,7 @@ public void baselineMetrics() {
* <p>
* If called with no arguments, this method returns an array containing an empty array (indicating the only possible
* combination the the one with no tag values at all).
*
*
* @param tagValueClazzes
* the set of tags
* @return every possible combination when taking one value for each of the given tags
Expand Down Expand Up @@ -211,7 +210,7 @@ private static List<List<AttributeValue>> getTagCombinations(
* <p>
* This method will check that the {@code TagValue}s passed in match the value of
* {@link MetricDefinition#getTagClasses()}.
*
*
* @param metricDefinition
* the definition of the metric
* @param metricTags
Expand Down Expand Up @@ -245,7 +244,7 @@ private MetricID getMetricId(MetricDefinition metricDefinition, AttributeValue..
* <p>
* Each created {@code CounterMetric} will be stored and calling this method twice with the same {@code MetricID}
* will return the same {@code CounterMetric}.
*
*
* @param metricId
* the {@code MetricID}
* @return the {@code CounterMetric} for {@code metricId}
Expand All @@ -259,7 +258,7 @@ private CounterMetric getCounterMetric(MetricID metricId) {
* <p>
* Each created {@code GaugeMetric} will be stored and calling this method twice with the same {@code MetricID} will
* return the same {@code GaugeMetric}.
*
*
* @param metricId
* the {@code MetricID}
* @return the {@code GaugeMetric} for {@code metricId}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 5f97f23

Please sign in to comment.