-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[exporter/prometheusremotewrite] prometheusremotewrite exporter add o…
…ption to send metadata (#27565) **Description:** <Describe what has changed.> <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> This PR adds an option to send metric Metadata to prometheus compatible backend (disabled by default). This contains information such as metric descrtiption, type, unit, and name. **Link to tracking Issue:** <Issue number if applicable> #13849 **Testing:** <Describe what testing was performed and which tests were added.> Tested in our testing environment with locally built image. **Documentation:** <Describe the documentation added.> --------- Co-authored-by: Antoine Toulme <[email protected]> Co-authored-by: Anthony Mirabella <[email protected]>
- Loading branch information
1 parent
d0ca48f
commit a0e6491
Showing
11 changed files
with
368 additions
and
8 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
.chloggen/prometheus-remote-write-add-option-to-send-metadata.yaml
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,27 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: exporter/prometheusremotewrite | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: prometheusremotewrite exporter add option to send metadata | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [ 13849 ] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [] |
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
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
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
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
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
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
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
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
64 changes: 64 additions & 0 deletions
64
pkg/translator/prometheusremotewrite/otlp_to_openmetrics_metadata.go
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,64 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package prometheusremotewrite // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheusremotewrite" | ||
|
||
import ( | ||
"github.com/prometheus/prometheus/prompb" | ||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
|
||
prometheustranslator "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus" | ||
) | ||
|
||
func otelMetricTypeToPromMetricType(otelMetric pmetric.Metric) prompb.MetricMetadata_MetricType { | ||
switch otelMetric.Type() { | ||
case pmetric.MetricTypeGauge: | ||
return prompb.MetricMetadata_GAUGE | ||
case pmetric.MetricTypeSum: | ||
metricType := prompb.MetricMetadata_GAUGE | ||
if otelMetric.Sum().IsMonotonic() { | ||
metricType = prompb.MetricMetadata_COUNTER | ||
} | ||
return metricType | ||
case pmetric.MetricTypeHistogram: | ||
return prompb.MetricMetadata_HISTOGRAM | ||
case pmetric.MetricTypeSummary: | ||
return prompb.MetricMetadata_SUMMARY | ||
case pmetric.MetricTypeExponentialHistogram: | ||
return prompb.MetricMetadata_HISTOGRAM | ||
} | ||
return prompb.MetricMetadata_UNKNOWN | ||
} | ||
|
||
func OtelMetricsToMetadata(md pmetric.Metrics, addMetricSuffixes bool) []*prompb.MetricMetadata { | ||
resourceMetricsSlice := md.ResourceMetrics() | ||
|
||
metadataLength := 0 | ||
for i := 0; i < resourceMetricsSlice.Len(); i++ { | ||
scopeMetricsSlice := resourceMetricsSlice.At(i).ScopeMetrics() | ||
for j := 0; j < scopeMetricsSlice.Len(); j++ { | ||
metadataLength += scopeMetricsSlice.At(j).Metrics().Len() | ||
} | ||
} | ||
|
||
var metadata = make([]*prompb.MetricMetadata, 0, metadataLength) | ||
for i := 0; i < resourceMetricsSlice.Len(); i++ { | ||
resourceMetrics := resourceMetricsSlice.At(i) | ||
scopeMetricsSlice := resourceMetrics.ScopeMetrics() | ||
|
||
for j := 0; j < scopeMetricsSlice.Len(); j++ { | ||
scopeMetrics := scopeMetricsSlice.At(j) | ||
for k := 0; k < scopeMetrics.Metrics().Len(); k++ { | ||
metric := scopeMetrics.Metrics().At(k) | ||
entry := prompb.MetricMetadata{ | ||
Type: otelMetricTypeToPromMetricType(metric), | ||
MetricFamilyName: prometheustranslator.BuildCompliantName(metric, "", addMetricSuffixes), | ||
Help: metric.Description(), | ||
} | ||
metadata = append(metadata, &entry) | ||
} | ||
} | ||
} | ||
|
||
return metadata | ||
} |
Oops, something went wrong.