Path: blob/main/component/otelcol/receiver/prometheus/internal/appendable.go
5365 views
// Copyright The OpenTelemetry Authors1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver/internal"1516import (17"context"18"regexp"19"time"2021"github.com/prometheus/prometheus/model/labels"22"github.com/prometheus/prometheus/storage"23"go.opentelemetry.io/collector/component"24"go.opentelemetry.io/collector/config"25"go.opentelemetry.io/collector/consumer"26"go.opentelemetry.io/collector/obsreport"27)2829// appendable translates Prometheus scraping diffs into OpenTelemetry format.30type appendable struct {31sink consumer.Metrics32metricAdjuster MetricsAdjuster33useStartTimeMetric bool34startTimeMetricRegex *regexp.Regexp35externalLabels labels.Labels3637settings component.ReceiverCreateSettings38obsrecv *obsreport.Receiver39}4041// NewAppendable returns a storage.Appendable instance that emits metrics to the sink.42func NewAppendable(43sink consumer.Metrics,44set component.ReceiverCreateSettings,45gcInterval time.Duration,46useStartTimeMetric bool,47startTimeMetricRegex *regexp.Regexp,48receiverID config.ComponentID,49externalLabels labels.Labels) storage.Appendable {5051var metricAdjuster MetricsAdjuster52if !useStartTimeMetric {53metricAdjuster = NewInitialPointAdjuster(set.Logger, gcInterval)54} else {55metricAdjuster = NewStartTimeMetricAdjuster(set.Logger, startTimeMetricRegex)56}5758return &appendable{59sink: sink,60settings: set,61metricAdjuster: metricAdjuster,62useStartTimeMetric: useStartTimeMetric,63startTimeMetricRegex: startTimeMetricRegex,64externalLabels: externalLabels,65obsrecv: obsreport.NewReceiver(obsreport.ReceiverSettings{ReceiverID: receiverID, Transport: transport, ReceiverCreateSettings: set}),66}67}6869func (o *appendable) Appender(ctx context.Context) storage.Appender {70return newTransaction(ctx, o.metricAdjuster, o.sink, o.externalLabels, o.settings, o.obsrecv)71}727374