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

Add Meter.Cache for dynamic meter registration #4092

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
add test case to MeterCacheTest to check tags immutability
  • Loading branch information
qweek committed Sep 22, 2023
commit 719940d2e077314eddffa61aaac439bcd47ff47e
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,34 @@ void provideGauge() {
assertThat(secondGauge).isNotEqualTo(firstGauge);
}

@Test
void provideCounterWithoutDuplicateTags() {
Meter.Provider<String, Counter> counterProvider = Counter.builder("my.counter")
.tag("my.default.tag", "my.default.value")
.register(registry, value -> value == null ? Tags.empty() : Tags.of("my.key", value));

assertThat(registry.getMeters()).hasSize(0);

Counter firstCounter = counterProvider.get("first.value");
firstCounter.increment();

assertThat(firstCounter.getId().getTags()).hasSize(2);
assertThat(firstCounter.getId().getTags()).contains(Tag.of("my.default.tag", "my.default.value"),
Tag.of("my.key", "first.value"));

Counter sameCounter = counterProvider.get("first.value");
sameCounter.increment();

assertThat(sameCounter.getId().getTags()).hasSize(2);
assertThat(sameCounter.getId().getTags()).contains(Tag.of("my.default.tag", "my.default.value"),
Tag.of("my.key", "first.value"));

Counter secondCounter = counterProvider.get("second.value");
secondCounter.increment();

assertThat(secondCounter.getId().getTags()).hasSize(2);
assertThat(secondCounter.getId().getTags()).contains(Tag.of("my.default.tag", "my.default.value"),
Tag.of("my.key", "second.value"));
}

}