-
Notifications
You must be signed in to change notification settings - Fork 812
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Prometheus text format serializers.
- Loading branch information
Showing
5 changed files
with
1,040 additions
and
16 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
59 changes: 59 additions & 0 deletions
59
exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/PrometheusType.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,59 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.exporter.prometheus; | ||
|
||
import io.opentelemetry.sdk.metrics.data.AggregationTemporality; | ||
import io.opentelemetry.sdk.metrics.data.DoubleSumData; | ||
import io.opentelemetry.sdk.metrics.data.LongSumData; | ||
import io.opentelemetry.sdk.metrics.data.MetricData; | ||
|
||
// Four types we use are same in prometheus and openmetrics format | ||
enum PrometheusType { | ||
GAUGE("gauge"), | ||
COUNTER("counter"), | ||
SUMMARY("summary"), | ||
HISTOGRAM("histogram"); | ||
|
||
private final String typeString; | ||
|
||
PrometheusType(String typeString) { | ||
this.typeString = typeString; | ||
} | ||
|
||
static PrometheusType forMetric(MetricData metric) { | ||
switch (metric.getType()) { | ||
case LONG_GAUGE: | ||
case DOUBLE_GAUGE: | ||
return GAUGE; | ||
case LONG_SUM: | ||
LongSumData longSumData = metric.getLongSumData(); | ||
if (longSumData.isMonotonic() | ||
&& longSumData.getAggregationTemporality() == AggregationTemporality.CUMULATIVE) { | ||
return COUNTER; | ||
} | ||
return GAUGE; | ||
case DOUBLE_SUM: | ||
DoubleSumData doubleSumData = metric.getDoubleSumData(); | ||
if (doubleSumData.isMonotonic() | ||
&& doubleSumData.getAggregationTemporality() == AggregationTemporality.CUMULATIVE) { | ||
return COUNTER; | ||
} | ||
return GAUGE; | ||
case SUMMARY: | ||
return SUMMARY; | ||
case HISTOGRAM: | ||
case EXPONENTIAL_HISTOGRAM: | ||
return HISTOGRAM; | ||
} | ||
throw new IllegalArgumentException( | ||
"Unsupported metric type, this generally indicates version misalignment " | ||
+ "among opentelemetry dependencies. Please make sure to use opentelemetry-bom."); | ||
} | ||
|
||
String getTypeString() { | ||
return typeString; | ||
} | ||
} |
Oops, something went wrong.