Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
85d327c
Bump org.testcontainers:junit-jupiter from 1.20.6 to 1.21.0 (#1333)
dependabot[bot] Apr 24, 2025
df8ddbf
Bump org.springframework.boot:spring-boot-starter-parent from 3.4.4 t…
dependabot[bot] Apr 28, 2025
41418c6
Eagerly reject null label values (#1335)
benjaminp Apr 29, 2025
2122007
add Zizmor (#1337)
zeitlinger Apr 29, 2025
f00a878
Add removeIf method to Meters
dao-jun Apr 30, 2025
d4c84ba
fix gh pages, add super linter (#1338)
zeitlinger Apr 30, 2025
8019b63
add release.yml (#1341)
zeitlinger May 5, 2025
cd55b36
Fix (#1342)
zeitlinger May 5, 2025
f81c726
fix lint (#1343)
zeitlinger May 5, 2025
d114861
Fix release (#1344)
zeitlinger May 5, 2025
fd0c402
Bump jetty-server.version from 12.0.19 to 12.0.20 (#1345)
dependabot[bot] May 5, 2025
06a76d2
Bump jdx/mise-action from 2.2.1 to 2.2.2 (#1348)
dependabot[bot] May 12, 2025
3f33085
Fix broken link to "Exclude protobuf exposition format" section (#1347)
izeye May 12, 2025
1aac666
Fix tests
dao-jun May 14, 2025
57b116e
add Zizmor (#1337)
zeitlinger Apr 29, 2025
63fdb1f
fix gh pages, add super linter (#1338)
zeitlinger Apr 30, 2025
5d85738
Synchronize common files from prometheus/prometheus (#1340)
prombot May 13, 2025
a6135c4
Bump jetty-server.version from 12.0.20 to 12.0.21 (#1349)
dependabot[bot] May 13, 2025
75d86fc
Bump org.apache.tomcat.embed:tomcat-embed-core from 11.0.6 to 11.0.7 …
dependabot[bot] May 13, 2025
90839ad
cleanup gh actions (#1351)
zeitlinger May 13, 2025
886c309
Fix gh pages (#1355)
zeitlinger May 15, 2025
5ad5b94
Fix gh pages (#1356)
zeitlinger May 15, 2025
07d50f2
Bump com.google.protobuf:protobuf-java from 4.30.2 to 4.31.0 (#1357)
dependabot[bot] May 15, 2025
9ffc12a
Merge branch 'main' into dev/add_removeIf
dao-jun May 15, 2025
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 @@ -10,6 +10,7 @@
import io.prometheus.metrics.model.snapshots.MetricSnapshot;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -136,6 +137,11 @@ public void remove(String... labelValues) {
data.remove(Arrays.asList(labelValues));
}

/** Remove the data points when the given function. */
public void removeIf(Function<List<String>, Boolean> f) {
data.entrySet().removeIf(entry -> f.apply(Collections.unmodifiableList(entry.getKey())));
}

/** Reset the metric (remove all data points). */
public void clear() {
data.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -35,6 +37,29 @@ public void testLabelRemoveWhileCollecting() throws Exception {
}
}

@Test
@SuppressWarnings("unchecked")
public void testLabelRemoveIf() throws Exception {
Counter counter =
Counter.builder().name("testLabelRemoveIf").labelNames("label1", "label2").build();
Field data = counter.getClass().getSuperclass().getDeclaredField("data");
data.setAccessible(true);

counter.labelValues("a", "b").inc(1.0);
counter.labelValues("a", "c").inc(3.0);
counter.labelValues("a", "d").inc(7.0);
counter.labelValues("e", "f").inc(8.0);

counter.removeIf(labels -> labels.size() == 2 && labels.get(0).equals("a"));

Map<List<String>, Counter.DataPoint> dataPoints =
(Map<List<String>, Counter.DataPoint>) data.get(counter);

assertThat(dataPoints).hasSize(1);
assertThat(dataPoints.get(Arrays.asList("e", "f"))).isNotNull();
assertThat(dataPoints.get(Arrays.asList("e", "f")).get()).isEqualTo(8.0D);
}

@Test
public void testClear() {
Counter counter = Counter.builder().name("test").labelNames("label1", "label2").build();
Expand Down