From 26c157e3bffb60210a3f65f218ed51be1809ca0a Mon Sep 17 00:00:00 2001 From: Pablo Baeyens Date: Fri, 2 Feb 2024 16:33:03 +0000 Subject: [PATCH] [component] Add MustNewType constructor for component.Type (#9414) **Description:** - Adds `component.MustNewType` to create a type. This function panics if the type has invalid characters. Add similar functions `component.MustNewID` and `component.MustNewIDWithName`. - Adds `component.Type.String` to recover the string - Use `component.MustNewType`, `component.MustNewID`, `component.MustNewIDWithName` and `component.Type.String` everywhere in this codebase. To do this I changed `component.Type` into an opaque struct and checked for compile-time errors. Some notes: 1. All components currently on core and contrib follow this rule. This is still breaking for other components. 2. A future PR will change this into a struct, to actually validate this (right now you can just do `component.Type("anything")` to bypass validation). I want to do this in two steps to avoid breaking contrib tests: we first introduce this function, and after that we change into a struct. **Link to tracking Issue:** Updates #9208 --- .../mx-psi_component-type-validation.yaml | 26 + .../internal/metadata/generated_status.go | 5 +- cmd/mdatagen/main_test.go | 10 +- cmd/mdatagen/templates/status.go.tmpl | 7 +- cmd/mdatagen/validate.go | 11 + component/componenttest/nop_host_test.go | 2 +- .../otelprometheuschecker_test.go | 8 +- component/config.go | 41 + component/config_test.go | 223 +++ component/identifiable.go | 33 +- component/identifiable_test.go | 9 +- config/configauth/configauth_test.go | 14 +- config/configgrpc/configgrpc_test.go | 41 +- config/confighttp/confighttp_test.go | 51 +- connector/connector_test.go | 65 +- connector/connectortest/connector.go | 9 +- connector/connectortest/connector_test.go | 4 +- .../internal/metadata/generated_status.go | 5 +- connector/logs_router_test.go | 8 +- connector/metrics_router_test.go | 8 +- connector/traces_router_test.go | 8 +- exporter/debugexporter/factory.go | 7 +- .../internal/metadata/generated_status.go | 5 +- exporter/exporter_test.go | 42 +- exporter/exporterhelper/common_test.go | 15 +- .../internal/persistent_queue.go | 2 +- .../internal/persistent_queue_test.go | 10 +- exporter/exporterhelper/logs_test.go | 6 +- exporter/exporterhelper/metrics_test.go | 6 +- exporter/exporterhelper/obsexporter_test.go | 2 +- exporter/exporterhelper/obsreport_test.go | 2 +- exporter/exporterhelper/queue_sender_test.go | 26 +- exporter/exporterhelper/retry_sender_test.go | 12 +- exporter/exporterhelper/traces_test.go | 6 +- .../exportertest/contract_checker_test.go | 4 +- exporter/exportertest/nop_exporter.go | 9 +- exporter/exportertest/nop_exporter_test.go | 4 +- exporter/loggingexporter/factory.go | 7 +- .../internal/metadata/generated_status.go | 5 +- exporter/otlpexporter/config_test.go | 2 +- .../internal/metadata/generated_status.go | 5 +- .../internal/metadata/generated_status.go | 5 +- .../internal/metadata/generated_status.go | 5 +- extension/extension_test.go | 30 +- extension/extensiontest/nop_extension.go | 9 +- extension/extensiontest/nop_extension_test.go | 4 +- .../extensiontest/statuswatcher_extension.go | 2 +- .../statuswatcher_extension_test.go | 2 +- .../internal/metadata/generated_status.go | 5 +- .../internal/metadata/generated_status.go | 5 +- internal/memorylimiter/memorylimiter_test.go | 2 +- .../sharedcomponent/sharedcomponent_test.go | 2 +- otelcol/command_components_test.go | 12 +- otelcol/config_test.go | 76 +- .../configunmarshaler/configs_test.go | 16 +- otelcol/otelcoltest/config_test.go | 28 +- otelcol/otelcoltest/nop_factories_test.go | 22 +- .../internal/metadata/generated_status.go | 5 +- processor/batchprocessor/metrics_test.go | 2 +- .../internal/metadata/generated_status.go | 5 +- .../memorylimiter_test.go | 2 +- processor/processor_test.go | 42 +- processor/processorhelper/obsreport_test.go | 2 +- processor/processortest/nop_processor.go | 9 +- processor/processortest/nop_processor_test.go | 4 +- .../processortest/unhealthy_processor.go | 2 +- .../processortest/unhealthy_processor_test.go | 2 +- .../otlpreceiver/internal/logs/otlp_test.go | 2 +- .../internal/metadata/generated_status.go | 5 +- .../internal/metrics/otlp_test.go | 2 +- .../otlpreceiver/internal/trace/otlp_test.go | 2 +- receiver/otlpreceiver/otlp_test.go | 2 +- receiver/receiver_test.go | 42 +- receiver/receiverhelper/obsreport_test.go | 2 +- .../receivertest/contract_checker_test.go | 2 +- receiver/receivertest/nop_receiver.go | 9 +- receiver/receivertest/nop_receiver_test.go | 6 +- receiver/scraperhelper/obsreport.go | 2 +- receiver/scraperhelper/obsreport_test.go | 4 +- receiver/scraperhelper/scraper.go | 2 +- .../scraperhelper/scrapercontroller_test.go | 8 +- receiver/scraperhelper/settings_test.go | 4 +- service/config_test.go | 20 +- service/extensions/extensions_test.go | 57 +- service/internal/components/loggers.go | 8 +- service/internal/graph/graph_test.go | 1433 +++++++++-------- service/internal/graph/nodes.go | 6 +- service/internal/graph/zpages.go | 2 +- .../testcomponents/example_connector.go | 4 +- .../testcomponents/example_exporter.go | 9 +- .../testcomponents/example_processor.go | 2 +- .../testcomponents/example_receiver.go | 2 +- .../internal/testcomponents/example_router.go | 2 +- .../testcomponents/example_router_test.go | 12 +- service/pipelines/config_test.go | 22 +- service/service_test.go | 73 +- 96 files changed, 1606 insertions(+), 1205 deletions(-) create mode 100755 .chloggen/mx-psi_component-type-validation.yaml diff --git a/.chloggen/mx-psi_component-type-validation.yaml b/.chloggen/mx-psi_component-type-validation.yaml new file mode 100755 index 00000000000..af38d42d60f --- /dev/null +++ b/.chloggen/mx-psi_component-type-validation.yaml @@ -0,0 +1,26 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: component + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Validate component.Type at creation and unmarshaling time. + +# One or more tracking issues or pull requests related to the change +issues: [9208] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: | + - A component.Type must start with an ASCII alphabetic character and can only contain ASCII alphanumeric characters and '_'. + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [api] diff --git a/cmd/mdatagen/internal/metadata/generated_status.go b/cmd/mdatagen/internal/metadata/generated_status.go index 02b54824865..773067ac829 100644 --- a/cmd/mdatagen/internal/metadata/generated_status.go +++ b/cmd/mdatagen/internal/metadata/generated_status.go @@ -9,8 +9,11 @@ import ( "go.opentelemetry.io/collector/component" ) +var ( + Type = component.MustNewType("file") +) + const ( - Type = "file" TracesStability = component.StabilityLevelBeta LogsStability = component.StabilityLevelDevelopment MetricsStability = component.StabilityLevelStable diff --git a/cmd/mdatagen/main_test.go b/cmd/mdatagen/main_test.go index 18d30eefcec..ce56247a78f 100644 --- a/cmd/mdatagen/main_test.go +++ b/cmd/mdatagen/main_test.go @@ -365,8 +365,11 @@ import ( "go.opentelemetry.io/otel/trace" ) +var ( + Type = component.MustNewType("foo") +) + const ( - Type = "foo" MetricsStability = component.StabilityLevelBeta ) @@ -399,8 +402,11 @@ import ( "go.opentelemetry.io/otel/trace" ) +var ( + Type = component.MustNewType("foo") +) + const ( - Type = "foo" MetricsStability = component.StabilityLevelAlpha ) diff --git a/cmd/mdatagen/templates/status.go.tmpl b/cmd/mdatagen/templates/status.go.tmpl index 654e6b1518a..850058b9cfa 100644 --- a/cmd/mdatagen/templates/status.go.tmpl +++ b/cmd/mdatagen/templates/status.go.tmpl @@ -8,8 +8,11 @@ import ( "go.opentelemetry.io/otel/trace" ) +var ( + Type = component.MustNewType("{{ .Type }}") +) + const ( - Type = "{{ .Type }}" {{- range $stability, $signals := .Status.Stability }} {{- range $signal := $signals }} {{ toCamelCase $signal }}Stability = component.StabilityLevel{{ casesTitle $stability }} @@ -23,4 +26,4 @@ func Meter(settings component.TelemetrySettings) metric.Meter { func Tracer(settings component.TelemetrySettings) trace.Tracer { return settings.TracerProvider.Tracer("{{ .ScopeName }}") -} \ No newline at end of file +} diff --git a/cmd/mdatagen/validate.go b/cmd/mdatagen/validate.go index aac3e3a6898..bc56375baf9 100644 --- a/cmd/mdatagen/validate.go +++ b/cmd/mdatagen/validate.go @@ -6,6 +6,7 @@ package main import ( "errors" "fmt" + "regexp" "go.uber.org/multierr" @@ -29,10 +30,20 @@ func (md *metadata) Validate() error { return errs } +// typeRegexp is used to validate the type of a component. +// A type must start with an ASCII alphabetic character and +// can only contain ASCII alphanumeric characters and '_'. +// This must be kept in sync with the regex in component/config.go. +var typeRegexp = regexp.MustCompile(`^[a-zA-Z][0-9a-zA-Z_]*$`) + func (md *metadata) validateType() error { if md.Type == "" { return errors.New("missing type") } + + if !typeRegexp.MatchString(md.Type) { + return fmt.Errorf("invalid character(s) in type %q", md.Type) + } return nil } diff --git a/component/componenttest/nop_host_test.go b/component/componenttest/nop_host_test.go index 1bcb92d1744..99d323681ca 100644 --- a/component/componenttest/nop_host_test.go +++ b/component/componenttest/nop_host_test.go @@ -21,5 +21,5 @@ func TestNewNopHost(t *testing.T) { nh.ReportFatalError(errors.New("TestError")) assert.Nil(t, nh.GetExporters()) // nolint: staticcheck assert.Nil(t, nh.GetExtensions()) - assert.Nil(t, nh.GetFactory(component.KindReceiver, "test")) + assert.Nil(t, nh.GetFactory(component.KindReceiver, component.MustNewType("test"))) } diff --git a/component/componenttest/otelprometheuschecker_test.go b/component/componenttest/otelprometheuschecker_test.go index 159122547bc..d7176134f54 100644 --- a/component/componenttest/otelprometheuschecker_test.go +++ b/component/componenttest/otelprometheuschecker_test.go @@ -36,10 +36,10 @@ func TestPromChecker(t *testing.T) { pc, err := newStubPromChecker() require.NoError(t, err) - scraper := component.NewID("fakeScraper") - receiver := component.NewID("fakeReceiver") - processor := component.NewID("fakeProcessor") - exporter := component.NewID("fakeExporter") + scraper := component.MustNewID("fakeScraper") + receiver := component.MustNewID("fakeReceiver") + processor := component.MustNewID("fakeProcessor") + exporter := component.MustNewID("fakeExporter") transport := "fakeTransport" assert.NoError(t, diff --git a/component/config.go b/component/config.go index f34f04b8db7..f54b3a176c2 100644 --- a/component/config.go +++ b/component/config.go @@ -4,7 +4,9 @@ package component // import "go.opentelemetry.io/collector/component" import ( + "fmt" "reflect" + "regexp" "go.uber.org/multierr" @@ -110,6 +112,45 @@ func callValidateIfPossible(v reflect.Value) error { // Type is the component type as it is used in the config. type Type string +// String returns the string representation of the type. +func (t Type) String() string { + return string(t) +} + +// typeRegexp is used to validate the type of a component. +// A type must start with an ASCII alphabetic character and +// can only contain ASCII alphanumeric characters and '_'. +// This must be kept in sync with the regex in cmd/mdatagen/validate.go. +var typeRegexp = regexp.MustCompile(`^[a-zA-Z][0-9a-zA-Z_]*$`) + +// NewType creates a type. It returns an error if the type is invalid. +// A type must +// - have at least one character, +// - start with an ASCII alphabetic character and +// - can only contain ASCII alphanumeric characters and '_'. +func NewType(ty string) (Type, error) { + if len(ty) == 0 { + return Type(""), fmt.Errorf("id must not be empty") + } + if !typeRegexp.MatchString(ty) { + return Type(""), fmt.Errorf("invalid character(s) in type %q", ty) + } + return Type(ty), nil +} + +// MustNewType creates a type. It panics if the type is invalid. +// A type must +// - have at least one character, +// - start with an ASCII alphabetic character and +// - can only contain ASCII alphanumeric characters and '_'. +func MustNewType(strType string) Type { + ty, err := NewType(strType) + if err != nil { + panic(err) + } + return ty +} + // DataType is a special Type that represents the data types supported by the collector. We currently support // collecting metrics, traces and logs, this can expand in the future. type DataType = Type diff --git a/component/config_test.go b/component/config_test.go index b42328678ea..fcddc343d20 100644 --- a/component/config_test.go +++ b/component/config_test.go @@ -5,12 +5,16 @@ package component import ( "errors" + "fmt" "reflect" "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) +var _ fmt.Stringer = (Type)("") + type configChildStruct struct { Child errConfig ChildPtr *errConfig @@ -194,3 +198,222 @@ func TestValidateConfig(t *testing.T) { }) } } + +func TestNewType(t *testing.T) { + tests := []struct { + name string + shouldErr bool + }{ + {name: "active_directory_ds"}, + {name: "aerospike"}, + {name: "alertmanager"}, + {name: "alibabacloud_logservice"}, + {name: "apache"}, + {name: "apachespark"}, + {name: "asapclient"}, + {name: "attributes"}, + {name: "awscloudwatch"}, + {name: "awscloudwatchlogs"}, + {name: "awscloudwatchmetrics"}, + {name: "awscontainerinsightreceiver"}, + {name: "awsecscontainermetrics"}, + {name: "awsemf"}, + {name: "awsfirehose"}, + {name: "awskinesis"}, + {name: "awsproxy"}, + {name: "awss3"}, + {name: "awsxray"}, + {name: "azureblob"}, + {name: "azuredataexplorer"}, + {name: "azureeventhub"}, + {name: "azuremonitor"}, + {name: "basicauth"}, + {name: "batch"}, + {name: "bearertokenauth"}, + {name: "bigip"}, + {name: "carbon"}, + {name: "cassandra"}, + {name: "chrony"}, + {name: "clickhouse"}, + {name: "cloudflare"}, + {name: "cloudfoundry"}, + {name: "collectd"}, + {name: "configschema"}, + {name: "coralogix"}, + {name: "couchdb"}, + {name: "count"}, + {name: "cumulativetodelta"}, + {name: "datadog"}, + {name: "dataset"}, + {name: "db_storage"}, + {name: "debug"}, + {name: "deltatorate"}, + {name: "demo"}, + {name: "docker_observer"}, + {name: "docker_stats"}, + {name: "dynatrace"}, + {name: "ecs_observer"}, + {name: "ecs_task_observer"}, + {name: "elasticsearch"}, + {name: "exceptions"}, + {name: "experimental_metricsgeneration"}, + {name: "expvar"}, + {name: "f5cloud"}, + {name: "failover"}, + {name: "file"}, + {name: "filelog"}, + {name: "filestats"}, + {name: "file_storage"}, + {name: "filter"}, + {name: "flinkmetrics"}, + {name: "fluentforward"}, + {name: "forward"}, + {name: "githubgen"}, + {name: "gitprovider"}, + {name: "golden"}, + {name: "googlecloud"}, + {name: "googlecloudpubsub"}, + {name: "googlecloudspanner"}, + {name: "googlemanagedprometheus"}, + {name: "groupbyattrs"}, + {name: "groupbytrace"}, + {name: "haproxy"}, + {name: "headers_setter"}, + {name: "health_check"}, + {name: "honeycombmarker"}, + {name: "hostmetrics"}, + {name: "host_observer"}, + {name: "httpcheck"}, + {name: "http_forwarder"}, + {name: "iis"}, + {name: "influxdb"}, + {name: "instana"}, + {name: "interval"}, + {name: "jaeger"}, + {name: "jaeger_encoding"}, + {name: "jaegerremotesampling"}, + {name: "jmx"}, + {name: "journald"}, + {name: "json_log_encoding"}, + {name: "k8sattributes"}, + {name: "k8s_cluster"}, + {name: "k8s_events"}, + {name: "k8sobjects"}, + {name: "k8s_observer"}, + {name: "kafka"}, + {name: "kafkametrics"}, + {name: "kinetica"}, + {name: "kubeletstats"}, + {name: "loadbalancing"}, + {name: "logging"}, + {name: "logicmonitor"}, + {name: "logstransform"}, + {name: "logzio"}, + {name: "loki"}, + {name: "mdatagen"}, + {name: "memcached"}, + {name: "memory_ballast"}, + {name: "memory_limiter"}, + {name: "metricstransform"}, + {name: "mezmo"}, + {name: "mongodb"}, + {name: "mongodbatlas"}, + {name: "mysql"}, + {name: "namedpipe"}, + {name: "nginx"}, + {name: "nsxt"}, + {name: "oauth2client"}, + {name: "oidc"}, + {name: "opamp"}, + {name: "opampsupervisor"}, + {name: "opencensus"}, + {name: "opensearch"}, + {name: "oracledb"}, + {name: "osquery"}, + {name: "otelarrow"}, + {name: "otelcontribcol"}, + {name: "oteltestbedcol"}, + {name: "otlp"}, + {name: "otlp_encoding"}, + {name: "otlphttp"}, + {name: "otlpjsonfile"}, + {name: "ottl"}, + {name: "podman_stats"}, + {name: "postgresql"}, + {name: "pprof"}, + {name: "probabilistic_sampler"}, + {name: "prometheus"}, + {name: "prometheusremotewrite"}, + {name: "prometheus_simple"}, + {name: "pulsar"}, + {name: "purefa"}, + {name: "purefb"}, + {name: "rabbitmq"}, + {name: "receiver_creator"}, + {name: "redaction"}, + {name: "redis"}, + {name: "remotetap"}, + {name: "resource"}, + {name: "resourcedetection"}, + {name: "riak"}, + {name: "routing"}, + {name: "saphana"}, + {name: "sapm"}, + {name: "schema"}, + {name: "sentry"}, + {name: "servicegraph"}, + {name: "signalfx"}, + {name: "sigv4auth"}, + {name: "skywalking"}, + {name: "snmp"}, + {name: "snowflake"}, + {name: "solace"}, + {name: "solarwindsapmsettings"}, + {name: "span"}, + {name: "spanmetrics"}, + {name: "splunkenterprise"}, + {name: "splunk_hec"}, + {name: "sqlquery"}, + {name: "sqlserver"}, + {name: "sshcheck"}, + {name: "statsd"}, + {name: "sumologic"}, + {name: "syslog"}, + {name: "tail_sampling"}, + {name: "tcplog"}, + {name: "telemetrygen"}, + {name: "tencentcloud_logservice"}, + {name: "text_encoding"}, + {name: "transform"}, + {name: "udplog"}, + {name: "vcenter"}, + {name: "wavefront"}, + {name: "webhookevent"}, + {name: "windowseventlog"}, + {name: "windowsperfcounters"}, + {name: "zipkin"}, + {name: "zipkin_encoding"}, + {name: "zookeeper"}, + {name: "zpages"}, + + {name: "", shouldErr: true}, + {name: "contains spaces", shouldErr: true}, + {name: "contains-dashes", shouldErr: true}, + {name: "0startswithnumber", shouldErr: true}, + {name: "contains/slash", shouldErr: true}, + {name: "contains:colon", shouldErr: true}, + {name: "contains#hash", shouldErr: true}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ty, err := NewType(tt.name) + if tt.shouldErr { + assert.Error(t, err) + } else { + require.NoError(t, err) + assert.Equal(t, tt.name, ty.String()) + } + }) + } +} diff --git a/component/identifiable.go b/component/identifiable.go index 331c348fe59..d2d65a5e24f 100644 --- a/component/identifiable.go +++ b/component/identifiable.go @@ -26,11 +26,23 @@ func NewID(typeVal Type) ID { return ID{typeVal: typeVal} } +// MustNewID builds a Type and returns a new ID with the given Type and empty name. +// See MustNewType to check the valid values of typeVal. +func MustNewID(typeVal string) ID { + return ID{typeVal: MustNewType(typeVal)} +} + // NewIDWithName returns a new ID with the given Type and name. func NewIDWithName(typeVal Type, nameVal string) ID { return ID{typeVal: typeVal, nameVal: nameVal} } +// MustNewIDWithName builds a Type and returns a new ID with the given Type and name. +// See MustNewType to check the valid values of typeVal. +func MustNewIDWithName(typeVal string, nameVal string) ID { + return ID{typeVal: MustNewType(typeVal), nameVal: nameVal} +} + // Type returns the type of the component. func (id ID) Type() Type { return id.typeVal @@ -51,34 +63,41 @@ func (id ID) MarshalText() (text []byte, err error) { func (id *ID) UnmarshalText(text []byte) error { idStr := string(text) items := strings.SplitN(idStr, typeAndNameSeparator, 2) + var typeStr, nameStr string if len(items) >= 1 { - id.typeVal = Type(strings.TrimSpace(items[0])) + typeStr = strings.TrimSpace(items[0]) } - if len(items) == 1 && id.typeVal == "" { + if len(items) == 1 && typeStr == "" { return errors.New("id must not be empty") } - if id.typeVal == "" { + if typeStr == "" { return fmt.Errorf("in %q id: the part before %s should not be empty", idStr, typeAndNameSeparator) } if len(items) > 1 { // "name" part is present. - id.nameVal = strings.TrimSpace(items[1]) - if id.nameVal == "" { + nameStr = strings.TrimSpace(items[1]) + if nameStr == "" { return fmt.Errorf("in %q id: the part after %s should not be empty", idStr, typeAndNameSeparator) } } + var err error + if id.typeVal, err = NewType(typeStr); err != nil { + return fmt.Errorf("in %q id: %w", idStr, err) + } + id.nameVal = nameStr + return nil } // String returns the ID string representation as "type[/name]" format. func (id ID) String() string { if id.nameVal == "" { - return string(id.typeVal) + return id.typeVal.String() } - return string(id.typeVal) + typeAndNameSeparator + id.nameVal + return id.typeVal.String() + typeAndNameSeparator + id.nameVal } diff --git a/component/identifiable_test.go b/component/identifiable_test.go index 6b55375adc3..25c449ef11c 100644 --- a/component/identifiable_test.go +++ b/component/identifiable_test.go @@ -10,13 +10,14 @@ import ( ) func TestMarshalText(t *testing.T) { - id := NewIDWithName("test", "name") + id := NewIDWithName(MustNewType("test"), "name") got, err := id.MarshalText() assert.NoError(t, err) assert.Equal(t, id.String(), string(got)) } func TestUnmarshalText(t *testing.T) { + validType := MustNewType("valid_type") var testCases = []struct { idStr string expectedErr bool @@ -24,15 +25,15 @@ func TestUnmarshalText(t *testing.T) { }{ { idStr: "valid_type", - expectedID: ID{typeVal: "valid_type", nameVal: ""}, + expectedID: ID{typeVal: validType, nameVal: ""}, }, { idStr: "valid_type/valid_name", - expectedID: ID{typeVal: "valid_type", nameVal: "valid_name"}, + expectedID: ID{typeVal: validType, nameVal: "valid_name"}, }, { idStr: " valid_type / valid_name ", - expectedID: ID{typeVal: "valid_type", nameVal: "valid_name"}, + expectedID: ID{typeVal: validType, nameVal: "valid_name"}, }, { idStr: "/valid_name", diff --git a/config/configauth/configauth_test.go b/config/configauth/configauth_test.go index 19497c2e7c5..43c84ceb497 100644 --- a/config/configauth/configauth_test.go +++ b/config/configauth/configauth_test.go @@ -13,6 +13,8 @@ import ( "go.opentelemetry.io/collector/extension/auth" ) +var mockID = component.MustNewID("mock") + func TestGetServer(t *testing.T) { testCases := []struct { desc string @@ -34,10 +36,10 @@ func TestGetServer(t *testing.T) { t.Run(tC.desc, func(t *testing.T) { // prepare cfg := &Authentication{ - AuthenticatorID: component.NewID("mock"), + AuthenticatorID: mockID, } ext := map[component.ID]component.Component{ - component.NewID("mock"): tC.authenticator, + mockID: tC.authenticator, } authenticator, err := cfg.GetServerAuthenticator(ext) @@ -56,7 +58,7 @@ func TestGetServer(t *testing.T) { func TestGetServerFails(t *testing.T) { cfg := &Authentication{ - AuthenticatorID: component.NewID("does-not-exist"), + AuthenticatorID: component.MustNewID("does_not_exist"), } authenticator, err := cfg.GetServerAuthenticator(map[component.ID]component.Component{}) @@ -85,10 +87,10 @@ func TestGetClient(t *testing.T) { t.Run(tC.desc, func(t *testing.T) { // prepare cfg := &Authentication{ - AuthenticatorID: component.NewID("mock"), + AuthenticatorID: mockID, } ext := map[component.ID]component.Component{ - component.NewID("mock"): tC.authenticator, + mockID: tC.authenticator, } authenticator, err := cfg.GetClientAuthenticator(ext) @@ -107,7 +109,7 @@ func TestGetClient(t *testing.T) { func TestGetClientFails(t *testing.T) { cfg := &Authentication{ - AuthenticatorID: component.NewID("does-not-exist"), + AuthenticatorID: component.MustNewID("does_not_exist"), } authenticator, err := cfg.GetClientAuthenticator(map[component.ID]component.Component{}) assert.ErrorIs(t, err, errAuthenticatorNotFound) diff --git a/config/configgrpc/configgrpc_test.go b/config/configgrpc/configgrpc_test.go index b70b9017cd3..3edbcaf141c 100644 --- a/config/configgrpc/configgrpc_test.go +++ b/config/configgrpc/configgrpc_test.go @@ -50,8 +50,15 @@ func init() { balancer.Register(testBalancerBuilder{}) } +var ( + componentID = component.MustNewID("component") + testAuthID = component.MustNewID("testauth") + mockID = component.MustNewID("mock") + doesntExistID = component.MustNewID("doesntexist") +) + func TestDefaultGrpcClientSettings(t *testing.T) { - tt, err := componenttest.SetupTelemetry(component.NewID("component")) + tt, err := componenttest.SetupTelemetry(componentID) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) @@ -66,7 +73,7 @@ func TestDefaultGrpcClientSettings(t *testing.T) { } func TestAllGrpcClientSettings(t *testing.T) { - tt, err := componenttest.SetupTelemetry(component.NewID("component")) + tt, err := componenttest.SetupTelemetry(componentID) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) @@ -96,11 +103,11 @@ func TestAllGrpcClientSettings(t *testing.T) { WaitForReady: true, BalancerName: "round_robin", Authority: "pseudo-authority", - Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")}, + Auth: &configauth.Authentication{AuthenticatorID: testAuthID}, }, host: &mockHost{ ext: map[component.ID]component.Component{ - component.NewID("testauth"): &authtest.MockClient{}, + testAuthID: &authtest.MockClient{}, }, }, }, @@ -125,11 +132,11 @@ func TestAllGrpcClientSettings(t *testing.T) { WaitForReady: true, BalancerName: "round_robin", Authority: "pseudo-authority", - Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")}, + Auth: &configauth.Authentication{AuthenticatorID: testAuthID}, }, host: &mockHost{ ext: map[component.ID]component.Component{ - component.NewID("testauth"): &authtest.MockClient{}, + testAuthID: &authtest.MockClient{}, }, }, }, @@ -154,11 +161,11 @@ func TestAllGrpcClientSettings(t *testing.T) { WaitForReady: true, BalancerName: "configgrpc_balancer_test", Authority: "pseudo-authority", - Auth: &configauth.Authentication{AuthenticatorID: component.NewID("testauth")}, + Auth: &configauth.Authentication{AuthenticatorID: testAuthID}, }, host: &mockHost{ ext: map[component.ID]component.Component{ - component.NewID("testauth"): &authtest.MockClient{}, + testAuthID: &authtest.MockClient{}, }, }, }, @@ -223,11 +230,11 @@ func TestGrpcServerAuthSettings(t *testing.T) { }, } gss.Auth = &configauth.Authentication{ - AuthenticatorID: component.NewID("mock"), + AuthenticatorID: mockID, } host := &mockHost{ ext: map[component.ID]component.Component{ - component.NewID("mock"): auth.NewServer(), + mockID: auth.NewServer(), }, } srv, err := gss.ToServer(host, componenttest.NewNopTelemetrySettings()) @@ -236,7 +243,7 @@ func TestGrpcServerAuthSettings(t *testing.T) { } func TestGRPCClientSettingsError(t *testing.T) { - tt, err := componenttest.SetupTelemetry(component.NewID("component")) + tt, err := componenttest.SetupTelemetry(componentID) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) @@ -303,7 +310,7 @@ func TestGRPCClientSettingsError(t *testing.T) { err: "failed to resolve authenticator \"doesntexist\": authenticator not found", settings: ClientConfig{ Endpoint: "localhost:1234", - Auth: &configauth.Authentication{AuthenticatorID: component.NewID("doesntexist")}, + Auth: &configauth.Authentication{AuthenticatorID: doesntExistID}, }, host: &mockHost{ext: map[component.ID]component.Component{}}, }, @@ -311,7 +318,7 @@ func TestGRPCClientSettingsError(t *testing.T) { err: "no extensions configuration available", settings: ClientConfig{ Endpoint: "localhost:1234", - Auth: &configauth.Authentication{AuthenticatorID: component.NewID("doesntexist")}, + Auth: &configauth.Authentication{AuthenticatorID: doesntExistID}, }, host: &mockHost{}, }, @@ -359,7 +366,7 @@ func TestGRPCClientSettingsError(t *testing.T) { } func TestUseSecure(t *testing.T) { - tt, err := componenttest.SetupTelemetry(component.NewID("component")) + tt, err := componenttest.SetupTelemetry(componentID) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) @@ -498,7 +505,7 @@ func TestGRPCServerSettings_ToListener_Error(t *testing.T) { } func TestHttpReception(t *testing.T) { - tt, err := componenttest.SetupTelemetry(component.NewID("component")) + tt, err := componenttest.SetupTelemetry(componentID) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) @@ -650,7 +657,7 @@ func TestReceiveOnUnixDomainSocket(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("skipping test on windows") } - tt, err := componenttest.SetupTelemetry(component.NewID("component")) + tt, err := componenttest.SetupTelemetry(componentID) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) @@ -879,7 +886,7 @@ func TestClientInfoInterceptors(t *testing.T) { }, } - tt, err := componenttest.SetupTelemetry(component.NewID("component")) + tt, err := componenttest.SetupTelemetry(componentID) require.NoError(t, err) defer func() { require.NoError(t, tt.Shutdown(context.Background())) diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index 5cfd9f25abf..9bd4d2186f5 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -42,10 +42,17 @@ func (c *customRoundTripper) RoundTrip(_ *http.Request) (*http.Response, error) return nil, nil } +var ( + testAuthID = component.MustNewID("testauth") + mockID = component.MustNewID("mock") + dummyID = component.MustNewID("dummy") + nonExistingID = component.MustNewID("nonexisting") +) + func TestAllHTTPClientSettings(t *testing.T) { host := &mockHost{ ext: map[component.ID]component.Component{ - component.NewID("testauth"): &authtest.MockClient{ResultRoundTripper: &customRoundTripper{}}, + testAuthID: &authtest.MockClient{ResultRoundTripper: &customRoundTripper{}}, }, } @@ -187,7 +194,7 @@ func TestAllHTTPClientSettings(t *testing.T) { func TestPartialHTTPClientSettings(t *testing.T) { host := &mockHost{ ext: map[component.ID]component.Component{ - component.NewID("testauth"): &authtest.MockClient{ResultRoundTripper: &customRoundTripper{}}, + testAuthID: &authtest.MockClient{ResultRoundTripper: &customRoundTripper{}}, }, } @@ -329,7 +336,7 @@ func TestHTTPClientSettingsError(t *testing.T) { err: "failed to resolve authenticator \"dummy\": authenticator not found", settings: HTTPClientConfig{ Endpoint: "https://localhost:1234/v1/traces", - Auth: &configauth.Authentication{AuthenticatorID: component.NewID("dummy")}, + Auth: &configauth.Authentication{AuthenticatorID: dummyID}, }, }, } @@ -357,7 +364,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { shouldErr: false, host: &mockHost{ ext: map[component.ID]component.Component{ - component.NewID("mock"): &authtest.MockClient{ + mockID: &authtest.MockClient{ ResultRoundTripper: &customRoundTripper{}, }, }, @@ -367,12 +374,12 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { name: "with_auth_configuration_and_no_extension", settings: HTTPClientConfig{ Endpoint: "localhost:1234", - Auth: &configauth.Authentication{AuthenticatorID: component.NewID("dummy")}, + Auth: &configauth.Authentication{AuthenticatorID: dummyID}, }, shouldErr: true, host: &mockHost{ ext: map[component.ID]component.Component{ - component.NewID("mock"): &authtest.MockClient{ResultRoundTripper: &customRoundTripper{}}, + mockID: &authtest.MockClient{ResultRoundTripper: &customRoundTripper{}}, }, }, }, @@ -380,7 +387,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { name: "with_auth_configuration_and_no_extension_map", settings: HTTPClientConfig{ Endpoint: "localhost:1234", - Auth: &configauth.Authentication{AuthenticatorID: component.NewID("dummy")}, + Auth: &configauth.Authentication{AuthenticatorID: dummyID}, }, shouldErr: true, host: componenttest.NewNopHost(), @@ -389,12 +396,12 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { name: "with_auth_configuration_has_extension", settings: HTTPClientConfig{ Endpoint: "localhost:1234", - Auth: &configauth.Authentication{AuthenticatorID: component.NewID("mock")}, + Auth: &configauth.Authentication{AuthenticatorID: mockID}, }, shouldErr: false, host: &mockHost{ ext: map[component.ID]component.Component{ - component.NewID("mock"): &authtest.MockClient{ResultRoundTripper: &customRoundTripper{}}, + mockID: &authtest.MockClient{ResultRoundTripper: &customRoundTripper{}}, }, }, }, @@ -402,13 +409,13 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { name: "with_auth_configuration_has_extension_and_headers", settings: HTTPClientConfig{ Endpoint: "localhost:1234", - Auth: &configauth.Authentication{AuthenticatorID: component.NewID("mock")}, + Auth: &configauth.Authentication{AuthenticatorID: mockID}, Headers: map[string]configopaque.String{"foo": "bar"}, }, shouldErr: false, host: &mockHost{ ext: map[component.ID]component.Component{ - component.NewID("mock"): &authtest.MockClient{ResultRoundTripper: &customRoundTripper{}}, + mockID: &authtest.MockClient{ResultRoundTripper: &customRoundTripper{}}, }, }, }, @@ -416,13 +423,13 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { name: "with_auth_configuration_has_extension_and_compression", settings: HTTPClientConfig{ Endpoint: "localhost:1234", - Auth: &configauth.Authentication{AuthenticatorID: component.NewID("mock")}, + Auth: &configauth.Authentication{AuthenticatorID: mockID}, Compression: configcompression.Gzip, }, shouldErr: false, host: &mockHost{ ext: map[component.ID]component.Component{ - component.NewID("mock"): &authtest.MockClient{ResultRoundTripper: &customRoundTripper{}}, + mockID: &authtest.MockClient{ResultRoundTripper: &customRoundTripper{}}, }, }, }, @@ -430,12 +437,12 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { name: "with_auth_configuration_has_err_extension", settings: HTTPClientConfig{ Endpoint: "localhost:1234", - Auth: &configauth.Authentication{AuthenticatorID: component.NewID("mock")}, + Auth: &configauth.Authentication{AuthenticatorID: mockID}, }, shouldErr: true, host: &mockHost{ ext: map[component.ID]component.Component{ - component.NewID("mock"): &authtest.MockClient{ + mockID: &authtest.MockClient{ ResultRoundTripper: &customRoundTripper{}, MustError: true}, }, }, @@ -862,13 +869,13 @@ func TestHttpCorsWithSettings(t *testing.T) { AllowedOrigins: []string{"*"}, }, Auth: &configauth.Authentication{ - AuthenticatorID: component.NewID("mock"), + AuthenticatorID: mockID, }, } host := &mockHost{ ext: map[component.ID]component.Component{ - component.NewID("mock"): auth.NewServer( + mockID: auth.NewServer( auth.WithServerAuthenticate(func(ctx context.Context, headers map[string][]string) (context.Context, error) { return ctx, errors.New("Settings failed") }), @@ -1128,13 +1135,13 @@ func TestServerAuth(t *testing.T) { hss := HTTPServerConfig{ Endpoint: "localhost:0", Auth: &configauth.Authentication{ - AuthenticatorID: component.NewID("mock"), + AuthenticatorID: mockID, }, } host := &mockHost{ ext: map[component.ID]component.Component{ - component.NewID("mock"): auth.NewServer( + mockID: auth.NewServer( auth.WithServerAuthenticate(func(ctx context.Context, headers map[string][]string) (context.Context, error) { authCalled = true return ctx, nil @@ -1162,7 +1169,7 @@ func TestServerAuth(t *testing.T) { func TestInvalidServerAuth(t *testing.T) { hss := HTTPServerConfig{ Auth: &configauth.Authentication{ - AuthenticatorID: component.NewID("non-existing"), + AuthenticatorID: nonExistingID, }, } @@ -1176,12 +1183,12 @@ func TestFailedServerAuth(t *testing.T) { hss := HTTPServerConfig{ Endpoint: "localhost:0", Auth: &configauth.Authentication{ - AuthenticatorID: component.NewID("mock"), + AuthenticatorID: mockID, }, } host := &mockHost{ ext: map[component.ID]component.Component{ - component.NewID("mock"): auth.NewServer( + mockID: auth.NewServer( auth.WithServerAuthenticate(func(ctx context.Context, headers map[string][]string) (context.Context, error) { return ctx, errors.New("Settings failed") }), diff --git a/connector/connector_test.go b/connector/connector_test.go index a2dc1305dfb..851add885d7 100644 --- a/connector/connector_test.go +++ b/connector/connector_test.go @@ -17,15 +17,17 @@ import ( "go.opentelemetry.io/collector/consumer/consumertest" ) +var ( + testType = component.MustNewType("test") + testID = component.MustNewIDWithName("type", "name") +) + func TestNewFactoryNoOptions(t *testing.T) { - const typeStr = "test" defaultCfg := struct{}{} - factory := NewFactory(typeStr, func() component.Config { return &defaultCfg }) - assert.EqualValues(t, typeStr, factory.Type()) + factory := NewFactory(testType, func() component.Config { return &defaultCfg }) + assert.EqualValues(t, testType, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) - testID := component.NewIDWithName("type", "name") - _, err := factory.CreateTracesToTraces(context.Background(), CreateSettings{ID: testID}, &defaultCfg, nil) assert.Equal(t, err, errDataTypes(testID, component.DataTypeTraces, component.DataTypeTraces)) _, err = factory.CreateTracesToMetrics(context.Background(), CreateSettings{ID: testID}, &defaultCfg, nil) @@ -49,17 +51,14 @@ func TestNewFactoryNoOptions(t *testing.T) { } func TestNewFactoryWithSameTypes(t *testing.T) { - const typeStr = "test" defaultCfg := struct{}{} - factory := NewFactory(typeStr, func() component.Config { return &defaultCfg }, + factory := NewFactory(testType, func() component.Config { return &defaultCfg }, WithTracesToTraces(createTracesToTraces, component.StabilityLevelAlpha), WithMetricsToMetrics(createMetricsToMetrics, component.StabilityLevelBeta), WithLogsToLogs(createLogsToLogs, component.StabilityLevelUnmaintained)) - assert.EqualValues(t, typeStr, factory.Type()) + assert.EqualValues(t, testType, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) - testID := component.NewIDWithName("type", "name") - assert.Equal(t, component.StabilityLevelAlpha, factory.TracesToTracesStability()) _, err := factory.CreateTracesToTraces(context.Background(), CreateSettings{ID: testID}, &defaultCfg, nil) assert.NoError(t, err) @@ -89,20 +88,17 @@ func TestNewFactoryWithSameTypes(t *testing.T) { } func TestNewFactoryWithTranslateTypes(t *testing.T) { - const typeStr = "test" defaultCfg := struct{}{} - factory := NewFactory(typeStr, func() component.Config { return &defaultCfg }, + factory := NewFactory(testType, func() component.Config { return &defaultCfg }, WithTracesToMetrics(createTracesToMetrics, component.StabilityLevelDevelopment), WithTracesToLogs(createTracesToLogs, component.StabilityLevelAlpha), WithMetricsToTraces(createMetricsToTraces, component.StabilityLevelBeta), WithMetricsToLogs(createMetricsToLogs, component.StabilityLevelStable), WithLogsToTraces(createLogsToTraces, component.StabilityLevelDeprecated), WithLogsToMetrics(createLogsToMetrics, component.StabilityLevelUnmaintained)) - assert.EqualValues(t, typeStr, factory.Type()) + assert.EqualValues(t, testType, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) - testID := component.NewIDWithName("type", "name") - _, err := factory.CreateTracesToTraces(context.Background(), CreateSettings{ID: testID}, &defaultCfg, nil) assert.Equal(t, err, errDataTypes(testID, component.DataTypeTraces, component.DataTypeTraces)) _, err = factory.CreateMetricsToMetrics(context.Background(), CreateSettings{ID: testID}, &defaultCfg, nil) @@ -136,9 +132,8 @@ func TestNewFactoryWithTranslateTypes(t *testing.T) { } func TestNewFactoryWithAllTypes(t *testing.T) { - const typeStr = "test" defaultCfg := struct{}{} - factory := NewFactory(typeStr, func() component.Config { return &defaultCfg }, + factory := NewFactory(testType, func() component.Config { return &defaultCfg }, WithTracesToTraces(createTracesToTraces, component.StabilityLevelAlpha), WithTracesToMetrics(createTracesToMetrics, component.StabilityLevelDevelopment), WithTracesToLogs(createTracesToLogs, component.StabilityLevelAlpha), @@ -148,7 +143,7 @@ func TestNewFactoryWithAllTypes(t *testing.T) { WithLogsToTraces(createLogsToTraces, component.StabilityLevelDeprecated), WithLogsToMetrics(createLogsToMetrics, component.StabilityLevelUnmaintained), WithLogsToLogs(createLogsToLogs, component.StabilityLevelUnmaintained)) - assert.EqualValues(t, typeStr, factory.Type()) + assert.EqualValues(t, testType, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) assert.Equal(t, component.StabilityLevelAlpha, factory.TracesToTracesStability()) @@ -189,8 +184,8 @@ func TestMakeFactoryMap(t *testing.T) { out map[component.Type]Factory } - p1 := NewFactory("p1", nil) - p2 := NewFactory("p2", nil) + p1 := NewFactory(component.MustNewType("p1"), nil) + p2 := NewFactory(component.MustNewType("p2"), nil) testCases := []testCase{ { name: "different names", @@ -202,7 +197,7 @@ func TestMakeFactoryMap(t *testing.T) { }, { name: "same name", - in: []Factory{p1, p2, NewFactory("p1", nil)}, + in: []Factory{p1, p2, NewFactory(component.MustNewType("p1"), nil)}, }, } @@ -223,9 +218,9 @@ func TestMakeFactoryMap(t *testing.T) { func TestBuilder(t *testing.T) { defaultCfg := struct{}{} factories, err := MakeFactoryMap([]Factory{ - NewFactory("err", nil), + NewFactory(component.MustNewType("err"), nil), NewFactory( - "all", + component.MustNewType("all"), func() component.Config { return &defaultCfg }, WithTracesToTraces(createTracesToTraces, component.StabilityLevelDevelopment), WithTracesToMetrics(createTracesToMetrics, component.StabilityLevelDevelopment), @@ -247,28 +242,28 @@ func TestBuilder(t *testing.T) { }{ { name: "unknown", - id: component.NewID("unknown"), + id: component.MustNewID("unknown"), err: func(_, _ component.DataType) string { return "connector factory not available for: \"unknown\"" }, }, { name: "err", - id: component.NewID("err"), + id: component.MustNewID("err"), err: func(expType, rcvType component.DataType) string { return fmt.Sprintf("connector \"err\" cannot connect from %s to %s: telemetry type is not supported", expType, rcvType) }, }, { name: "all", - id: component.NewID("all"), + id: component.MustNewID("all"), err: func(_, _ component.DataType) string { return "" }, }, { name: "all/named", - id: component.NewIDWithName("all", "named"), + id: component.MustNewIDWithName("all", "named"), err: func(_, _ component.DataType) string { return "" }, @@ -366,7 +361,7 @@ func TestBuilderMissingConfig(t *testing.T) { defaultCfg := struct{}{} factories, err := MakeFactoryMap([]Factory{ NewFactory( - "all", + component.MustNewType("all"), func() component.Config { return &defaultCfg }, WithTracesToTraces(createTracesToTraces, component.StabilityLevelDevelopment), WithTracesToMetrics(createTracesToMetrics, component.StabilityLevelDevelopment), @@ -383,7 +378,7 @@ func TestBuilderMissingConfig(t *testing.T) { require.NoError(t, err) bErr := NewBuilder(map[component.ID]component.Config{}, factories) - missingID := component.NewIDWithName("all", "missing") + missingID := component.MustNewIDWithName("all", "missing") t2t, err := bErr.CreateTracesToTraces(context.Background(), createSettings(missingID), nil) assert.EqualError(t, err, "connector \"all/missing\" is not configured") @@ -423,17 +418,17 @@ func TestBuilderMissingConfig(t *testing.T) { } func TestBuilderGetters(t *testing.T) { - factories, err := MakeFactoryMap([]Factory{NewFactory("foo", nil)}...) + factories, err := MakeFactoryMap([]Factory{NewFactory(component.MustNewType("foo"), nil)}...) require.NoError(t, err) - cfgs := map[component.ID]component.Config{component.NewID("foo"): struct{}{}} + cfgs := map[component.ID]component.Config{component.MustNewID("foo"): struct{}{}} b := NewBuilder(cfgs, factories) - assert.True(t, b.IsConfigured(component.NewID("foo"))) - assert.False(t, b.IsConfigured(component.NewID("bar"))) + assert.True(t, b.IsConfigured(component.MustNewID("foo"))) + assert.False(t, b.IsConfigured(component.MustNewID("bar"))) - assert.NotNil(t, b.Factory(component.NewID("foo").Type())) - assert.Nil(t, b.Factory(component.NewID("bar").Type())) + assert.NotNil(t, b.Factory(component.MustNewID("foo").Type())) + assert.Nil(t, b.Factory(component.MustNewID("bar").Type())) } var nopInstance = &nopConnector{ diff --git a/connector/connectortest/connector.go b/connector/connectortest/connector.go index 137a353423c..d30fb65b6a5 100644 --- a/connector/connectortest/connector.go +++ b/connector/connectortest/connector.go @@ -13,11 +13,12 @@ import ( "go.opentelemetry.io/collector/consumer/consumertest" ) -const typeStr = "nop" +var nopType = component.MustNewType("nop") // NewNopCreateSettings returns a new nop settings for Create* functions. func NewNopCreateSettings() connector.CreateSettings { return connector.CreateSettings{ + ID: component.NewID(nopType), TelemetrySettings: componenttest.NewNopTelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo(), } @@ -28,7 +29,7 @@ type nopConfig struct{} // NewNopFactory returns a connector.Factory that constructs nop processors. func NewNopFactory() connector.Factory { return connector.NewFactory( - "nop", + nopType, func() component.Config { return &nopConfig{} }, @@ -93,8 +94,8 @@ func NewNopBuilder() *connector.Builder { // Use a different ID than receivertest and exportertest to avoid ambiguous // configuration scenarios. Ambiguous IDs are detected in the 'otelcol' package, // but lower level packages such as 'service' assume that IDs are disambiguated. - connID := component.NewIDWithName(typeStr, "conn") + connID := component.NewIDWithName(nopType, "conn") return connector.NewBuilder( map[component.ID]component.Config{connID: nopFactory.CreateDefaultConfig()}, - map[component.Type]connector.Factory{typeStr: nopFactory}) + map[component.Type]connector.Factory{nopType: nopFactory}) } diff --git a/connector/connectortest/connector_test.go b/connector/connectortest/connector_test.go index d8db553d9a1..4a2894f8544 100644 --- a/connector/connectortest/connector_test.go +++ b/connector/connectortest/connector_test.go @@ -21,7 +21,7 @@ import ( func TestNewNopConnectorFactory(t *testing.T) { factory := NewNopFactory() require.NotNil(t, factory) - assert.Equal(t, component.Type("nop"), factory.Type()) + assert.Equal(t, component.MustNewType("nop"), factory.Type()) cfg := factory.CreateDefaultConfig() assert.Equal(t, &nopConfig{}, cfg) @@ -87,7 +87,7 @@ func TestNewNopBuilder(t *testing.T) { factory := NewNopFactory() cfg := factory.CreateDefaultConfig() set := NewNopCreateSettings() - set.ID = component.NewIDWithName(typeStr, "conn") + set.ID = component.NewIDWithName(nopType, "conn") tracesToTraces, err := factory.CreateTracesToTraces(context.Background(), set, cfg, consumertest.NewNop()) require.NoError(t, err) diff --git a/connector/forwardconnector/internal/metadata/generated_status.go b/connector/forwardconnector/internal/metadata/generated_status.go index 82477a52d7c..9505adb84d7 100644 --- a/connector/forwardconnector/internal/metadata/generated_status.go +++ b/connector/forwardconnector/internal/metadata/generated_status.go @@ -9,8 +9,11 @@ import ( "go.opentelemetry.io/collector/component" ) +var ( + Type = component.MustNewType("forward") +) + const ( - Type = "forward" TracesToTracesStability = component.StabilityLevelBeta MetricsToMetricsStability = component.StabilityLevelBeta LogsToLogsStability = component.StabilityLevelBeta diff --git a/connector/logs_router_test.go b/connector/logs_router_test.go index 3fd0d701cc0..accce0a03cd 100644 --- a/connector/logs_router_test.go +++ b/connector/logs_router_test.go @@ -48,7 +48,7 @@ func fuzzLogs(numIDs, numCons, numLogs int) func(*testing.T) { // If any consumer is mutating, the router must report mutating for i := 0; i < numCons; i++ { - allIDs = append(allIDs, component.NewIDWithName("sink", strconv.Itoa(numCons))) + allIDs = append(allIDs, component.MustNewIDWithName("sink", strconv.Itoa(numCons))) // Random chance for each consumer to be mutating if (numCons+numLogs+i)%4 == 0 { allCons = append(allCons, &mutatingLogsSink{LogsSink: new(consumertest.LogsSink)}) @@ -108,8 +108,8 @@ func TestLogsRouterConsumers(t *testing.T) { ctx := context.Background() ld := testdata.GenerateLogs(1) - fooID := component.NewID("foo") - barID := component.NewID("bar") + fooID := component.MustNewID("foo") + barID := component.MustNewID("bar") foo := new(consumertest.LogsSink) bar := new(consumertest.LogsSink) @@ -150,7 +150,7 @@ func TestLogsRouterConsumers(t *testing.T) { assert.Nil(t, none) assert.Error(t, err) - fake, err := r.Consumer(component.NewID("fake")) + fake, err := r.Consumer(component.MustNewID("fake")) assert.Nil(t, fake) assert.Error(t, err) } diff --git a/connector/metrics_router_test.go b/connector/metrics_router_test.go index 69126b04ada..62dd54c11e0 100644 --- a/connector/metrics_router_test.go +++ b/connector/metrics_router_test.go @@ -48,7 +48,7 @@ func fuzzMetrics(numIDs, numCons, numMetrics int) func(*testing.T) { // If any consumer is mutating, the router must report mutating for i := 0; i < numCons; i++ { - allIDs = append(allIDs, component.NewIDWithName("sink", strconv.Itoa(numCons))) + allIDs = append(allIDs, component.MustNewIDWithName("sink", strconv.Itoa(numCons))) // Random chance for each consumer to be mutating if (numCons+numMetrics+i)%4 == 0 { allCons = append(allCons, &mutatingMetricsSink{MetricsSink: new(consumertest.MetricsSink)}) @@ -108,8 +108,8 @@ func TestMetricsRouterConsumers(t *testing.T) { ctx := context.Background() md := testdata.GenerateMetrics(1) - fooID := component.NewID("foo") - barID := component.NewID("bar") + fooID := component.MustNewID("foo") + barID := component.MustNewID("bar") foo := new(consumertest.MetricsSink) bar := new(consumertest.MetricsSink) @@ -150,7 +150,7 @@ func TestMetricsRouterConsumers(t *testing.T) { assert.Nil(t, none) assert.Error(t, err) - fake, err := r.Consumer(component.NewID("fake")) + fake, err := r.Consumer(component.MustNewID("fake")) assert.Nil(t, fake) assert.Error(t, err) } diff --git a/connector/traces_router_test.go b/connector/traces_router_test.go index a89a687f9bc..33a2124ed3e 100644 --- a/connector/traces_router_test.go +++ b/connector/traces_router_test.go @@ -48,7 +48,7 @@ func fuzzTraces(numIDs, numCons, numTraces int) func(*testing.T) { // If any consumer is mutating, the router must report mutating for i := 0; i < numCons; i++ { - allIDs = append(allIDs, component.NewIDWithName("sink", strconv.Itoa(numCons))) + allIDs = append(allIDs, component.MustNewIDWithName("sink", strconv.Itoa(numCons))) // Random chance for each consumer to be mutating if (numCons+numTraces+i)%4 == 0 { allCons = append(allCons, &mutatingTracesSink{TracesSink: new(consumertest.TracesSink)}) @@ -108,8 +108,8 @@ func TestTracesRouterConsumer(t *testing.T) { ctx := context.Background() td := testdata.GenerateTraces(1) - fooID := component.NewID("foo") - barID := component.NewID("bar") + fooID := component.MustNewID("foo") + barID := component.MustNewID("bar") foo := new(consumertest.TracesSink) bar := new(consumertest.TracesSink) @@ -150,7 +150,7 @@ func TestTracesRouterConsumer(t *testing.T) { assert.Nil(t, none) assert.Error(t, err) - fake, err := r.Consumer(component.NewID("fake")) + fake, err := r.Consumer(component.MustNewID("fake")) assert.Nil(t, fake) assert.Error(t, err) } diff --git a/exporter/debugexporter/factory.go b/exporter/debugexporter/factory.go index 5264c42866c..e9e75130dd6 100644 --- a/exporter/debugexporter/factory.go +++ b/exporter/debugexporter/factory.go @@ -13,9 +13,10 @@ import ( "go.opentelemetry.io/collector/exporter/internal/common" ) +// The value of "type" key in configuration. +var componentType = component.MustNewType("debug") + const ( - // The value of "type" key in configuration. - typeStr = "debug" defaultSamplingInitial = 2 defaultSamplingThereafter = 500 ) @@ -23,7 +24,7 @@ const ( // NewFactory creates a factory for Debug exporter func NewFactory() exporter.Factory { return exporter.NewFactory( - typeStr, + componentType, createDefaultConfig, exporter.WithTraces(createTracesExporter, metadata.TracesStability), exporter.WithMetrics(createMetricsExporter, metadata.MetricsStability), diff --git a/exporter/debugexporter/internal/metadata/generated_status.go b/exporter/debugexporter/internal/metadata/generated_status.go index 00fdd4b26ad..53acecdba3c 100644 --- a/exporter/debugexporter/internal/metadata/generated_status.go +++ b/exporter/debugexporter/internal/metadata/generated_status.go @@ -9,8 +9,11 @@ import ( "go.opentelemetry.io/collector/component" ) +var ( + Type = component.MustNewType("debug") +) + const ( - Type = "debug" TracesStability = component.StabilityLevelDevelopment MetricsStability = component.StabilityLevelDevelopment LogsStability = component.StabilityLevelDevelopment diff --git a/exporter/exporter_test.go b/exporter/exporter_test.go index eafa2c03f47..108e55fb582 100644 --- a/exporter/exporter_test.go +++ b/exporter/exporter_test.go @@ -16,12 +16,12 @@ import ( ) func TestNewFactory(t *testing.T) { - const typeStr = "test" + var testType = component.MustNewType("test") defaultCfg := struct{}{} factory := NewFactory( - typeStr, + testType, func() component.Config { return &defaultCfg }) - assert.EqualValues(t, typeStr, factory.Type()) + assert.EqualValues(t, testType, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) _, err := factory.CreateTracesExporter(context.Background(), CreateSettings{}, &defaultCfg) assert.Error(t, err) @@ -32,15 +32,15 @@ func TestNewFactory(t *testing.T) { } func TestNewFactoryWithOptions(t *testing.T) { - const typeStr = "test" + var testType = component.MustNewType("test") defaultCfg := struct{}{} factory := NewFactory( - typeStr, + testType, func() component.Config { return &defaultCfg }, WithTraces(createTraces, component.StabilityLevelDevelopment), WithMetrics(createMetrics, component.StabilityLevelAlpha), WithLogs(createLogs, component.StabilityLevelDeprecated)) - assert.EqualValues(t, typeStr, factory.Type()) + assert.EqualValues(t, testType, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) assert.Equal(t, component.StabilityLevelDevelopment, factory.TracesExporterStability()) @@ -63,8 +63,8 @@ func TestMakeFactoryMap(t *testing.T) { out map[component.Type]Factory } - p1 := NewFactory("p1", nil) - p2 := NewFactory("p2", nil) + p1 := NewFactory(component.MustNewType("p1"), nil) + p2 := NewFactory(component.MustNewType("p2"), nil) testCases := []testCase{ { name: "different names", @@ -76,7 +76,7 @@ func TestMakeFactoryMap(t *testing.T) { }, { name: "same name", - in: []Factory{p1, p2, NewFactory("p1", nil)}, + in: []Factory{p1, p2, NewFactory(component.MustNewType("p1"), nil)}, }, } @@ -97,9 +97,9 @@ func TestMakeFactoryMap(t *testing.T) { func TestBuilder(t *testing.T) { defaultCfg := struct{}{} factories, err := MakeFactoryMap([]Factory{ - NewFactory("err", nil), + NewFactory(component.MustNewType("err"), nil), NewFactory( - "all", + component.MustNewType("all"), func() component.Config { return &defaultCfg }, WithTraces(createTraces, component.StabilityLevelDevelopment), WithMetrics(createMetrics, component.StabilityLevelAlpha), @@ -115,21 +115,21 @@ func TestBuilder(t *testing.T) { }{ { name: "unknown", - id: component.NewID("unknown"), + id: component.MustNewID("unknown"), err: "exporter factory not available for: \"unknown\"", }, { name: "err", - id: component.NewID("err"), + id: component.MustNewID("err"), err: "telemetry type is not supported", }, { name: "all", - id: component.NewID("all"), + id: component.MustNewID("all"), }, { name: "all/named", - id: component.NewIDWithName("all", "named"), + id: component.MustNewIDWithName("all", "named"), }, } @@ -172,7 +172,7 @@ func TestBuilderMissingConfig(t *testing.T) { defaultCfg := struct{}{} factories, err := MakeFactoryMap([]Factory{ NewFactory( - "all", + component.MustNewType("all"), func() component.Config { return &defaultCfg }, WithTraces(createTraces, component.StabilityLevelDevelopment), WithMetrics(createMetrics, component.StabilityLevelAlpha), @@ -183,7 +183,7 @@ func TestBuilderMissingConfig(t *testing.T) { require.NoError(t, err) bErr := NewBuilder(map[component.ID]component.Config{}, factories) - missingID := component.NewIDWithName("all", "missing") + missingID := component.MustNewIDWithName("all", "missing") te, err := bErr.CreateTraces(context.Background(), createSettings(missingID)) assert.EqualError(t, err, "exporter \"all/missing\" is not configured") @@ -199,14 +199,14 @@ func TestBuilderMissingConfig(t *testing.T) { } func TestBuilderFactory(t *testing.T) { - factories, err := MakeFactoryMap([]Factory{NewFactory("foo", nil)}...) + factories, err := MakeFactoryMap([]Factory{NewFactory(component.MustNewType("foo"), nil)}...) require.NoError(t, err) - cfgs := map[component.ID]component.Config{component.NewID("foo"): struct{}{}} + cfgs := map[component.ID]component.Config{component.MustNewID("foo"): struct{}{}} b := NewBuilder(cfgs, factories) - assert.NotNil(t, b.Factory(component.NewID("foo").Type())) - assert.Nil(t, b.Factory(component.NewID("bar").Type())) + assert.NotNil(t, b.Factory(component.MustNewID("foo").Type())) + assert.Nil(t, b.Factory(component.MustNewID("bar").Type())) } var nopInstance = &nopExporter{ diff --git a/exporter/exporterhelper/common_test.go b/exporter/exporterhelper/common_test.go index bbc009fb7ae..5ed2c5a1dc2 100644 --- a/exporter/exporterhelper/common_test.go +++ b/exporter/exporterhelper/common_test.go @@ -22,7 +22,8 @@ import ( ) var ( - defaultID = component.NewID("test") + defaultType = component.MustNewType("test") + defaultID = component.NewID(defaultType) defaultSettings = func() exporter.CreateSettings { set := exportertest.NewNopCreateSettings() set.ID = defaultID @@ -35,11 +36,11 @@ func newNoopObsrepSender(_ *ObsReport) requestSender { } func TestBaseExporter(t *testing.T) { - be, err := newBaseExporter(defaultSettings, "", false, nil, nil, newNoopObsrepSender) + be, err := newBaseExporter(defaultSettings, defaultType, false, nil, nil, newNoopObsrepSender) require.NoError(t, err) require.NoError(t, be.Start(context.Background(), componenttest.NewNopHost())) require.NoError(t, be.Shutdown(context.Background())) - be, err = newBaseExporter(defaultSettings, "", true, nil, nil, newNoopObsrepSender) + be, err = newBaseExporter(defaultSettings, defaultType, true, nil, nil, newNoopObsrepSender) require.NoError(t, err) require.NoError(t, be.Start(context.Background(), componenttest.NewNopHost())) require.NoError(t, be.Shutdown(context.Background())) @@ -48,7 +49,7 @@ func TestBaseExporter(t *testing.T) { func TestBaseExporterWithOptions(t *testing.T) { want := errors.New("my error") be, err := newBaseExporter( - defaultSettings, "", false, nil, nil, newNoopObsrepSender, + defaultSettings, defaultType, false, nil, nil, newNoopObsrepSender, WithStart(func(ctx context.Context, host component.Host) error { return want }), WithShutdown(func(ctx context.Context) error { return want }), WithTimeout(NewDefaultTimeoutSettings()), @@ -68,12 +69,12 @@ func checkStatus(t *testing.T, sd sdktrace.ReadOnlySpan, err error) { } func TestQueueRetryOptionsWithRequestExporter(t *testing.T) { - bs, err := newBaseExporter(exportertest.NewNopCreateSettings(), "", true, nil, nil, newNoopObsrepSender, + bs, err := newBaseExporter(exportertest.NewNopCreateSettings(), defaultType, true, nil, nil, newNoopObsrepSender, WithRetry(configretry.NewDefaultBackOffConfig())) require.Nil(t, err) require.True(t, bs.requestExporter) require.Panics(t, func() { - _, _ = newBaseExporter(exportertest.NewNopCreateSettings(), "", true, nil, nil, newNoopObsrepSender, + _, _ = newBaseExporter(exportertest.NewNopCreateSettings(), defaultType, true, nil, nil, newNoopObsrepSender, WithRetry(configretry.NewDefaultBackOffConfig()), WithQueue(NewDefaultQueueSettings())) }) } @@ -84,7 +85,7 @@ func TestBaseExporterLogging(t *testing.T) { set.Logger = zap.New(logger) rCfg := configretry.NewDefaultBackOffConfig() rCfg.Enabled = false - bs, err := newBaseExporter(set, "", true, nil, nil, newNoopObsrepSender, WithRetry(rCfg)) + bs, err := newBaseExporter(set, defaultType, true, nil, nil, newNoopObsrepSender, WithRetry(rCfg)) require.Nil(t, err) require.True(t, bs.requestExporter) sendErr := bs.send(context.Background(), newErrorRequest()) diff --git a/exporter/exporterhelper/internal/persistent_queue.go b/exporter/exporterhelper/internal/persistent_queue.go index 0a6629cb87e..9f23ab6a98c 100644 --- a/exporter/exporterhelper/internal/persistent_queue.go +++ b/exporter/exporterhelper/internal/persistent_queue.go @@ -511,7 +511,7 @@ func toStorageClient(ctx context.Context, storageID component.ID, host component return nil, errWrongExtensionType } - return storageExt.GetClient(ctx, component.KindExporter, ownerID, string(signal)) + return storageExt.GetClient(ctx, component.KindExporter, ownerID, signal.String()) } func getItemKey(index uint64) string { diff --git a/exporter/exporterhelper/internal/persistent_queue_test.go b/exporter/exporterhelper/internal/persistent_queue_test.go index 166449bdb25..8b74f9a5fac 100644 --- a/exporter/exporterhelper/internal/persistent_queue_test.go +++ b/exporter/exporterhelper/internal/persistent_queue_test.go @@ -293,14 +293,14 @@ func TestToStorageClient(t *testing.T) { for _, tC := range testCases { t.Run(tC.desc, func(t *testing.T) { - storageID := component.NewIDWithName("file_storage", strconv.Itoa(tC.storageIndex)) + storageID := component.MustNewIDWithName("file_storage", strconv.Itoa(tC.storageIndex)) var extensions = map[component.ID]component.Component{} for i := 0; i < tC.numStorages; i++ { - extensions[component.NewIDWithName("file_storage", strconv.Itoa(i))] = NewMockStorageExtension(tC.getClientError) + extensions[component.MustNewIDWithName("file_storage", strconv.Itoa(i))] = NewMockStorageExtension(tC.getClientError) } host := &mockHost{ext: extensions} - ownerID := component.NewID("foo_exporter") + ownerID := component.MustNewID("foo_exporter") // execute client, err := toStorageClient(context.Background(), storageID, host, ownerID, component.DataTypeTraces) @@ -318,7 +318,7 @@ func TestToStorageClient(t *testing.T) { } func TestInvalidStorageExtensionType(t *testing.T) { - storageID := component.NewIDWithName("extension", "extension") + storageID := component.MustNewIDWithName("extension", "extension") // make a test extension factory := extensiontest.NewNopFactory() @@ -330,7 +330,7 @@ func TestInvalidStorageExtensionType(t *testing.T) { storageID: extension, } host := &mockHost{ext: extensions} - ownerID := component.NewID("foo_exporter") + ownerID := component.MustNewID("foo_exporter") // execute client, err := toStorageClient(context.Background(), storageID, host, ownerID, component.DataTypeTraces) diff --git a/exporter/exporterhelper/logs_test.go b/exporter/exporterhelper/logs_test.go index 92bbd48edac..5349f767398 100644 --- a/exporter/exporterhelper/logs_test.go +++ b/exporter/exporterhelper/logs_test.go @@ -37,7 +37,7 @@ const ( ) var ( - fakeLogsExporterName = component.NewIDWithName("fake_logs_exporter", "with_name") + fakeLogsExporterName = component.MustNewIDWithName("fake_logs_exporter", "with_name") fakeLogsExporterConfig = struct{}{} ) @@ -157,12 +157,12 @@ func TestLogsRequestExporter_Default_ExportError(t *testing.T) { func TestLogsExporter_WithPersistentQueue(t *testing.T) { qCfg := NewDefaultQueueSettings() - storageID := component.NewIDWithName("file_storage", "storage") + storageID := component.MustNewIDWithName("file_storage", "storage") qCfg.StorageID = &storageID rCfg := configretry.NewDefaultBackOffConfig() ts := consumertest.LogsSink{} set := exportertest.NewNopCreateSettings() - set.ID = component.NewIDWithName("test_logs", "with_persistent_queue") + set.ID = component.MustNewIDWithName("test_logs", "with_persistent_queue") te, err := NewLogsExporter(context.Background(), set, &fakeLogsExporterConfig, ts.ConsumeLogs, WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) diff --git a/exporter/exporterhelper/metrics_test.go b/exporter/exporterhelper/metrics_test.go index 770ea801e48..65125b4469c 100644 --- a/exporter/exporterhelper/metrics_test.go +++ b/exporter/exporterhelper/metrics_test.go @@ -37,7 +37,7 @@ const ( ) var ( - fakeMetricsExporterName = component.NewIDWithName("fake_metrics_exporter", "with_name") + fakeMetricsExporterName = component.MustNewIDWithName("fake_metrics_exporter", "with_name") fakeMetricsExporterConfig = struct{}{} ) @@ -158,12 +158,12 @@ func TestMetricsRequestExporter_Default_ExportError(t *testing.T) { func TestMetricsExporter_WithPersistentQueue(t *testing.T) { qCfg := NewDefaultQueueSettings() - storageID := component.NewIDWithName("file_storage", "storage") + storageID := component.MustNewIDWithName("file_storage", "storage") qCfg.StorageID = &storageID rCfg := configretry.NewDefaultBackOffConfig() ms := consumertest.MetricsSink{} set := exportertest.NewNopCreateSettings() - set.ID = component.NewIDWithName("test_metrics", "with_persistent_queue") + set.ID = component.MustNewIDWithName("test_metrics", "with_persistent_queue") te, err := NewMetricsExporter(context.Background(), set, &fakeTracesExporterConfig, ms.ConsumeMetrics, WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) diff --git a/exporter/exporterhelper/obsexporter_test.go b/exporter/exporterhelper/obsexporter_test.go index c37a4287082..f6f46ccbad2 100644 --- a/exporter/exporterhelper/obsexporter_test.go +++ b/exporter/exporterhelper/obsexporter_test.go @@ -20,7 +20,7 @@ import ( ) var ( - exporterID = component.NewID("fakeExporter") + exporterID = component.MustNewID("fakeExporter") errFake = errors.New("errFake") ) diff --git a/exporter/exporterhelper/obsreport_test.go b/exporter/exporterhelper/obsreport_test.go index 267748f5416..e0101f112df 100644 --- a/exporter/exporterhelper/obsreport_test.go +++ b/exporter/exporterhelper/obsreport_test.go @@ -15,7 +15,7 @@ import ( ) func TestExportEnqueueFailure(t *testing.T) { - exporterID := component.NewID("fakeExporter") + exporterID := component.MustNewID("fakeExporter") tt, err := componenttest.SetupTelemetry(exporterID) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) diff --git a/exporter/exporterhelper/queue_sender_test.go b/exporter/exporterhelper/queue_sender_test.go index d56ec6d78b1..58da1190e9a 100644 --- a/exporter/exporterhelper/queue_sender_test.go +++ b/exporter/exporterhelper/queue_sender_test.go @@ -26,7 +26,7 @@ func TestQueuedRetry_StopWhileWaiting(t *testing.T) { qCfg := NewDefaultQueueSettings() qCfg.NumConsumers = 1 rCfg := configretry.NewDefaultBackOffConfig() - be, err := newBaseExporter(defaultSettings, "", false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) + be, err := newBaseExporter(defaultSettings, defaultType, false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) ocs := be.obsrepSender.(*observabilityConsumerSender) require.NoError(t, be.Start(context.Background(), componenttest.NewNopHost())) @@ -58,7 +58,7 @@ func TestQueuedRetry_DoNotPreserveCancellation(t *testing.T) { qCfg := NewDefaultQueueSettings() qCfg.NumConsumers = 1 rCfg := configretry.NewDefaultBackOffConfig() - be, err := newBaseExporter(defaultSettings, "", false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) + be, err := newBaseExporter(defaultSettings, defaultType, false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) ocs := be.obsrepSender.(*observabilityConsumerSender) require.NoError(t, be.Start(context.Background(), componenttest.NewNopHost())) @@ -88,7 +88,7 @@ func TestQueuedRetry_RejectOnFull(t *testing.T) { set := exportertest.NewNopCreateSettings() logger, observed := observer.New(zap.ErrorLevel) set.Logger = zap.New(logger) - be, err := newBaseExporter(set, "", false, nil, nil, newNoopObsrepSender, WithQueue(qCfg)) + be, err := newBaseExporter(set, defaultType, false, nil, nil, newNoopObsrepSender, WithQueue(qCfg)) require.NoError(t, err) require.NoError(t, be.Start(context.Background(), componenttest.NewNopHost())) t.Cleanup(func() { @@ -108,7 +108,7 @@ func TestQueuedRetryHappyPath(t *testing.T) { qCfg := NewDefaultQueueSettings() rCfg := configretry.NewDefaultBackOffConfig() set := exporter.CreateSettings{ID: defaultID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()} - be, err := newBaseExporter(set, "", false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) + be, err := newBaseExporter(set, defaultType, false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) ocs := be.obsrepSender.(*observabilityConsumerSender) require.NoError(t, be.Start(context.Background(), componenttest.NewNopHost())) @@ -145,7 +145,7 @@ func TestQueuedRetry_QueueMetricsReported(t *testing.T) { qCfg.NumConsumers = 0 // to make every request go straight to the queue rCfg := configretry.NewDefaultBackOffConfig() set := exporter.CreateSettings{ID: defaultID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()} - be, err := newBaseExporter(set, "", false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) + be, err := newBaseExporter(set, defaultType, false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) require.NoError(t, be.Start(context.Background(), componenttest.NewNopHost())) @@ -237,11 +237,11 @@ func TestQueuedRetryPersistenceEnabled(t *testing.T) { t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) qCfg := NewDefaultQueueSettings() - storageID := component.NewIDWithName("file_storage", "storage") + storageID := component.MustNewIDWithName("file_storage", "storage") qCfg.StorageID = &storageID // enable persistence rCfg := configretry.NewDefaultBackOffConfig() set := exporter.CreateSettings{ID: defaultID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()} - be, err := newBaseExporter(set, "", false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) + be, err := newBaseExporter(set, defaultType, false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) var extensions = map[component.ID]component.Component{ @@ -261,11 +261,11 @@ func TestQueuedRetryPersistenceEnabledStorageError(t *testing.T) { t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) qCfg := NewDefaultQueueSettings() - storageID := component.NewIDWithName("file_storage", "storage") + storageID := component.MustNewIDWithName("file_storage", "storage") qCfg.StorageID = &storageID // enable persistence rCfg := configretry.NewDefaultBackOffConfig() set := exporter.CreateSettings{ID: defaultID, TelemetrySettings: tt.TelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo()} - be, err := newBaseExporter(set, "", false, mockRequestMarshaler, mockRequestUnmarshaler(&mockRequest{}), newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) + be, err := newBaseExporter(set, defaultType, false, mockRequestMarshaler, mockRequestUnmarshaler(&mockRequest{}), newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) var extensions = map[component.ID]component.Component{ @@ -280,7 +280,7 @@ func TestQueuedRetryPersistenceEnabledStorageError(t *testing.T) { func TestQueuedRetryPersistentEnabled_NoDataLossOnShutdown(t *testing.T) { qCfg := NewDefaultQueueSettings() qCfg.NumConsumers = 1 - storageID := component.NewIDWithName("file_storage", "storage") + storageID := component.MustNewIDWithName("file_storage", "storage") qCfg.StorageID = &storageID // enable persistence to ensure data is re-queued on shutdown rCfg := configretry.NewDefaultBackOffConfig() @@ -288,7 +288,7 @@ func TestQueuedRetryPersistentEnabled_NoDataLossOnShutdown(t *testing.T) { rCfg.MaxElapsedTime = 0 // retry infinitely so shutdown can be triggered mockReq := newErrorRequest() - be, err := newBaseExporter(defaultSettings, "", false, mockRequestMarshaler, mockRequestUnmarshaler(mockReq), + be, err := newBaseExporter(defaultSettings, defaultType, false, mockRequestMarshaler, mockRequestUnmarshaler(mockReq), newNoopObsrepSender, WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) @@ -312,7 +312,7 @@ func TestQueuedRetryPersistentEnabled_NoDataLossOnShutdown(t *testing.T) { // start the exporter again replacing the preserved mockRequest in the unmarshaler with a new one that doesn't fail. replacedReq := newMockRequest(1, nil) - be, err = newBaseExporter(defaultSettings, "", false, mockRequestMarshaler, mockRequestUnmarshaler(replacedReq), + be, err = newBaseExporter(defaultSettings, defaultType, false, mockRequestMarshaler, mockRequestUnmarshaler(replacedReq), newNoopObsrepSender, WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) require.NoError(t, be.Start(context.Background(), host)) @@ -323,7 +323,7 @@ func TestQueuedRetryPersistentEnabled_NoDataLossOnShutdown(t *testing.T) { } func TestQueueSenderNoStartShutdown(t *testing.T) { - qs := newQueueSender(NewDefaultQueueSettings(), exportertest.NewNopCreateSettings(), "", nil, nil, nil) + qs := newQueueSender(NewDefaultQueueSettings(), exportertest.NewNopCreateSettings(), defaultType, nil, nil, nil) assert.NoError(t, qs.Shutdown(context.Background())) } diff --git a/exporter/exporterhelper/retry_sender_test.go b/exporter/exporterhelper/retry_sender_test.go index 55089e9677c..b26c465e1dc 100644 --- a/exporter/exporterhelper/retry_sender_test.go +++ b/exporter/exporterhelper/retry_sender_test.go @@ -38,7 +38,7 @@ func TestQueuedRetry_DropOnPermanentError(t *testing.T) { qCfg := NewDefaultQueueSettings() rCfg := configretry.NewDefaultBackOffConfig() mockR := newMockRequest(2, consumererror.NewPermanent(errors.New("bad data"))) - be, err := newBaseExporter(defaultSettings, "", false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) + be, err := newBaseExporter(defaultSettings, defaultType, false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) ocs := be.obsrepSender.(*observabilityConsumerSender) require.NoError(t, be.Start(context.Background(), componenttest.NewNopHost())) @@ -61,7 +61,7 @@ func TestQueuedRetry_DropOnNoRetry(t *testing.T) { qCfg := NewDefaultQueueSettings() rCfg := configretry.NewDefaultBackOffConfig() rCfg.Enabled = false - be, err := newBaseExporter(defaultSettings, "", false, mockRequestMarshaler, + be, err := newBaseExporter(defaultSettings, defaultType, false, mockRequestMarshaler, mockRequestUnmarshaler(newMockRequest(2, errors.New("transient error"))), newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) @@ -88,7 +88,7 @@ func TestQueuedRetry_OnError(t *testing.T) { qCfg.NumConsumers = 1 rCfg := configretry.NewDefaultBackOffConfig() rCfg.InitialInterval = 0 - be, err := newBaseExporter(defaultSettings, "", false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) + be, err := newBaseExporter(defaultSettings, defaultType, false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) require.NoError(t, be.Start(context.Background(), componenttest.NewNopHost())) t.Cleanup(func() { @@ -116,7 +116,7 @@ func TestQueuedRetry_MaxElapsedTime(t *testing.T) { rCfg := configretry.NewDefaultBackOffConfig() rCfg.InitialInterval = time.Millisecond rCfg.MaxElapsedTime = 100 * time.Millisecond - be, err := newBaseExporter(defaultSettings, "", false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) + be, err := newBaseExporter(defaultSettings, defaultType, false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) ocs := be.obsrepSender.(*observabilityConsumerSender) require.NoError(t, be.Start(context.Background(), componenttest.NewNopHost())) @@ -162,7 +162,7 @@ func TestQueuedRetry_ThrottleError(t *testing.T) { qCfg.NumConsumers = 1 rCfg := configretry.NewDefaultBackOffConfig() rCfg.InitialInterval = 10 * time.Millisecond - be, err := newBaseExporter(defaultSettings, "", false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) + be, err := newBaseExporter(defaultSettings, defaultType, false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) ocs := be.obsrepSender.(*observabilityConsumerSender) require.NoError(t, be.Start(context.Background(), componenttest.NewNopHost())) @@ -194,7 +194,7 @@ func TestQueuedRetry_RetryOnError(t *testing.T) { qCfg.QueueSize = 1 rCfg := configretry.NewDefaultBackOffConfig() rCfg.InitialInterval = 0 - be, err := newBaseExporter(defaultSettings, "", false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) + be, err := newBaseExporter(defaultSettings, defaultType, false, nil, nil, newObservabilityConsumerSender, WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) ocs := be.obsrepSender.(*observabilityConsumerSender) require.NoError(t, be.Start(context.Background(), componenttest.NewNopHost())) diff --git a/exporter/exporterhelper/traces_test.go b/exporter/exporterhelper/traces_test.go index d99b9025c91..be5a45ac30d 100644 --- a/exporter/exporterhelper/traces_test.go +++ b/exporter/exporterhelper/traces_test.go @@ -37,7 +37,7 @@ const ( ) var ( - fakeTracesExporterName = component.NewIDWithName("fake_traces_exporter", "with_name") + fakeTracesExporterName = component.MustNewIDWithName("fake_traces_exporter", "with_name") fakeTracesExporterConfig = struct{}{} ) @@ -155,12 +155,12 @@ func TestTracesRequestExporter_Default_ExportError(t *testing.T) { func TestTracesExporter_WithPersistentQueue(t *testing.T) { qCfg := NewDefaultQueueSettings() - storageID := component.NewIDWithName("file_storage", "storage") + storageID := component.MustNewIDWithName("file_storage", "storage") qCfg.StorageID = &storageID rCfg := configretry.NewDefaultBackOffConfig() ts := consumertest.TracesSink{} set := exportertest.NewNopCreateSettings() - set.ID = component.NewIDWithName("test_traces", "with_persistent_queue") + set.ID = component.MustNewIDWithName("test_traces", "with_persistent_queue") te, err := NewTracesExporter(context.Background(), set, &fakeTracesExporterConfig, ts.ConsumeTraces, WithRetry(rCfg), WithQueue(qCfg)) require.NoError(t, err) diff --git a/exporter/exportertest/contract_checker_test.go b/exporter/exportertest/contract_checker_test.go index c99baa28792..7b0a6d5abb3 100644 --- a/exporter/exportertest/contract_checker_test.go +++ b/exporter/exportertest/contract_checker_test.go @@ -78,7 +78,7 @@ func (mef *mockExporterFactory) createMockLogsExporter( func newMockExporterFactory(mr *mockReceiver) exporter.Factory { mef := &mockExporterFactory{mr: mr} return exporter.NewFactory( - "pass_through_exporter", + component.MustNewType("pass_through_exporter"), func() component.Config { return &nopConfig{} }, exporter.WithTraces(mef.createMockTracesExporter, component.StabilityLevelBeta), exporter.WithMetrics(mef.createMockMetricsExporter, component.StabilityLevelBeta), @@ -87,7 +87,7 @@ func newMockExporterFactory(mr *mockReceiver) exporter.Factory { } func newMockReceiverFactory(mr *mockReceiver) receiver.Factory { - return receiver.NewFactory("pass_through_receiver", + return receiver.NewFactory(component.MustNewType("pass_through_receiver"), func() component.Config { return &nopConfig{} }, receiver.WithTraces(func(_ context.Context, _ receiver.CreateSettings, _ component.Config, c consumer.Traces) (receiver.Traces, error) { mr.Traces = c diff --git a/exporter/exportertest/nop_exporter.go b/exporter/exportertest/nop_exporter.go index 4911116058a..e7e9f350331 100644 --- a/exporter/exportertest/nop_exporter.go +++ b/exporter/exportertest/nop_exporter.go @@ -12,11 +12,12 @@ import ( "go.opentelemetry.io/collector/exporter" ) -const typeStr = "nop" +var nopType = component.MustNewType("nop") // NewNopCreateSettings returns a new nop settings for Create*Exporter functions. func NewNopCreateSettings() exporter.CreateSettings { return exporter.CreateSettings{ + ID: component.NewID(nopType), TelemetrySettings: componenttest.NewNopTelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo(), } @@ -25,7 +26,7 @@ func NewNopCreateSettings() exporter.CreateSettings { // NewNopFactory returns an exporter.Factory that constructs nop exporters. func NewNopFactory() exporter.Factory { return exporter.NewFactory( - "nop", + nopType, func() component.Config { return &nopConfig{} }, exporter.WithTraces(createTracesExporter, component.StabilityLevelStable), exporter.WithMetrics(createMetricsExporter, component.StabilityLevelStable), @@ -62,6 +63,6 @@ type nopExporter struct { func NewNopBuilder() *exporter.Builder { nopFactory := NewNopFactory() return exporter.NewBuilder( - map[component.ID]component.Config{component.NewID(typeStr): nopFactory.CreateDefaultConfig()}, - map[component.Type]exporter.Factory{typeStr: nopFactory}) + map[component.ID]component.Config{component.NewID(nopType): nopFactory.CreateDefaultConfig()}, + map[component.Type]exporter.Factory{nopType: nopFactory}) } diff --git a/exporter/exportertest/nop_exporter_test.go b/exporter/exportertest/nop_exporter_test.go index ed7a36bc062..6ae95efc08d 100644 --- a/exporter/exportertest/nop_exporter_test.go +++ b/exporter/exportertest/nop_exporter_test.go @@ -20,7 +20,7 @@ import ( func TestNewNopFactory(t *testing.T) { factory := NewNopFactory() require.NotNil(t, factory) - assert.Equal(t, component.Type("nop"), factory.Type()) + assert.Equal(t, component.MustNewType("nop"), factory.Type()) cfg := factory.CreateDefaultConfig() assert.Equal(t, &nopConfig{}, cfg) @@ -50,7 +50,7 @@ func TestNewNopBuilder(t *testing.T) { factory := NewNopFactory() cfg := factory.CreateDefaultConfig() set := NewNopCreateSettings() - set.ID = component.NewID(typeStr) + set.ID = component.NewID(nopType) traces, err := factory.CreateTracesExporter(context.Background(), set, cfg) require.NoError(t, err) diff --git a/exporter/loggingexporter/factory.go b/exporter/loggingexporter/factory.go index 70157fc2d98..1f38b315db0 100644 --- a/exporter/loggingexporter/factory.go +++ b/exporter/loggingexporter/factory.go @@ -15,9 +15,10 @@ import ( "go.opentelemetry.io/collector/exporter/loggingexporter/internal/metadata" ) +// The value of "type" key in configuration. +var componentType = component.MustNewType("logging") + const ( - // The value of "type" key in configuration. - typeStr = "logging" defaultSamplingInitial = 2 defaultSamplingThereafter = 500 ) @@ -25,7 +26,7 @@ const ( // NewFactory creates a factory for Logging exporter func NewFactory() exporter.Factory { return exporter.NewFactory( - typeStr, + componentType, createDefaultConfig, exporter.WithTraces(createTracesExporter, metadata.TracesStability), exporter.WithMetrics(createMetricsExporter, metadata.MetricsStability), diff --git a/exporter/loggingexporter/internal/metadata/generated_status.go b/exporter/loggingexporter/internal/metadata/generated_status.go index 20698f3672a..dc0bf4e123d 100644 --- a/exporter/loggingexporter/internal/metadata/generated_status.go +++ b/exporter/loggingexporter/internal/metadata/generated_status.go @@ -9,8 +9,11 @@ import ( "go.opentelemetry.io/collector/component" ) +var ( + Type = component.MustNewType("logging") +) + const ( - Type = "logging" TracesStability = component.StabilityLevelDeprecated MetricsStability = component.StabilityLevelDeprecated LogsStability = component.StabilityLevelDeprecated diff --git a/exporter/otlpexporter/config_test.go b/exporter/otlpexporter/config_test.go index cedc4adae2f..ae2fac324d8 100644 --- a/exporter/otlpexporter/config_test.go +++ b/exporter/otlpexporter/config_test.go @@ -74,7 +74,7 @@ func TestUnmarshalConfig(t *testing.T) { }, WriteBufferSize: 512 * 1024, BalancerName: "round_robin", - Auth: &configauth.Authentication{AuthenticatorID: component.NewID("nop")}, + Auth: &configauth.Authentication{AuthenticatorID: component.MustNewID("nop")}, }, }, cfg) } diff --git a/exporter/otlpexporter/internal/metadata/generated_status.go b/exporter/otlpexporter/internal/metadata/generated_status.go index 6876ebc2b26..f4222df7521 100644 --- a/exporter/otlpexporter/internal/metadata/generated_status.go +++ b/exporter/otlpexporter/internal/metadata/generated_status.go @@ -9,8 +9,11 @@ import ( "go.opentelemetry.io/collector/component" ) +var ( + Type = component.MustNewType("otlp") +) + const ( - Type = "otlp" LogsStability = component.StabilityLevelBeta TracesStability = component.StabilityLevelStable MetricsStability = component.StabilityLevelStable diff --git a/exporter/otlphttpexporter/internal/metadata/generated_status.go b/exporter/otlphttpexporter/internal/metadata/generated_status.go index f6f8933d685..8917eb822f7 100644 --- a/exporter/otlphttpexporter/internal/metadata/generated_status.go +++ b/exporter/otlphttpexporter/internal/metadata/generated_status.go @@ -9,8 +9,11 @@ import ( "go.opentelemetry.io/collector/component" ) +var ( + Type = component.MustNewType("otlphttp") +) + const ( - Type = "otlphttp" LogsStability = component.StabilityLevelBeta TracesStability = component.StabilityLevelStable MetricsStability = component.StabilityLevelStable diff --git a/extension/ballastextension/internal/metadata/generated_status.go b/extension/ballastextension/internal/metadata/generated_status.go index 70ced31503c..02205c5623e 100644 --- a/extension/ballastextension/internal/metadata/generated_status.go +++ b/extension/ballastextension/internal/metadata/generated_status.go @@ -9,8 +9,11 @@ import ( "go.opentelemetry.io/collector/component" ) +var ( + Type = component.MustNewType("memory_ballast") +) + const ( - Type = "memory_ballast" ExtensionStability = component.StabilityLevelDeprecated ) diff --git a/extension/extension_test.go b/extension/extension_test.go index 23a57d0bcc9..af75db9feea 100644 --- a/extension/extension_test.go +++ b/extension/extension_test.go @@ -21,18 +21,18 @@ type nopExtension struct { } func TestNewFactory(t *testing.T) { - const typeStr = "test" + var testType = component.MustNewType("test") defaultCfg := struct{}{} nopExtensionInstance := new(nopExtension) factory := NewFactory( - typeStr, + testType, func() component.Config { return &defaultCfg }, func(ctx context.Context, settings CreateSettings, extension component.Config) (Extension, error) { return nopExtensionInstance, nil }, component.StabilityLevelDevelopment) - assert.EqualValues(t, typeStr, factory.Type()) + assert.EqualValues(t, testType, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) assert.Equal(t, component.StabilityLevelDevelopment, factory.ExtensionStability()) @@ -48,8 +48,8 @@ func TestMakeFactoryMap(t *testing.T) { out map[component.Type]Factory } - p1 := NewFactory("p1", nil, nil, component.StabilityLevelAlpha) - p2 := NewFactory("p2", nil, nil, component.StabilityLevelAlpha) + p1 := NewFactory(component.MustNewType("p1"), nil, nil, component.StabilityLevelAlpha) + p2 := NewFactory(component.MustNewType("p2"), nil, nil, component.StabilityLevelAlpha) testCases := []testCase{ { name: "different names", @@ -61,7 +61,7 @@ func TestMakeFactoryMap(t *testing.T) { }, { name: "same name", - in: []Factory{p1, p2, NewFactory("p1", nil, nil, component.StabilityLevelAlpha)}, + in: []Factory{p1, p2, NewFactory(component.MustNewType("p1"), nil, nil, component.StabilityLevelAlpha)}, }, } for i := range testCases { @@ -79,14 +79,14 @@ func TestMakeFactoryMap(t *testing.T) { } func TestBuilder(t *testing.T) { - const typeStr = "test" + var testType = component.MustNewType("test") defaultCfg := struct{}{} - testID := component.NewID(typeStr) - unknownID := component.NewID("unknown") + testID := component.NewID(testType) + unknownID := component.MustNewID("unknown") factories, err := MakeFactoryMap([]Factory{ NewFactory( - typeStr, + testType, func() component.Config { return &defaultCfg }, func(ctx context.Context, settings CreateSettings, extension component.Config) (Extension, error) { return nopExtension{CreateSettings: settings}, nil @@ -111,20 +111,20 @@ func TestBuilder(t *testing.T) { assert.EqualError(t, err, "extension factory not available for: \"unknown\"") assert.Nil(t, missingType) - missingCfg, err := b.Create(context.Background(), createSettings(component.NewIDWithName(typeStr, "foo"))) + missingCfg, err := b.Create(context.Background(), createSettings(component.NewIDWithName(testType, "foo"))) assert.EqualError(t, err, "extension \"test/foo\" is not configured") assert.Nil(t, missingCfg) } func TestBuilderFactory(t *testing.T) { - factories, err := MakeFactoryMap([]Factory{NewFactory("foo", nil, nil, component.StabilityLevelDevelopment)}...) + factories, err := MakeFactoryMap([]Factory{NewFactory(component.MustNewType("foo"), nil, nil, component.StabilityLevelDevelopment)}...) require.NoError(t, err) - cfgs := map[component.ID]component.Config{component.NewID("foo"): struct{}{}} + cfgs := map[component.ID]component.Config{component.MustNewID("foo"): struct{}{}} b := NewBuilder(cfgs, factories) - assert.NotNil(t, b.Factory(component.NewID("foo").Type())) - assert.Nil(t, b.Factory(component.NewID("bar").Type())) + assert.NotNil(t, b.Factory(component.MustNewID("foo").Type())) + assert.Nil(t, b.Factory(component.MustNewID("bar").Type())) } func createSettings(id component.ID) CreateSettings { diff --git a/extension/extensiontest/nop_extension.go b/extension/extensiontest/nop_extension.go index 192650a0442..fcb9ab001f7 100644 --- a/extension/extensiontest/nop_extension.go +++ b/extension/extensiontest/nop_extension.go @@ -11,11 +11,12 @@ import ( "go.opentelemetry.io/collector/extension" ) -const typeStr = "nop" +var nopType = component.MustNewType("nop") // NewNopCreateSettings returns a new nop settings for extension.Factory Create* functions. func NewNopCreateSettings() extension.CreateSettings { return extension.CreateSettings{ + ID: component.NewID(nopType), TelemetrySettings: componenttest.NewNopTelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo(), } @@ -24,7 +25,7 @@ func NewNopCreateSettings() extension.CreateSettings { // NewNopFactory returns an extension.Factory that constructs nop extensions. func NewNopFactory() extension.Factory { return extension.NewFactory( - "nop", + nopType, func() component.Config { return &nopConfig{} }, @@ -48,6 +49,6 @@ type nopExtension struct { func NewNopBuilder() *extension.Builder { nopFactory := NewNopFactory() return extension.NewBuilder( - map[component.ID]component.Config{component.NewID(typeStr): nopFactory.CreateDefaultConfig()}, - map[component.Type]extension.Factory{typeStr: nopFactory}) + map[component.ID]component.Config{component.NewID(nopType): nopFactory.CreateDefaultConfig()}, + map[component.Type]extension.Factory{nopType: nopFactory}) } diff --git a/extension/extensiontest/nop_extension_test.go b/extension/extensiontest/nop_extension_test.go index c188feecdfc..7ebda6195ae 100644 --- a/extension/extensiontest/nop_extension_test.go +++ b/extension/extensiontest/nop_extension_test.go @@ -17,7 +17,7 @@ import ( func TestNewNopFactory(t *testing.T) { factory := NewNopFactory() require.NotNil(t, factory) - assert.Equal(t, component.Type("nop"), factory.Type()) + assert.Equal(t, component.MustNewType("nop"), factory.Type()) cfg := factory.CreateDefaultConfig() assert.Equal(t, &nopConfig{}, cfg) @@ -34,7 +34,7 @@ func TestNewNopBuilder(t *testing.T) { factory := NewNopFactory() cfg := factory.CreateDefaultConfig() set := NewNopCreateSettings() - set.ID = component.NewID(typeStr) + set.ID = component.NewID(nopType) ext, err := factory.CreateExtension(context.Background(), set, cfg) require.NoError(t, err) diff --git a/extension/extensiontest/statuswatcher_extension.go b/extension/extensiontest/statuswatcher_extension.go index e501353dcc6..eee0db94165 100644 --- a/extension/extensiontest/statuswatcher_extension.go +++ b/extension/extensiontest/statuswatcher_extension.go @@ -24,7 +24,7 @@ func NewStatusWatcherExtensionFactory( onStatusChanged func(source *component.InstanceID, event *component.StatusEvent), ) extension.Factory { return extension.NewFactory( - "statuswatcher", + component.MustNewType("statuswatcher"), func() component.Config { return &struct{}{} }, diff --git a/extension/extensiontest/statuswatcher_extension_test.go b/extension/extensiontest/statuswatcher_extension_test.go index 0bfdf4f5eda..14f9859e354 100644 --- a/extension/extensiontest/statuswatcher_extension_test.go +++ b/extension/extensiontest/statuswatcher_extension_test.go @@ -23,7 +23,7 @@ func TestStatusWatcherExtension(t *testing.T) { }, ) require.NotNil(t, factory) - assert.Equal(t, component.Type("statuswatcher"), factory.Type()) + assert.Equal(t, component.MustNewType("statuswatcher"), factory.Type()) cfg := factory.CreateDefaultConfig() assert.Equal(t, &struct{}{}, cfg) diff --git a/extension/memorylimiterextension/internal/metadata/generated_status.go b/extension/memorylimiterextension/internal/metadata/generated_status.go index b76d2f1cd74..c5131e1f7a7 100644 --- a/extension/memorylimiterextension/internal/metadata/generated_status.go +++ b/extension/memorylimiterextension/internal/metadata/generated_status.go @@ -9,8 +9,11 @@ import ( "go.opentelemetry.io/collector/component" ) +var ( + Type = component.MustNewType("memory_limiter") +) + const ( - Type = "memory_limiter" ExtensionStability = component.StabilityLevelDevelopment ) diff --git a/extension/zpagesextension/internal/metadata/generated_status.go b/extension/zpagesextension/internal/metadata/generated_status.go index 72170d1f87b..5460b8c79f9 100644 --- a/extension/zpagesextension/internal/metadata/generated_status.go +++ b/extension/zpagesextension/internal/metadata/generated_status.go @@ -9,8 +9,11 @@ import ( "go.opentelemetry.io/collector/component" ) +var ( + Type = component.MustNewType("zpages") +) + const ( - Type = "zpages" ExtensionStability = component.StabilityLevelBeta ) diff --git a/internal/memorylimiter/memorylimiter_test.go b/internal/memorylimiter/memorylimiter_test.go index c3395791a75..e9e92a33f70 100644 --- a/internal/memorylimiter/memorylimiter_test.go +++ b/internal/memorylimiter/memorylimiter_test.go @@ -173,7 +173,7 @@ type host struct { func (h *host) GetExtensions() map[component.ID]component.Component { ret := make(map[component.ID]component.Component) - ret[component.NewID("ballast")] = &ballastExtension{ballastSize: h.ballastSize} + ret[component.MustNewID("ballast")] = &ballastExtension{ballastSize: h.ballastSize} return ret } diff --git a/internal/sharedcomponent/sharedcomponent_test.go b/internal/sharedcomponent/sharedcomponent_test.go index 09589d7ad63..8ba96a28734 100644 --- a/internal/sharedcomponent/sharedcomponent_test.go +++ b/internal/sharedcomponent/sharedcomponent_test.go @@ -15,7 +15,7 @@ import ( "go.opentelemetry.io/collector/component/componenttest" ) -var id = component.NewID("test") +var id = component.MustNewID("test") type baseComponent struct { component.StartFunc diff --git a/otelcol/command_components_test.go b/otelcol/command_components_test.go index 3fe9a2cdd51..141fb586010 100644 --- a/otelcol/command_components_test.go +++ b/otelcol/command_components_test.go @@ -16,6 +16,8 @@ import ( "go.opentelemetry.io/collector/component" ) +var nopType = component.MustNewType("nop") + func TestNewBuildSubCommand(t *testing.T) { cfgProvider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nop.yaml")})) require.NoError(t, err) @@ -31,7 +33,7 @@ func TestNewBuildSubCommand(t *testing.T) { ExpectedYamlStruct := componentsOutput{ BuildInfo: component.NewDefaultBuildInfo(), Receivers: []componentWithStability{{ - Name: component.Type("nop"), + Name: nopType, Stability: map[string]string{ "logs": "Stable", "metrics": "Stable", @@ -39,7 +41,7 @@ func TestNewBuildSubCommand(t *testing.T) { }, }}, Processors: []componentWithStability{{ - Name: component.Type("nop"), + Name: nopType, Stability: map[string]string{ "logs": "Stable", "metrics": "Stable", @@ -47,7 +49,7 @@ func TestNewBuildSubCommand(t *testing.T) { }, }}, Exporters: []componentWithStability{{ - Name: component.Type("nop"), + Name: nopType, Stability: map[string]string{ "logs": "Stable", "metrics": "Stable", @@ -55,7 +57,7 @@ func TestNewBuildSubCommand(t *testing.T) { }, }}, Connectors: []componentWithStability{{ - Name: component.Type("nop"), + Name: nopType, Stability: map[string]string{ "logs-to-logs": "Development", "logs-to-metrics": "Development", @@ -71,7 +73,7 @@ func TestNewBuildSubCommand(t *testing.T) { }, }}, Extensions: []componentWithStability{{ - Name: component.Type("nop"), + Name: nopType, Stability: map[string]string{ "extension": "Stable", }, diff --git a/otelcol/config_test.go b/otelcol/config_test.go index 9a4ddb87c4f..e482e6c8ae8 100644 --- a/otelcol/config_test.go +++ b/otelcol/config_test.go @@ -76,7 +76,7 @@ func TestConfigValidate(t *testing.T) { name: "invalid-extension-reference", cfgFn: func() *Config { cfg := generateConfig() - cfg.Service.Extensions = append(cfg.Service.Extensions, component.NewIDWithName("nop", "2")) + cfg.Service.Extensions = append(cfg.Service.Extensions, component.MustNewIDWithName("nop", "2")) return cfg }, expected: errors.New(`service::extensions: references extension "nop/2" which is not configured`), @@ -85,8 +85,8 @@ func TestConfigValidate(t *testing.T) { name: "invalid-receiver-reference", cfgFn: func() *Config { cfg := generateConfig() - pipe := cfg.Service.Pipelines[component.NewID("traces")] - pipe.Receivers = append(pipe.Receivers, component.NewIDWithName("nop", "2")) + pipe := cfg.Service.Pipelines[component.MustNewID("traces")] + pipe.Receivers = append(pipe.Receivers, component.MustNewIDWithName("nop", "2")) return cfg }, expected: errors.New(`service::pipelines::traces: references receiver "nop/2" which is not configured`), @@ -95,8 +95,8 @@ func TestConfigValidate(t *testing.T) { name: "invalid-processor-reference", cfgFn: func() *Config { cfg := generateConfig() - pipe := cfg.Service.Pipelines[component.NewID("traces")] - pipe.Processors = append(pipe.Processors, component.NewIDWithName("nop", "2")) + pipe := cfg.Service.Pipelines[component.MustNewID("traces")] + pipe.Processors = append(pipe.Processors, component.MustNewIDWithName("nop", "2")) return cfg }, expected: errors.New(`service::pipelines::traces: references processor "nop/2" which is not configured`), @@ -105,8 +105,8 @@ func TestConfigValidate(t *testing.T) { name: "invalid-exporter-reference", cfgFn: func() *Config { cfg := generateConfig() - pipe := cfg.Service.Pipelines[component.NewID("traces")] - pipe.Exporters = append(pipe.Exporters, component.NewIDWithName("nop", "2")) + pipe := cfg.Service.Pipelines[component.MustNewID("traces")] + pipe.Exporters = append(pipe.Exporters, component.MustNewIDWithName("nop", "2")) return cfg }, expected: errors.New(`service::pipelines::traces: references exporter "nop/2" which is not configured`), @@ -115,7 +115,7 @@ func TestConfigValidate(t *testing.T) { name: "invalid-receiver-config", cfgFn: func() *Config { cfg := generateConfig() - cfg.Receivers[component.NewID("nop")] = &errConfig{ + cfg.Receivers[component.MustNewID("nop")] = &errConfig{ validateErr: errInvalidRecvConfig, } return cfg @@ -126,7 +126,7 @@ func TestConfigValidate(t *testing.T) { name: "invalid-exporter-config", cfgFn: func() *Config { cfg := generateConfig() - cfg.Exporters[component.NewID("nop")] = &errConfig{ + cfg.Exporters[component.MustNewID("nop")] = &errConfig{ validateErr: errInvalidExpConfig, } return cfg @@ -137,7 +137,7 @@ func TestConfigValidate(t *testing.T) { name: "invalid-processor-config", cfgFn: func() *Config { cfg := generateConfig() - cfg.Processors[component.NewID("nop")] = &errConfig{ + cfg.Processors[component.MustNewID("nop")] = &errConfig{ validateErr: errInvalidProcConfig, } return cfg @@ -148,7 +148,7 @@ func TestConfigValidate(t *testing.T) { name: "invalid-extension-config", cfgFn: func() *Config { cfg := generateConfig() - cfg.Extensions[component.NewID("nop")] = &errConfig{ + cfg.Extensions[component.MustNewID("nop")] = &errConfig{ validateErr: errInvalidExtConfig, } return cfg @@ -159,7 +159,7 @@ func TestConfigValidate(t *testing.T) { name: "invalid-connector-config", cfgFn: func() *Config { cfg := generateConfig() - cfg.Connectors[component.NewIDWithName("nop", "conn")] = &errConfig{ + cfg.Connectors[component.MustNewIDWithName("nop", "conn")] = &errConfig{ validateErr: errInvalidConnConfig, } return cfg @@ -170,34 +170,34 @@ func TestConfigValidate(t *testing.T) { name: "ambiguous-connector-name-as-receiver", cfgFn: func() *Config { cfg := generateConfig() - cfg.Receivers[component.NewID("nop/2")] = &errConfig{} - cfg.Connectors[component.NewID("nop/2")] = &errConfig{} - pipe := cfg.Service.Pipelines[component.NewID("traces")] - pipe.Receivers = append(pipe.Receivers, component.NewIDWithName("nop", "2")) - pipe.Exporters = append(pipe.Exporters, component.NewIDWithName("nop", "2")) + cfg.Receivers[component.MustNewID("nop2")] = &errConfig{} + cfg.Connectors[component.MustNewID("nop2")] = &errConfig{} + pipe := cfg.Service.Pipelines[component.MustNewID("traces")] + pipe.Receivers = append(pipe.Receivers, component.MustNewIDWithName("nop", "2")) + pipe.Exporters = append(pipe.Exporters, component.MustNewIDWithName("nop", "2")) return cfg }, - expected: errors.New(`connectors::nop/2: ambiguous ID: Found both "nop/2" receiver and "nop/2" connector. Change one of the components' IDs to eliminate ambiguity (e.g. rename "nop/2" connector to "nop/2/connector")`), + expected: errors.New(`connectors::nop2: ambiguous ID: Found both "nop2" receiver and "nop2" connector. Change one of the components' IDs to eliminate ambiguity (e.g. rename "nop2" connector to "nop2/connector")`), }, { name: "ambiguous-connector-name-as-exporter", cfgFn: func() *Config { cfg := generateConfig() - cfg.Exporters[component.NewID("nop/2")] = &errConfig{} - cfg.Connectors[component.NewID("nop/2")] = &errConfig{} - pipe := cfg.Service.Pipelines[component.NewID("traces")] - pipe.Receivers = append(pipe.Receivers, component.NewIDWithName("nop", "2")) - pipe.Exporters = append(pipe.Exporters, component.NewIDWithName("nop", "2")) + cfg.Exporters[component.MustNewID("nop2")] = &errConfig{} + cfg.Connectors[component.MustNewID("nop2")] = &errConfig{} + pipe := cfg.Service.Pipelines[component.MustNewID("traces")] + pipe.Receivers = append(pipe.Receivers, component.MustNewIDWithName("nop", "2")) + pipe.Exporters = append(pipe.Exporters, component.MustNewIDWithName("nop", "2")) return cfg }, - expected: errors.New(`connectors::nop/2: ambiguous ID: Found both "nop/2" exporter and "nop/2" connector. Change one of the components' IDs to eliminate ambiguity (e.g. rename "nop/2" connector to "nop/2/connector")`), + expected: errors.New(`connectors::nop2: ambiguous ID: Found both "nop2" exporter and "nop2" connector. Change one of the components' IDs to eliminate ambiguity (e.g. rename "nop2" connector to "nop2/connector")`), }, { name: "invalid-connector-reference-as-receiver", cfgFn: func() *Config { cfg := generateConfig() - pipe := cfg.Service.Pipelines[component.NewID("traces")] - pipe.Receivers = append(pipe.Receivers, component.NewIDWithName("nop", "conn2")) + pipe := cfg.Service.Pipelines[component.MustNewID("traces")] + pipe.Receivers = append(pipe.Receivers, component.MustNewIDWithName("nop", "conn2")) return cfg }, expected: errors.New(`service::pipelines::traces: references receiver "nop/conn2" which is not configured`), @@ -206,8 +206,8 @@ func TestConfigValidate(t *testing.T) { name: "invalid-connector-reference-as-receiver", cfgFn: func() *Config { cfg := generateConfig() - pipe := cfg.Service.Pipelines[component.NewID("traces")] - pipe.Exporters = append(pipe.Exporters, component.NewIDWithName("nop", "conn2")) + pipe := cfg.Service.Pipelines[component.MustNewID("traces")] + pipe.Exporters = append(pipe.Exporters, component.MustNewIDWithName("nop", "conn2")) return cfg }, expected: errors.New(`service::pipelines::traces: references exporter "nop/conn2" which is not configured`), @@ -234,19 +234,19 @@ func TestConfigValidate(t *testing.T) { func generateConfig() *Config { return &Config{ Receivers: map[component.ID]component.Config{ - component.NewID("nop"): &errConfig{}, + component.MustNewID("nop"): &errConfig{}, }, Exporters: map[component.ID]component.Config{ - component.NewID("nop"): &errConfig{}, + component.MustNewID("nop"): &errConfig{}, }, Processors: map[component.ID]component.Config{ - component.NewID("nop"): &errConfig{}, + component.MustNewID("nop"): &errConfig{}, }, Connectors: map[component.ID]component.Config{ - component.NewIDWithName("nop", "conn"): &errConfig{}, + component.MustNewIDWithName("nop", "conn"): &errConfig{}, }, Extensions: map[component.ID]component.Config{ - component.NewID("nop"): &errConfig{}, + component.MustNewID("nop"): &errConfig{}, }, Service: service.Config{ Telemetry: telemetry.Config{ @@ -265,12 +265,12 @@ func generateConfig() *Config { Address: ":8080", }, }, - Extensions: []component.ID{component.NewID("nop")}, + Extensions: []component.ID{component.MustNewID("nop")}, Pipelines: pipelines.Config{ - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, }, diff --git a/otelcol/internal/configunmarshaler/configs_test.go b/otelcol/internal/configunmarshaler/configs_test.go index bc869456455..f6cd2865281 100644 --- a/otelcol/internal/configunmarshaler/configs_test.go +++ b/otelcol/internal/configunmarshaler/configs_test.go @@ -18,6 +18,8 @@ import ( "go.opentelemetry.io/collector/receiver/receivertest" ) +var nopType = component.MustNewType("nop") + var testKinds = []struct { kind string factories map[component.Type]component.Factory @@ -25,31 +27,31 @@ var testKinds = []struct { { kind: "receiver", factories: map[component.Type]component.Factory{ - "nop": receivertest.NewNopFactory(), + nopType: receivertest.NewNopFactory(), }, }, { kind: "processor", factories: map[component.Type]component.Factory{ - "nop": processortest.NewNopFactory(), + nopType: processortest.NewNopFactory(), }, }, { kind: "exporter", factories: map[component.Type]component.Factory{ - "nop": exportertest.NewNopFactory(), + nopType: exportertest.NewNopFactory(), }, }, { kind: "connector", factories: map[component.Type]component.Factory{ - "nop": connectortest.NewNopFactory(), + nopType: connectortest.NewNopFactory(), }, }, { kind: "extension", factories: map[component.Type]component.Factory{ - "nop": extensiontest.NewNopFactory(), + nopType: extensiontest.NewNopFactory(), }, }, } @@ -65,8 +67,8 @@ func TestUnmarshal(t *testing.T) { require.NoError(t, cfgs.Unmarshal(conf)) assert.Equal(t, map[component.ID]component.Config{ - component.NewID("nop"): tk.factories["nop"].CreateDefaultConfig(), - component.NewIDWithName("nop", "my"+tk.kind): tk.factories["nop"].CreateDefaultConfig(), + component.NewID(nopType): tk.factories[nopType].CreateDefaultConfig(), + component.NewIDWithName(nopType, "my"+tk.kind): tk.factories[nopType].CreateDefaultConfig(), }, cfgs.Configs()) }) } diff --git a/otelcol/otelcoltest/config_test.go b/otelcol/otelcoltest/config_test.go index 1ab8ad1304d..71502de536e 100644 --- a/otelcol/otelcoltest/config_test.go +++ b/otelcol/otelcoltest/config_test.go @@ -23,39 +23,39 @@ func TestLoadConfig(t *testing.T) { // Verify extensions. require.Len(t, cfg.Extensions, 2) - assert.Contains(t, cfg.Extensions, component.NewID("nop")) - assert.Contains(t, cfg.Extensions, component.NewIDWithName("nop", "myextension")) + assert.Contains(t, cfg.Extensions, component.MustNewID("nop")) + assert.Contains(t, cfg.Extensions, component.MustNewIDWithName("nop", "myextension")) // Verify receivers require.Len(t, cfg.Receivers, 2) - assert.Contains(t, cfg.Receivers, component.NewID("nop")) - assert.Contains(t, cfg.Receivers, component.NewIDWithName("nop", "myreceiver")) + assert.Contains(t, cfg.Receivers, component.MustNewID("nop")) + assert.Contains(t, cfg.Receivers, component.MustNewIDWithName("nop", "myreceiver")) // Verify exporters assert.Len(t, cfg.Exporters, 2) - assert.Contains(t, cfg.Exporters, component.NewID("nop")) - assert.Contains(t, cfg.Exporters, component.NewIDWithName("nop", "myexporter")) + assert.Contains(t, cfg.Exporters, component.MustNewID("nop")) + assert.Contains(t, cfg.Exporters, component.MustNewIDWithName("nop", "myexporter")) // Verify procs assert.Len(t, cfg.Processors, 2) - assert.Contains(t, cfg.Processors, component.NewID("nop")) - assert.Contains(t, cfg.Processors, component.NewIDWithName("nop", "myprocessor")) + assert.Contains(t, cfg.Processors, component.MustNewID("nop")) + assert.Contains(t, cfg.Processors, component.MustNewIDWithName("nop", "myprocessor")) // Verify connectors assert.Len(t, cfg.Connectors, 1) - assert.Contains(t, cfg.Connectors, component.NewIDWithName("nop", "myconnector")) + assert.Contains(t, cfg.Connectors, component.MustNewIDWithName("nop", "myconnector")) // Verify service. require.Len(t, cfg.Service.Extensions, 1) - assert.Contains(t, cfg.Service.Extensions, component.NewID("nop")) + assert.Contains(t, cfg.Service.Extensions, component.MustNewID("nop")) require.Len(t, cfg.Service.Pipelines, 1) assert.Equal(t, &pipelines.PipelineConfig{ - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop")}, + Receivers: []component.ID{component.MustNewID("nop")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, - cfg.Service.Pipelines[component.NewID("traces")], + cfg.Service.Pipelines[component.MustNewID("traces")], "Did not load pipeline config correctly") } diff --git a/otelcol/otelcoltest/nop_factories_test.go b/otelcol/otelcoltest/nop_factories_test.go index b70720c026b..1f77ecdd68e 100644 --- a/otelcol/otelcoltest/nop_factories_test.go +++ b/otelcol/otelcoltest/nop_factories_test.go @@ -11,32 +11,34 @@ import ( "go.opentelemetry.io/collector/component" ) +var nopType = component.MustNewType("nop") + func TestNopFactories(t *testing.T) { nopFactories, err := NopFactories() require.NoError(t, err) require.Equal(t, 1, len(nopFactories.Receivers)) - nopReceiverFactory, ok := nopFactories.Receivers["nop"] + nopReceiverFactory, ok := nopFactories.Receivers[nopType] require.True(t, ok) - require.Equal(t, component.Type("nop"), nopReceiverFactory.Type()) + require.Equal(t, nopType, nopReceiverFactory.Type()) require.Equal(t, 1, len(nopFactories.Processors)) - nopProcessorFactory, ok := nopFactories.Processors["nop"] + nopProcessorFactory, ok := nopFactories.Processors[nopType] require.True(t, ok) - require.Equal(t, component.Type("nop"), nopProcessorFactory.Type()) + require.Equal(t, nopType, nopProcessorFactory.Type()) require.Equal(t, 1, len(nopFactories.Exporters)) - nopExporterFactory, ok := nopFactories.Exporters["nop"] + nopExporterFactory, ok := nopFactories.Exporters[nopType] require.True(t, ok) - require.Equal(t, component.Type("nop"), nopExporterFactory.Type()) + require.Equal(t, nopType, nopExporterFactory.Type()) require.Equal(t, 1, len(nopFactories.Extensions)) - nopExtensionFactory, ok := nopFactories.Extensions["nop"] + nopExtensionFactory, ok := nopFactories.Extensions[nopType] require.True(t, ok) - require.Equal(t, component.Type("nop"), nopExtensionFactory.Type()) + require.Equal(t, nopType, nopExtensionFactory.Type()) require.Equal(t, 1, len(nopFactories.Connectors)) - nopConnectorFactory, ok := nopFactories.Connectors["nop"] + nopConnectorFactory, ok := nopFactories.Connectors[nopType] require.True(t, ok) - require.Equal(t, component.Type("nop"), nopConnectorFactory.Type()) + require.Equal(t, nopType, nopConnectorFactory.Type()) } diff --git a/processor/batchprocessor/internal/metadata/generated_status.go b/processor/batchprocessor/internal/metadata/generated_status.go index eb9c10bdafe..2ccbff8e2b3 100644 --- a/processor/batchprocessor/internal/metadata/generated_status.go +++ b/processor/batchprocessor/internal/metadata/generated_status.go @@ -9,8 +9,11 @@ import ( "go.opentelemetry.io/collector/component" ) +var ( + Type = component.MustNewType("batch") +) + const ( - Type = "batch" TracesStability = component.StabilityLevelBeta MetricsStability = component.StabilityLevelBeta LogsStability = component.StabilityLevelBeta diff --git a/processor/batchprocessor/metrics_test.go b/processor/batchprocessor/metrics_test.go index 76f354a4932..47345e99d57 100644 --- a/processor/batchprocessor/metrics_test.go +++ b/processor/batchprocessor/metrics_test.go @@ -75,7 +75,7 @@ func setupTelemetry(t *testing.T) testTelemetry { func (tt *testTelemetry) NewProcessorCreateSettings() processor.CreateSettings { settings := processortest.NewNopCreateSettings() settings.MeterProvider = tt.meterProvider - settings.ID = component.NewID(typeStr) + settings.ID = component.MustNewID("batch") return settings } diff --git a/processor/memorylimiterprocessor/internal/metadata/generated_status.go b/processor/memorylimiterprocessor/internal/metadata/generated_status.go index 7068f5e29eb..5fd2a9e9bc0 100644 --- a/processor/memorylimiterprocessor/internal/metadata/generated_status.go +++ b/processor/memorylimiterprocessor/internal/metadata/generated_status.go @@ -9,8 +9,11 @@ import ( "go.opentelemetry.io/collector/component" ) +var ( + Type = component.MustNewType("memory_limiter") +) + const ( - Type = "memory_limiter" TracesStability = component.StabilityLevelBeta MetricsStability = component.StabilityLevelBeta LogsStability = component.StabilityLevelBeta diff --git a/processor/memorylimiterprocessor/memorylimiter_test.go b/processor/memorylimiterprocessor/memorylimiter_test.go index 6a3c3999ce9..626bf877d7c 100644 --- a/processor/memorylimiterprocessor/memorylimiter_test.go +++ b/processor/memorylimiterprocessor/memorylimiter_test.go @@ -467,7 +467,7 @@ type host struct { func (h *host) GetExtensions() map[component.ID]component.Component { ret := make(map[component.ID]component.Component) - ret[component.NewID("ballast")] = &ballastExtension{ballastSize: h.ballastSize} + ret[component.MustNewID("ballast")] = &ballastExtension{ballastSize: h.ballastSize} return ret } diff --git a/processor/processor_test.go b/processor/processor_test.go index 11d70512186..c72f7edb698 100644 --- a/processor/processor_test.go +++ b/processor/processor_test.go @@ -17,12 +17,12 @@ import ( ) func TestNewFactory(t *testing.T) { - const typeStr = "test" + var testType = component.MustNewType("test") defaultCfg := struct{}{} factory := NewFactory( - typeStr, + testType, func() component.Config { return &defaultCfg }) - assert.EqualValues(t, typeStr, factory.Type()) + assert.EqualValues(t, testType, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) _, err := factory.CreateTracesProcessor(context.Background(), CreateSettings{}, &defaultCfg, nil) assert.Error(t, err) @@ -33,15 +33,15 @@ func TestNewFactory(t *testing.T) { } func TestNewFactoryWithOptions(t *testing.T) { - const typeStr = "test" + var testType = component.MustNewType("test") defaultCfg := struct{}{} factory := NewFactory( - typeStr, + testType, func() component.Config { return &defaultCfg }, WithTraces(createTraces, component.StabilityLevelAlpha), WithMetrics(createMetrics, component.StabilityLevelBeta), WithLogs(createLogs, component.StabilityLevelUnmaintained)) - assert.EqualValues(t, typeStr, factory.Type()) + assert.EqualValues(t, testType, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) assert.Equal(t, component.StabilityLevelAlpha, factory.TracesProcessorStability()) @@ -64,8 +64,8 @@ func TestMakeFactoryMap(t *testing.T) { out map[component.Type]Factory } - p1 := NewFactory("p1", nil) - p2 := NewFactory("p2", nil) + p1 := NewFactory(component.MustNewType("p1"), nil) + p2 := NewFactory(component.MustNewType("p2"), nil) testCases := []testCase{ { name: "different names", @@ -77,7 +77,7 @@ func TestMakeFactoryMap(t *testing.T) { }, { name: "same name", - in: []Factory{p1, p2, NewFactory("p1", nil)}, + in: []Factory{p1, p2, NewFactory(component.MustNewType("p1"), nil)}, }, } @@ -98,9 +98,9 @@ func TestMakeFactoryMap(t *testing.T) { func TestBuilder(t *testing.T) { defaultCfg := struct{}{} factories, err := MakeFactoryMap([]Factory{ - NewFactory("err", nil), + NewFactory(component.MustNewType("err"), nil), NewFactory( - "all", + component.MustNewType("all"), func() component.Config { return &defaultCfg }, WithTraces(createTraces, component.StabilityLevelDevelopment), WithMetrics(createMetrics, component.StabilityLevelAlpha), @@ -116,21 +116,21 @@ func TestBuilder(t *testing.T) { }{ { name: "unknown", - id: component.NewID("unknown"), + id: component.MustNewID("unknown"), err: "processor factory not available for: \"unknown\"", }, { name: "err", - id: component.NewID("err"), + id: component.MustNewID("err"), err: "telemetry type is not supported", }, { name: "all", - id: component.NewID("all"), + id: component.MustNewID("all"), }, { name: "all/named", - id: component.NewIDWithName("all", "named"), + id: component.MustNewIDWithName("all", "named"), }, } @@ -173,7 +173,7 @@ func TestBuilderMissingConfig(t *testing.T) { defaultCfg := struct{}{} factories, err := MakeFactoryMap([]Factory{ NewFactory( - "all", + component.MustNewType("all"), func() component.Config { return &defaultCfg }, WithTraces(createTraces, component.StabilityLevelDevelopment), WithMetrics(createMetrics, component.StabilityLevelAlpha), @@ -184,7 +184,7 @@ func TestBuilderMissingConfig(t *testing.T) { require.NoError(t, err) bErr := NewBuilder(map[component.ID]component.Config{}, factories) - missingID := component.NewIDWithName("all", "missing") + missingID := component.MustNewIDWithName("all", "missing") te, err := bErr.CreateTraces(context.Background(), createSettings(missingID), nil) assert.EqualError(t, err, "processor \"all/missing\" is not configured") @@ -200,14 +200,14 @@ func TestBuilderMissingConfig(t *testing.T) { } func TestBuilderFactory(t *testing.T) { - factories, err := MakeFactoryMap([]Factory{NewFactory("foo", nil)}...) + factories, err := MakeFactoryMap([]Factory{NewFactory(component.MustNewType("foo"), nil)}...) require.NoError(t, err) - cfgs := map[component.ID]component.Config{component.NewID("foo"): struct{}{}} + cfgs := map[component.ID]component.Config{component.MustNewID("foo"): struct{}{}} b := NewBuilder(cfgs, factories) - assert.NotNil(t, b.Factory(component.NewID("foo").Type())) - assert.Nil(t, b.Factory(component.NewID("bar").Type())) + assert.NotNil(t, b.Factory(component.MustNewID("foo").Type())) + assert.Nil(t, b.Factory(component.MustNewID("bar").Type())) } var nopInstance = &nopProcessor{ diff --git a/processor/processorhelper/obsreport_test.go b/processor/processorhelper/obsreport_test.go index 41a395c37ba..2cd4500e299 100644 --- a/processor/processorhelper/obsreport_test.go +++ b/processor/processorhelper/obsreport_test.go @@ -16,7 +16,7 @@ import ( ) var ( - processorID = component.NewID("fakeProcessor") + processorID = component.MustNewID("fakeProcessor") ) func TestProcessorTraceData(t *testing.T) { diff --git a/processor/processortest/nop_processor.go b/processor/processortest/nop_processor.go index 2e5133f6bdc..dad0a9f0566 100644 --- a/processor/processortest/nop_processor.go +++ b/processor/processortest/nop_processor.go @@ -13,11 +13,12 @@ import ( "go.opentelemetry.io/collector/processor" ) -const typeStr = "nop" +var nopType = component.MustNewType("nop") // NewNopCreateSettings returns a new nop settings for Create* functions. func NewNopCreateSettings() processor.CreateSettings { return processor.CreateSettings{ + ID: component.NewID(nopType), TelemetrySettings: componenttest.NewNopTelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo(), } @@ -26,7 +27,7 @@ func NewNopCreateSettings() processor.CreateSettings { // NewNopFactory returns a component.ProcessorFactory that constructs nop processors. func NewNopFactory() processor.Factory { return processor.NewFactory( - "nop", + nopType, func() component.Config { return &nopConfig{} }, processor.WithTraces(createTracesProcessor, component.StabilityLevelStable), processor.WithMetrics(createMetricsProcessor, component.StabilityLevelStable), @@ -63,6 +64,6 @@ type nopProcessor struct { func NewNopBuilder() *processor.Builder { nopFactory := NewNopFactory() return processor.NewBuilder( - map[component.ID]component.Config{component.NewID(typeStr): nopFactory.CreateDefaultConfig()}, - map[component.Type]processor.Factory{typeStr: nopFactory}) + map[component.ID]component.Config{component.NewID(nopType): nopFactory.CreateDefaultConfig()}, + map[component.Type]processor.Factory{nopType: nopFactory}) } diff --git a/processor/processortest/nop_processor_test.go b/processor/processortest/nop_processor_test.go index 44f581bd2eb..77e9131ed62 100644 --- a/processor/processortest/nop_processor_test.go +++ b/processor/processortest/nop_processor_test.go @@ -22,7 +22,7 @@ import ( func TestNewNopFactory(t *testing.T) { factory := NewNopFactory() require.NotNil(t, factory) - assert.Equal(t, component.Type("nop"), factory.Type()) + assert.Equal(t, component.MustNewType("nop"), factory.Type()) cfg := factory.CreateDefaultConfig() assert.Equal(t, &nopConfig{}, cfg) @@ -55,7 +55,7 @@ func TestNewNopBuilder(t *testing.T) { factory := NewNopFactory() cfg := factory.CreateDefaultConfig() set := NewNopCreateSettings() - set.ID = component.NewID(typeStr) + set.ID = component.NewID(nopType) traces, err := factory.CreateTracesProcessor(context.Background(), set, cfg, consumertest.NewNop()) require.NoError(t, err) diff --git a/processor/processortest/unhealthy_processor.go b/processor/processortest/unhealthy_processor.go index 508fbfde897..99269e3bae0 100644 --- a/processor/processortest/unhealthy_processor.go +++ b/processor/processortest/unhealthy_processor.go @@ -24,7 +24,7 @@ func NewUnhealthyProcessorCreateSettings() processor.CreateSettings { // NewUnhealthyProcessorFactory returns a component.ProcessorFactory that constructs nop processors. func NewUnhealthyProcessorFactory() processor.Factory { return processor.NewFactory( - "unhealthy", + component.MustNewType("unhealthy"), func() component.Config { return &struct{}{} }, diff --git a/processor/processortest/unhealthy_processor_test.go b/processor/processortest/unhealthy_processor_test.go index adc80322f22..f00c4236a19 100644 --- a/processor/processortest/unhealthy_processor_test.go +++ b/processor/processortest/unhealthy_processor_test.go @@ -22,7 +22,7 @@ import ( func TestNewUnhealthyProcessorFactory(t *testing.T) { factory := NewUnhealthyProcessorFactory() require.NotNil(t, factory) - assert.Equal(t, component.Type("unhealthy"), factory.Type()) + assert.Equal(t, component.MustNewType("unhealthy"), factory.Type()) cfg := factory.CreateDefaultConfig() assert.Equal(t, &struct{}{}, cfg) diff --git a/receiver/otlpreceiver/internal/logs/otlp_test.go b/receiver/otlpreceiver/internal/logs/otlp_test.go index 14563482de5..b2d3178d011 100644 --- a/receiver/otlpreceiver/internal/logs/otlp_test.go +++ b/receiver/otlpreceiver/internal/logs/otlp_test.go @@ -92,7 +92,7 @@ func otlpReceiverOnGRPCServer(t *testing.T, lc consumer.Logs) net.Addr { }) set := receivertest.NewNopCreateSettings() - set.ID = component.NewIDWithName("otlp", "log") + set.ID = component.MustNewIDWithName("otlp", "log") obsreport, err := receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{ ReceiverID: set.ID, Transport: "grpc", diff --git a/receiver/otlpreceiver/internal/metadata/generated_status.go b/receiver/otlpreceiver/internal/metadata/generated_status.go index ec7a695b15f..8a7bc0b7be0 100644 --- a/receiver/otlpreceiver/internal/metadata/generated_status.go +++ b/receiver/otlpreceiver/internal/metadata/generated_status.go @@ -9,8 +9,11 @@ import ( "go.opentelemetry.io/collector/component" ) +var ( + Type = component.MustNewType("otlp") +) + const ( - Type = "otlp" LogsStability = component.StabilityLevelBeta TracesStability = component.StabilityLevelStable MetricsStability = component.StabilityLevelStable diff --git a/receiver/otlpreceiver/internal/metrics/otlp_test.go b/receiver/otlpreceiver/internal/metrics/otlp_test.go index 1e532b8f174..babc366119f 100644 --- a/receiver/otlpreceiver/internal/metrics/otlp_test.go +++ b/receiver/otlpreceiver/internal/metrics/otlp_test.go @@ -93,7 +93,7 @@ func otlpReceiverOnGRPCServer(t *testing.T, mc consumer.Metrics) net.Addr { }) set := receivertest.NewNopCreateSettings() - set.ID = component.NewIDWithName("otlp", "metrics") + set.ID = component.MustNewIDWithName("otlp", "metrics") obsreport, err := receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{ ReceiverID: set.ID, Transport: "grpc", diff --git a/receiver/otlpreceiver/internal/trace/otlp_test.go b/receiver/otlpreceiver/internal/trace/otlp_test.go index 499684969e1..58bfc61f4fc 100644 --- a/receiver/otlpreceiver/internal/trace/otlp_test.go +++ b/receiver/otlpreceiver/internal/trace/otlp_test.go @@ -89,7 +89,7 @@ func otlpReceiverOnGRPCServer(t *testing.T, tc consumer.Traces) net.Addr { }) set := receivertest.NewNopCreateSettings() - set.ID = component.NewIDWithName("otlp", "trace") + set.ID = component.MustNewIDWithName("otlp", "trace") obsreport, err := receiverhelper.NewObsReport(receiverhelper.ObsReportSettings{ ReceiverID: set.ID, Transport: "grpc", diff --git a/receiver/otlpreceiver/otlp_test.go b/receiver/otlpreceiver/otlp_test.go index 81728fbd625..3c8409fd421 100644 --- a/receiver/otlpreceiver/otlp_test.go +++ b/receiver/otlpreceiver/otlp_test.go @@ -48,7 +48,7 @@ import ( const otlpReceiverName = "receiver_test" -var otlpReceiverID = component.NewIDWithName("otlp", otlpReceiverName) +var otlpReceiverID = component.MustNewIDWithName("otlp", otlpReceiverName) func TestJsonHttp(t *testing.T) { tests := []struct { diff --git a/receiver/receiver_test.go b/receiver/receiver_test.go index d04dd88247d..910d562d476 100644 --- a/receiver/receiver_test.go +++ b/receiver/receiver_test.go @@ -17,12 +17,12 @@ import ( ) func TestNewFactory(t *testing.T) { - const typeStr = "test" + var testType = component.MustNewType("test") defaultCfg := struct{}{} factory := NewFactory( - typeStr, + testType, func() component.Config { return &defaultCfg }) - assert.EqualValues(t, typeStr, factory.Type()) + assert.EqualValues(t, testType, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) _, err := factory.CreateTracesReceiver(context.Background(), CreateSettings{}, &defaultCfg, nil) assert.Error(t, err) @@ -33,15 +33,15 @@ func TestNewFactory(t *testing.T) { } func TestNewFactoryWithOptions(t *testing.T) { - const typeStr = "test" + var testType = component.MustNewType("test") defaultCfg := struct{}{} factory := NewFactory( - typeStr, + testType, func() component.Config { return &defaultCfg }, WithTraces(createTraces, component.StabilityLevelDeprecated), WithMetrics(createMetrics, component.StabilityLevelAlpha), WithLogs(createLogs, component.StabilityLevelStable)) - assert.EqualValues(t, typeStr, factory.Type()) + assert.EqualValues(t, testType, factory.Type()) assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig()) assert.Equal(t, component.StabilityLevelDeprecated, factory.TracesReceiverStability()) @@ -64,8 +64,8 @@ func TestMakeFactoryMap(t *testing.T) { out map[component.Type]Factory } - p1 := NewFactory("p1", nil) - p2 := NewFactory("p2", nil) + p1 := NewFactory(component.MustNewType("p1"), nil) + p2 := NewFactory(component.MustNewType("p2"), nil) testCases := []testCase{ { name: "different names", @@ -77,7 +77,7 @@ func TestMakeFactoryMap(t *testing.T) { }, { name: "same name", - in: []Factory{p1, p2, NewFactory("p1", nil)}, + in: []Factory{p1, p2, NewFactory(component.MustNewType("p1"), nil)}, }, } @@ -98,9 +98,9 @@ func TestMakeFactoryMap(t *testing.T) { func TestBuilder(t *testing.T) { defaultCfg := struct{}{} factories, err := MakeFactoryMap([]Factory{ - NewFactory("err", nil), + NewFactory(component.MustNewType("err"), nil), NewFactory( - "all", + component.MustNewType("all"), func() component.Config { return &defaultCfg }, WithTraces(createTraces, component.StabilityLevelDevelopment), WithMetrics(createMetrics, component.StabilityLevelAlpha), @@ -116,21 +116,21 @@ func TestBuilder(t *testing.T) { }{ { name: "unknown", - id: component.NewID("unknown"), + id: component.MustNewID("unknown"), err: "receiver factory not available for: \"unknown\"", }, { name: "err", - id: component.NewID("err"), + id: component.MustNewID("err"), err: "telemetry type is not supported", }, { name: "all", - id: component.NewID("all"), + id: component.MustNewID("all"), }, { name: "all/named", - id: component.NewIDWithName("all", "named"), + id: component.MustNewIDWithName("all", "named"), }, } @@ -173,7 +173,7 @@ func TestBuilderMissingConfig(t *testing.T) { defaultCfg := struct{}{} factories, err := MakeFactoryMap([]Factory{ NewFactory( - "all", + component.MustNewType("all"), func() component.Config { return &defaultCfg }, WithTraces(createTraces, component.StabilityLevelDevelopment), WithMetrics(createMetrics, component.StabilityLevelAlpha), @@ -184,7 +184,7 @@ func TestBuilderMissingConfig(t *testing.T) { require.NoError(t, err) bErr := NewBuilder(map[component.ID]component.Config{}, factories) - missingID := component.NewIDWithName("all", "missing") + missingID := component.MustNewIDWithName("all", "missing") te, err := bErr.CreateTraces(context.Background(), createSettings(missingID), nil) assert.EqualError(t, err, "receiver \"all/missing\" is not configured") @@ -200,14 +200,14 @@ func TestBuilderMissingConfig(t *testing.T) { } func TestBuilderFactory(t *testing.T) { - factories, err := MakeFactoryMap([]Factory{NewFactory("foo", nil)}...) + factories, err := MakeFactoryMap([]Factory{NewFactory(component.MustNewType("foo"), nil)}...) require.NoError(t, err) - cfgs := map[component.ID]component.Config{component.NewID("foo"): struct{}{}} + cfgs := map[component.ID]component.Config{component.MustNewID("foo"): struct{}{}} b := NewBuilder(cfgs, factories) - assert.NotNil(t, b.Factory(component.NewID("foo").Type())) - assert.Nil(t, b.Factory(component.NewID("bar").Type())) + assert.NotNil(t, b.Factory(component.MustNewID("foo").Type())) + assert.Nil(t, b.Factory(component.MustNewID("bar").Type())) } var nopInstance = &nopReceiver{ diff --git a/receiver/receiverhelper/obsreport_test.go b/receiver/receiverhelper/obsreport_test.go index 3e229cbc07a..3a417e176aa 100644 --- a/receiver/receiverhelper/obsreport_test.go +++ b/receiver/receiverhelper/obsreport_test.go @@ -25,7 +25,7 @@ const ( ) var ( - receiverID = component.NewID("fakeReceiver") + receiverID = component.MustNewID("fakeReceiver") errFake = errors.New("errFake") ) diff --git a/receiver/receivertest/contract_checker_test.go b/receiver/receivertest/contract_checker_test.go index 2212d0b6196..359d40015df 100644 --- a/receiver/receivertest/contract_checker_test.go +++ b/receiver/receivertest/contract_checker_test.go @@ -83,7 +83,7 @@ func (g *exampleGenerator) Generate() []UniqueIDAttrVal { func newExampleFactory() receiver.Factory { return receiver.NewFactory( - "example_receiver", + component.MustNewType("example_receiver"), func() component.Config { return &exampleReceiverConfig{} }, diff --git a/receiver/receivertest/nop_receiver.go b/receiver/receivertest/nop_receiver.go index 6113bd03c58..4c5565e6019 100644 --- a/receiver/receivertest/nop_receiver.go +++ b/receiver/receivertest/nop_receiver.go @@ -12,11 +12,12 @@ import ( "go.opentelemetry.io/collector/receiver" ) -const typeStr = "nop" +var componentType = component.MustNewType("nop") // NewNopCreateSettings returns a new nop settings for Create* functions. func NewNopCreateSettings() receiver.CreateSettings { return receiver.CreateSettings{ + ID: component.NewID(componentType), TelemetrySettings: componenttest.NewNopTelemetrySettings(), BuildInfo: component.NewDefaultBuildInfo(), } @@ -25,7 +26,7 @@ func NewNopCreateSettings() receiver.CreateSettings { // NewNopFactory returns a receiver.Factory that constructs nop receivers. func NewNopFactory() receiver.Factory { return receiver.NewFactory( - "nop", + componentType, func() component.Config { return &nopConfig{} }, receiver.WithTraces(createTraces, component.StabilityLevelStable), receiver.WithMetrics(createMetrics, component.StabilityLevelStable), @@ -58,6 +59,6 @@ type nopReceiver struct { func NewNopBuilder() *receiver.Builder { nopFactory := NewNopFactory() return receiver.NewBuilder( - map[component.ID]component.Config{component.NewID(typeStr): nopFactory.CreateDefaultConfig()}, - map[component.Type]receiver.Factory{typeStr: nopFactory}) + map[component.ID]component.Config{component.NewID(componentType): nopFactory.CreateDefaultConfig()}, + map[component.Type]receiver.Factory{componentType: nopFactory}) } diff --git a/receiver/receivertest/nop_receiver_test.go b/receiver/receivertest/nop_receiver_test.go index f2f74d3f17e..d384e6b1fb7 100644 --- a/receiver/receivertest/nop_receiver_test.go +++ b/receiver/receivertest/nop_receiver_test.go @@ -15,10 +15,12 @@ import ( "go.opentelemetry.io/collector/consumer/consumertest" ) +var nopType = component.MustNewType("nop") + func TestNewNopFactory(t *testing.T) { factory := NewNopFactory() require.NotNil(t, factory) - assert.Equal(t, component.Type("nop"), factory.Type()) + assert.Equal(t, nopType, factory.Type()) cfg := factory.CreateDefaultConfig() assert.Equal(t, &nopConfig{}, cfg) @@ -45,7 +47,7 @@ func TestNewNopBuilder(t *testing.T) { factory := NewNopFactory() cfg := factory.CreateDefaultConfig() set := NewNopCreateSettings() - set.ID = component.NewID(typeStr) + set.ID = component.NewID(nopType) traces, err := factory.CreateTracesReceiver(context.Background(), set, cfg, consumertest.NewNop()) require.NoError(t, err) diff --git a/receiver/scraperhelper/obsreport.go b/receiver/scraperhelper/obsreport.go index f8d03f5684d..a8ba76b66e7 100644 --- a/receiver/scraperhelper/obsreport.go +++ b/receiver/scraperhelper/obsreport.go @@ -130,7 +130,7 @@ func (s *ObsReport) EndMetricsOp( // end span according to errors if span.IsRecording() { span.SetAttributes( - attribute.String(obsmetrics.FormatKey, string(component.DataTypeMetrics)), + attribute.String(obsmetrics.FormatKey, component.DataTypeMetrics.String()), attribute.Int64(obsmetrics.ScrapedMetricPointsKey, int64(numScrapedMetrics)), attribute.Int64(obsmetrics.ErroredMetricPointsKey, int64(numErroredMetrics)), ) diff --git a/receiver/scraperhelper/obsreport_test.go b/receiver/scraperhelper/obsreport_test.go index e804bb0fa12..6ccbc8041cd 100644 --- a/receiver/scraperhelper/obsreport_test.go +++ b/receiver/scraperhelper/obsreport_test.go @@ -21,8 +21,8 @@ import ( ) var ( - receiverID = component.NewID("fakeReceiver") - scraperID = component.NewID("fakeScraper") + receiverID = component.MustNewID("fakeReceiver") + scraperID = component.MustNewID("fakeScraper") errFake = errors.New("errFake") partialErrFake = scrapererror.NewPartialScrapeError(errFake, 1) diff --git a/receiver/scraperhelper/scraper.go b/receiver/scraperhelper/scraper.go index 70bfe099d3a..f97eb65a403 100644 --- a/receiver/scraperhelper/scraper.go +++ b/receiver/scraperhelper/scraper.go @@ -67,7 +67,7 @@ func NewScraper(name string, scrape ScrapeFunc, options ...ScraperOption) (Scrap } bs := &baseScraper{ ScrapeFunc: scrape, - id: component.NewID(component.Type(name)), + id: component.NewID(component.MustNewType(name)), } for _, op := range options { op(bs) diff --git a/receiver/scraperhelper/scrapercontroller_test.go b/receiver/scraperhelper/scrapercontroller_test.go index 05005c4453d..bf8ba9d4327 100644 --- a/receiver/scraperhelper/scrapercontroller_test.go +++ b/receiver/scraperhelper/scrapercontroller_test.go @@ -134,7 +134,7 @@ func TestScrapeController(t *testing.T) { for _, test := range testCases { test := test t.Run(test.name, func(t *testing.T) { - receiverID := component.NewID("receiver") + receiverID := component.MustNewID("receiver") tt, err := componenttest.SetupTelemetry(receiverID) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) @@ -326,7 +326,7 @@ func assertScraperViews(t *testing.T, tt componenttest.TestTelemetry, expectedEr } } - require.NoError(t, tt.CheckScraperMetrics(component.NewID("receiver"), component.NewID("scraper"), expectedScraped, expectedErrored)) + require.NoError(t, tt.CheckScraperMetrics(component.MustNewID("receiver"), component.MustNewID("scraper"), expectedScraped, expectedErrored)) } func TestSingleScrapePerInterval(t *testing.T) { @@ -337,7 +337,7 @@ func TestSingleScrapePerInterval(t *testing.T) { tickerCh := make(chan time.Time) - scp, err := NewScraper("", tsm.scrape) + scp, err := NewScraper("scaper", tsm.scrape) assert.NoError(t, err) receiver, err := NewScraperControllerReceiver( @@ -379,7 +379,7 @@ func TestScrapeControllerStartsOnInit(t *testing.T) { ch: make(chan int, 1), } - scp, err := NewScraper("", tsm.scrape) + scp, err := NewScraper("scraper", tsm.scrape) require.NoError(t, err, "Must not error when creating scraper") r, err := NewScraperControllerReceiver( diff --git a/receiver/scraperhelper/settings_test.go b/receiver/scraperhelper/settings_test.go index 0fa0d57f915..64a5cd67300 100644 --- a/receiver/scraperhelper/settings_test.go +++ b/receiver/scraperhelper/settings_test.go @@ -8,6 +8,8 @@ import ( "time" "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/collector/component" ) func TestScrapeControllerSettings(t *testing.T) { @@ -20,7 +22,7 @@ func TestScrapeControllerSettings(t *testing.T) { }{ { name: "default configuration", - set: NewDefaultScraperControllerSettings(""), + set: NewDefaultScraperControllerSettings(component.MustNewType("test")), errVal: "", }, { diff --git a/service/config_test.go b/service/config_test.go index c3b659d0dec..6ac9d6e625a 100644 --- a/service/config_test.go +++ b/service/config_test.go @@ -42,7 +42,7 @@ func TestConfigValidate(t *testing.T) { name: "duplicate-processor-reference", cfgFn: func() *Config { cfg := generateConfig() - pipe := cfg.Pipelines[component.NewID("traces")] + pipe := cfg.Pipelines[component.MustNewID("traces")] pipe.Processors = append(pipe.Processors, pipe.Processors...) return cfg }, @@ -52,10 +52,10 @@ func TestConfigValidate(t *testing.T) { name: "invalid-service-pipeline-type", cfgFn: func() *Config { cfg := generateConfig() - cfg.Pipelines[component.NewID("wrongtype")] = &pipelines.PipelineConfig{ - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop")}, + cfg.Pipelines[component.MustNewID("wrongtype")] = &pipelines.PipelineConfig{ + Receivers: []component.ID{component.MustNewID("nop")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("nop")}, } return cfg }, @@ -99,12 +99,12 @@ func generateConfig() *Config { Address: ":8080", }, }, - Extensions: extensions.Config{component.NewID("nop")}, + Extensions: extensions.Config{component.MustNewID("nop")}, Pipelines: pipelines.Config{ - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, } diff --git a/service/extensions/extensions_test.go b/service/extensions/extensions_test.go index e2a0db4275f..4f1f735852e 100644 --- a/service/extensions/extensions_test.go +++ b/service/extensions/extensions_test.go @@ -38,17 +38,17 @@ func TestBuildExtensions(t *testing.T) { { name: "extension_not_configured", config: Config{ - component.NewID("myextension"), + component.MustNewID("myextension"), }, wantErrMsg: "failed to create extension \"myextension\": extension \"myextension\" is not configured", }, { name: "missing_extension_factory", extensionsConfigs: map[component.ID]component.Config{ - component.NewID("unknown"): nopExtensionConfig, + component.MustNewID("unknown"): nopExtensionConfig, }, config: Config{ - component.NewID("unknown"), + component.MustNewID("unknown"), }, wantErrMsg: "failed to create extension \"unknown\": extension factory not available for: \"unknown\"", }, @@ -212,11 +212,11 @@ func TestNotifyConfig(t *testing.T) { notificationError := errors.New("Error processing config") nopExtensionFactory := extensiontest.NewNopFactory() nopExtensionConfig := nopExtensionFactory.CreateDefaultConfig() - n1ExtensionFactory := newConfigWatcherExtensionFactory("notifiable1", func() error { return nil }) + n1ExtensionFactory := newConfigWatcherExtensionFactory(component.MustNewType("notifiable1"), func() error { return nil }) n1ExtensionConfig := n1ExtensionFactory.CreateDefaultConfig() - n2ExtensionFactory := newConfigWatcherExtensionFactory("notifiable2", func() error { return nil }) + n2ExtensionFactory := newConfigWatcherExtensionFactory(component.MustNewType("notifiable2"), func() error { return nil }) n2ExtensionConfig := n1ExtensionFactory.CreateDefaultConfig() - nErrExtensionFactory := newConfigWatcherExtensionFactory("notifiableErr", func() error { return notificationError }) + nErrExtensionFactory := newConfigWatcherExtensionFactory(component.MustNewType("notifiableErr"), func() error { return notificationError }) nErrExtensionConfig := nErrExtensionFactory.CreateDefaultConfig() tests := []struct { @@ -230,52 +230,52 @@ func TestNotifyConfig(t *testing.T) { { name: "No notifiable extensions", factories: map[component.Type]extension.Factory{ - "nop": nopExtensionFactory, + component.MustNewType("nop"): nopExtensionFactory, }, extensionsConfigs: map[component.ID]component.Config{ - component.NewID("nop"): nopExtensionConfig, + component.MustNewID("nop"): nopExtensionConfig, }, serviceExtensions: []component.ID{ - component.NewID("nop"), + component.MustNewID("nop"), }, }, { name: "One notifiable extension", factories: map[component.Type]extension.Factory{ - "notifiable1": n1ExtensionFactory, + component.MustNewType("notifiable1"): n1ExtensionFactory, }, extensionsConfigs: map[component.ID]component.Config{ - component.NewID("notifiable1"): n1ExtensionConfig, + component.MustNewID("notifiable1"): n1ExtensionConfig, }, serviceExtensions: []component.ID{ - component.NewID("notifiable1"), + component.MustNewID("notifiable1"), }, }, { name: "Multiple notifiable extensions", factories: map[component.Type]extension.Factory{ - "notifiable1": n1ExtensionFactory, - "notifiable2": n2ExtensionFactory, + component.MustNewType("notifiable1"): n1ExtensionFactory, + component.MustNewType("notifiable2"): n2ExtensionFactory, }, extensionsConfigs: map[component.ID]component.Config{ - component.NewID("notifiable1"): n1ExtensionConfig, - component.NewID("notifiable2"): n2ExtensionConfig, + component.MustNewID("notifiable1"): n1ExtensionConfig, + component.MustNewID("notifiable2"): n2ExtensionConfig, }, serviceExtensions: []component.ID{ - component.NewID("notifiable1"), - component.NewID("notifiable2"), + component.MustNewID("notifiable1"), + component.MustNewID("notifiable2"), }, }, { name: "Errors in extension notification", factories: map[component.Type]extension.Factory{ - "notifiableErr": nErrExtensionFactory, + component.MustNewType("notifiableErr"): nErrExtensionFactory, }, extensionsConfigs: map[component.ID]component.Config{ - component.NewID("notifiableErr"): nErrExtensionConfig, + component.MustNewID("notifiableErr"): nErrExtensionConfig, }, serviceExtensions: []component.ID{ - component.NewID("notifiableErr"), + component.MustNewID("notifiableErr"), }, want: notificationError, }, @@ -335,7 +335,7 @@ func newConfigWatcherExtensionFactory(name component.Type, fn func() error) exte func newBadExtensionFactory() extension.Factory { return extension.NewFactory( - "bf", + component.MustNewType("bf"), func() component.Config { return &struct{}{} }, @@ -348,7 +348,7 @@ func newBadExtensionFactory() extension.Factory { func newCreateErrorExtensionFactory() extension.Factory { return extension.NewFactory( - "err", + component.MustNewType("err"), func() component.Config { return &struct{}{} }, @@ -410,14 +410,15 @@ func TestStatusReportedOnStartupShutdown(t *testing.T) { }, } { t.Run(tc.name, func(t *testing.T) { - compID := component.NewID("statustest") - factory := newStatusTestExtensionFactory("statustest", tc.startErr, tc.shutdownErr) + statusType := component.MustNewType("statustest") + compID := component.NewID(statusType) + factory := newStatusTestExtensionFactory(statusType, tc.startErr, tc.shutdownErr) config := factory.CreateDefaultConfig() extensionsConfigs := map[component.ID]component.Config{ compID: config, } factories := map[component.Type]extension.Factory{ - "statustest": factory, + statusType: factory, } extensions, err := New( context.Background(), @@ -484,7 +485,7 @@ func newStatusTestExtensionFactory(name component.Type, startErr, shutdownErr er func newRecordingExtensionFactory(startCallback func(set extension.CreateSettings, host component.Host) error, shutdownCallback func(set extension.CreateSettings) error) extension.Factory { return extension.NewFactory( - "recording", + component.MustNewType("recording"), func() component.Config { return &recordingExtensionConfig{} }, @@ -519,7 +520,7 @@ func (ext *recordingExtension) Dependencies() []component.ID { } deps := make([]component.ID, len(ext.config.dependencies)) for i, dep := range ext.config.dependencies { - deps[i] = component.NewIDWithName("recording", dep) + deps[i] = component.MustNewIDWithName("recording", dep) } return deps } diff --git a/service/internal/components/loggers.go b/service/internal/components/loggers.go index 026d4e189b2..f4178977b2d 100644 --- a/service/internal/components/loggers.go +++ b/service/internal/components/loggers.go @@ -25,7 +25,7 @@ func ReceiverLogger(logger *zap.Logger, id component.ID, dt component.DataType) return logger.With( zap.String(zapKindKey, strings.ToLower(component.KindReceiver.String())), zap.String(zapNameKey, id.String()), - zap.String(zapDataTypeKey, string(dt))) + zap.String(zapDataTypeKey, dt.String())) } func ProcessorLogger(logger *zap.Logger, id component.ID, pipelineID component.ID) *zap.Logger { @@ -38,7 +38,7 @@ func ProcessorLogger(logger *zap.Logger, id component.ID, pipelineID component.I func ExporterLogger(logger *zap.Logger, id component.ID, dt component.DataType) *zap.Logger { return logger.With( zap.String(zapKindKey, strings.ToLower(component.KindExporter.String())), - zap.String(zapDataTypeKey, string(dt)), + zap.String(zapDataTypeKey, dt.String()), zap.String(zapNameKey, id.String())) } @@ -52,6 +52,6 @@ func ConnectorLogger(logger *zap.Logger, id component.ID, expDT, rcvDT component return logger.With( zap.String(zapKindKey, strings.ToLower(component.KindConnector.String())), zap.String(zapNameKey, id.String()), - zap.String(zapExporterInPipeline, string(expDT)), - zap.String(zapReceiverInPipeline, string(rcvDT))) + zap.String(zapExporterInPipeline, expDT.String()), + zap.String(zapReceiverInPipeline, rcvDT.String())) } diff --git a/service/internal/graph/graph_test.go b/service/internal/graph/graph_test.go index 84c922f407e..f2eb413a381 100644 --- a/service/internal/graph/graph_test.go +++ b/service/internal/graph/graph_test.go @@ -90,48 +90,48 @@ func TestGraphStartStop(t *testing.T) { { name: "single", edges: [][2]component.ID{ - {component.NewIDWithName("r", "1"), component.NewIDWithName("p", "1")}, - {component.NewIDWithName("r", "2"), component.NewIDWithName("p", "1")}, - {component.NewIDWithName("p", "1"), component.NewIDWithName("p", "2")}, - {component.NewIDWithName("p", "2"), component.NewIDWithName("e", "1")}, - {component.NewIDWithName("p", "1"), component.NewIDWithName("e", "2")}, + {component.MustNewIDWithName("r", "1"), component.MustNewIDWithName("p", "1")}, + {component.MustNewIDWithName("r", "2"), component.MustNewIDWithName("p", "1")}, + {component.MustNewIDWithName("p", "1"), component.MustNewIDWithName("p", "2")}, + {component.MustNewIDWithName("p", "2"), component.MustNewIDWithName("e", "1")}, + {component.MustNewIDWithName("p", "1"), component.MustNewIDWithName("e", "2")}, }, }, { name: "multi", edges: [][2]component.ID{ // Pipeline 1 - {component.NewIDWithName("r", "1"), component.NewIDWithName("p", "1")}, - {component.NewIDWithName("r", "2"), component.NewIDWithName("p", "1")}, - {component.NewIDWithName("p", "1"), component.NewIDWithName("p", "2")}, - {component.NewIDWithName("p", "2"), component.NewIDWithName("e", "1")}, - {component.NewIDWithName("p", "1"), component.NewIDWithName("e", "2")}, + {component.MustNewIDWithName("r", "1"), component.MustNewIDWithName("p", "1")}, + {component.MustNewIDWithName("r", "2"), component.MustNewIDWithName("p", "1")}, + {component.MustNewIDWithName("p", "1"), component.MustNewIDWithName("p", "2")}, + {component.MustNewIDWithName("p", "2"), component.MustNewIDWithName("e", "1")}, + {component.MustNewIDWithName("p", "1"), component.MustNewIDWithName("e", "2")}, // Pipeline 2, shares r1 and e2 - {component.NewIDWithName("r", "1"), component.NewIDWithName("p", "3")}, - {component.NewIDWithName("p", "3"), component.NewIDWithName("e", "2")}, + {component.MustNewIDWithName("r", "1"), component.MustNewIDWithName("p", "3")}, + {component.MustNewIDWithName("p", "3"), component.MustNewIDWithName("e", "2")}, }, }, { name: "connected", edges: [][2]component.ID{ // Pipeline 1 - {component.NewIDWithName("r", "1"), component.NewIDWithName("p", "1")}, - {component.NewIDWithName("r", "2"), component.NewIDWithName("p", "1")}, - {component.NewIDWithName("p", "1"), component.NewIDWithName("p", "2")}, - {component.NewIDWithName("p", "2"), component.NewIDWithName("e", "1")}, - {component.NewIDWithName("p", "1"), component.NewIDWithName("c", "1")}, + {component.MustNewIDWithName("r", "1"), component.MustNewIDWithName("p", "1")}, + {component.MustNewIDWithName("r", "2"), component.MustNewIDWithName("p", "1")}, + {component.MustNewIDWithName("p", "1"), component.MustNewIDWithName("p", "2")}, + {component.MustNewIDWithName("p", "2"), component.MustNewIDWithName("e", "1")}, + {component.MustNewIDWithName("p", "1"), component.MustNewIDWithName("c", "1")}, // Pipeline 2, shares r1 and c1 - {component.NewIDWithName("r", "1"), component.NewIDWithName("p", "3")}, - {component.NewIDWithName("p", "3"), component.NewIDWithName("c", "1")}, + {component.MustNewIDWithName("r", "1"), component.MustNewIDWithName("p", "3")}, + {component.MustNewIDWithName("p", "3"), component.MustNewIDWithName("c", "1")}, // Pipeline 3, emits to e2 and c2 - {component.NewIDWithName("c", "1"), component.NewIDWithName("e", "2")}, - {component.NewIDWithName("c", "1"), component.NewIDWithName("c", "2")}, + {component.MustNewIDWithName("c", "1"), component.MustNewIDWithName("e", "2")}, + {component.MustNewIDWithName("c", "1"), component.MustNewIDWithName("c", "2")}, // Pipeline 4, also emits to e2 - {component.NewIDWithName("c", "2"), component.NewIDWithName("e", "2")}, + {component.MustNewIDWithName("c", "2"), component.MustNewIDWithName("e", "2")}, }, }, } @@ -171,10 +171,10 @@ func TestGraphStartStop(t *testing.T) { func TestGraphStartStopCycle(t *testing.T) { pg := &Graph{componentGraph: simple.NewDirectedGraph()} - r1 := &testNode{id: component.NewIDWithName("r", "1")} - p1 := &testNode{id: component.NewIDWithName("p", "1")} - c1 := &testNode{id: component.NewIDWithName("c", "1")} - e1 := &testNode{id: component.NewIDWithName("e", "1")} + r1 := &testNode{id: component.MustNewIDWithName("r", "1")} + p1 := &testNode{id: component.MustNewIDWithName("p", "1")} + c1 := &testNode{id: component.MustNewIDWithName("c", "1")} + e1 := &testNode{id: component.MustNewIDWithName("e", "1")} pg.instanceIDs = map[int64]*component.InstanceID{ r1.ID(): {}, @@ -201,11 +201,11 @@ func TestGraphStartStopComponentError(t *testing.T) { pg := &Graph{componentGraph: simple.NewDirectedGraph()} pg.telemetry = servicetelemetry.NewNopTelemetrySettings() r1 := &testNode{ - id: component.NewIDWithName("r", "1"), + id: component.MustNewIDWithName("r", "1"), startErr: errors.New("foo"), } e1 := &testNode{ - id: component.NewIDWithName("e", "1"), + id: component.MustNewIDWithName("e", "1"), shutdownErr: errors.New("bar"), } pg.instanceIDs = map[int64]*component.InstanceID{ @@ -229,20 +229,20 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_simple.yaml", pipelineConfigs: pipelines.Config{ - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewID("metrics"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("metrics"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewID("logs"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("logs"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 1, @@ -250,20 +250,20 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_simple_mutate.yaml", pipelineConfigs: pipelines.Config{ - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewID("metrics"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("metrics"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewID("logs"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("logs"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 1, @@ -271,20 +271,20 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_simple_multi_proc.yaml", pipelineConfigs: pipelines.Config{ - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewID("exampleprocessor"), component.NewIDWithName("exampleprocessor", "mutate")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor"), component.MustNewIDWithName("exampleprocessor", "mutate")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewID("metrics"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewID("exampleprocessor"), component.NewIDWithName("exampleprocessor", "mutate")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("metrics"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor"), component.MustNewIDWithName("exampleprocessor", "mutate")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewID("logs"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewID("exampleprocessor"), component.NewIDWithName("exampleprocessor", "mutate")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("logs"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor"), component.MustNewIDWithName("exampleprocessor", "mutate")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 1, @@ -292,17 +292,17 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_simple_no_proc.yaml", pipelineConfigs: pipelines.Config{ - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewID("metrics"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("metrics"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewID("logs"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("logs"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 1, @@ -310,20 +310,20 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_multi.yaml", pipelineConfigs: pipelines.Config{ - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("examplereceiver"), component.NewIDWithName("examplereceiver", "1")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate"), component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter"), component.NewIDWithName("exampleexporter", "1")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewID("examplereceiver"), component.MustNewIDWithName("examplereceiver", "1")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate"), component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter"), component.MustNewIDWithName("exampleexporter", "1")}, }, - component.NewID("metrics"): { - Receivers: []component.ID{component.NewID("examplereceiver"), component.NewIDWithName("examplereceiver", "1")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate"), component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter"), component.NewIDWithName("exampleexporter", "1")}, + component.MustNewID("metrics"): { + Receivers: []component.ID{component.MustNewID("examplereceiver"), component.MustNewIDWithName("examplereceiver", "1")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate"), component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter"), component.MustNewIDWithName("exampleexporter", "1")}, }, - component.NewID("logs"): { - Receivers: []component.ID{component.NewID("examplereceiver"), component.NewIDWithName("examplereceiver", "1")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate"), component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter"), component.NewIDWithName("exampleexporter", "1")}, + component.MustNewID("logs"): { + Receivers: []component.ID{component.MustNewID("examplereceiver"), component.MustNewIDWithName("examplereceiver", "1")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate"), component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter"), component.MustNewIDWithName("exampleexporter", "1")}, }, }, expectedPerExporter: 2, @@ -331,17 +331,17 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_multi_no_proc.yaml", pipelineConfigs: pipelines.Config{ - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("examplereceiver"), component.NewIDWithName("examplereceiver", "1")}, - Exporters: []component.ID{component.NewID("exampleexporter"), component.NewIDWithName("exampleexporter", "1")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewID("examplereceiver"), component.MustNewIDWithName("examplereceiver", "1")}, + Exporters: []component.ID{component.MustNewID("exampleexporter"), component.MustNewIDWithName("exampleexporter", "1")}, }, - component.NewID("metrics"): { - Receivers: []component.ID{component.NewID("examplereceiver"), component.NewIDWithName("examplereceiver", "1")}, - Exporters: []component.ID{component.NewID("exampleexporter"), component.NewIDWithName("exampleexporter", "1")}, + component.MustNewID("metrics"): { + Receivers: []component.ID{component.MustNewID("examplereceiver"), component.MustNewIDWithName("examplereceiver", "1")}, + Exporters: []component.ID{component.MustNewID("exampleexporter"), component.MustNewIDWithName("exampleexporter", "1")}, }, - component.NewID("logs"): { - Receivers: []component.ID{component.NewID("examplereceiver"), component.NewIDWithName("examplereceiver", "1")}, - Exporters: []component.ID{component.NewID("exampleexporter"), component.NewIDWithName("exampleexporter", "1")}, + component.MustNewID("logs"): { + Receivers: []component.ID{component.MustNewID("examplereceiver"), component.MustNewIDWithName("examplereceiver", "1")}, + Exporters: []component.ID{component.MustNewID("exampleexporter"), component.MustNewIDWithName("exampleexporter", "1")}, }, }, expectedPerExporter: 2, @@ -349,32 +349,32 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "multi_pipeline_receivers_and_exporters.yaml", pipelineConfigs: pipelines.Config{ - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewIDWithName("traces", "1"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("traces", "1"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewID("metrics"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("metrics"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewIDWithName("metrics", "1"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("metrics", "1"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewID("logs"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("logs"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewIDWithName("logs", "1"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("logs", "1"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 2, @@ -382,15 +382,15 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_conn_simple_traces.yaml", pipelineConfigs: pipelines.Config{ - component.NewIDWithName("traces", "in"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, + component.MustNewIDWithName("traces", "in"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, }, - component.NewIDWithName("traces", "out"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("traces", "out"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 1, @@ -398,15 +398,15 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_conn_simple_metrics.yaml", pipelineConfigs: pipelines.Config{ - component.NewIDWithName("metrics", "in"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, + component.MustNewIDWithName("metrics", "in"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, }, - component.NewIDWithName("metrics", "out"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("metrics", "out"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 1, @@ -414,15 +414,15 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_conn_simple_logs.yaml", pipelineConfigs: pipelines.Config{ - component.NewIDWithName("logs", "in"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, + component.MustNewIDWithName("logs", "in"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, }, - component.NewIDWithName("logs", "out"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("logs", "out"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 1, @@ -430,25 +430,25 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_conn_fork_merge_traces.yaml", pipelineConfigs: pipelines.Config{ - component.NewIDWithName("traces", "in"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, + component.MustNewIDWithName("traces", "in"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, }, - component.NewIDWithName("traces", "type0"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "merge")}, + component.MustNewIDWithName("traces", "type0"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "merge")}, }, - component.NewIDWithName("traces", "type1"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "merge")}, + component.MustNewIDWithName("traces", "type1"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "merge")}, }, - component.NewIDWithName("traces", "out"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "merge")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("traces", "out"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "merge")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 2, @@ -456,25 +456,25 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_conn_fork_merge_metrics.yaml", pipelineConfigs: pipelines.Config{ - component.NewIDWithName("metrics", "in"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, + component.MustNewIDWithName("metrics", "in"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, }, - component.NewIDWithName("metrics", "type0"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "merge")}, + component.MustNewIDWithName("metrics", "type0"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "merge")}, }, - component.NewIDWithName("metrics", "type1"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "merge")}, + component.MustNewIDWithName("metrics", "type1"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "merge")}, }, - component.NewIDWithName("metrics", "out"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "merge")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("metrics", "out"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "merge")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 2, @@ -482,25 +482,25 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_conn_fork_merge_logs.yaml", pipelineConfigs: pipelines.Config{ - component.NewIDWithName("logs", "in"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, + component.MustNewIDWithName("logs", "in"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, }, - component.NewIDWithName("logs", "type0"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "merge")}, + component.MustNewIDWithName("logs", "type0"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "merge")}, }, - component.NewIDWithName("logs", "type1"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "merge")}, + component.MustNewIDWithName("logs", "type1"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "merge")}, }, - component.NewIDWithName("logs", "out"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "merge")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("logs", "out"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "merge")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 2, @@ -508,20 +508,20 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_conn_translate_from_traces.yaml", pipelineConfigs: pipelines.Config{ - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleconnector")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleconnector")}, }, - component.NewID("metrics"): { - Receivers: []component.ID{component.NewID("exampleconnector")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("metrics"): { + Receivers: []component.ID{component.MustNewID("exampleconnector")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewID("logs"): { - Receivers: []component.ID{component.NewID("exampleconnector")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("logs"): { + Receivers: []component.ID{component.MustNewID("exampleconnector")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 1, @@ -529,20 +529,20 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_conn_translate_from_metrics.yaml", pipelineConfigs: pipelines.Config{ - component.NewID("metrics"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleconnector")}, + component.MustNewID("metrics"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleconnector")}, }, - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("exampleconnector")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewID("exampleconnector")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewID("logs"): { - Receivers: []component.ID{component.NewID("exampleconnector")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("logs"): { + Receivers: []component.ID{component.MustNewID("exampleconnector")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 1, @@ -550,20 +550,20 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_conn_translate_from_logs.yaml", pipelineConfigs: pipelines.Config{ - component.NewID("logs"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleconnector")}, + component.MustNewID("logs"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleconnector")}, }, - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("exampleconnector")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewID("exampleconnector")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewID("metrics"): { - Receivers: []component.ID{component.NewID("exampleconnector")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewID("metrics"): { + Receivers: []component.ID{component.MustNewID("exampleconnector")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 1, @@ -571,35 +571,35 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_conn_matrix.yaml", pipelineConfigs: pipelines.Config{ - component.NewIDWithName("traces", "in"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, + component.MustNewIDWithName("traces", "in"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate")}, + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, }, - component.NewIDWithName("metrics", "in"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, + component.MustNewIDWithName("metrics", "in"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate")}, + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, }, - component.NewIDWithName("logs", "in"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, + component.MustNewIDWithName("logs", "in"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate")}, + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, }, - component.NewIDWithName("traces", "out"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("traces", "out"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewIDWithName("metrics", "out"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("metrics", "out"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewIDWithName("logs", "out"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, - Processors: []component.ID{component.NewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("logs", "out"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, + Processors: []component.ID{component.MustNewIDWithName("exampleprocessor", "mutate")}, // mutate propagates upstream to connector + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 3, @@ -607,29 +607,29 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_conn_lanes.yaml", pipelineConfigs: pipelines.Config{ - component.NewIDWithName("traces", "in"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Exporters: []component.ID{component.NewID("mockforward")}, + component.MustNewIDWithName("traces", "in"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Exporters: []component.ID{component.MustNewID("mockforward")}, }, - component.NewIDWithName("traces", "out"): { - Receivers: []component.ID{component.NewID("mockforward")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("traces", "out"): { + Receivers: []component.ID{component.MustNewID("mockforward")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewIDWithName("metrics", "in"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Exporters: []component.ID{component.NewID("mockforward")}, + component.MustNewIDWithName("metrics", "in"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Exporters: []component.ID{component.MustNewID("mockforward")}, }, - component.NewIDWithName("metrics", "out"): { - Receivers: []component.ID{component.NewID("mockforward")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("metrics", "out"): { + Receivers: []component.ID{component.MustNewID("mockforward")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewIDWithName("logs", "in"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Exporters: []component.ID{component.NewID("mockforward")}, + component.MustNewIDWithName("logs", "in"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Exporters: []component.ID{component.MustNewID("mockforward")}, }, - component.NewIDWithName("logs", "out"): { - Receivers: []component.ID{component.NewID("mockforward")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("logs", "out"): { + Receivers: []component.ID{component.MustNewID("mockforward")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 1, @@ -637,25 +637,25 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_conn_mutate_traces.yaml", pipelineConfigs: pipelines.Config{ - component.NewIDWithName("traces", "in"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, + component.MustNewIDWithName("traces", "in"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, }, - component.NewIDWithName("traces", "out0"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("traces", "out0"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewIDWithName("traces", "middle"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "mutate")}, + component.MustNewIDWithName("traces", "middle"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "mutate")}, }, - component.NewIDWithName("traces", "out1"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "mutate")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("traces", "out1"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "mutate")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 2, @@ -663,25 +663,25 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_conn_mutate_metrics.yaml", pipelineConfigs: pipelines.Config{ - component.NewIDWithName("metrics", "in"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, + component.MustNewIDWithName("metrics", "in"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, }, - component.NewIDWithName("metrics", "out0"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("metrics", "out0"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewIDWithName("metrics", "middle"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "mutate")}, + component.MustNewIDWithName("metrics", "middle"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "mutate")}, }, - component.NewIDWithName("metrics", "out1"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "mutate")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("metrics", "out1"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "mutate")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 2, @@ -689,25 +689,25 @@ func TestConnectorPipelinesGraph(t *testing.T) { { name: "pipelines_conn_mutate_logs.yaml", pipelineConfigs: pipelines.Config{ - component.NewIDWithName("logs", "in"): { - Receivers: []component.ID{component.NewID("examplereceiver")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, + component.MustNewIDWithName("logs", "in"): { + Receivers: []component.ID{component.MustNewID("examplereceiver")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, }, - component.NewIDWithName("logs", "out0"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("logs", "out0"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, - component.NewIDWithName("logs", "middle"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "inherit_mutate")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewIDWithName("exampleconnector", "mutate")}, + component.MustNewIDWithName("logs", "middle"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "inherit_mutate")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewIDWithName("exampleconnector", "mutate")}, }, - component.NewIDWithName("logs", "out1"): { - Receivers: []component.ID{component.NewIDWithName("exampleconnector", "mutate")}, - Processors: []component.ID{component.NewID("exampleprocessor")}, - Exporters: []component.ID{component.NewID("exampleexporter")}, + component.MustNewIDWithName("logs", "out1"): { + Receivers: []component.ID{component.MustNewIDWithName("exampleconnector", "mutate")}, + Processors: []component.ID{component.MustNewID("exampleprocessor")}, + Exporters: []component.ID{component.MustNewID("exampleexporter")}, }, }, expectedPerExporter: 2, @@ -722,8 +722,8 @@ func TestConnectorPipelinesGraph(t *testing.T) { BuildInfo: component.NewDefaultBuildInfo(), ReceiverBuilder: receiver.NewBuilder( map[component.ID]component.Config{ - component.NewID("examplereceiver"): testcomponents.ExampleReceiverFactory.CreateDefaultConfig(), - component.NewIDWithName("examplereceiver", "1"): testcomponents.ExampleReceiverFactory.CreateDefaultConfig(), + component.MustNewID("examplereceiver"): testcomponents.ExampleReceiverFactory.CreateDefaultConfig(), + component.MustNewIDWithName("examplereceiver", "1"): testcomponents.ExampleReceiverFactory.CreateDefaultConfig(), }, map[component.Type]receiver.Factory{ testcomponents.ExampleReceiverFactory.Type(): testcomponents.ExampleReceiverFactory, @@ -731,8 +731,8 @@ func TestConnectorPipelinesGraph(t *testing.T) { ), ProcessorBuilder: processor.NewBuilder( map[component.ID]component.Config{ - component.NewID("exampleprocessor"): testcomponents.ExampleProcessorFactory.CreateDefaultConfig(), - component.NewIDWithName("exampleprocessor", "mutate"): testcomponents.ExampleProcessorFactory.CreateDefaultConfig(), + component.MustNewID("exampleprocessor"): testcomponents.ExampleProcessorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("exampleprocessor", "mutate"): testcomponents.ExampleProcessorFactory.CreateDefaultConfig(), }, map[component.Type]processor.Factory{ testcomponents.ExampleProcessorFactory.Type(): testcomponents.ExampleProcessorFactory, @@ -740,8 +740,8 @@ func TestConnectorPipelinesGraph(t *testing.T) { ), ExporterBuilder: exporter.NewBuilder( map[component.ID]component.Config{ - component.NewID("exampleexporter"): testcomponents.ExampleExporterFactory.CreateDefaultConfig(), - component.NewIDWithName("exampleexporter", "1"): testcomponents.ExampleExporterFactory.CreateDefaultConfig(), + component.MustNewID("exampleexporter"): testcomponents.ExampleExporterFactory.CreateDefaultConfig(), + component.MustNewIDWithName("exampleexporter", "1"): testcomponents.ExampleExporterFactory.CreateDefaultConfig(), }, map[component.Type]exporter.Factory{ testcomponents.ExampleExporterFactory.Type(): testcomponents.ExampleExporterFactory, @@ -749,11 +749,11 @@ func TestConnectorPipelinesGraph(t *testing.T) { ), ConnectorBuilder: connector.NewBuilder( map[component.ID]component.Config{ - component.NewID("exampleconnector"): testcomponents.ExampleConnectorFactory.CreateDefaultConfig(), - component.NewIDWithName("exampleconnector", "merge"): testcomponents.ExampleConnectorFactory.CreateDefaultConfig(), - component.NewIDWithName("exampleconnector", "mutate"): testcomponents.ExampleConnectorFactory.CreateDefaultConfig(), - component.NewIDWithName("exampleconnector", "inherit_mutate"): testcomponents.ExampleConnectorFactory.CreateDefaultConfig(), - component.NewID("mockforward"): testcomponents.MockForwardConnectorFactory.CreateDefaultConfig(), + component.MustNewID("exampleconnector"): testcomponents.ExampleConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("exampleconnector", "merge"): testcomponents.ExampleConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("exampleconnector", "mutate"): testcomponents.ExampleConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("exampleconnector", "inherit_mutate"): testcomponents.ExampleConnectorFactory.CreateDefaultConfig(), + component.MustNewID("mockforward"): testcomponents.MockForwardConnectorFactory.CreateDefaultConfig(), }, map[component.Type]connector.Factory{ testcomponents.ExampleConnectorFactory.Type(): testcomponents.ExampleConnectorFactory, @@ -984,24 +984,24 @@ func TestConnectorPipelinesGraph(t *testing.T) { } func TestConnectorRouter(t *testing.T) { - rcvrID := component.NewID("examplereceiver") - routeTracesID := component.NewIDWithName("examplerouter", "traces") - routeMetricsID := component.NewIDWithName("examplerouter", "metrics") - routeLogsID := component.NewIDWithName("examplerouter", "logs") - expRightID := component.NewIDWithName("exampleexporter", "right") - expLeftID := component.NewIDWithName("exampleexporter", "left") + rcvrID := component.MustNewID("examplereceiver") + routeTracesID := component.MustNewIDWithName("examplerouter", "traces") + routeMetricsID := component.MustNewIDWithName("examplerouter", "metrics") + routeLogsID := component.MustNewIDWithName("examplerouter", "logs") + expRightID := component.MustNewIDWithName("exampleexporter", "right") + expLeftID := component.MustNewIDWithName("exampleexporter", "left") - tracesInID := component.NewIDWithName("traces", "in") - tracesRightID := component.NewIDWithName("traces", "right") - tracesLeftID := component.NewIDWithName("traces", "left") + tracesInID := component.MustNewIDWithName("traces", "in") + tracesRightID := component.MustNewIDWithName("traces", "right") + tracesLeftID := component.MustNewIDWithName("traces", "left") - metricsInID := component.NewIDWithName("metrics", "in") - metricsRightID := component.NewIDWithName("metrics", "right") - metricsLeftID := component.NewIDWithName("metrics", "left") + metricsInID := component.MustNewIDWithName("metrics", "in") + metricsRightID := component.MustNewIDWithName("metrics", "right") + metricsLeftID := component.MustNewIDWithName("metrics", "left") - logsInID := component.NewIDWithName("logs", "in") - logsRightID := component.NewIDWithName("logs", "right") - logsLeftID := component.NewIDWithName("logs", "left") + logsInID := component.MustNewIDWithName("logs", "in") + logsRightID := component.MustNewIDWithName("logs", "right") + logsLeftID := component.MustNewIDWithName("logs", "left") ctx := context.Background() set := Settings{ @@ -1188,15 +1188,15 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_supported_exporter_logs", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("bf"): badExporterFactory.CreateDefaultConfig(), + component.MustNewID("bf"): badExporterFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewID("logs"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("bf")}, + component.MustNewID("logs"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("bf")}, }, }, expected: "failed to create \"bf\" exporter for data type \"logs\": telemetry type is not supported", @@ -1204,15 +1204,15 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_supported_exporter_metrics", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("bf"): badExporterFactory.CreateDefaultConfig(), + component.MustNewID("bf"): badExporterFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewID("metrics"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("bf")}, + component.MustNewID("metrics"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("bf")}, }, }, expected: "failed to create \"bf\" exporter for data type \"metrics\": telemetry type is not supported", @@ -1220,15 +1220,15 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_supported_exporter_traces", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("bf"): badExporterFactory.CreateDefaultConfig(), + component.MustNewID("bf"): badExporterFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("bf")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("bf")}, }, }, expected: "failed to create \"bf\" exporter for data type \"traces\": telemetry type is not supported", @@ -1236,19 +1236,19 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_supported_processor_logs", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, processorCfgs: map[component.ID]component.Config{ - component.NewID("bf"): badProcessorFactory.CreateDefaultConfig(), + component.MustNewID("bf"): badProcessorFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewID("logs"): { - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("bf")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewID("logs"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Processors: []component.ID{component.MustNewID("bf")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "failed to create \"bf\" processor, in pipeline \"logs\": telemetry type is not supported", @@ -1256,19 +1256,19 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_supported_processor_metrics", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, processorCfgs: map[component.ID]component.Config{ - component.NewID("bf"): badProcessorFactory.CreateDefaultConfig(), + component.MustNewID("bf"): badProcessorFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewID("metrics"): { - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("bf")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewID("metrics"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Processors: []component.ID{component.MustNewID("bf")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "failed to create \"bf\" processor, in pipeline \"metrics\": telemetry type is not supported", @@ -1276,19 +1276,19 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_supported_processor_traces", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, processorCfgs: map[component.ID]component.Config{ - component.NewID("bf"): badProcessorFactory.CreateDefaultConfig(), + component.MustNewID("bf"): badProcessorFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("bf")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Processors: []component.ID{component.MustNewID("bf")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "failed to create \"bf\" processor, in pipeline \"traces\": telemetry type is not supported", @@ -1296,15 +1296,15 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_supported_receiver_logs", receiverCfgs: map[component.ID]component.Config{ - component.NewID("bf"): badReceiverFactory.CreateDefaultConfig(), + component.MustNewID("bf"): badReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewID("logs"): { - Receivers: []component.ID{component.NewID("bf")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewID("logs"): { + Receivers: []component.ID{component.MustNewID("bf")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "failed to create \"bf\" receiver for data type \"logs\": telemetry type is not supported", @@ -1312,15 +1312,15 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_supported_receiver_metrics", receiverCfgs: map[component.ID]component.Config{ - component.NewID("bf"): badReceiverFactory.CreateDefaultConfig(), + component.MustNewID("bf"): badReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewID("metrics"): { - Receivers: []component.ID{component.NewID("bf")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewID("metrics"): { + Receivers: []component.ID{component.MustNewID("bf")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "failed to create \"bf\" receiver for data type \"metrics\": telemetry type is not supported", @@ -1328,15 +1328,15 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_supported_receiver_traces", receiverCfgs: map[component.ID]component.Config{ - component.NewID("bf"): badReceiverFactory.CreateDefaultConfig(), + component.MustNewID("bf"): badReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("bf")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewID("bf")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "failed to create \"bf\" receiver for data type \"traces\": telemetry type is not supported", @@ -1344,22 +1344,22 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_supported_connector_traces_traces.yaml", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewID("bf"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewID("bf"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewIDWithName("traces", "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("bf")}, + component.MustNewIDWithName("traces", "in"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("bf")}, }, - component.NewIDWithName("traces", "out"): { - Receivers: []component.ID{component.NewID("bf")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewIDWithName("traces", "out"): { + Receivers: []component.ID{component.MustNewID("bf")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "connector \"bf\" used as exporter in traces pipeline but not used in any supported receiver pipeline", @@ -1367,22 +1367,22 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_supported_connector_traces_metrics.yaml", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewID("bf"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewID("bf"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewIDWithName("traces", "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("bf")}, + component.MustNewIDWithName("traces", "in"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("bf")}, }, - component.NewIDWithName("metrics", "out"): { - Receivers: []component.ID{component.NewID("bf")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewIDWithName("metrics", "out"): { + Receivers: []component.ID{component.MustNewID("bf")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "connector \"bf\" used as exporter in traces pipeline but not used in any supported receiver pipeline", @@ -1390,22 +1390,22 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_supported_connector_traces_logs.yaml", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewID("bf"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewID("bf"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewIDWithName("traces", "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("bf")}, + component.MustNewIDWithName("traces", "in"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("bf")}, }, - component.NewIDWithName("logs", "out"): { - Receivers: []component.ID{component.NewID("bf")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewIDWithName("logs", "out"): { + Receivers: []component.ID{component.MustNewID("bf")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "connector \"bf\" used as exporter in traces pipeline but not used in any supported receiver pipeline", @@ -1413,22 +1413,22 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_supported_connector_metrics_traces.yaml", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewID("bf"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewID("bf"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewIDWithName("metrics", "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("bf")}, + component.MustNewIDWithName("metrics", "in"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("bf")}, }, - component.NewIDWithName("traces", "out"): { - Receivers: []component.ID{component.NewID("bf")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewIDWithName("traces", "out"): { + Receivers: []component.ID{component.MustNewID("bf")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "connector \"bf\" used as exporter in metrics pipeline but not used in any supported receiver pipeline", @@ -1436,22 +1436,22 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_supported_connector_metrics_metrics.yaml", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewID("bf"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewID("bf"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewIDWithName("metrics", "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("bf")}, + component.MustNewIDWithName("metrics", "in"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("bf")}, }, - component.NewIDWithName("metrics", "out"): { - Receivers: []component.ID{component.NewID("bf")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewIDWithName("metrics", "out"): { + Receivers: []component.ID{component.MustNewID("bf")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "connector \"bf\" used as exporter in metrics pipeline but not used in any supported receiver pipeline", @@ -1459,22 +1459,22 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_supported_connector_metrics_logs.yaml", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewID("bf"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewID("bf"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewIDWithName("metrics", "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("bf")}, + component.MustNewIDWithName("metrics", "in"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("bf")}, }, - component.NewIDWithName("logs", "out"): { - Receivers: []component.ID{component.NewID("bf")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewIDWithName("logs", "out"): { + Receivers: []component.ID{component.MustNewID("bf")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "connector \"bf\" used as exporter in metrics pipeline but not used in any supported receiver pipeline", @@ -1482,22 +1482,22 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_supported_connector_logs_traces.yaml", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewID("bf"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewID("bf"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewIDWithName("logs", "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("bf")}, + component.MustNewIDWithName("logs", "in"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("bf")}, }, - component.NewIDWithName("traces", "out"): { - Receivers: []component.ID{component.NewID("bf")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewIDWithName("traces", "out"): { + Receivers: []component.ID{component.MustNewID("bf")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "connector \"bf\" used as exporter in logs pipeline but not used in any supported receiver pipeline", @@ -1505,22 +1505,22 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_supported_connector_logs_metrics.yaml", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewID("bf"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewID("bf"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewIDWithName("logs", "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("bf")}, + component.MustNewIDWithName("logs", "in"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("bf")}, }, - component.NewIDWithName("metrics", "out"): { - Receivers: []component.ID{component.NewID("bf")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewIDWithName("metrics", "out"): { + Receivers: []component.ID{component.MustNewID("bf")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "connector \"bf\" used as exporter in logs pipeline but not used in any supported receiver pipeline", @@ -1528,22 +1528,22 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_supported_connector_logs_logs.yaml", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewID("bf"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewID("bf"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewIDWithName("logs", "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("bf")}, + component.MustNewIDWithName("logs", "in"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("bf")}, }, - component.NewIDWithName("logs", "out"): { - Receivers: []component.ID{component.NewID("bf")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewIDWithName("logs", "out"): { + Receivers: []component.ID{component.MustNewID("bf")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "connector \"bf\" used as exporter in logs pipeline but not used in any supported receiver pipeline", @@ -1551,18 +1551,18 @@ func TestGraphBuildErrors(t *testing.T) { { name: "orphaned-connector-use-as-exporter", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewIDWithName("nop", "conn"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("nop", "conn"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewIDWithName("metrics", "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "conn")}, + component.MustNewIDWithName("metrics", "in"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "conn")}, }, }, expected: `connector "nop/conn" used as exporter in metrics pipeline but not used in any supported receiver pipeline`, @@ -1570,18 +1570,18 @@ func TestGraphBuildErrors(t *testing.T) { { name: "orphaned-connector-use-as-receiver", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewIDWithName("nop", "conn"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("nop", "conn"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewIDWithName("traces", "out"): { - Receivers: []component.ID{component.NewIDWithName("nop", "conn")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewIDWithName("traces", "out"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "conn")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: `connector "nop/conn" used as receiver in traces pipeline but not used in any supported exporter pipeline`, @@ -1589,26 +1589,26 @@ func TestGraphBuildErrors(t *testing.T) { { name: "partially-orphaned-connector-use-as-exporter", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewID("mockforward"): mfConnectorFactory.CreateDefaultConfig(), + component.MustNewID("mockforward"): mfConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewIDWithName("traces", "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("mockforward")}, + component.MustNewIDWithName("traces", "in"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("mockforward")}, }, - component.NewIDWithName("traces", "out"): { - Receivers: []component.ID{component.NewID("mockforward")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewIDWithName("traces", "out"): { + Receivers: []component.ID{component.MustNewID("mockforward")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, - component.NewIDWithName("metrics", "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("mockforward")}, + component.MustNewIDWithName("metrics", "in"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("mockforward")}, }, }, expected: `connector "mockforward" used as exporter in metrics pipeline but not used in any supported receiver pipeline`, @@ -1616,26 +1616,26 @@ func TestGraphBuildErrors(t *testing.T) { { name: "partially-orphaned-connector-use-as-receiver", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewID("mockforward"): mfConnectorFactory.CreateDefaultConfig(), + component.MustNewID("mockforward"): mfConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewIDWithName("metrics", "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("mockforward")}, + component.MustNewIDWithName("metrics", "in"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("mockforward")}, }, - component.NewIDWithName("metrics", "out"): { - Receivers: []component.ID{component.NewID("mockforward")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewIDWithName("metrics", "out"): { + Receivers: []component.ID{component.MustNewID("mockforward")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, - component.NewIDWithName("traces", "out"): { - Receivers: []component.ID{component.NewID("mockforward")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewIDWithName("traces", "out"): { + Receivers: []component.ID{component.MustNewID("mockforward")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: `connector "mockforward" used as receiver in traces pipeline but not used in any supported exporter pipeline`, @@ -1643,22 +1643,22 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_allowed_simple_cycle_traces.yaml", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, processorCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopProcessorFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopProcessorFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewIDWithName("nop", "conn"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("nop", "conn"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewID("traces"): { - Receivers: []component.ID{component.NewIDWithName("nop", "conn")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "conn")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "conn")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "conn")}, }, }, expected: `cycle detected: ` + @@ -1669,22 +1669,22 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_allowed_simple_cycle_metrics.yaml", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, processorCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopProcessorFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopProcessorFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewIDWithName("nop", "conn"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("nop", "conn"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewID("metrics"): { - Receivers: []component.ID{component.NewIDWithName("nop", "conn")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "conn")}, + component.MustNewID("metrics"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "conn")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "conn")}, }, }, expected: `cycle detected: ` + @@ -1695,22 +1695,22 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_allowed_simple_cycle_logs.yaml", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, processorCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopProcessorFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopProcessorFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewIDWithName("nop", "conn"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("nop", "conn"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewID("logs"): { - Receivers: []component.ID{component.NewIDWithName("nop", "conn")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "conn")}, + component.MustNewID("logs"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "conn")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "conn")}, }, }, expected: `cycle detected: ` + @@ -1721,39 +1721,39 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_allowed_deep_cycle_traces.yaml", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, processorCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopProcessorFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopProcessorFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewIDWithName("nop", "conn"): nopConnectorFactory.CreateDefaultConfig(), - component.NewIDWithName("nop", "conn1"): nopConnectorFactory.CreateDefaultConfig(), - component.NewIDWithName("nop", "conn2"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("nop", "conn"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("nop", "conn1"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("nop", "conn2"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewIDWithName("traces", "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "conn")}, + component.MustNewIDWithName("traces", "in"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "conn")}, }, - component.NewIDWithName("traces", "1"): { - Receivers: []component.ID{component.NewIDWithName("nop", "conn")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "conn1")}, + component.MustNewIDWithName("traces", "1"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "conn")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "conn1")}, }, - component.NewIDWithName("traces", "2"): { - Receivers: []component.ID{component.NewIDWithName("nop", "conn1")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "conn2"), component.NewIDWithName("nop", "conn")}, + component.MustNewIDWithName("traces", "2"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "conn1")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "conn2"), component.MustNewIDWithName("nop", "conn")}, }, - component.NewIDWithName("traces", "out"): { - Receivers: []component.ID{component.NewIDWithName("nop", "conn2")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewIDWithName("traces", "out"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "conn2")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: `cycle detected: ` + @@ -1766,39 +1766,39 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_allowed_deep_cycle_metrics.yaml", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, processorCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopProcessorFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopProcessorFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewIDWithName("nop", "conn"): nopConnectorFactory.CreateDefaultConfig(), - component.NewIDWithName("nop", "conn1"): nopConnectorFactory.CreateDefaultConfig(), - component.NewIDWithName("nop", "conn2"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("nop", "conn"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("nop", "conn1"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("nop", "conn2"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewIDWithName("metrics", "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "conn")}, + component.MustNewIDWithName("metrics", "in"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "conn")}, }, - component.NewIDWithName("metrics", "1"): { - Receivers: []component.ID{component.NewIDWithName("nop", "conn")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "conn1")}, + component.MustNewIDWithName("metrics", "1"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "conn")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "conn1")}, }, - component.NewIDWithName("metrics", "2"): { - Receivers: []component.ID{component.NewIDWithName("nop", "conn1")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "conn2"), component.NewIDWithName("nop", "conn")}, + component.MustNewIDWithName("metrics", "2"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "conn1")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "conn2"), component.MustNewIDWithName("nop", "conn")}, }, - component.NewIDWithName("metrics", "out"): { - Receivers: []component.ID{component.NewIDWithName("nop", "conn2")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewIDWithName("metrics", "out"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "conn2")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: `cycle detected: ` + @@ -1811,39 +1811,39 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_allowed_deep_cycle_logs.yaml", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, processorCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopProcessorFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopProcessorFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewIDWithName("nop", "conn"): nopConnectorFactory.CreateDefaultConfig(), - component.NewIDWithName("nop", "conn1"): nopConnectorFactory.CreateDefaultConfig(), - component.NewIDWithName("nop", "conn2"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("nop", "conn"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("nop", "conn1"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("nop", "conn2"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewIDWithName("logs", "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "conn")}, + component.MustNewIDWithName("logs", "in"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "conn")}, }, - component.NewIDWithName("logs", "1"): { - Receivers: []component.ID{component.NewIDWithName("nop", "conn")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "conn1")}, + component.MustNewIDWithName("logs", "1"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "conn")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "conn1")}, }, - component.NewIDWithName("logs", "2"): { - Receivers: []component.ID{component.NewIDWithName("nop", "conn1")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "conn2"), component.NewIDWithName("nop", "conn")}, + component.MustNewIDWithName("logs", "2"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "conn1")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "conn2"), component.MustNewIDWithName("nop", "conn")}, }, - component.NewIDWithName("logs", "out"): { - Receivers: []component.ID{component.NewIDWithName("nop", "conn2")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewIDWithName("logs", "out"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "conn2")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: `cycle detected: ` + @@ -1856,55 +1856,55 @@ func TestGraphBuildErrors(t *testing.T) { { name: "not_allowed_deep_cycle_multi_signal.yaml", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, processorCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopProcessorFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopProcessorFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopExporterFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopExporterFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewIDWithName("nop", "fork"): nopConnectorFactory.CreateDefaultConfig(), - component.NewIDWithName("nop", "count"): nopConnectorFactory.CreateDefaultConfig(), - component.NewIDWithName("nop", "forkagain"): nopConnectorFactory.CreateDefaultConfig(), - component.NewIDWithName("nop", "rawlog"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("nop", "fork"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("nop", "count"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("nop", "forkagain"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewIDWithName("nop", "rawlog"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewIDWithName("traces", "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "fork")}, - }, - component.NewIDWithName("traces", "copy1"): { - Receivers: []component.ID{component.NewIDWithName("nop", "fork")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "count")}, - }, - component.NewIDWithName("traces", "copy2"): { - Receivers: []component.ID{component.NewIDWithName("nop", "fork")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "forkagain")}, - }, - component.NewIDWithName("traces", "copy2a"): { - Receivers: []component.ID{component.NewIDWithName("nop", "forkagain")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "count")}, - }, - component.NewIDWithName("traces", "copy2b"): { - Receivers: []component.ID{component.NewIDWithName("nop", "forkagain")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "rawlog")}, - }, - component.NewIDWithName("metrics", "count"): { - Receivers: []component.ID{component.NewIDWithName("nop", "count")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop")}, - }, - component.NewIDWithName("logs", "raw"): { - Receivers: []component.ID{component.NewIDWithName("nop", "rawlog")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewIDWithName("nop", "fork")}, // cannot loop back to "nop/fork" + component.MustNewIDWithName("traces", "in"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "fork")}, + }, + component.MustNewIDWithName("traces", "copy1"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "fork")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "count")}, + }, + component.MustNewIDWithName("traces", "copy2"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "fork")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "forkagain")}, + }, + component.MustNewIDWithName("traces", "copy2a"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "forkagain")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "count")}, + }, + component.MustNewIDWithName("traces", "copy2b"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "forkagain")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "rawlog")}, + }, + component.MustNewIDWithName("metrics", "count"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "count")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("nop")}, + }, + component.MustNewIDWithName("logs", "raw"): { + Receivers: []component.ID{component.MustNewIDWithName("nop", "rawlog")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewIDWithName("nop", "fork")}, // cannot loop back to "nop/fork" }, }, expected: `cycle detected: ` + @@ -1919,15 +1919,15 @@ func TestGraphBuildErrors(t *testing.T) { { name: "unknown_exporter_config", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop"), component.NewIDWithName("nop", "1")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("nop"), component.MustNewIDWithName("nop", "1")}, }, }, expected: "failed to create \"nop/1\" exporter for data type \"traces\": exporter \"nop/1\" is not configured", @@ -1935,15 +1935,15 @@ func TestGraphBuildErrors(t *testing.T) { { name: "unknown_exporter_factory", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("unknown"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("unknown"): nopReceiverFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("unknown")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("unknown")}, }, }, expected: "failed to create \"unknown\" exporter for data type \"traces\": exporter factory not available for: \"unknown\"", @@ -1951,19 +1951,19 @@ func TestGraphBuildErrors(t *testing.T) { { name: "unknown_processor_config", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, processorCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopProcessorFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopProcessorFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewID("metrics"): { - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("nop"), component.NewIDWithName("nop", "1")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewID("metrics"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Processors: []component.ID{component.MustNewID("nop"), component.MustNewIDWithName("nop", "1")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "failed to create \"nop/1\" processor, in pipeline \"metrics\": processor \"nop/1\" is not configured", @@ -1971,19 +1971,19 @@ func TestGraphBuildErrors(t *testing.T) { { name: "unknown_processor_factory", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, processorCfgs: map[component.ID]component.Config{ - component.NewID("unknown"): nopProcessorFactory.CreateDefaultConfig(), + component.MustNewID("unknown"): nopProcessorFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewID("metrics"): { - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("unknown")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewID("metrics"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Processors: []component.ID{component.MustNewID("unknown")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "failed to create \"unknown\" processor, in pipeline \"metrics\": processor factory not available for: \"unknown\"", @@ -1991,15 +1991,15 @@ func TestGraphBuildErrors(t *testing.T) { { name: "unknown_receiver_config", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewID("logs"): { - Receivers: []component.ID{component.NewID("nop"), component.NewIDWithName("nop", "1")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewID("logs"): { + Receivers: []component.ID{component.MustNewID("nop"), component.MustNewIDWithName("nop", "1")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "failed to create \"nop/1\" receiver for data type \"logs\": receiver \"nop/1\" is not configured", @@ -2007,15 +2007,15 @@ func TestGraphBuildErrors(t *testing.T) { { name: "unknown_receiver_factory", receiverCfgs: map[component.ID]component.Config{ - component.NewID("unknown"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("unknown"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewID("logs"): { - Receivers: []component.ID{component.NewID("unknown")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewID("logs"): { + Receivers: []component.ID{component.MustNewID("unknown")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "failed to create \"unknown\" receiver for data type \"logs\": receiver factory not available for: \"unknown\"", @@ -2023,22 +2023,22 @@ func TestGraphBuildErrors(t *testing.T) { { name: "unknown_connector_factory", receiverCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, exporterCfgs: map[component.ID]component.Config{ - component.NewID("nop"): nopReceiverFactory.CreateDefaultConfig(), + component.MustNewID("nop"): nopReceiverFactory.CreateDefaultConfig(), }, connectorCfgs: map[component.ID]component.Config{ - component.NewID("unknown"): nopConnectorFactory.CreateDefaultConfig(), + component.MustNewID("unknown"): nopConnectorFactory.CreateDefaultConfig(), }, pipelineCfgs: pipelines.Config{ - component.NewIDWithName("traces", "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("unknown")}, + component.MustNewIDWithName("traces", "in"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("unknown")}, }, - component.NewIDWithName("traces", "out"): { - Receivers: []component.ID{component.NewID("unknown")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewIDWithName("traces", "out"): { + Receivers: []component.ID{component.MustNewID("unknown")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, }, expected: "connector factory not available for: \"unknown\"", @@ -2138,12 +2138,12 @@ func TestGraphFailToStartAndShutdown(t *testing.T) { dataTypes := []component.DataType{component.DataTypeTraces, component.DataTypeMetrics, component.DataTypeLogs} for _, dt := range dataTypes { - t.Run(string(dt)+"/receiver", func(t *testing.T) { + t.Run(dt.String()+"/receiver", func(t *testing.T) { set.PipelineConfigs = pipelines.Config{ component.NewID(dt): { - Receivers: []component.ID{component.NewID("nop"), component.NewID("err")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop")}, + Receivers: []component.ID{component.MustNewID("nop"), component.MustNewID("err")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, } pipelines, err := Build(context.Background(), set) @@ -2152,12 +2152,12 @@ func TestGraphFailToStartAndShutdown(t *testing.T) { assert.Error(t, pipelines.ShutdownAll(context.Background())) }) - t.Run(string(dt)+"/processor", func(t *testing.T) { + t.Run(dt.String()+"/processor", func(t *testing.T) { set.PipelineConfigs = pipelines.Config{ component.NewID(dt): { - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("nop"), component.NewID("err")}, - Exporters: []component.ID{component.NewID("nop")}, + Receivers: []component.ID{component.MustNewID("nop")}, + Processors: []component.ID{component.MustNewID("nop"), component.MustNewID("err")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, } pipelines, err := Build(context.Background(), set) @@ -2166,12 +2166,12 @@ func TestGraphFailToStartAndShutdown(t *testing.T) { assert.Error(t, pipelines.ShutdownAll(context.Background())) }) - t.Run(string(dt)+"/exporter", func(t *testing.T) { + t.Run(dt.String()+"/exporter", func(t *testing.T) { set.PipelineConfigs = pipelines.Config{ component.NewID(dt): { - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop"), component.NewID("err")}, + Receivers: []component.ID{component.MustNewID("nop")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("nop"), component.MustNewID("err")}, }, } pipelines, err := Build(context.Background(), set) @@ -2181,17 +2181,17 @@ func TestGraphFailToStartAndShutdown(t *testing.T) { }) for _, dt2 := range dataTypes { - t.Run(string(dt)+"/"+string(dt2)+"/connector", func(t *testing.T) { + t.Run(dt.String()+"/"+dt2.String()+"/connector", func(t *testing.T) { set.PipelineConfigs = pipelines.Config{ component.NewIDWithName(dt, "in"): { - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop"), component.NewIDWithName("err", "conn")}, + Receivers: []component.ID{component.MustNewID("nop")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("nop"), component.MustNewIDWithName("err", "conn")}, }, component.NewIDWithName(dt2, "out"): { - Receivers: []component.ID{component.NewID("nop"), component.NewIDWithName("err", "conn")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop")}, + Receivers: []component.ID{component.MustNewID("nop"), component.MustNewIDWithName("err", "conn")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, } pipelines, err := Build(context.Background(), set) @@ -2205,13 +2205,13 @@ func TestGraphFailToStartAndShutdown(t *testing.T) { func TestStatusReportedOnStartupShutdown(t *testing.T) { - rNoErr := &testNode{id: component.NewIDWithName("r-no-err", "1")} - rStErr := &testNode{id: component.NewIDWithName("r-st-err", "1"), startErr: assert.AnError} - rSdErr := &testNode{id: component.NewIDWithName("r-sd-err", "1"), shutdownErr: assert.AnError} + rNoErr := &testNode{id: component.MustNewIDWithName("r_no_err", "1")} + rStErr := &testNode{id: component.MustNewIDWithName("r_st_err", "1"), startErr: assert.AnError} + rSdErr := &testNode{id: component.MustNewIDWithName("r_sd_err", "1"), shutdownErr: assert.AnError} - eNoErr := &testNode{id: component.NewIDWithName("e-no-err", "1")} - eStErr := &testNode{id: component.NewIDWithName("e-st-err", "1"), startErr: assert.AnError} - eSdErr := &testNode{id: component.NewIDWithName("e-sd-err", "1"), shutdownErr: assert.AnError} + eNoErr := &testNode{id: component.MustNewIDWithName("e_no_err", "1")} + eStErr := &testNode{id: component.MustNewIDWithName("e_st_err", "1"), startErr: assert.AnError} + eSdErr := &testNode{id: component.MustNewIDWithName("e_sd_err", "1"), shutdownErr: assert.AnError} instanceIDs := map[*testNode]*component.InstanceID{ rNoErr: {ID: rNoErr.id}, @@ -2390,9 +2390,10 @@ func (g *Graph) getReceivers() map[component.DataType]map[component.ID]component // - E instances of the connector as a receiver. // - R instances of the connector as an exporter. func expectedInstances(m pipelines.Config, pID component.ID) (int, int) { + exConnectorType := component.MustNewType("exampleconnector") var r, e int for _, rID := range m[pID].Receivers { - if rID.Type() != "exampleconnector" { + if rID.Type() != exConnectorType { r++ continue } @@ -2409,7 +2410,7 @@ func expectedInstances(m pipelines.Config, pID component.ID) (int, int) { r += len(typeMap) } for _, eID := range m[pID].Exporters { - if eID.Type() != "exampleconnector" { + if eID.Type() != exConnectorType { e++ continue } @@ -2429,31 +2430,31 @@ func expectedInstances(m pipelines.Config, pID component.ID) (int, int) { } func newBadReceiverFactory() receiver.Factory { - return receiver.NewFactory("bf", func() component.Config { + return receiver.NewFactory(component.MustNewType("bf"), func() component.Config { return &struct{}{} }) } func newBadProcessorFactory() processor.Factory { - return processor.NewFactory("bf", func() component.Config { + return processor.NewFactory(component.MustNewType("bf"), func() component.Config { return &struct{}{} }) } func newBadExporterFactory() exporter.Factory { - return exporter.NewFactory("bf", func() component.Config { + return exporter.NewFactory(component.MustNewType("bf"), func() component.Config { return &struct{}{} }) } func newBadConnectorFactory() connector.Factory { - return connector.NewFactory("bf", func() component.Config { + return connector.NewFactory(component.MustNewType("bf"), func() component.Config { return &struct{}{} }) } func newErrReceiverFactory() receiver.Factory { - return receiver.NewFactory("err", + return receiver.NewFactory(component.MustNewType("err"), func() component.Config { return &struct{}{} }, receiver.WithTraces(func(context.Context, receiver.CreateSettings, component.Config, consumer.Traces) (receiver.Traces, error) { return &errComponent{}, nil @@ -2468,7 +2469,7 @@ func newErrReceiverFactory() receiver.Factory { } func newErrProcessorFactory() processor.Factory { - return processor.NewFactory("err", + return processor.NewFactory(component.MustNewType("err"), func() component.Config { return &struct{}{} }, processor.WithTraces(func(context.Context, processor.CreateSettings, component.Config, consumer.Traces) (processor.Traces, error) { return &errComponent{}, nil @@ -2483,7 +2484,7 @@ func newErrProcessorFactory() processor.Factory { } func newErrExporterFactory() exporter.Factory { - return exporter.NewFactory("err", + return exporter.NewFactory(component.MustNewType("err"), func() component.Config { return &struct{}{} }, exporter.WithTraces(func(context.Context, exporter.CreateSettings, component.Config) (exporter.Traces, error) { return &errComponent{}, nil @@ -2498,7 +2499,7 @@ func newErrExporterFactory() exporter.Factory { } func newErrConnectorFactory() connector.Factory { - return connector.NewFactory("err", func() component.Config { + return connector.NewFactory(component.MustNewType("err"), func() component.Config { return &struct{}{} }, connector.WithTracesToTraces(func(context.Context, connector.CreateSettings, component.Config, consumer.Traces) (connector.Traces, error) { diff --git a/service/internal/graph/nodes.go b/service/internal/graph/nodes.go index 79d627d5bf7..13726d1c760 100644 --- a/service/internal/graph/nodes.go +++ b/service/internal/graph/nodes.go @@ -61,7 +61,7 @@ type receiverNode struct { func newReceiverNode(pipelineType component.DataType, recvID component.ID) *receiverNode { return &receiverNode{ - nodeID: newNodeID(receiverSeed, string(pipelineType), recvID.String()), + nodeID: newNodeID(receiverSeed, pipelineType.String(), recvID.String()), componentID: recvID, pipelineType: pipelineType, } @@ -165,7 +165,7 @@ type exporterNode struct { func newExporterNode(pipelineType component.DataType, exprID component.ID) *exporterNode { return &exporterNode{ - nodeID: newNodeID(exporterSeed, string(pipelineType), exprID.String()), + nodeID: newNodeID(exporterSeed, pipelineType.String(), exprID.String()), componentID: exprID, pipelineType: pipelineType, } @@ -215,7 +215,7 @@ type connectorNode struct { func newConnectorNode(exprPipelineType, rcvrPipelineType component.DataType, connID component.ID) *connectorNode { return &connectorNode{ - nodeID: newNodeID(connectorSeed, connID.String(), string(exprPipelineType), string(rcvrPipelineType)), + nodeID: newNodeID(connectorSeed, connID.String(), exprPipelineType.String(), rcvrPipelineType.String()), componentID: connID, exprPipelineType: exprPipelineType, rcvrPipelineType: rcvrPipelineType, diff --git a/service/internal/graph/zpages.go b/service/internal/graph/zpages.go index 0c7c0829eed..0f2793974e9 100644 --- a/service/internal/graph/zpages.go +++ b/service/internal/graph/zpages.go @@ -55,7 +55,7 @@ func (g *Graph) HandleZPages(w http.ResponseWriter, r *http.Request) { sumData.Rows = append(sumData.Rows, zpages.SummaryPipelinesTableRowData{ FullName: c.String(), - InputType: string(c.Type()), + InputType: c.Type().String(), MutatesData: p.capabilitiesNode.getConsumer().Capabilities().MutatesData, Receivers: recvIDs, Processors: procIDs, diff --git a/service/internal/testcomponents/example_connector.go b/service/internal/testcomponents/example_connector.go index c5c10b92b78..75c5145cf7b 100644 --- a/service/internal/testcomponents/example_connector.go +++ b/service/internal/testcomponents/example_connector.go @@ -15,7 +15,7 @@ import ( "go.opentelemetry.io/collector/pdata/ptrace" ) -const connType = "exampleconnector" +var connType = component.MustNewType("exampleconnector") // ExampleConnectorFactory is factory for ExampleConnector. var ExampleConnectorFactory = connector.NewFactory( @@ -36,7 +36,7 @@ var ExampleConnectorFactory = connector.NewFactory( ) var MockForwardConnectorFactory = connector.NewFactory( - "mockforward", + component.MustNewType("mockforward"), createExampleConnectorDefaultConfig, connector.WithTracesToTraces(createExampleTracesToTraces, component.StabilityLevelDevelopment), connector.WithMetricsToMetrics(createExampleMetricsToMetrics, component.StabilityLevelDevelopment), diff --git a/service/internal/testcomponents/example_exporter.go b/service/internal/testcomponents/example_exporter.go index 7c5f512d361..653a2ad4a47 100644 --- a/service/internal/testcomponents/example_exporter.go +++ b/service/internal/testcomponents/example_exporter.go @@ -14,14 +14,13 @@ import ( "go.opentelemetry.io/collector/pdata/ptrace" ) -const ( - typeStr = "exampleexporter" - stability = component.StabilityLevelDevelopment -) +var testType = component.MustNewType("exampleexporter") + +const stability = component.StabilityLevelDevelopment // ExampleExporterFactory is factory for ExampleExporter. var ExampleExporterFactory = exporter.NewFactory( - typeStr, + testType, createExporterDefaultConfig, exporter.WithTraces(createTracesExporter, stability), exporter.WithMetrics(createMetricsExporter, stability), diff --git a/service/internal/testcomponents/example_processor.go b/service/internal/testcomponents/example_processor.go index 8189264b5c3..9f73611853b 100644 --- a/service/internal/testcomponents/example_processor.go +++ b/service/internal/testcomponents/example_processor.go @@ -11,7 +11,7 @@ import ( "go.opentelemetry.io/collector/processor" ) -const procType = "exampleprocessor" +var procType = component.MustNewType("exampleprocessor") // ExampleProcessorFactory is factory for ExampleProcessor. var ExampleProcessorFactory = processor.NewFactory( diff --git a/service/internal/testcomponents/example_receiver.go b/service/internal/testcomponents/example_receiver.go index e59d9cb67bb..34b0372b03b 100644 --- a/service/internal/testcomponents/example_receiver.go +++ b/service/internal/testcomponents/example_receiver.go @@ -11,7 +11,7 @@ import ( "go.opentelemetry.io/collector/receiver" ) -const receiverType = component.Type("examplereceiver") +var receiverType = component.MustNewType("examplereceiver") // ExampleReceiverFactory is factory for ExampleReceiver. var ExampleReceiverFactory = receiver.NewFactory( diff --git a/service/internal/testcomponents/example_router.go b/service/internal/testcomponents/example_router.go index 45d2a17c561..3eafbf13cb6 100644 --- a/service/internal/testcomponents/example_router.go +++ b/service/internal/testcomponents/example_router.go @@ -14,7 +14,7 @@ import ( "go.opentelemetry.io/collector/pdata/ptrace" ) -const routerType = "examplerouter" +var routerType = component.MustNewType("examplerouter") // ExampleRouterFactory is factory for ExampleRouter. var ExampleRouterFactory = connector.NewFactory( diff --git a/service/internal/testcomponents/example_router_test.go b/service/internal/testcomponents/example_router_test.go index a34a70160e0..23f94854b2a 100644 --- a/service/internal/testcomponents/example_router_test.go +++ b/service/internal/testcomponents/example_router_test.go @@ -31,8 +31,8 @@ func TestExampleRouter(t *testing.T) { } func TestTracesRouter(t *testing.T) { - leftID := component.NewIDWithName("sink", "left") - rightID := component.NewIDWithName("sink", "right") + leftID := component.MustNewIDWithName("sink", "left") + rightID := component.MustNewIDWithName("sink", "right") sinkLeft := new(consumertest.TracesSink) sinkRight := new(consumertest.TracesSink) @@ -70,8 +70,8 @@ func TestTracesRouter(t *testing.T) { } func TestMetricsRouter(t *testing.T) { - leftID := component.NewIDWithName("sink", "left") - rightID := component.NewIDWithName("sink", "right") + leftID := component.MustNewIDWithName("sink", "left") + rightID := component.MustNewIDWithName("sink", "right") sinkLeft := new(consumertest.MetricsSink) sinkRight := new(consumertest.MetricsSink) @@ -109,8 +109,8 @@ func TestMetricsRouter(t *testing.T) { } func TestLogsRouter(t *testing.T) { - leftID := component.NewIDWithName("sink", "left") - rightID := component.NewIDWithName("sink", "right") + leftID := component.MustNewIDWithName("sink", "left") + rightID := component.MustNewIDWithName("sink", "right") sinkLeft := new(consumertest.LogsSink) sinkRight := new(consumertest.LogsSink) diff --git a/service/pipelines/config_test.go b/service/pipelines/config_test.go index e08dff3741a..7ad94d5ab3f 100644 --- a/service/pipelines/config_test.go +++ b/service/pipelines/config_test.go @@ -28,7 +28,7 @@ func TestConfigValidate(t *testing.T) { name: "duplicate-processor-reference", cfgFn: func() Config { cfg := generateConfig() - pipe := cfg[component.NewID("traces")] + pipe := cfg[component.MustNewID("traces")] pipe.Processors = append(pipe.Processors, pipe.Processors...) return cfg }, @@ -38,7 +38,7 @@ func TestConfigValidate(t *testing.T) { name: "missing-pipeline-receivers", cfgFn: func() Config { cfg := generateConfig() - cfg[component.NewID("traces")].Receivers = nil + cfg[component.MustNewID("traces")].Receivers = nil return cfg }, expected: fmt.Errorf(`pipeline "traces": %w`, errMissingServicePipelineReceivers), @@ -47,7 +47,7 @@ func TestConfigValidate(t *testing.T) { name: "missing-pipeline-exporters", cfgFn: func() Config { cfg := generateConfig() - cfg[component.NewID("traces")].Exporters = nil + cfg[component.MustNewID("traces")].Exporters = nil return cfg }, expected: fmt.Errorf(`pipeline "traces": %w`, errMissingServicePipelineExporters), @@ -63,10 +63,10 @@ func TestConfigValidate(t *testing.T) { name: "invalid-service-pipeline-type", cfgFn: func() Config { cfg := generateConfig() - cfg[component.NewID("wrongtype")] = &PipelineConfig{ - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop")}, + cfg[component.MustNewID("wrongtype")] = &PipelineConfig{ + Receivers: []component.ID{component.MustNewID("nop")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("nop")}, } return cfg }, @@ -84,10 +84,10 @@ func TestConfigValidate(t *testing.T) { func generateConfig() Config { return map[component.ID]*PipelineConfig{ - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.MustNewID("nop")}, + Processors: []component.ID{component.MustNewID("nop")}, + Exporters: []component.ID{component.MustNewID("nop")}, }, } } diff --git a/service/service_test.go b/service/service_test.go index 47d0061fd6a..172007ce277 100644 --- a/service/service_test.go +++ b/service/service_test.go @@ -168,6 +168,11 @@ func ownMetricsTestCases() []ownMetricsTestCase { }} } +var ( + nopType = component.MustNewType("nop") + wrongType = component.MustNewType("wrong") +) + func TestServiceGetFactory(t *testing.T) { set := newNopSettings() srv, err := New(context.Background(), set, newNopConfig()) @@ -178,23 +183,23 @@ func TestServiceGetFactory(t *testing.T) { assert.NoError(t, srv.Shutdown(context.Background())) }) - assert.Nil(t, srv.host.GetFactory(component.KindReceiver, "wrongtype")) - assert.Equal(t, set.Receivers.Factory("nop"), srv.host.GetFactory(component.KindReceiver, "nop")) + assert.Nil(t, srv.host.GetFactory(component.KindReceiver, wrongType)) + assert.Equal(t, set.Receivers.Factory(nopType), srv.host.GetFactory(component.KindReceiver, nopType)) - assert.Nil(t, srv.host.GetFactory(component.KindProcessor, "wrongtype")) - assert.Equal(t, set.Processors.Factory("nop"), srv.host.GetFactory(component.KindProcessor, "nop")) + assert.Nil(t, srv.host.GetFactory(component.KindProcessor, wrongType)) + assert.Equal(t, set.Processors.Factory(nopType), srv.host.GetFactory(component.KindProcessor, nopType)) - assert.Nil(t, srv.host.GetFactory(component.KindExporter, "wrongtype")) - assert.Equal(t, set.Exporters.Factory("nop"), srv.host.GetFactory(component.KindExporter, "nop")) + assert.Nil(t, srv.host.GetFactory(component.KindExporter, wrongType)) + assert.Equal(t, set.Exporters.Factory(nopType), srv.host.GetFactory(component.KindExporter, nopType)) - assert.Nil(t, srv.host.GetFactory(component.KindConnector, "wrongtype")) - assert.Equal(t, set.Connectors.Factory("nop"), srv.host.GetFactory(component.KindConnector, "nop")) + assert.Nil(t, srv.host.GetFactory(component.KindConnector, wrongType)) + assert.Equal(t, set.Connectors.Factory(nopType), srv.host.GetFactory(component.KindConnector, nopType)) - assert.Nil(t, srv.host.GetFactory(component.KindExtension, "wrongtype")) - assert.Equal(t, set.Extensions.Factory("nop"), srv.host.GetFactory(component.KindExtension, "nop")) + assert.Nil(t, srv.host.GetFactory(component.KindExtension, wrongType)) + assert.Equal(t, set.Extensions.Factory(nopType), srv.host.GetFactory(component.KindExtension, nopType)) // Try retrieve non existing component.Kind. - assert.Nil(t, srv.host.GetFactory(42, "nop")) + assert.Nil(t, srv.host.GetFactory(42, nopType)) } func TestServiceGetExtensions(t *testing.T) { @@ -209,7 +214,7 @@ func TestServiceGetExtensions(t *testing.T) { extMap := srv.host.GetExtensions() assert.Len(t, extMap, 1) - assert.Contains(t, extMap, component.NewID("nop")) + assert.Contains(t, extMap, component.NewID(nopType)) } func TestServiceGetExporters(t *testing.T) { @@ -224,18 +229,18 @@ func TestServiceGetExporters(t *testing.T) { expMap := srv.host.GetExporters() assert.Len(t, expMap, 3) assert.Len(t, expMap[component.DataTypeTraces], 1) - assert.Contains(t, expMap[component.DataTypeTraces], component.NewID("nop")) + assert.Contains(t, expMap[component.DataTypeTraces], component.NewID(nopType)) assert.Len(t, expMap[component.DataTypeMetrics], 1) - assert.Contains(t, expMap[component.DataTypeMetrics], component.NewID("nop")) + assert.Contains(t, expMap[component.DataTypeMetrics], component.NewID(nopType)) assert.Len(t, expMap[component.DataTypeLogs], 1) - assert.Contains(t, expMap[component.DataTypeLogs], component.NewID("nop")) + assert.Contains(t, expMap[component.DataTypeLogs], component.NewID(nopType)) } // TestServiceTelemetryCleanupOnError tests that if newService errors due to an invalid config telemetry is cleaned up // and another service with a valid config can be started right after. func TestServiceTelemetryCleanupOnError(t *testing.T) { invalidCfg := newNopConfig() - invalidCfg.Pipelines[component.NewID("traces")].Processors[0] = component.NewID("invalid") + invalidCfg.Pipelines[component.MustNewID("traces")].Processors[0] = component.MustNewID("invalid") // Create a service with an invalid config and expect an error _, err := New(context.Background(), newNopSettings(), invalidCfg) require.Error(t, err) @@ -270,12 +275,12 @@ func testCollectorStartHelper(t *testing.T, tc ownMetricsTestCase) { set := newNopSettings() set.BuildInfo = component.BuildInfo{Version: "test version", Command: otelCommand} set.Extensions = extension.NewBuilder( - map[component.ID]component.Config{component.NewID("zpages"): &zpagesextension.Config{TCPAddr: confignet.TCPAddr{Endpoint: zpagesAddr}}}, - map[component.Type]extension.Factory{"zpages": zpagesextension.NewFactory()}) + map[component.ID]component.Config{component.MustNewID("zpages"): &zpagesextension.Config{TCPAddr: confignet.TCPAddr{Endpoint: zpagesAddr}}}, + map[component.Type]extension.Factory{component.MustNewType("zpages"): zpagesextension.NewFactory()}) set.LoggingOptions = []zap.Option{zap.Hooks(hook)} cfg := newNopConfig() - cfg.Extensions = []component.ID{component.NewID("zpages")} + cfg.Extensions = []component.ID{component.MustNewID("zpages")} cfg.Telemetry.Metrics.Address = metricsAddr cfg.Telemetry.Resource = make(map[string]*string) // Include resource attributes under the service::telemetry::resource key. @@ -351,7 +356,7 @@ func TestExtensionNotificationFailure(t *testing.T) { set := newNopSettings() cfg := newNopConfig() - var extName component.Type = "configWatcher" + var extName = component.MustNewType("configWatcher") configWatcherExtensionFactory := newConfigWatcherExtensionFactory(extName) set.Extensions = extension.NewBuilder( map[component.ID]component.Config{component.NewID(extName): configWatcherExtensionFactory.CreateDefaultConfig()}, @@ -374,7 +379,7 @@ func TestNilCollectorEffectiveConfig(t *testing.T) { set.CollectorConf = nil cfg := newNopConfig() - var extName component.Type = "configWatcher" + var extName = component.MustNewType("configWatcher") configWatcherExtensionFactory := newConfigWatcherExtensionFactory(extName) set.Extensions = extension.NewBuilder( map[component.ID]component.Config{component.NewID(extName): configWatcherExtensionFactory.CreateDefaultConfig()}, @@ -527,27 +532,27 @@ func newNopSettings() Settings { func newNopConfig() Config { return newNopConfigPipelineConfigs(pipelines.Config{ - component.NewID("traces"): { - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewID("traces"): { + Receivers: []component.ID{component.NewID(nopType)}, + Processors: []component.ID{component.NewID(nopType)}, + Exporters: []component.ID{component.NewID(nopType)}, }, - component.NewID("metrics"): { - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewID("metrics"): { + Receivers: []component.ID{component.NewID(nopType)}, + Processors: []component.ID{component.NewID(nopType)}, + Exporters: []component.ID{component.NewID(nopType)}, }, - component.NewID("logs"): { - Receivers: []component.ID{component.NewID("nop")}, - Processors: []component.ID{component.NewID("nop")}, - Exporters: []component.ID{component.NewID("nop")}, + component.MustNewID("logs"): { + Receivers: []component.ID{component.NewID(nopType)}, + Processors: []component.ID{component.NewID(nopType)}, + Exporters: []component.ID{component.NewID(nopType)}, }, }) } func newNopConfigPipelineConfigs(pipelineCfgs pipelines.Config) Config { return Config{ - Extensions: extensions.Config{component.NewID("nop")}, + Extensions: extensions.Config{component.NewID(nopType)}, Pipelines: pipelineCfgs, Telemetry: telemetry.Config{ Logs: telemetry.LogsConfig{