Path: blob/main/component/otelcol/receiver/prometheus/internal/metadata.go
5414 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"github.com/prometheus/prometheus/model/textparse"18"github.com/prometheus/prometheus/scrape"19)2021type dataPoint struct {22value float6423boundary float6424}2526// internalMetricMetadata allows looking up metadata for internal scrape metrics27var internalMetricMetadata = map[string]*scrape.MetricMetadata{28scrapeUpMetricName: {29Metric: scrapeUpMetricName,30Type: textparse.MetricTypeGauge,31Help: "The scraping was successful",32},33"scrape_duration_seconds": {34Metric: "scrape_duration_seconds",35Unit: "seconds",36Type: textparse.MetricTypeGauge,37Help: "Duration of the scrape",38},39"scrape_samples_scraped": {40Metric: "scrape_samples_scraped",41Type: textparse.MetricTypeGauge,42Help: "The number of samples the target exposed",43},44"scrape_series_added": {45Metric: "scrape_series_added",46Type: textparse.MetricTypeGauge,47Help: "The approximate number of new series in this scrape",48},49"scrape_samples_post_metric_relabeling": {50Metric: "scrape_samples_post_metric_relabeling",51Type: textparse.MetricTypeGauge,52Help: "The number of samples remaining after metric relabeling was applied",53},54}5556func metadataForMetric(metricName string, mc scrape.MetricMetadataStore) (*scrape.MetricMetadata, string) {57if metadata, ok := internalMetricMetadata[metricName]; ok {58return metadata, metricName59}60if metadata, ok := mc.GetMetadata(metricName); ok {61return &metadata, metricName62}63// If we didn't find metadata with the original name,64// try with suffixes trimmed, in-case it is a "merged" metric type.65normalizedName := normalizeMetricName(metricName)66if metadata, ok := mc.GetMetadata(normalizedName); ok {67if metadata.Type == textparse.MetricTypeCounter {68return &metadata, metricName69}70return &metadata, normalizedName71}72// Otherwise, the metric is unknown73return &scrape.MetricMetadata{74Metric: metricName,75Type: textparse.MetricTypeUnknown,76}, metricName77}787980