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

replace total and current with count #36

Draft
wants to merge 1 commit into
base: metric_name_validation
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
public class MetricNameValidator {
private static final Pattern ALLOWED_CHARACTERS = Pattern.compile("[a-z][a-z0-9_]*");
static final Set<String> ALLOWED_SUFFIXES = Set.of(
"total",
"current",
"count",
"ratio",
"status" /*a workaround for enums */,
"usage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public void testMeterIsOverridden() {
public void testLookupByName() {
var apmMeter = new APMMeterService(TELEMETRY_ENABLED, () -> testOtel, () -> noopOtel).getMeterRegistry();

DoubleCounter registeredCounter = apmMeter.registerDoubleCounter("es.test.name.total", "desc", "unit");
DoubleCounter lookedUpCounter = apmMeter.getDoubleCounter("es.test.name.total");
DoubleCounter registeredCounter = apmMeter.registerDoubleCounter("es.test.name.count", "desc", "unit");
DoubleCounter lookedUpCounter = apmMeter.getDoubleCounter("es.test.name.count");

assertThat(lookedUpCounter, sameInstance(registeredCounter));
}
Expand All @@ -110,18 +110,18 @@ public void testAllInstrumentsSwitchProviders() {
APMMeterRegistry registry = apmMeter.getMeterRegistry();

Supplier<DoubleWithAttributes> doubleObserver = () -> new DoubleWithAttributes(1.5, Collections.emptyMap());
DoubleCounter dc = registry.registerDoubleCounter("es.test.dc.total", "", "");
DoubleUpDownCounter dudc = registry.registerDoubleUpDownCounter("es.test.dudc.current", "", "");
DoubleCounter dc = registry.registerDoubleCounter("es.test.dc.count", "", "");
DoubleUpDownCounter dudc = registry.registerDoubleUpDownCounter("es.test.dudc.count", "", "");
DoubleHistogram dh = registry.registerDoubleHistogram("es.test.dh.histogram", "", "");
DoubleAsyncCounter dac = registry.registerDoubleAsyncCounter("es.test.dac.total", "", "", doubleObserver);
DoubleGauge dg = registry.registerDoubleGauge("es.test.dg.current", "", "", doubleObserver);
DoubleAsyncCounter dac = registry.registerDoubleAsyncCounter("es.test.dac.count", "", "", doubleObserver);
DoubleGauge dg = registry.registerDoubleGauge("es.test.dg.count", "", "", doubleObserver);

Supplier<LongWithAttributes> longObserver = () -> new LongWithAttributes(100, Collections.emptyMap());
LongCounter lc = registry.registerLongCounter("es.test.lc.total", "", "");
LongUpDownCounter ludc = registry.registerLongUpDownCounter("es.test.ludc.total", "", "");
LongCounter lc = registry.registerLongCounter("es.test.lc.count", "", "");
LongUpDownCounter ludc = registry.registerLongUpDownCounter("es.test.ludc.count", "", "");
LongHistogram lh = registry.registerLongHistogram("es.test.lh.histogram", "", "");
LongAsyncCounter lac = registry.registerLongAsyncCounter("es.test.lac.total", "", "", longObserver);
LongGauge lg = registry.registerLongGauge("es.test.lg.current", "", "", longObserver);
LongAsyncCounter lac = registry.registerLongAsyncCounter("es.test.lac.count", "", "", longObserver);
LongGauge lg = registry.registerLongGauge("es.test.lg.count", "", "", longObserver);

apmMeter.setEnabled(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import static org.hamcrest.Matchers.sameInstance;

public class MeterRegistryConcurrencyTests extends ESTestCase {
private final String name = "es.test.name.total";
private final String name = "es.test.name.count";
private final String description = "desc";
private final String unit = "kg";
private final Meter noopMeter = OpenTelemetry.noop().getMeter("noop");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class MetricNameValidatorTests extends ESTestCase {
public void testMetricNameNotNull() {
String metricName = "es.somemodule.somemetric.total";
String metricName = "es.somemodule.somemetric.count";
assertThat(MetricNameValidator.validate(metricName), equalTo(metricName));

expectThrows(NullPointerException.class, () -> MetricNameValidator.validate(null));
Expand All @@ -27,47 +27,47 @@ public void testMaxMetricNameLength() {
}

public void testESPrefixAndDotSeparator() {
MetricNameValidator.validate("es.somemodule.somemetric.total");
MetricNameValidator.validate("es.somemodule.somemetric.count");

expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("somemodule.somemetric.total"));
expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("somemodule.somemetric.count"));
// verify . is a separator
expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("es_somemodule_somemetric_total"));
expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("es_somemodule.somemetric.total"));
expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("es_somemodule.somemetric.count"));
}

public void testNameElementRegex() {
MetricNameValidator.validate("es.somemodulename0.somemetric.total");
MetricNameValidator.validate("es.some_module_name0.somemetric.total");
MetricNameValidator.validate("es.s.somemetric.total");

expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("es.someModuleName0.somemetric.total"));
expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("es.SomeModuleName.somemetric.total"));
expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("es.0some_module_name0.somemetric.total"));
expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("es.some_#_name0.somemetric.total"));
expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("es.some-name0.somemetric.total"));
MetricNameValidator.validate("es.somemodulename0.somemetric.count");
MetricNameValidator.validate("es.some_module_name0.somemetric.count");
MetricNameValidator.validate("es.s.somemetric.count");

expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("es.someModuleName0.somemetric.count"));
expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("es.SomeModuleName.somemetric.count"));
expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("es.0some_module_name0.somemetric.count"));
expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("es.some_#_name0.somemetric.count"));
expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("es.some-name0.somemetric.count"));
}

public void testNameHas3Elements() {
MetricNameValidator.validate("es.group.total");
MetricNameValidator.validate("es.group.subgroup.total");
MetricNameValidator.validate("es.group.count");
MetricNameValidator.validate("es.group.subgroup.count");

expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("es"));
expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("es."));
expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("es.sth"));
}

public void testNumberOfElementsLimit() {
MetricNameValidator.validate("es.a2.a3.a4.a5.a6.a7.a8.a9.total");
MetricNameValidator.validate("es.a2.a3.a4.a5.a6.a7.a8.a9.count");

expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("es.a2.a3.a4.a5.a6.a7.a8.a9.a10.total"));
expectThrows(IllegalArgumentException.class, () -> MetricNameValidator.validate("es.a2.a3.a4.a5.a6.a7.a8.a9.a10.count"));
}

public void testElementLengthLimit() {
MetricNameValidator.validate("es." + "a".repeat(MetricNameValidator.MAX_ELEMENT_LENGTH) + ".total");
MetricNameValidator.validate("es." + "a".repeat(MetricNameValidator.MAX_ELEMENT_LENGTH) + ".count");

expectThrows(
IllegalArgumentException.class,
() -> MetricNameValidator.validate("es." + "a".repeat(MetricNameValidator.MAX_ELEMENT_LENGTH + 1) + ".total")
() -> MetricNameValidator.validate("es." + "a".repeat(MetricNameValidator.MAX_ELEMENT_LENGTH + 1) + ".count")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void init() {
// testing that a value reported is then used in a callback
public void testLongAsyncCounter() throws Exception {
AtomicReference<LongWithAttributes> attrs = new AtomicReference<>();
LongAsyncCounter longAsyncCounter = registry.registerLongAsyncCounter("es.test.name.total", "desc", "unit", attrs::get);
LongAsyncCounter longAsyncCounter = registry.registerLongAsyncCounter("es.test.name.count", "desc", "unit", attrs::get);

attrs.set(new LongWithAttributes(1L, Map.of("k", 1L)));

Expand Down Expand Up @@ -70,7 +70,7 @@ public void testLongAsyncCounter() throws Exception {

public void testDoubleAsyncAdapter() throws Exception {
AtomicReference<DoubleWithAttributes> attrs = new AtomicReference<>();
DoubleAsyncCounter doubleAsyncCounter = registry.registerDoubleAsyncCounter("es.test.name.total", "desc", "unit", attrs::get);
DoubleAsyncCounter doubleAsyncCounter = registry.registerDoubleAsyncCounter("es.test.name.count", "desc", "unit", attrs::get);

attrs.set(new DoubleWithAttributes(1.0, Map.of("k", 1.0)));

Expand Down Expand Up @@ -102,7 +102,7 @@ public void testDoubleAsyncAdapter() throws Exception {

public void testNullGaugeRecord() throws Exception {
DoubleAsyncCounter dcounter = registry.registerDoubleAsyncCounter(
"es.test.name.total",
"es.test.name.count",
"desc",
"unit",
new AtomicReference<DoubleWithAttributes>()::get
Expand All @@ -112,7 +112,7 @@ public void testNullGaugeRecord() throws Exception {
assertThat(metrics, hasSize(0));

LongAsyncCounter lcounter = registry.registerLongAsyncCounter(
"es.test.name.total",
"es.test.name.count",
"desc",
"unit",
new AtomicReference<LongWithAttributes>()::get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void init() {
// testing that a value reported is then used in a callback
public void testLongGaugeRecord() throws Exception {
AtomicReference<LongWithAttributes> attrs = new AtomicReference<>();
LongGauge gauge = registry.registerLongGauge("es.test.name.total", "desc", "unit", attrs::get);
LongGauge gauge = registry.registerLongGauge("es.test.name.count", "desc", "unit", attrs::get);

attrs.set(new LongWithAttributes(1L, Map.of("k", 1L)));

Expand Down Expand Up @@ -71,7 +71,7 @@ public void testLongGaugeRecord() throws Exception {
// testing that a value reported is then used in a callback
public void testDoubleGaugeRecord() throws Exception {
AtomicReference<DoubleWithAttributes> attrs = new AtomicReference<>();
DoubleGauge gauge = registry.registerDoubleGauge("es.test.name.total", "desc", "unit", attrs::get);
DoubleGauge gauge = registry.registerDoubleGauge("es.test.name.count", "desc", "unit", attrs::get);

attrs.set(new DoubleWithAttributes(1.0d, Map.of("k", 1L)));

Expand Down Expand Up @@ -103,7 +103,7 @@ public void testDoubleGaugeRecord() throws Exception {

public void testNullGaugeRecord() throws Exception {
DoubleGauge dgauge = registry.registerDoubleGauge(
"es.test.name.total",
"es.test.name.count",
"desc",
"unit",
new AtomicReference<DoubleWithAttributes>()::get
Expand All @@ -112,7 +112,7 @@ public void testNullGaugeRecord() throws Exception {
List<Measurement> metrics = otelMeter.getRecorder().getMeasurements(dgauge);
assertThat(metrics, hasSize(0));

LongGauge lgauge = registry.registerLongGauge("es.test.name.total", "desc", "unit", new AtomicReference<LongWithAttributes>()::get);
LongGauge lgauge = registry.registerLongGauge("es.test.name.count", "desc", "unit", new AtomicReference<LongWithAttributes>()::get);
otelMeter.collectMetrics();
metrics = otelMeter.getRecorder().getMeasurements(lgauge);
assertThat(metrics, hasSize(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ public DesiredBalanceReconciler(ClusterSettings clusterSettings, ThreadPool thre

unassignedShards = LongGaugeMetric.create(
meterRegistry,
"es.allocator.desired_balance.shards.unassigned.current",
"es.allocator.desired_balance.shards.unassigned.count",
"Current number of unassigned shards",
"{shard}"
);
totalAllocations = LongGaugeMetric.create(
meterRegistry,
"es.allocator.desired_balance.shards.current",
"es.allocator.desired_balance.shards.count",
"Total number of shards",
"{shard}"
);
undesiredAllocations = LongGaugeMetric.create(
meterRegistry,
"es.allocator.desired_balance.allocations.undesired.current",
"es.allocator.desired_balance.allocations.undesired.count",
"Total number of shards allocated on undesired nodes",
"{shard}"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
* breakers).
*
* The circuit breaker name is part of the (long) counter metric name instead of being an attribute because aggregating distinct circuit
* breakers trip counter values does not make sense, as for instance, summing es.breaker.field_data.trip.total and
* es.breaker.in_flight_requests.trip.total.
* breakers trip counter values does not make sense, as for instance, summing es.breaker.field_data.trip.count and
* es.breaker.in_flight_requests.trip.count.
* Those counters trip for different reasons even if the underlying reason is "too much memory usage". Aggregating them together results in
* losing the ability to understand where the underlying issue is (too much field data, too many concurrent requests, too large concurrent
* requests?). Aggregating each one of them separately to get, for instance, cluster level or cloud region level statistics is perfectly
Expand All @@ -39,12 +39,12 @@
*/
public class CircuitBreakerMetrics {
public static final CircuitBreakerMetrics NOOP = new CircuitBreakerMetrics(TelemetryProvider.NOOP, Collections.emptyMap());
public static final String ES_BREAKER_PARENT_TRIP_COUNT_TOTAL = "es.breaker.parent.trip.total";
public static final String ES_BREAKER_FIELD_DATA_TRIP_COUNT_TOTAL = "es.breaker.field_data.trip.total";
public static final String ES_BREAKER_REQUEST_TRIP_COUNT_TOTAL = "es.breaker.request.trip.total";
public static final String ES_BREAKER_IN_FLIGHT_REQUESTS_TRIP_COUNT_TOTAL = "es.breaker.in_flight_requests.trip.total";
public static final String ES_BREAKER_PARENT_TRIP_COUNT_TOTAL = "es.breaker.parent.trip.count";
public static final String ES_BREAKER_FIELD_DATA_TRIP_COUNT_TOTAL = "es.breaker.field_data.trip.count";
public static final String ES_BREAKER_REQUEST_TRIP_COUNT_TOTAL = "es.breaker.request.trip.count";
public static final String ES_BREAKER_IN_FLIGHT_REQUESTS_TRIP_COUNT_TOTAL = "es.breaker.in_flight_requests.trip.count";

private static final String ES_BREAKER_CUSTOM_TRIP_COUNT_TOTAL_TEMPLATE = "es.breaker.%s.trip.total";
private static final String ES_BREAKER_CUSTOM_TRIP_COUNT_TOTAL_TEMPLATE = "es.breaker.%s.trip.count";
private final MeterRegistry registry;
private final LongCounter parentTripCountTotal;
private final LongCounter fielddataTripCountTotal;
Expand Down
Loading
Loading