-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redesign of Collector architecture (#901).
Signed-off-by: Marcin Kielar <[email protected]>
- Loading branch information
Marcin Kielar
committed
Dec 8, 2023
1 parent
60f72b6
commit ede5cc3
Showing
36 changed files
with
820 additions
and
544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/NameFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.prometheus.metrics.core.metrics; | ||
|
||
import io.prometheus.metrics.model.registry.MetricNameFilter; | ||
import io.prometheus.metrics.model.registry.PrometheusRegistry; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class NameFilterTest { | ||
@Test | ||
public void testCounterWithCallback() { | ||
AtomicInteger accessCount = new AtomicInteger(); | ||
CounterWithCallback metrics = CounterWithCallback.builder() | ||
.name("my_counter") | ||
.callback(cb -> { | ||
accessCount.incrementAndGet(); | ||
cb.call(1.0); | ||
}) | ||
.build(); | ||
|
||
|
||
PrometheusRegistry registry = new PrometheusRegistry(); | ||
registry.register(metrics); | ||
|
||
var result1 = registry.scrape(MetricNameFilter.builder().nameMustBeEqualTo("XXX").build()); | ||
Assert.assertEquals(accessCount.get(), 0); | ||
Assert.assertTrue(result1.stream().toList().isEmpty()); | ||
|
||
var result2 = registry.scrape(MetricNameFilter.builder().nameMustBeEqualTo("my_counter").build()); | ||
Assert.assertEquals(accessCount.get(), 1); | ||
Assert.assertEquals(result2.stream().toList().size(), 1); | ||
Assert.assertEquals(result2.get(0).getMetadata().getPrometheusName(), "my_counter"); | ||
} | ||
|
||
@Test | ||
public void testGaugeWithCallback() { | ||
AtomicInteger accessCount = new AtomicInteger(); | ||
GaugeWithCallback metrics = GaugeWithCallback.builder() | ||
.name("my_gauge") | ||
.callback(cb -> { | ||
accessCount.incrementAndGet(); | ||
cb.call(1.0); | ||
}) | ||
.build(); | ||
|
||
|
||
PrometheusRegistry registry = new PrometheusRegistry(); | ||
registry.register(metrics); | ||
|
||
var result1 = registry.scrape(MetricNameFilter.builder().nameMustBeEqualTo("XXX").build()); | ||
Assert.assertEquals(accessCount.get(), 0); | ||
Assert.assertTrue(result1.stream().toList().isEmpty()); | ||
|
||
var result2 = registry.scrape(MetricNameFilter.builder().nameMustBeEqualTo("my_gauge").build()); | ||
Assert.assertEquals(accessCount.get(), 1); | ||
Assert.assertEquals(result2.stream().toList().size(), 1); | ||
Assert.assertEquals(result2.get(0).getMetadata().getPrometheusName(), "my_gauge"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.