From 3f5370e4d1570a099efd64d9c7012a5d36309e5d Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Tue, 16 May 2023 21:54:40 -0700 Subject: [PATCH] [chore] use metadata.Type with nsxtreceiver (#21992) --- receiver/nsxtreceiver/config_test.go | 4 +++- receiver/nsxtreceiver/documentation.md | 2 +- receiver/nsxtreceiver/factory.go | 8 ++------ receiver/nsxtreceiver/factory_test.go | 4 +++- .../nsxtreceiver/internal/metadata/generated_config.go | 6 +++--- .../nsxtreceiver/internal/metadata/generated_status.go | 2 +- receiver/nsxtreceiver/metadata.yaml | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/receiver/nsxtreceiver/config_test.go b/receiver/nsxtreceiver/config_test.go index 49b7743f46a3..fc5c6a40ff94 100644 --- a/receiver/nsxtreceiver/config_test.go +++ b/receiver/nsxtreceiver/config_test.go @@ -24,6 +24,8 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/confmap/confmaptest" + + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/nsxtreceiver/internal/metadata" ) func TestMetricValidation(t *testing.T) { @@ -96,7 +98,7 @@ 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)) diff --git a/receiver/nsxtreceiver/documentation.md b/receiver/nsxtreceiver/documentation.md index e864f6720bf9..99b2f5b5a57d 100644 --- a/receiver/nsxtreceiver/documentation.md +++ b/receiver/nsxtreceiver/documentation.md @@ -1,6 +1,6 @@ [comment]: <> (Code generated by mdatagen. DO NOT EDIT.) -# nsxtreceiver +# nsxt ## Default Metrics diff --git a/receiver/nsxtreceiver/factory.go b/receiver/nsxtreceiver/factory.go index 0ee4fc3ce820..056175b9e101 100644 --- a/receiver/nsxtreceiver/factory.go +++ b/receiver/nsxtreceiver/factory.go @@ -27,16 +27,12 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/nsxtreceiver/internal/metadata" ) -const ( - typeStr = "nsxt" -) - var errConfigNotNSX = errors.New("config was not a NSX receiver config") // NewFactory creates a new receiver factory func NewFactory() receiver.Factory { return receiver.NewFactory( - typeStr, + metadata.Type, createDefaultConfig, receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability), ) @@ -59,7 +55,7 @@ func createMetricsReceiver(ctx context.Context, params receiver.CreateSettings, s := newScraper(cfg, params) scraper, err := scraperhelper.NewScraper( - typeStr, + metadata.Type, s.scrape, scraperhelper.WithStart(s.start), ) diff --git a/receiver/nsxtreceiver/factory_test.go b/receiver/nsxtreceiver/factory_test.go index 6183e06f8172..3deff18cd0b1 100644 --- a/receiver/nsxtreceiver/factory_test.go +++ b/receiver/nsxtreceiver/factory_test.go @@ -24,12 +24,14 @@ import ( "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/receiver/receivertest" "go.opentelemetry.io/collector/receiver/scraperhelper" + + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/nsxtreceiver/internal/metadata" ) func TestType(t *testing.T) { factory := NewFactory() ft := factory.Type() - require.EqualValues(t, typeStr, ft) + require.EqualValues(t, metadata.Type, ft) } func TestDefaultConfig(t *testing.T) { diff --git a/receiver/nsxtreceiver/internal/metadata/generated_config.go b/receiver/nsxtreceiver/internal/metadata/generated_config.go index 3306d2d0f231..1f0fe8fe234c 100644 --- a/receiver/nsxtreceiver/internal/metadata/generated_config.go +++ b/receiver/nsxtreceiver/internal/metadata/generated_config.go @@ -23,7 +23,7 @@ func (ms *MetricConfig) Unmarshal(parser *confmap.Conf) error { return nil } -// MetricsConfig provides config for nsxtreceiver metrics. +// MetricsConfig provides config for nsxt metrics. type MetricsConfig struct { NsxtNodeCPUUtilization MetricConfig `mapstructure:"nsxt.node.cpu.utilization"` NsxtNodeFilesystemUsage MetricConfig `mapstructure:"nsxt.node.filesystem.usage"` @@ -65,7 +65,7 @@ type ResourceAttributeConfig struct { Enabled bool `mapstructure:"enabled"` } -// ResourceAttributesConfig provides config for nsxtreceiver resource attributes. +// ResourceAttributesConfig provides config for nsxt resource attributes. type ResourceAttributesConfig struct { DeviceID ResourceAttributeConfig `mapstructure:"device.id"` NsxtNodeID ResourceAttributeConfig `mapstructure:"nsxt.node.id"` @@ -90,7 +90,7 @@ func DefaultResourceAttributesConfig() ResourceAttributesConfig { } } -// MetricsBuilderConfig is a configuration for nsxtreceiver metrics builder. +// MetricsBuilderConfig is a configuration for nsxt metrics builder. type MetricsBuilderConfig struct { Metrics MetricsConfig `mapstructure:"metrics"` ResourceAttributes ResourceAttributesConfig `mapstructure:"resource_attributes"` diff --git a/receiver/nsxtreceiver/internal/metadata/generated_status.go b/receiver/nsxtreceiver/internal/metadata/generated_status.go index 024d061d8c45..55bcfbc8bafa 100644 --- a/receiver/nsxtreceiver/internal/metadata/generated_status.go +++ b/receiver/nsxtreceiver/internal/metadata/generated_status.go @@ -7,6 +7,6 @@ import ( ) const ( - Type = "nsxtreceiver" + Type = "nsxt" MetricsStability = component.StabilityLevelAlpha ) diff --git a/receiver/nsxtreceiver/metadata.yaml b/receiver/nsxtreceiver/metadata.yaml index ed2422b6cd72..ae9be5fd3462 100644 --- a/receiver/nsxtreceiver/metadata.yaml +++ b/receiver/nsxtreceiver/metadata.yaml @@ -1,4 +1,4 @@ -type: nsxtreceiver +type: nsxt status: class: receiver