-
Notifications
You must be signed in to change notification settings - Fork 812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Prometheus text format serializers. #4178
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this cause the entire prometheus export to crash, or is this handled in the exporter later? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its not wired up to an exporter yet so I believe that's a decision that is yet to be made. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can never be thrown when the BOM is used, if it did happen to be thrown then the export would fail. I've seen various linkage exceptions related to unaligned dependencies and think it's mostly not possible to use OTel without alignment so leant towards just making this an exception instead of log / fallback, but either approach would be fine here. |
||
"Unsupported metric type, this generally indicates version misalignment " | ||
+ "among opentelemetry dependencies. Please make sure to use opentelemetry-bom."); | ||
} | ||
|
||
String getTypeString() { | ||
return typeString; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for a prometheus collector which prefers cumulative temporality to get non-monotonic, delta, sum data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe after we added preferred aggregation support it isn't possible when using our SDK. It could be possible if someone used the exporter without our SDK though (creating arbitrary MetricData).