From fd6f7173eb8d297e93470c686bde5d1072762575 Mon Sep 17 00:00:00 2001 From: BominRahmani Date: Wed, 10 May 2023 17:02:04 -0400 Subject: [PATCH 1/2] [chore][receiver/prometheus] create metadata --- receiver/prometheusreceiver/README.md | 18 +++++----- receiver/prometheusreceiver/config_test.go | 36 ++++++++++--------- receiver/prometheusreceiver/doc.go | 2 ++ receiver/prometheusreceiver/factory.go | 12 +++---- receiver/prometheusreceiver/factory_test.go | 4 ++- .../internal/metadata/generated_status.go | 12 +++++++ receiver/prometheusreceiver/metadata.yaml | 8 +++++ 7 files changed, 58 insertions(+), 34 deletions(-) create mode 100644 receiver/prometheusreceiver/internal/metadata/generated_status.go create mode 100644 receiver/prometheusreceiver/metadata.yaml diff --git a/receiver/prometheusreceiver/README.md b/receiver/prometheusreceiver/README.md index bbd3111260d9..03e83a3ca0ab 100644 --- a/receiver/prometheusreceiver/README.md +++ b/receiver/prometheusreceiver/README.md @@ -1,10 +1,15 @@ # Prometheus Receiver -| Status | | -| ------------------------ |-------------------| -| Stability | [beta] | -| Supported pipeline types | metrics | -| Distributions | [core], [contrib] | + +| Status | | +| ------------- |-----------| +| Stability | [beta]: metrics | +| Distributions | [core], [contrib] | + +[beta]: https://github.com/open-telemetry/opentelemetry-collector#beta +[core]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol +[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib + Receives metric data in [Prometheus](https://prometheus.io/) format. See the [Design](DESIGN.md) for additional information on this receiver. @@ -113,6 +118,3 @@ This receiver accepts exemplars coming in Prometheus format and converts it to O [sc]: https://github.com/prometheus/prometheus/blob/v2.28.1/docs/configuration/configuration.md#scrape_config -[beta]: https://github.com/open-telemetry/opentelemetry-collector#beta -[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib -[core]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol \ No newline at end of file diff --git a/receiver/prometheusreceiver/config_test.go b/receiver/prometheusreceiver/config_test.go index 75d2d69cfa1d..9ab52513fae7 100644 --- a/receiver/prometheusreceiver/config_test.go +++ b/receiver/prometheusreceiver/config_test.go @@ -26,6 +26,8 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap/confmaptest" + + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver/internal/metadata" ) func TestLoadConfig(t *testing.T) { @@ -34,14 +36,14 @@ func TestLoadConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - sub, err := cm.Sub(component.NewIDWithName(typeStr, "").String()) + sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) require.NoError(t, err) require.NoError(t, component.UnmarshalConfig(sub, cfg)) r0 := cfg.(*Config) assert.Equal(t, r0, factory.CreateDefaultConfig()) - sub, err = cm.Sub(component.NewIDWithName(typeStr, "customname").String()) + sub, err = cm.Sub(component.NewIDWithName(metadata.Type, "customname").String()) require.NoError(t, err) require.NoError(t, component.UnmarshalConfig(sub, cfg)) @@ -65,7 +67,7 @@ func TestLoadTargetAllocatorConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - sub, err := cm.Sub(component.NewIDWithName(typeStr, "").String()) + sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) require.NoError(t, err) require.NoError(t, component.UnmarshalConfig(sub, cfg)) @@ -75,7 +77,7 @@ func TestLoadTargetAllocatorConfig(t *testing.T) { assert.Equal(t, 30*time.Second, r0.TargetAllocator.Interval) assert.Equal(t, "collector-1", r0.TargetAllocator.CollectorID) - sub, err = cm.Sub(component.NewIDWithName(typeStr, "withScrape").String()) + sub, err = cm.Sub(component.NewIDWithName(metadata.Type, "withScrape").String()) require.NoError(t, err) cfg = factory.CreateDefaultConfig() require.NoError(t, component.UnmarshalConfig(sub, cfg)) @@ -90,7 +92,7 @@ func TestLoadTargetAllocatorConfig(t *testing.T) { assert.Equal(t, "demo", r1.PrometheusConfig.ScrapeConfigs[0].JobName) assert.Equal(t, promModel.Duration(5*time.Second), r1.PrometheusConfig.ScrapeConfigs[0].ScrapeInterval) - sub, err = cm.Sub(component.NewIDWithName(typeStr, "withOnlyScrape").String()) + sub, err = cm.Sub(component.NewIDWithName(metadata.Type, "withOnlyScrape").String()) require.NoError(t, err) cfg = factory.CreateDefaultConfig() require.NoError(t, component.UnmarshalConfig(sub, cfg)) @@ -107,7 +109,7 @@ func TestLoadConfigFailsOnUnknownSection(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - sub, err := cm.Sub(component.NewIDWithName(typeStr, "").String()) + sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) require.NoError(t, err) require.Error(t, component.UnmarshalConfig(sub, cfg)) } @@ -121,7 +123,7 @@ func TestLoadConfigFailsOnUnknownPrometheusSection(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - sub, err := cm.Sub(component.NewIDWithName(typeStr, "").String()) + sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) require.NoError(t, err) require.Error(t, component.UnmarshalConfig(sub, cfg)) } @@ -133,7 +135,7 @@ func TestLoadConfigFailsOnRenameDisallowed(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - sub, err := cm.Sub(component.NewIDWithName(typeStr, "").String()) + sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) require.NoError(t, err) require.NoError(t, component.UnmarshalConfig(sub, cfg)) assert.Error(t, component.ValidateConfig(cfg)) @@ -146,7 +148,7 @@ func TestRejectUnsupportedPrometheusFeatures(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - sub, err := cm.Sub(component.NewIDWithName(typeStr, "").String()) + sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) require.NoError(t, err) require.NoError(t, component.UnmarshalConfig(sub, cfg)) @@ -171,7 +173,7 @@ func TestNonExistentAuthCredentialsFile(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - sub, err := cm.Sub(component.NewIDWithName(typeStr, "").String()) + sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) require.NoError(t, err) require.NoError(t, component.UnmarshalConfig(sub, cfg)) @@ -190,7 +192,7 @@ func TestTLSConfigNonExistentCertFile(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - sub, err := cm.Sub(component.NewIDWithName(typeStr, "").String()) + sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) require.NoError(t, err) require.NoError(t, component.UnmarshalConfig(sub, cfg)) @@ -209,7 +211,7 @@ func TestTLSConfigNonExistentKeyFile(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - sub, err := cm.Sub(component.NewIDWithName(typeStr, "").String()) + sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) require.NoError(t, err) require.NoError(t, component.UnmarshalConfig(sub, cfg)) @@ -228,7 +230,7 @@ func TestTLSConfigCertFileWithoutKeyFile(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - sub, err := cm.Sub(component.NewIDWithName(typeStr, "").String()) + sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) require.NoError(t, err) require.NoError(t, component.UnmarshalConfig(sub, cfg)) @@ -247,7 +249,7 @@ func TestTLSConfigKeyFileWithoutCertFile(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - sub, err := cm.Sub(component.NewIDWithName(typeStr, "").String()) + sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) require.NoError(t, err) require.NoError(t, component.UnmarshalConfig(sub, cfg)) @@ -266,7 +268,7 @@ func TestKubernetesSDConfigWithoutKeyFile(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - sub, err := cm.Sub(component.NewIDWithName(typeStr, "").String()) + sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) require.NoError(t, err) require.NoError(t, component.UnmarshalConfig(sub, cfg)) @@ -285,7 +287,7 @@ func TestFileSDConfigJsonNilTargetGroup(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - sub, err := cm.Sub(component.NewIDWithName(typeStr, "").String()) + sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) require.NoError(t, err) require.NoError(t, component.UnmarshalConfig(sub, cfg)) @@ -304,7 +306,7 @@ func TestFileSDConfigYamlNilTargetGroup(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - sub, err := cm.Sub(component.NewIDWithName(typeStr, "").String()) + sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) require.NoError(t, err) require.NoError(t, component.UnmarshalConfig(sub, cfg)) diff --git a/receiver/prometheusreceiver/doc.go b/receiver/prometheusreceiver/doc.go index ba754aef807e..b2d4b8bbc757 100644 --- a/receiver/prometheusreceiver/doc.go +++ b/receiver/prometheusreceiver/doc.go @@ -12,5 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:generate mdatagen metadata.yaml + // Package prometheusreceiver autodiscovers and scrapes Prometheus metrics handlers, often served at /metrics. package prometheusreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver" diff --git a/receiver/prometheusreceiver/factory.go b/receiver/prometheusreceiver/factory.go index ed96a18d19a2..ac792b50a9b3 100644 --- a/receiver/prometheusreceiver/factory.go +++ b/receiver/prometheusreceiver/factory.go @@ -24,15 +24,11 @@ import ( "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/receiver" -) - -// This file implements config for Prometheus receiver. -const ( - typeStr = "prometheus" - stability = component.StabilityLevelBeta + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver/internal/metadata" ) +// This file implements config for Prometheus receiver. var useCreatedMetricGate = featuregate.GlobalRegistry().MustRegister( "receiver.prometheusreceiver.UseCreatedMetric", featuregate.StageAlpha, @@ -45,9 +41,9 @@ var errRenamingDisallowed = errors.New("metric renaming using metric_relabel_con // NewFactory creates a new Prometheus receiver factory. func NewFactory() receiver.Factory { return receiver.NewFactory( - typeStr, + metadata.Type, createDefaultConfig, - receiver.WithMetrics(createMetricsReceiver, stability)) + receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability)) } func createDefaultConfig() component.Config { diff --git a/receiver/prometheusreceiver/factory_test.go b/receiver/prometheusreceiver/factory_test.go index f140af699ffd..84c995749c44 100644 --- a/receiver/prometheusreceiver/factory_test.go +++ b/receiver/prometheusreceiver/factory_test.go @@ -25,6 +25,8 @@ import ( "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/receiver/receivertest" + + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver/internal/metadata" ) func TestCreateDefaultConfig(t *testing.T) { @@ -50,7 +52,7 @@ func TestFactoryCanParseServiceDiscoveryConfigs(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() - sub, err := cm.Sub(component.NewIDWithName(typeStr, "").String()) + sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) require.NoError(t, err) assert.NoError(t, component.UnmarshalConfig(sub, cfg)) } diff --git a/receiver/prometheusreceiver/internal/metadata/generated_status.go b/receiver/prometheusreceiver/internal/metadata/generated_status.go new file mode 100644 index 000000000000..793e897d7681 --- /dev/null +++ b/receiver/prometheusreceiver/internal/metadata/generated_status.go @@ -0,0 +1,12 @@ +// Code generated by mdatagen. DO NOT EDIT. + +package metadata + +import ( + "go.opentelemetry.io/collector/component" +) + +const ( + Type = "prometheus" + MetricsStability = component.StabilityLevelBeta +) diff --git a/receiver/prometheusreceiver/metadata.yaml b/receiver/prometheusreceiver/metadata.yaml new file mode 100644 index 000000000000..c91f57b68fc2 --- /dev/null +++ b/receiver/prometheusreceiver/metadata.yaml @@ -0,0 +1,8 @@ +type: prometheus + +status: + class: receiver + stability: + beta: [metrics] + distributions: [core, contrib] + From 773c820a08505511df2b3b3471d26251281af2dd Mon Sep 17 00:00:00 2001 From: BominRahmani Date: Fri, 12 May 2023 10:01:35 -0400 Subject: [PATCH 2/2] trigger ci