|
40 | 40 | import io.micrometer.core.ipc.http.HttpUrlConnectionSender;
|
41 | 41 | import io.micrometer.registry.otlp.internal.CumulativeBase2ExponentialHistogram;
|
42 | 42 | import io.micrometer.registry.otlp.internal.DeltaBase2ExponentialHistogram;
|
43 |
| -import io.micrometer.registry.otlp.internal.ExponentialHistogramSnapShot; |
44 | 43 | import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest;
|
45 | 44 | import io.opentelemetry.proto.common.v1.AnyValue;
|
46 | 45 | import io.opentelemetry.proto.common.v1.KeyValue;
|
@@ -69,11 +68,6 @@ public class OtlpMeterRegistry extends PushMeterRegistry {
|
69 | 68 |
|
70 | 69 | private static final ThreadFactory DEFAULT_THREAD_FACTORY = new NamedThreadFactory("otlp-metrics-publisher");
|
71 | 70 |
|
72 |
| - private static final ExponentialHistogramDataPoint.Buckets EMPTY_EXPONETIAL_HISTOGRAM_BUCKETS = ExponentialHistogramDataPoint.Buckets |
73 |
| - .newBuilder() |
74 |
| - .addAllBucketCounts(Collections.emptyList()) |
75 |
| - .build(); |
76 |
| - |
77 | 71 | private static final double[] EMPTY_SLO_WITH_POSITIVE_INF = new double[] { Double.POSITIVE_INFINITY };
|
78 | 72 |
|
79 | 73 | private static final String TELEMETRY_SDK_NAME = "telemetry.sdk.name";
|
@@ -351,125 +345,6 @@ private long getInitialDelay() {
|
351 | 345 | return stepMillis - (clock.wallTime() % stepMillis) + 1;
|
352 | 346 | }
|
353 | 347 |
|
354 |
| - // VisibleForTesting |
355 |
| - Metric writeHistogramSupport(HistogramSupport histogramSupport) { |
356 |
| - Metric.Builder metricBuilder = getMetricBuilder(histogramSupport.getId()); |
357 |
| - boolean isTimeBased = histogramSupport instanceof Timer || histogramSupport instanceof LongTaskTimer; |
358 |
| - HistogramSnapshot histogramSnapshot = histogramSupport.takeSnapshot(); |
359 |
| - |
360 |
| - Iterable<? extends KeyValue> tags = getTagsForId(histogramSupport.getId()); |
361 |
| - long startTimeNanos = getStartTimeNanos(histogramSupport); |
362 |
| - double total = isTimeBased ? histogramSnapshot.total(getBaseTimeUnit()) : histogramSnapshot.total(); |
363 |
| - long count = histogramSnapshot.count(); |
364 |
| - |
365 |
| - // if percentiles configured, use summary |
366 |
| - if (histogramSnapshot.percentileValues().length != 0) { |
367 |
| - SummaryDataPoint.Builder summaryData = SummaryDataPoint.newBuilder() |
368 |
| - .addAllAttributes(tags) |
369 |
| - .setStartTimeUnixNano(startTimeNanos) |
370 |
| - .setTimeUnixNano(getTimeUnixNano()) |
371 |
| - .setSum(total) |
372 |
| - .setCount(count); |
373 |
| - for (ValueAtPercentile percentile : histogramSnapshot.percentileValues()) { |
374 |
| - summaryData.addQuantileValues(SummaryDataPoint.ValueAtQuantile.newBuilder() |
375 |
| - .setQuantile(percentile.percentile()) |
376 |
| - .setValue(TimeUtils.convert(percentile.value(), TimeUnit.NANOSECONDS, getBaseTimeUnit()))); |
377 |
| - } |
378 |
| - metricBuilder.setSummary(Summary.newBuilder().addDataPoints(summaryData)); |
379 |
| - return metricBuilder.build(); |
380 |
| - } |
381 |
| - |
382 |
| - ExponentialHistogramSnapShot exponentialHistogramSnapShot = getExponentialHistogramSnapShot(histogramSupport); |
383 |
| - if (exponentialHistogramSnapShot != null) { |
384 |
| - ExponentialHistogramDataPoint.Builder exponentialDataPoint = ExponentialHistogramDataPoint.newBuilder() |
385 |
| - .addAllAttributes(tags) |
386 |
| - .setStartTimeUnixNano(startTimeNanos) |
387 |
| - .setTimeUnixNano(getTimeUnixNano()) |
388 |
| - .setCount(count) |
389 |
| - .setSum(total) |
390 |
| - .setScale(exponentialHistogramSnapShot.scale()) |
391 |
| - .setZeroCount(exponentialHistogramSnapShot.zeroCount()) |
392 |
| - .setZeroThreshold(exponentialHistogramSnapShot.zeroThreshold()) |
393 |
| - .setPositive(ExponentialHistogramDataPoint.Buckets.newBuilder() |
394 |
| - .addAllBucketCounts(exponentialHistogramSnapShot.bucketsCount()) |
395 |
| - .setOffset(exponentialHistogramSnapShot.offset()) |
396 |
| - .build()) |
397 |
| - // Micrometer doesn't support negative recordings. |
398 |
| - .setNegative(EMPTY_EXPONETIAL_HISTOGRAM_BUCKETS); |
399 |
| - |
400 |
| - if (isDelta()) { |
401 |
| - exponentialDataPoint |
402 |
| - .setMax(isTimeBased ? histogramSnapshot.max(getBaseTimeUnit()) : histogramSnapshot.max()); |
403 |
| - } |
404 |
| - |
405 |
| - return metricBuilder |
406 |
| - .setExponentialHistogram(ExponentialHistogram.newBuilder() |
407 |
| - .setAggregationTemporality(otlpAggregationTemporality) |
408 |
| - .addDataPoints(exponentialDataPoint) |
409 |
| - .build()) |
410 |
| - .build(); |
411 |
| - } |
412 |
| - |
413 |
| - HistogramDataPoint.Builder histogramDataPoint = HistogramDataPoint.newBuilder() |
414 |
| - .addAllAttributes(tags) |
415 |
| - .setStartTimeUnixNano(startTimeNanos) |
416 |
| - .setTimeUnixNano(getTimeUnixNano()) |
417 |
| - .setSum(total) |
418 |
| - .setCount(count); |
419 |
| - |
420 |
| - if (isDelta()) { |
421 |
| - histogramDataPoint.setMax(isTimeBased ? histogramSnapshot.max(getBaseTimeUnit()) : histogramSnapshot.max()); |
422 |
| - } |
423 |
| - // if histogram enabled, add histogram buckets |
424 |
| - if (histogramSnapshot.histogramCounts().length != 0) { |
425 |
| - for (CountAtBucket countAtBucket : histogramSnapshot.histogramCounts()) { |
426 |
| - if (countAtBucket.bucket() != Double.POSITIVE_INFINITY) { |
427 |
| - // OTLP expects explicit bounds to not contain POSITIVE_INFINITY but |
428 |
| - // there should be a |
429 |
| - // bucket count representing values between last bucket and |
430 |
| - // POSITIVE_INFINITY. |
431 |
| - histogramDataPoint.addExplicitBounds( |
432 |
| - isTimeBased ? countAtBucket.bucket(getBaseTimeUnit()) : countAtBucket.bucket()); |
433 |
| - } |
434 |
| - histogramDataPoint.addBucketCounts((long) countAtBucket.count()); |
435 |
| - } |
436 |
| - metricBuilder.setHistogram(io.opentelemetry.proto.metrics.v1.Histogram.newBuilder() |
437 |
| - .setAggregationTemporality(otlpAggregationTemporality) |
438 |
| - .addDataPoints(histogramDataPoint)); |
439 |
| - return metricBuilder.build(); |
440 |
| - } |
441 |
| - |
442 |
| - return metricBuilder |
443 |
| - .setHistogram(io.opentelemetry.proto.metrics.v1.Histogram.newBuilder() |
444 |
| - .setAggregationTemporality(otlpAggregationTemporality) |
445 |
| - .addDataPoints(histogramDataPoint)) |
446 |
| - .build(); |
447 |
| - } |
448 |
| - |
449 |
| - @Nullable |
450 |
| - private static ExponentialHistogramSnapShot getExponentialHistogramSnapShot( |
451 |
| - final HistogramSupport histogramSupport) { |
452 |
| - if (histogramSupport instanceof OtlpHistogramSupport) { |
453 |
| - return ((OtlpHistogramSupport) histogramSupport).getExponentialHistogramSnapShot(); |
454 |
| - } |
455 |
| - |
456 |
| - return null; |
457 |
| - } |
458 |
| - |
459 |
| - // VisibleForTesting |
460 |
| - Metric writeFunctionTimer(FunctionTimer functionTimer) { |
461 |
| - return getMetricBuilder(functionTimer.getId()) |
462 |
| - .setHistogram(io.opentelemetry.proto.metrics.v1.Histogram.newBuilder() |
463 |
| - .addDataPoints(HistogramDataPoint.newBuilder() |
464 |
| - .addAllAttributes(getTagsForId(functionTimer.getId())) |
465 |
| - .setStartTimeUnixNano(getStartTimeNanos((functionTimer))) |
466 |
| - .setTimeUnixNano(getTimeUnixNano()) |
467 |
| - .setSum(functionTimer.totalTime(getBaseTimeUnit())) |
468 |
| - .setCount((long) functionTimer.count())) |
469 |
| - .setAggregationTemporality(otlpAggregationTemporality)) |
470 |
| - .build(); |
471 |
| - } |
472 |
| - |
473 | 348 | private boolean isCumulative() {
|
474 | 349 | return this.aggregationTemporality == AggregationTemporality.CUMULATIVE;
|
475 | 350 | }
|
@@ -516,14 +391,15 @@ static Histogram getHistogram(Clock clock, DistributionStatisticConfig distribut
|
516 | 391 |
|
517 | 392 | static Histogram getHistogram(final Clock clock, final DistributionStatisticConfig distributionStatisticConfig,
|
518 | 393 | final OtlpConfig otlpConfig, @Nullable final TimeUnit baseTimeUnit) {
|
519 |
| - // While publishing to OTLP, we export either Histogram datapoint (Explicit Bucket |
| 394 | + // While publishing to OTLP, we export either Histogram datapoint (Explicit |
| 395 | + // ExponentialBucket |
520 | 396 | // or Exponential) / Summary
|
521 | 397 | // datapoint. So, we will make the histogram either of them and not both.
|
522 | 398 | // Though AbstractTimer/Distribution Summary prefers publishing percentiles,
|
523 | 399 | // exporting of histograms over percentiles is preferred in OTLP.
|
524 | 400 | if (distributionStatisticConfig.isPublishingHistogram()) {
|
525 |
| - if (histogramFlavour(otlpConfig.histogramFlavour(), |
526 |
| - distributionStatisticConfig) == HistogramFlavour.BASE2_EXPONENTIAL_BUCKET_HISTOGRAM) { |
| 401 | + if (HistogramFlavour.BASE2_EXPONENTIAL_BUCKET_HISTOGRAM |
| 402 | + .equals(histogramFlavour(otlpConfig.histogramFlavour(), distributionStatisticConfig))) { |
527 | 403 | Double minimumExpectedValue = distributionStatisticConfig.getMinimumExpectedValueAsDouble();
|
528 | 404 | if (minimumExpectedValue == null) {
|
529 | 405 | minimumExpectedValue = 0.0;
|
|
0 commit comments