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

Fix Snapshots creation #122

Merged
merged 1 commit into from
Jan 4, 2024
Merged
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
7 changes: 6 additions & 1 deletion core/src/main/java/com/uber/m3/tally/ScopeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.uber.m3.util.ImmutableMap;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -172,7 +173,11 @@ String fullyQualifiedName(String name) {
public Snapshot snapshot() {
Snapshot snap = new SnapshotImpl();

for (ScopeImpl subscope : registry.subscopes.values()) {
ArrayList<ScopeImpl> scopes = new ArrayList<>();
scopes.add(this);
scopes.addAll(registry.subscopes.values());

for (ScopeImpl subscope : scopes) {
ImmutableMap<String, String> tags = new ImmutableMap.Builder<String, String>()
.putAll(this.tags)
.putAll(subscope.tags)
Expand Down
10 changes: 9 additions & 1 deletion core/src/test/java/com/uber/m3/tally/TestScopeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,27 @@ public void testCreate() {

testScope.tagged(tags).counter("counter").inc(1);

testScope.counter("untagged_counter").inc(1);

Snapshot snapshot = testScope.snapshot();
assertNotNull(snapshot);

Map<ScopeKey, CounterSnapshot> counters = snapshot.counters();
assertNotNull(counters);
assertEquals(1, counters.size());
assertEquals(2, counters.size());

CounterSnapshot counterSnapshot = counters.get(new ScopeKey("counter", tags));
assertNotNull(counterSnapshot);

assertEquals("counter", counterSnapshot.name());
assertEquals(tags, counterSnapshot.tags());
assertEquals(1, counterSnapshot.value());

counterSnapshot = counters.get(new ScopeKey("untagged_counter", ImmutableMap.EMPTY));
assertNotNull(counterSnapshot);
assertEquals("untagged_counter", counterSnapshot.name());
assertEquals(ImmutableMap.EMPTY, counterSnapshot.tags());
assertEquals(1, counterSnapshot.value());
}

@Test
Expand Down
Loading