Skip to content

Commit

Permalink
Merge branch '1.7.x' into 1.8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatan-ivanov committed Apr 19, 2022
2 parents e74b79e + eb617d1 commit 8083ed5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -194,12 +194,12 @@ public DistributionSummary newDistributionSummary(Meter.Id id, DistributionStati
double count = summary.count();

if (percentileValues.length > 0) {
List<String> quantileKeys = new LinkedList<>(tagKeys);
List<String> quantileKeys = new ArrayList<>(tagKeys);
quantileKeys.add("quantile");

// satisfies https://prometheus.io/docs/concepts/metric_types/#summary
for (ValueAtPercentile v : percentileValues) {
List<String> quantileValues = new LinkedList<>(tagValues);
List<String> quantileValues = new ArrayList<>(tagValues);
quantileValues.add(Collector.doubleToGoString(v.percentile()));
samples.add(new Collector.MetricFamilySamples.Sample(
conventionName, quantileKeys, quantileValues, v.value()));
Expand All @@ -211,23 +211,23 @@ public DistributionSummary newDistributionSummary(Meter.Id id, DistributionStati
// Prometheus doesn't balk at a metric being BOTH a histogram and a summary
type = Collector.Type.HISTOGRAM;

List<String> histogramKeys = new LinkedList<>(tagKeys);
List<String> histogramKeys = new ArrayList<>(tagKeys);
String sampleName = conventionName + "_bucket";
switch (summary.histogramFlavor()) {
case Prometheus:
histogramKeys.add("le");

// satisfies https://prometheus.io/docs/concepts/metric_types/#histogram
for (CountAtBucket c : histogramCounts) {
final List<String> histogramValues = new LinkedList<>(tagValues);
final List<String> histogramValues = new ArrayList<>(tagValues);
histogramValues.add(Collector.doubleToGoString(c.bucket()));
samples.add(new Collector.MetricFamilySamples.Sample(
sampleName, histogramKeys, histogramValues, c.count()));
}

if (Double.isFinite(histogramCounts[histogramCounts.length - 1].bucket())) {
// the +Inf bucket should always equal `count`
final List<String> histogramValues = new LinkedList<>(tagValues);
final List<String> histogramValues = new ArrayList<>(tagValues);
histogramValues.add("+Inf");
samples.add(new Collector.MetricFamilySamples.Sample(
sampleName, histogramKeys, histogramValues, count));
Expand All @@ -237,7 +237,7 @@ public DistributionSummary newDistributionSummary(Meter.Id id, DistributionStati
histogramKeys.add("vmrange");

for (CountAtBucket c : histogramCounts) {
final List<String> histogramValuesVM = new LinkedList<>(tagValues);
final List<String> histogramValuesVM = new ArrayList<>(tagValues);
histogramValuesVM.add(FixedBoundaryVictoriaMetricsHistogram.getRangeTagValue(c.bucket()));
samples.add(new Collector.MetricFamilySamples.Sample(
sampleName, histogramKeys, histogramValuesVM, c.count()));
Expand Down Expand Up @@ -336,13 +336,13 @@ protected Meter newMeter(Meter.Id id, Meter.Type type, Iterable<Measurement> mea
applyToCollector(id, (collector) -> {
List<String> tagValues = tagValues(id);
collector.add(tagValues, (conventionName, tagKeys) -> {
List<String> statKeys = new LinkedList<>(tagKeys);
List<String> statKeys = new ArrayList<>(tagKeys);
statKeys.add("statistic");

return Stream.of(new MicrometerCollector.Family(finalPromType, conventionName,
stream(measurements.spliterator(), false)
.map(m -> {
List<String> statValues = new LinkedList<>(tagValues);
List<String> statValues = new ArrayList<>(tagValues);
statValues.add(m.getStatistic().toString());

String name = conventionName;
Expand Down Expand Up @@ -393,12 +393,12 @@ private void addDistributionStatisticSamples(DistributionStatisticConfig distrib
double count = histogramSnapshot.count();

if (percentileValues.length > 0) {
List<String> quantileKeys = new LinkedList<>(tagKeys);
List<String> quantileKeys = new ArrayList<>(tagKeys);
quantileKeys.add("quantile");

// satisfies https://prometheus.io/docs/concepts/metric_types/#summary
for (ValueAtPercentile v : percentileValues) {
List<String> quantileValues = new LinkedList<>(tagValues);
List<String> quantileValues = new ArrayList<>(tagValues);
quantileValues.add(Collector.doubleToGoString(v.percentile()));
samples.add(new Collector.MetricFamilySamples.Sample(
conventionName, quantileKeys, quantileValues, v.value(TimeUnit.SECONDS)));
Expand All @@ -410,7 +410,7 @@ private void addDistributionStatisticSamples(DistributionStatisticConfig distrib
// Prometheus doesn't balk at a metric being BOTH a histogram and a summary
type = Collector.Type.HISTOGRAM;

List<String> histogramKeys = new LinkedList<>(tagKeys);
List<String> histogramKeys = new ArrayList<>(tagKeys);

String sampleName = conventionName + "_bucket";
switch (prometheusConfig.histogramFlavor()) {
Expand All @@ -419,14 +419,14 @@ private void addDistributionStatisticSamples(DistributionStatisticConfig distrib

// satisfies https://prometheus.io/docs/concepts/metric_types/#histogram
for (CountAtBucket c : histogramCounts) {
final List<String> histogramValues = new LinkedList<>(tagValues);
final List<String> histogramValues = new ArrayList<>(tagValues);
histogramValues.add(Collector.doubleToGoString(c.bucket(TimeUnit.SECONDS)));
samples.add(new Collector.MetricFamilySamples.Sample(
sampleName, histogramKeys, histogramValues, c.count()));
}

// the +Inf bucket should always equal `count`
final List<String> histogramValues = new LinkedList<>(tagValues);
final List<String> histogramValues = new ArrayList<>(tagValues);
histogramValues.add("+Inf");
samples.add(new Collector.MetricFamilySamples.Sample(
sampleName, histogramKeys, histogramValues, count));
Expand All @@ -435,7 +435,7 @@ private void addDistributionStatisticSamples(DistributionStatisticConfig distrib
histogramKeys.add("vmrange");

for (CountAtBucket c : histogramCounts) {
final List<String> histogramValuesVM = new LinkedList<>(tagValues);
final List<String> histogramValuesVM = new ArrayList<>(tagValues);
histogramValuesVM.add(FixedBoundaryVictoriaMetricsHistogram.getRangeTagValue(c.bucket()));
samples.add(new Collector.MetricFamilySamples.Sample(
sampleName, histogramKeys, histogramValuesVM, c.count()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.junit.jupiter.api.Test;

import java.time.Duration;
import java.util.LinkedList;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -53,12 +53,12 @@ void totalTimeWhenStateObjectChangedToNullShouldWorkWithChangedTimeUnit() {
@Issue("#1814")
@Test
void meanShouldWorkIfTotalNotCalled() {
Queue<Long> counts = new LinkedList<>();
Queue<Long> counts = new ArrayDeque<>();
counts.add(2L);
counts.add(5L);
counts.add(10L);

Queue<Double> totalTimes = new LinkedList<>();
Queue<Double> totalTimes = new ArrayDeque<>();
totalTimes.add(150.0);
totalTimes.add(300.0);
totalTimes.add(1000.0);
Expand Down

0 comments on commit 8083ed5

Please sign in to comment.