-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prometheusremotewrite: Hash labels using xxhash for performance
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
- Loading branch information
Showing
18 changed files
with
773 additions
and
634 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
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: breaking | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: prometheusremotewrite | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Change prometheusremotewrite.FromMetrics's tsMap argument to have uint64 keys instead of strings, for more performant hashing. | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [31385] | ||
|
||
# (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: [api] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package prometheusremotewrite | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/prometheus/prometheus/prompb" | ||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
"go.uber.org/multierr" | ||
|
||
prometheustranslator "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus" | ||
) | ||
|
||
type Settings struct { | ||
Namespace string | ||
ExternalLabels map[string]string | ||
DisableTargetInfo bool | ||
ExportCreatedMetric bool | ||
AddMetricSuffixes bool | ||
SendMetadata bool | ||
} | ||
|
||
type MetricsConverter interface { | ||
// AddSample adds a sample and returns the metric hash. | ||
AddSample(*prompb.Sample, []prompb.Label) uint64 | ||
// AddExemplars converts exemplars. | ||
AddExemplars(uint64, pmetric.HistogramDataPoint, []bucketBoundsData) | ||
// AddGaugeNumberDataPoints converts Gauge metric data points. | ||
AddGaugeNumberDataPoints(pmetric.NumberDataPointSlice, pcommon.Resource, pmetric.Metric, Settings, string) error | ||
// AddSumNumberDataPoints converts Sum metric data points. | ||
AddSumNumberDataPoints(pmetric.NumberDataPointSlice, pcommon.Resource, pmetric.Metric, Settings, string) error | ||
// AddSummaryDataPoints converts summary metric data points, each to len(QuantileValues) + 2 samples. | ||
AddSummaryDataPoints(pmetric.SummaryDataPointSlice, pcommon.Resource, pmetric.Metric, Settings, string) error | ||
// AddHistogramDataPoints converts histogram metric data points, each to 2 + min(len(ExplicitBounds), len(BucketCount)) + 1 samples. | ||
// It ignores extra buckets if len(ExplicitBounds) > len(BucketCounts). | ||
AddHistogramDataPoints(pmetric.HistogramDataPointSlice, pcommon.Resource, pmetric.Metric, Settings, string) error | ||
// AddExponentialHistogramDataPoints converts exponential histogtram metric data points. | ||
AddExponentialHistogramDataPoints(pmetric.ExponentialHistogramDataPointSlice, pcommon.Resource, Settings, string) error | ||
AddMetricIfNeeded([]prompb.Label, pcommon.Timestamp, pcommon.Timestamp) | ||
} | ||
|
||
// FromMetrics converts pmetric.Metrics to another metrics format via the converter. | ||
func FromMetrics(md pmetric.Metrics, settings Settings, converter MetricsConverter) (errs error) { | ||
resourceMetricsSlice := md.ResourceMetrics() | ||
for i := 0; i < resourceMetricsSlice.Len(); i++ { | ||
resourceMetrics := resourceMetricsSlice.At(i) | ||
resource := resourceMetrics.Resource() | ||
scopeMetricsSlice := resourceMetrics.ScopeMetrics() | ||
// keep track of the most recent timestamp in the ResourceMetrics for | ||
// use with the "target" info metric | ||
var mostRecentTimestamp pcommon.Timestamp | ||
for j := 0; j < scopeMetricsSlice.Len(); j++ { | ||
metricSlice := scopeMetricsSlice.At(j).Metrics() | ||
|
||
// TODO: decide if instrumentation library information should be exported as labels | ||
for k := 0; k < metricSlice.Len(); k++ { | ||
metric := metricSlice.At(k) | ||
mostRecentTimestamp = maxTimestamp(mostRecentTimestamp, mostRecentTimestampInMetric(metric)) | ||
|
||
if !isValidAggregationTemporality(metric) { | ||
errs = multierr.Append(errs, fmt.Errorf("invalid temporality and type combination for metric %q", metric.Name())) | ||
continue | ||
} | ||
|
||
promName := prometheustranslator.BuildCompliantName(metric, settings.Namespace, settings.AddMetricSuffixes) | ||
|
||
// handle individual metrics based on type | ||
//exhaustive:enforce | ||
switch metric.Type() { | ||
case pmetric.MetricTypeGauge: | ||
dataPoints := metric.Gauge().DataPoints() | ||
if dataPoints.Len() == 0 { | ||
errs = multierr.Append(errs, fmt.Errorf("empty data points. %s is dropped", metric.Name())) | ||
break | ||
} | ||
errs = multierr.Append(errs, converter.AddGaugeNumberDataPoints(dataPoints, resource, metric, settings, promName)) | ||
case pmetric.MetricTypeSum: | ||
dataPoints := metric.Sum().DataPoints() | ||
if dataPoints.Len() == 0 { | ||
errs = multierr.Append(errs, fmt.Errorf("empty data points. %s is dropped", metric.Name())) | ||
break | ||
} | ||
errs = multierr.Append(errs, converter.AddSumNumberDataPoints(dataPoints, resource, metric, settings, promName)) | ||
case pmetric.MetricTypeHistogram: | ||
dataPoints := metric.Histogram().DataPoints() | ||
if dataPoints.Len() == 0 { | ||
errs = multierr.Append(errs, fmt.Errorf("empty data points. %s is dropped", metric.Name())) | ||
break | ||
} | ||
errs = multierr.Append(errs, converter.AddHistogramDataPoints(dataPoints, resource, metric, settings, promName)) | ||
case pmetric.MetricTypeExponentialHistogram: | ||
dataPoints := metric.ExponentialHistogram().DataPoints() | ||
if dataPoints.Len() == 0 { | ||
errs = multierr.Append(errs, fmt.Errorf("empty data points. %s is dropped", metric.Name())) | ||
break | ||
} | ||
errs = multierr.Append(errs, converter.AddExponentialHistogramDataPoints( | ||
dataPoints, | ||
resource, | ||
settings, | ||
promName, | ||
)) | ||
case pmetric.MetricTypeSummary: | ||
dataPoints := metric.Summary().DataPoints() | ||
if dataPoints.Len() == 0 { | ||
errs = multierr.Append(errs, fmt.Errorf("empty data points. %s is dropped", metric.Name())) | ||
break | ||
} | ||
errs = multierr.Append(errs, converter.AddSummaryDataPoints(dataPoints, resource, metric, settings, promName)) | ||
default: | ||
errs = multierr.Append(errs, errors.New("unsupported metric type")) | ||
} | ||
} | ||
} | ||
addResourceTargetInfo(resource, settings, mostRecentTimestamp, converter) | ||
} | ||
|
||
return | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.