Skip to content

Commit c4763d7

Browse files
Merge branch '1.12.x' into 1.13.x
2 parents ab092d9 + 0ff46ed commit c4763d7

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

.gitattributes

-1
This file was deleted.

docs/modules/ROOT/pages/concepts/gauges.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Note that, in this form, unlike other meter types, you do not get a reference to
4242

4343
This pattern should be less common than the `DoubleFunction` form. Remember that frequent setting of the observed `Number` results in a lot of intermediate values that never get published. Only the _instantaneous value_ of the gauge at publish time is ever sent to the monitoring system.
4444

45-
WARNING: Attempting to construct a gauge with a primitive number or one of its `java.lang` object forms is always incorrect. These numbers are immutable. Thus, the gauge cannot ever be changed. Attempting to "`re-register`" the gauge with a different number does not work, as the registry maintains only one meter for each unique combination of name and tags.
45+
WARNING: Attempting to construct a gauge with a primitive number or one of its `java.lang` object forms is always incorrect. These numbers are immutable. Thus, the gauge cannot ever be changed. Attempting to "re-register" the gauge with a different number does not work, as the registry maintains only one meter for each unique combination of name and tags. "Re-registering" a gauge can happen indirectly for example as the result of a `MeterFilter` modifying the name and/or the tags of two different gauges so that they will be the same after the filter is applied.
4646

4747
== Gauge Fluent Builder
4848

micrometer-test/src/main/java/io/micrometer/core/tck/MeterRegistryCompatibilityKit.java

+26
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.micrometer.core.annotation.Timed;
2020
import io.micrometer.core.instrument.Timer;
2121
import io.micrometer.core.instrument.*;
22+
import io.micrometer.core.instrument.config.MeterFilter;
2223
import io.micrometer.core.instrument.distribution.CountAtBucket;
2324
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;
2425
import io.micrometer.core.instrument.distribution.HistogramSnapshot;
@@ -444,6 +445,31 @@ void strongReferenceGauges() {
444445
assertThat(registry.get("strong.ref").gauge().value()).isEqualTo(1.0);
445446
}
446447

448+
@Test
449+
@DisplayName("gauges cannot be registered twice")
450+
void gaugesCannotBeRegisteredTwice() {
451+
AtomicInteger n1 = registry.gauge("my.gauge", new AtomicInteger(1));
452+
AtomicInteger n2 = registry.gauge("my.gauge", new AtomicInteger(2));
453+
454+
assertThat(registry.get("my.gauge").gauges()).hasSize(1);
455+
assertThat(registry.get("my.gauge").gauge().value()).isEqualTo(1);
456+
assertThat(n1).isNotNull().hasValue(1);
457+
assertThat(n2).isNotNull().hasValue(2);
458+
}
459+
460+
@Test
461+
@DisplayName("gauges cannot be registered effectively twice")
462+
void gaugesCannotBeRegisteredEffectivelyTwice() {
463+
registry.config().meterFilter(MeterFilter.ignoreTags("ignored"));
464+
AtomicInteger n1 = registry.gauge("my.gauge", Tags.of("ignored", "1"), new AtomicInteger(1));
465+
AtomicInteger n2 = registry.gauge("my.gauge", Tags.of("ignored", "2"), new AtomicInteger(2));
466+
467+
assertThat(registry.get("my.gauge").gauges()).hasSize(1);
468+
assertThat(registry.get("my.gauge").gauge().value()).isEqualTo(1);
469+
assertThat(n1).isNotNull().hasValue(1);
470+
assertThat(n2).isNotNull().hasValue(2);
471+
}
472+
447473
}
448474

449475
@DisplayName("long task timers")

0 commit comments

Comments
 (0)