Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye committed Jun 15, 2024
1 parent 796c1e5 commit aef9680
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* Default implementation of {@link ExemplarSamplerFactory}.
*
* @author Jonatan Ivanov
* @since 1.13.0
*/
class DefaultExemplarSamplerFactory implements ExemplarSamplerFactory {

Expand All @@ -39,7 +38,7 @@ class DefaultExemplarSamplerFactory implements ExemplarSamplerFactory {

private final SpanContext spanContext;

public DefaultExemplarSamplerFactory(SpanContext spanContext, ExemplarsProperties exemplarsProperties) {
DefaultExemplarSamplerFactory(SpanContext spanContext, ExemplarsProperties exemplarsProperties) {
this.spanContext = spanContext;
this.exemplarsProperties = exemplarsProperties;
}
Expand All @@ -52,10 +51,9 @@ public ExemplarSampler createExemplarSampler(int numberOfExemplars) {
}

@Override
public ExemplarSampler createExemplarSampler(double[] histogramClassicUpperBounds) {
public ExemplarSampler createExemplarSampler(double[] histogramUpperBounds) {
ExemplarSamplerConfig config = exemplarSamplerConfigsByHistogramUpperBounds.computeIfAbsent(
histogramClassicUpperBounds,
key -> new ExemplarSamplerConfig(exemplarsProperties, histogramClassicUpperBounds));
histogramUpperBounds, key -> new ExemplarSamplerConfig(exemplarsProperties, histogramUpperBounds));
return new ExemplarSampler(config, spanContext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* A factory that creates {@link ExemplarSampler} instances with the desired properties.
*
* @author Jonatan Ivanov
* @since 1.13.0
*/
interface ExemplarSamplerFactory {

Expand All @@ -34,7 +33,7 @@ interface ExemplarSamplerFactory {

/**
* Creates an {@link ExemplarSampler} that stores exemplars for the defined histogram
* buckets. This means as many exemplars as many buckets are defined.
* buckets. This means as many exemplars as buckets are defined.
* @param histogramUpperBounds histogram buckets to store exemplars for.
* @return a new {@link ExemplarSampler} instance.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,18 +871,18 @@ void openMetricsScrapeWithExemplars() throws InterruptedException {

Timer timerWithHistogram = Timer.builder("timer.withHistogram").publishPercentileHistogram().register(registry);
timerWithHistogram.record(15, TimeUnit.MILLISECONDS);
Thread.sleep(5); // sleeping 5ms since the sample interval limit is 1ms
sleepToAvoidRateLimiting();
timerWithHistogram.record(150, TimeUnit.MILLISECONDS);
Thread.sleep(5); // sleeping 5ms since the sample interval limit is 1ms
sleepToAvoidRateLimiting();
timerWithHistogram.record(60, TimeUnit.SECONDS);

Timer timerWithSlos = Timer.builder("timer.withSlos")
.serviceLevelObjectives(Duration.ofMillis(100), Duration.ofMillis(200), Duration.ofMillis(300))
.register(registry);
timerWithSlos.record(Duration.ofMillis(15));
Thread.sleep(5); // sleeping 5ms since the sample interval limit is 1ms
sleepToAvoidRateLimiting();
timerWithSlos.record(Duration.ofMillis(1_500));
Thread.sleep(5); // sleeping 5ms since the sample interval limit is 1ms
sleepToAvoidRateLimiting();
timerWithSlos.record(Duration.ofMillis(150));

DistributionSummary summary = DistributionSummary.builder("summary.noHistogram").register(registry);
Expand All @@ -894,18 +894,18 @@ void openMetricsScrapeWithExemplars() throws InterruptedException {
.publishPercentileHistogram()
.register(registry);
summaryWithHistogram.record(0.15);
Thread.sleep(5); // sleeping 5ms since the sample interval limit is 1ms
sleepToAvoidRateLimiting();
summaryWithHistogram.record(5E18);
Thread.sleep(5); // sleeping 5ms since the sample interval limit is 1ms
sleepToAvoidRateLimiting();
summaryWithHistogram.record(15);

DistributionSummary slos = DistributionSummary.builder("summary.withSlos")
.serviceLevelObjectives(100, 200, 300)
.register(registry);
slos.record(10);
Thread.sleep(5); // sleeping 5ms since the sample interval limit is 1ms
sleepToAvoidRateLimiting();
slos.record(1_000);
Thread.sleep(5); // sleeping 5ms since the sample interval limit is 1ms
sleepToAvoidRateLimiting();
slos.record(250);

String scraped = registry.scrape("application/openmetrics-text");
Expand Down Expand Up @@ -944,6 +944,10 @@ void openMetricsScrapeWithExemplars() throws InterruptedException {
assertThat(scraped).endsWith("# EOF\n");
}

private static void sleepToAvoidRateLimiting() throws InterruptedException {
Thread.sleep(5); // sleeping 5ms since the sample interval limit is 1ms
}

@Test
void noExemplarsIfNoSampler() {
PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT, prometheusRegistry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,26 @@ public static void main(String[] args) throws InterruptedException {

Timer timer = Timer.builder("test.timer").publishPercentileHistogram().register(registry);
timer.record(Duration.ofNanos(1_000 * 100));
sleep(); // sleeping to avoid rate-limiting
sleepToAvoidRateLimiting();
timer.record(Duration.ofMillis(2));
sleep(); // sleeping to avoid rate-limiting
sleepToAvoidRateLimiting();
timer.record(Duration.ofMillis(100));
sleep(); // sleeping to avoid rate-limiting
sleepToAvoidRateLimiting();
timer.record(Duration.ofSeconds(60));

DistributionSummary distributionSummary = DistributionSummary.builder("test.distribution")
.publishPercentileHistogram()
.register(registry);
distributionSummary.record(0.15);
sleep(); // sleeping to avoid rate-limiting
sleepToAvoidRateLimiting();
distributionSummary.record(15);
sleep(); // sleeping to avoid rate-limiting
sleepToAvoidRateLimiting();
distributionSummary.record(5E18);

System.out.println(registry.scrape(CONTENT_TYPE_OPENMETRICS_100));
}

static void sleep() {
static void sleepToAvoidRateLimiting() {
try {
// sleeping 100ms since the sample interval limit is 90ms
Thread.sleep(100);
Expand Down

0 comments on commit aef9680

Please sign in to comment.