metadata.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver/internal"
  4. import (
  5. "github.com/prometheus/prometheus/model/textparse"
  6. "github.com/prometheus/prometheus/scrape"
  7. )
  8. type dataPoint struct {
  9. value float64
  10. boundary float64
  11. }
  12. // internalMetricMetadata allows looking up metadata for internal scrape metrics
  13. var internalMetricMetadata = map[string]*scrape.MetricMetadata{
  14. scrapeUpMetricName: {
  15. Metric: scrapeUpMetricName,
  16. Type: textparse.MetricTypeGauge,
  17. Help: "The scraping was successful",
  18. },
  19. "scrape_duration_seconds": {
  20. Metric: "scrape_duration_seconds",
  21. Unit: "seconds",
  22. Type: textparse.MetricTypeGauge,
  23. Help: "Duration of the scrape",
  24. },
  25. "scrape_samples_scraped": {
  26. Metric: "scrape_samples_scraped",
  27. Type: textparse.MetricTypeGauge,
  28. Help: "The number of samples the target exposed",
  29. },
  30. "scrape_series_added": {
  31. Metric: "scrape_series_added",
  32. Type: textparse.MetricTypeGauge,
  33. Help: "The approximate number of new series in this scrape",
  34. },
  35. "scrape_samples_post_metric_relabeling": {
  36. Metric: "scrape_samples_post_metric_relabeling",
  37. Type: textparse.MetricTypeGauge,
  38. Help: "The number of samples remaining after metric relabeling was applied",
  39. },
  40. }
  41. func metadataForMetric(metricName string, mc scrape.MetricMetadataStore) (*scrape.MetricMetadata, string) {
  42. if metadata, ok := internalMetricMetadata[metricName]; ok {
  43. return metadata, metricName
  44. }
  45. if metadata, ok := mc.GetMetadata(metricName); ok {
  46. return &metadata, metricName
  47. }
  48. // If we didn't find metadata with the original name,
  49. // try with suffixes trimmed, in-case it is a "merged" metric type.
  50. normalizedName := normalizeMetricName(metricName)
  51. if metadata, ok := mc.GetMetadata(normalizedName); ok {
  52. if metadata.Type == textparse.MetricTypeCounter {
  53. return &metadata, metricName
  54. }
  55. return &metadata, normalizedName
  56. }
  57. // Otherwise, the metric is unknown
  58. return &scrape.MetricMetadata{
  59. Metric: metricName,
  60. Type: textparse.MetricTypeUnknown,
  61. }, metricName
  62. }