diff --git a/cmd/mdatagen/doc.go b/cmd/mdatagen/doc.go deleted file mode 100644 index 8f1fc6a7176..00000000000 --- a/cmd/mdatagen/doc.go +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -// Generate a test metrics builder from a sample metrics set covering all configuration options. -//go:generate mdatagen metadata-sample.yaml - -package main diff --git a/cmd/mdatagen/documentation.md b/cmd/mdatagen/documentation.md deleted file mode 100644 index 1955e081535..00000000000 --- a/cmd/mdatagen/documentation.md +++ /dev/null @@ -1,96 +0,0 @@ -[comment]: <> (Code generated by mdatagen. DO NOT EDIT.) - -# file - -## Default Metrics - -The following metrics are emitted by default. Each of them can be disabled by applying the following configuration: - -```yaml -metrics: - : - enabled: false -``` - -### default.metric - -Monotonic cumulative sum int metric enabled by default. - -The metric will be become optional soon. - -| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | -| ---- | ----------- | ---------- | ----------------------- | --------- | -| s | Sum | Int | Cumulative | true | - -#### Attributes - -| Name | Description | Values | -| ---- | ----------- | ------ | -| string_attr | Attribute with any string value. | Any Str | -| state | Integer attribute with overridden name. | Any Int | -| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` | -| slice_attr | Attribute with a slice value. | Any Slice | -| map_attr | Attribute with a map value. | Any Map | - -### default.metric.to_be_removed - -[DEPRECATED] Non-monotonic delta sum double metric enabled by default. - -The metric will be will be removed soon. - -| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | -| ---- | ----------- | ---------- | ----------------------- | --------- | -| s | Sum | Double | Delta | false | - -## Optional Metrics - -The following metrics are not emitted by default. Each of them can be enabled by applying the following configuration: - -```yaml -metrics: - : - enabled: true -``` - -### optional.metric - -[DEPRECATED] Gauge double metric disabled by default. - -| Unit | Metric Type | Value Type | -| ---- | ----------- | ---------- | -| 1 | Gauge | Double | - -#### Attributes - -| Name | Description | Values | -| ---- | ----------- | ------ | -| string_attr | Attribute with any string value. | Any Str | -| boolean_attr | Attribute with a boolean value. | Any Bool | - -### optional.metric.empty_unit - -[DEPRECATED] Gauge double metric disabled by default. - -| Unit | Metric Type | Value Type | -| ---- | ----------- | ---------- | -| | Gauge | Double | - -#### Attributes - -| Name | Description | Values | -| ---- | ----------- | ------ | -| string_attr | Attribute with any string value. | Any Str | -| boolean_attr | Attribute with a boolean value. | Any Bool | - -## Resource Attributes - -| Name | Description | Values | Enabled | -| ---- | ----------- | ------ | ------- | -| map.resource.attr | Resource attribute with a map value. | Any Map | true | -| optional.resource.attr | Explicitly disabled ResourceAttribute. | Any Str | false | -| slice.resource.attr | Resource attribute with a slice value. | Any Slice | true | -| string.enum.resource.attr | Resource attribute with a known set of string values. | Str: ``one``, ``two`` | true | -| string.resource.attr | Resource attribute with any string value. | Any Str | true | -| string.resource.attr_disable_warning | Resource attribute with any string value. | Any Str | true | -| string.resource.attr_remove_warning | Resource attribute with any string value. | Any Str | false | -| string.resource.attr_to_be_removed | Resource attribute with any string value. | Any Str | true | diff --git a/cmd/mdatagen/internal/metadata/generated_config.go b/cmd/mdatagen/internal/metadata/generated_config.go deleted file mode 100644 index 92937f48dbf..00000000000 --- a/cmd/mdatagen/internal/metadata/generated_config.go +++ /dev/null @@ -1,122 +0,0 @@ -// Code generated by mdatagen. DO NOT EDIT. - -package metadata - -import "go.opentelemetry.io/collector/confmap" - -// MetricConfig provides common config for a particular metric. -type MetricConfig struct { - Enabled bool `mapstructure:"enabled"` - - enabledSetByUser bool -} - -func (ms *MetricConfig) Unmarshal(parser *confmap.Conf) error { - if parser == nil { - return nil - } - err := parser.Unmarshal(ms) - if err != nil { - return err - } - ms.enabledSetByUser = parser.IsSet("enabled") - return nil -} - -// MetricsConfig provides config for file metrics. -type MetricsConfig struct { - DefaultMetric MetricConfig `mapstructure:"default.metric"` - DefaultMetricToBeRemoved MetricConfig `mapstructure:"default.metric.to_be_removed"` - OptionalMetric MetricConfig `mapstructure:"optional.metric"` - OptionalMetricEmptyUnit MetricConfig `mapstructure:"optional.metric.empty_unit"` -} - -func DefaultMetricsConfig() MetricsConfig { - return MetricsConfig{ - DefaultMetric: MetricConfig{ - Enabled: true, - }, - DefaultMetricToBeRemoved: MetricConfig{ - Enabled: true, - }, - OptionalMetric: MetricConfig{ - Enabled: false, - }, - OptionalMetricEmptyUnit: MetricConfig{ - Enabled: false, - }, - } -} - -// ResourceAttributeConfig provides common config for a particular resource attribute. -type ResourceAttributeConfig struct { - Enabled bool `mapstructure:"enabled"` - - enabledSetByUser bool -} - -func (rac *ResourceAttributeConfig) Unmarshal(parser *confmap.Conf) error { - if parser == nil { - return nil - } - err := parser.Unmarshal(rac) - if err != nil { - return err - } - rac.enabledSetByUser = parser.IsSet("enabled") - return nil -} - -// ResourceAttributesConfig provides config for file resource attributes. -type ResourceAttributesConfig struct { - MapResourceAttr ResourceAttributeConfig `mapstructure:"map.resource.attr"` - OptionalResourceAttr ResourceAttributeConfig `mapstructure:"optional.resource.attr"` - SliceResourceAttr ResourceAttributeConfig `mapstructure:"slice.resource.attr"` - StringEnumResourceAttr ResourceAttributeConfig `mapstructure:"string.enum.resource.attr"` - StringResourceAttr ResourceAttributeConfig `mapstructure:"string.resource.attr"` - StringResourceAttrDisableWarning ResourceAttributeConfig `mapstructure:"string.resource.attr_disable_warning"` - StringResourceAttrRemoveWarning ResourceAttributeConfig `mapstructure:"string.resource.attr_remove_warning"` - StringResourceAttrToBeRemoved ResourceAttributeConfig `mapstructure:"string.resource.attr_to_be_removed"` -} - -func DefaultResourceAttributesConfig() ResourceAttributesConfig { - return ResourceAttributesConfig{ - MapResourceAttr: ResourceAttributeConfig{ - Enabled: true, - }, - OptionalResourceAttr: ResourceAttributeConfig{ - Enabled: false, - }, - SliceResourceAttr: ResourceAttributeConfig{ - Enabled: true, - }, - StringEnumResourceAttr: ResourceAttributeConfig{ - Enabled: true, - }, - StringResourceAttr: ResourceAttributeConfig{ - Enabled: true, - }, - StringResourceAttrDisableWarning: ResourceAttributeConfig{ - Enabled: true, - }, - StringResourceAttrRemoveWarning: ResourceAttributeConfig{ - Enabled: false, - }, - StringResourceAttrToBeRemoved: ResourceAttributeConfig{ - Enabled: true, - }, - } -} - -// MetricsBuilderConfig is a configuration for file metrics builder. -type MetricsBuilderConfig struct { - Metrics MetricsConfig `mapstructure:"metrics"` - ResourceAttributes ResourceAttributesConfig `mapstructure:"resource_attributes"` -} - -func DefaultMetricsBuilderConfig() MetricsBuilderConfig { - return MetricsBuilderConfig{ - Metrics: DefaultMetricsConfig(), - ResourceAttributes: DefaultResourceAttributesConfig(), - } -} diff --git a/cmd/mdatagen/internal/metadata/generated_config_test.go b/cmd/mdatagen/internal/metadata/generated_config_test.go deleted file mode 100644 index bfb90940386..00000000000 --- a/cmd/mdatagen/internal/metadata/generated_config_test.go +++ /dev/null @@ -1,145 +0,0 @@ -// Code generated by mdatagen. DO NOT EDIT. - -package metadata - -import ( - "path/filepath" - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/stretchr/testify/require" - - "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/confmap/confmaptest" -) - -func TestMetricsBuilderConfig(t *testing.T) { - tests := []struct { - name string - want MetricsBuilderConfig - }{ - { - name: "default", - want: DefaultMetricsBuilderConfig(), - }, - { - name: "all_set", - want: MetricsBuilderConfig{ - Metrics: MetricsConfig{ - DefaultMetric: MetricConfig{Enabled: true}, - DefaultMetricToBeRemoved: MetricConfig{Enabled: true}, - OptionalMetric: MetricConfig{Enabled: true}, - OptionalMetricEmptyUnit: MetricConfig{Enabled: true}, - }, - ResourceAttributes: ResourceAttributesConfig{ - MapResourceAttr: ResourceAttributeConfig{Enabled: true}, - OptionalResourceAttr: ResourceAttributeConfig{Enabled: true}, - SliceResourceAttr: ResourceAttributeConfig{Enabled: true}, - StringEnumResourceAttr: ResourceAttributeConfig{Enabled: true}, - StringResourceAttr: ResourceAttributeConfig{Enabled: true}, - StringResourceAttrDisableWarning: ResourceAttributeConfig{Enabled: true}, - StringResourceAttrRemoveWarning: ResourceAttributeConfig{Enabled: true}, - StringResourceAttrToBeRemoved: ResourceAttributeConfig{Enabled: true}, - }, - }, - }, - { - name: "none_set", - want: MetricsBuilderConfig{ - Metrics: MetricsConfig{ - DefaultMetric: MetricConfig{Enabled: false}, - DefaultMetricToBeRemoved: MetricConfig{Enabled: false}, - OptionalMetric: MetricConfig{Enabled: false}, - OptionalMetricEmptyUnit: MetricConfig{Enabled: false}, - }, - ResourceAttributes: ResourceAttributesConfig{ - MapResourceAttr: ResourceAttributeConfig{Enabled: false}, - OptionalResourceAttr: ResourceAttributeConfig{Enabled: false}, - SliceResourceAttr: ResourceAttributeConfig{Enabled: false}, - StringEnumResourceAttr: ResourceAttributeConfig{Enabled: false}, - StringResourceAttr: ResourceAttributeConfig{Enabled: false}, - StringResourceAttrDisableWarning: ResourceAttributeConfig{Enabled: false}, - StringResourceAttrRemoveWarning: ResourceAttributeConfig{Enabled: false}, - StringResourceAttrToBeRemoved: ResourceAttributeConfig{Enabled: false}, - }, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - cfg := loadMetricsBuilderConfig(t, tt.name) - if diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(MetricConfig{}, ResourceAttributeConfig{})); diff != "" { - t.Errorf("Config mismatch (-expected +actual):\n%s", diff) - } - }) - } -} - -func loadMetricsBuilderConfig(t *testing.T, name string) MetricsBuilderConfig { - cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) - require.NoError(t, err) - sub, err := cm.Sub(name) - require.NoError(t, err) - cfg := DefaultMetricsBuilderConfig() - require.NoError(t, component.UnmarshalConfig(sub, &cfg)) - return cfg -} - -func TestResourceAttributesConfig(t *testing.T) { - tests := []struct { - name string - want ResourceAttributesConfig - }{ - { - name: "default", - want: DefaultResourceAttributesConfig(), - }, - { - name: "all_set", - want: ResourceAttributesConfig{ - MapResourceAttr: ResourceAttributeConfig{Enabled: true}, - OptionalResourceAttr: ResourceAttributeConfig{Enabled: true}, - SliceResourceAttr: ResourceAttributeConfig{Enabled: true}, - StringEnumResourceAttr: ResourceAttributeConfig{Enabled: true}, - StringResourceAttr: ResourceAttributeConfig{Enabled: true}, - StringResourceAttrDisableWarning: ResourceAttributeConfig{Enabled: true}, - StringResourceAttrRemoveWarning: ResourceAttributeConfig{Enabled: true}, - StringResourceAttrToBeRemoved: ResourceAttributeConfig{Enabled: true}, - }, - }, - { - name: "none_set", - want: ResourceAttributesConfig{ - MapResourceAttr: ResourceAttributeConfig{Enabled: false}, - OptionalResourceAttr: ResourceAttributeConfig{Enabled: false}, - SliceResourceAttr: ResourceAttributeConfig{Enabled: false}, - StringEnumResourceAttr: ResourceAttributeConfig{Enabled: false}, - StringResourceAttr: ResourceAttributeConfig{Enabled: false}, - StringResourceAttrDisableWarning: ResourceAttributeConfig{Enabled: false}, - StringResourceAttrRemoveWarning: ResourceAttributeConfig{Enabled: false}, - StringResourceAttrToBeRemoved: ResourceAttributeConfig{Enabled: false}, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - cfg := loadResourceAttributesConfig(t, tt.name) - if diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(ResourceAttributeConfig{})); diff != "" { - t.Errorf("Config mismatch (-expected +actual):\n%s", diff) - } - }) - } -} - -func loadResourceAttributesConfig(t *testing.T, name string) ResourceAttributesConfig { - cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) - require.NoError(t, err) - sub, err := cm.Sub(name) - require.NoError(t, err) - sub, err = sub.Sub("resource_attributes") - require.NoError(t, err) - cfg := DefaultResourceAttributesConfig() - require.NoError(t, component.UnmarshalConfig(sub, &cfg)) - return cfg -} diff --git a/cmd/mdatagen/internal/metadata/generated_metrics.go b/cmd/mdatagen/internal/metadata/generated_metrics.go deleted file mode 100644 index a6d8a7e4169..00000000000 --- a/cmd/mdatagen/internal/metadata/generated_metrics.go +++ /dev/null @@ -1,425 +0,0 @@ -// Code generated by mdatagen. DO NOT EDIT. - -package metadata - -import ( - "time" - - "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/pdata/pcommon" - "go.opentelemetry.io/collector/pdata/pmetric" - "go.opentelemetry.io/collector/receiver" - conventions "go.opentelemetry.io/collector/semconv/v1.9.0" -) - -// AttributeEnumAttr specifies the a value enum_attr attribute. -type AttributeEnumAttr int - -const ( - _ AttributeEnumAttr = iota - AttributeEnumAttrRed - AttributeEnumAttrGreen - AttributeEnumAttrBlue -) - -// String returns the string representation of the AttributeEnumAttr. -func (av AttributeEnumAttr) String() string { - switch av { - case AttributeEnumAttrRed: - return "red" - case AttributeEnumAttrGreen: - return "green" - case AttributeEnumAttrBlue: - return "blue" - } - return "" -} - -// MapAttributeEnumAttr is a helper map of string to AttributeEnumAttr attribute value. -var MapAttributeEnumAttr = map[string]AttributeEnumAttr{ - "red": AttributeEnumAttrRed, - "green": AttributeEnumAttrGreen, - "blue": AttributeEnumAttrBlue, -} - -type metricDefaultMetric struct { - data pmetric.Metric // data buffer for generated metric. - config MetricConfig // metric config provided by user. - capacity int // max observed number of data points added to the metric. -} - -// init fills default.metric metric with initial data. -func (m *metricDefaultMetric) init() { - m.data.SetName("default.metric") - m.data.SetDescription("Monotonic cumulative sum int metric enabled by default.") - m.data.SetUnit("s") - m.data.SetEmptySum() - m.data.Sum().SetIsMonotonic(true) - m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) - m.data.Sum().DataPoints().EnsureCapacity(m.capacity) -} - -func (m *metricDefaultMetric) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, stringAttrAttributeValue string, overriddenIntAttrAttributeValue int64, enumAttrAttributeValue string, sliceAttrAttributeValue []any, mapAttrAttributeValue map[string]any) { - if !m.config.Enabled { - return - } - dp := m.data.Sum().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetIntValue(val) - dp.Attributes().PutStr("string_attr", stringAttrAttributeValue) - dp.Attributes().PutInt("state", overriddenIntAttrAttributeValue) - dp.Attributes().PutStr("enum_attr", enumAttrAttributeValue) - dp.Attributes().PutEmptySlice("slice_attr").FromRaw(sliceAttrAttributeValue) - dp.Attributes().PutEmptyMap("map_attr").FromRaw(mapAttrAttributeValue) -} - -// updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricDefaultMetric) updateCapacity() { - if m.data.Sum().DataPoints().Len() > m.capacity { - m.capacity = m.data.Sum().DataPoints().Len() - } -} - -// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. -func (m *metricDefaultMetric) emit(metrics pmetric.MetricSlice) { - if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 { - m.updateCapacity() - m.data.MoveTo(metrics.AppendEmpty()) - m.init() - } -} - -func newMetricDefaultMetric(cfg MetricConfig) metricDefaultMetric { - m := metricDefaultMetric{config: cfg} - if cfg.Enabled { - m.data = pmetric.NewMetric() - m.init() - } - return m -} - -type metricDefaultMetricToBeRemoved struct { - data pmetric.Metric // data buffer for generated metric. - config MetricConfig // metric config provided by user. - capacity int // max observed number of data points added to the metric. -} - -// init fills default.metric.to_be_removed metric with initial data. -func (m *metricDefaultMetricToBeRemoved) init() { - m.data.SetName("default.metric.to_be_removed") - m.data.SetDescription("[DEPRECATED] Non-monotonic delta sum double metric enabled by default.") - m.data.SetUnit("s") - m.data.SetEmptySum() - m.data.Sum().SetIsMonotonic(false) - m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityDelta) -} - -func (m *metricDefaultMetricToBeRemoved) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val float64) { - if !m.config.Enabled { - return - } - dp := m.data.Sum().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetDoubleValue(val) -} - -// updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricDefaultMetricToBeRemoved) updateCapacity() { - if m.data.Sum().DataPoints().Len() > m.capacity { - m.capacity = m.data.Sum().DataPoints().Len() - } -} - -// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. -func (m *metricDefaultMetricToBeRemoved) emit(metrics pmetric.MetricSlice) { - if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 { - m.updateCapacity() - m.data.MoveTo(metrics.AppendEmpty()) - m.init() - } -} - -func newMetricDefaultMetricToBeRemoved(cfg MetricConfig) metricDefaultMetricToBeRemoved { - m := metricDefaultMetricToBeRemoved{config: cfg} - if cfg.Enabled { - m.data = pmetric.NewMetric() - m.init() - } - return m -} - -type metricOptionalMetric struct { - data pmetric.Metric // data buffer for generated metric. - config MetricConfig // metric config provided by user. - capacity int // max observed number of data points added to the metric. -} - -// init fills optional.metric metric with initial data. -func (m *metricOptionalMetric) init() { - m.data.SetName("optional.metric") - m.data.SetDescription("[DEPRECATED] Gauge double metric disabled by default.") - m.data.SetUnit("1") - m.data.SetEmptyGauge() - m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) -} - -func (m *metricOptionalMetric) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val float64, stringAttrAttributeValue string, booleanAttrAttributeValue bool) { - if !m.config.Enabled { - return - } - dp := m.data.Gauge().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetDoubleValue(val) - dp.Attributes().PutStr("string_attr", stringAttrAttributeValue) - dp.Attributes().PutBool("boolean_attr", booleanAttrAttributeValue) -} - -// updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricOptionalMetric) updateCapacity() { - if m.data.Gauge().DataPoints().Len() > m.capacity { - m.capacity = m.data.Gauge().DataPoints().Len() - } -} - -// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. -func (m *metricOptionalMetric) emit(metrics pmetric.MetricSlice) { - if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { - m.updateCapacity() - m.data.MoveTo(metrics.AppendEmpty()) - m.init() - } -} - -func newMetricOptionalMetric(cfg MetricConfig) metricOptionalMetric { - m := metricOptionalMetric{config: cfg} - if cfg.Enabled { - m.data = pmetric.NewMetric() - m.init() - } - return m -} - -type metricOptionalMetricEmptyUnit struct { - data pmetric.Metric // data buffer for generated metric. - config MetricConfig // metric config provided by user. - capacity int // max observed number of data points added to the metric. -} - -// init fills optional.metric.empty_unit metric with initial data. -func (m *metricOptionalMetricEmptyUnit) init() { - m.data.SetName("optional.metric.empty_unit") - m.data.SetDescription("[DEPRECATED] Gauge double metric disabled by default.") - m.data.SetUnit("") - m.data.SetEmptyGauge() - m.data.Gauge().DataPoints().EnsureCapacity(m.capacity) -} - -func (m *metricOptionalMetricEmptyUnit) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val float64, stringAttrAttributeValue string, booleanAttrAttributeValue bool) { - if !m.config.Enabled { - return - } - dp := m.data.Gauge().DataPoints().AppendEmpty() - dp.SetStartTimestamp(start) - dp.SetTimestamp(ts) - dp.SetDoubleValue(val) - dp.Attributes().PutStr("string_attr", stringAttrAttributeValue) - dp.Attributes().PutBool("boolean_attr", booleanAttrAttributeValue) -} - -// updateCapacity saves max length of data point slices that will be used for the slice capacity. -func (m *metricOptionalMetricEmptyUnit) updateCapacity() { - if m.data.Gauge().DataPoints().Len() > m.capacity { - m.capacity = m.data.Gauge().DataPoints().Len() - } -} - -// emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. -func (m *metricOptionalMetricEmptyUnit) emit(metrics pmetric.MetricSlice) { - if m.config.Enabled && m.data.Gauge().DataPoints().Len() > 0 { - m.updateCapacity() - m.data.MoveTo(metrics.AppendEmpty()) - m.init() - } -} - -func newMetricOptionalMetricEmptyUnit(cfg MetricConfig) metricOptionalMetricEmptyUnit { - m := metricOptionalMetricEmptyUnit{config: cfg} - if cfg.Enabled { - m.data = pmetric.NewMetric() - m.init() - } - return m -} - -// MetricsBuilder provides an interface for scrapers to report metrics while taking care of all the transformations -// required to produce metric representation defined in metadata and user config. -type MetricsBuilder struct { - config MetricsBuilderConfig // config of the metrics builder. - startTime pcommon.Timestamp // start time that will be applied to all recorded data points. - metricsCapacity int // maximum observed number of metrics per resource. - metricsBuffer pmetric.Metrics // accumulates metrics data before emitting. - buildInfo component.BuildInfo // contains version information. - metricDefaultMetric metricDefaultMetric - metricDefaultMetricToBeRemoved metricDefaultMetricToBeRemoved - metricOptionalMetric metricOptionalMetric - metricOptionalMetricEmptyUnit metricOptionalMetricEmptyUnit -} - -// metricBuilderOption applies changes to default metrics builder. -type metricBuilderOption func(*MetricsBuilder) - -// WithStartTime sets startTime on the metrics builder. -func WithStartTime(startTime pcommon.Timestamp) metricBuilderOption { - return func(mb *MetricsBuilder) { - mb.startTime = startTime - } -} - -func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.CreateSettings, options ...metricBuilderOption) *MetricsBuilder { - if !mbc.Metrics.DefaultMetric.enabledSetByUser { - settings.Logger.Warn("[WARNING] Please set `enabled` field explicitly for `default.metric`: This metric will be disabled by default soon.") - } - if mbc.Metrics.DefaultMetricToBeRemoved.Enabled { - settings.Logger.Warn("[WARNING] `default.metric.to_be_removed` should not be enabled: This metric is deprecated and will be removed soon.") - } - if mbc.Metrics.OptionalMetric.enabledSetByUser { - settings.Logger.Warn("[WARNING] `optional.metric` should not be configured: This metric is deprecated and will be removed soon.") - } - if mbc.Metrics.OptionalMetricEmptyUnit.enabledSetByUser { - settings.Logger.Warn("[WARNING] `optional.metric.empty_unit` should not be configured: This metric is deprecated and will be removed soon.") - } - if !mbc.ResourceAttributes.StringResourceAttrDisableWarning.enabledSetByUser { - settings.Logger.Warn("[WARNING] Please set `enabled` field explicitly for `string.resource.attr_disable_warning`: This resource_attribute will be disabled by default soon.") - } - if mbc.ResourceAttributes.StringResourceAttrRemoveWarning.enabledSetByUser { - settings.Logger.Warn("[WARNING] `string.resource.attr_remove_warning` should not be configured: This resource_attribute is deprecated and will be removed soon.") - } - if mbc.ResourceAttributes.StringResourceAttrToBeRemoved.Enabled { - settings.Logger.Warn("[WARNING] `string.resource.attr_to_be_removed` should not be enabled: This resource_attribute is deprecated and will be removed soon.") - } - mb := &MetricsBuilder{ - config: mbc, - startTime: pcommon.NewTimestampFromTime(time.Now()), - metricsBuffer: pmetric.NewMetrics(), - buildInfo: settings.BuildInfo, - metricDefaultMetric: newMetricDefaultMetric(mbc.Metrics.DefaultMetric), - metricDefaultMetricToBeRemoved: newMetricDefaultMetricToBeRemoved(mbc.Metrics.DefaultMetricToBeRemoved), - metricOptionalMetric: newMetricOptionalMetric(mbc.Metrics.OptionalMetric), - metricOptionalMetricEmptyUnit: newMetricOptionalMetricEmptyUnit(mbc.Metrics.OptionalMetricEmptyUnit), - } - for _, op := range options { - op(mb) - } - return mb -} - -// NewResourceBuilder returns a new resource builder that should be used to build a resource associated with for the emitted metrics. -func (mb *MetricsBuilder) NewResourceBuilder() *ResourceBuilder { - return NewResourceBuilder(mb.config.ResourceAttributes) -} - -// updateCapacity updates max length of metrics and resource attributes that will be used for the slice capacity. -func (mb *MetricsBuilder) updateCapacity(rm pmetric.ResourceMetrics) { - if mb.metricsCapacity < rm.ScopeMetrics().At(0).Metrics().Len() { - mb.metricsCapacity = rm.ScopeMetrics().At(0).Metrics().Len() - } -} - -// ResourceMetricsOption applies changes to provided resource metrics. -type ResourceMetricsOption func(pmetric.ResourceMetrics) - -// WithResource sets the provided resource on the emitted ResourceMetrics. -// It's recommended to use ResourceBuilder to create the resource. -func WithResource(res pcommon.Resource) ResourceMetricsOption { - return func(rm pmetric.ResourceMetrics) { - res.CopyTo(rm.Resource()) - } -} - -// WithStartTimeOverride overrides start time for all the resource metrics data points. -// This option should be only used if different start time has to be set on metrics coming from different resources. -func WithStartTimeOverride(start pcommon.Timestamp) ResourceMetricsOption { - return func(rm pmetric.ResourceMetrics) { - var dps pmetric.NumberDataPointSlice - metrics := rm.ScopeMetrics().At(0).Metrics() - for i := 0; i < metrics.Len(); i++ { - switch metrics.At(i).Type() { - case pmetric.MetricTypeGauge: - dps = metrics.At(i).Gauge().DataPoints() - case pmetric.MetricTypeSum: - dps = metrics.At(i).Sum().DataPoints() - } - for j := 0; j < dps.Len(); j++ { - dps.At(j).SetStartTimestamp(start) - } - } - } -} - -// EmitForResource saves all the generated metrics under a new resource and updates the internal state to be ready for -// recording another set of data points as part of another resource. This function can be helpful when one scraper -// needs to emit metrics from several resources. Otherwise calling this function is not required, -// just `Emit` function can be called instead. -// Resource attributes should be provided as ResourceMetricsOption arguments. -func (mb *MetricsBuilder) EmitForResource(rmo ...ResourceMetricsOption) { - rm := pmetric.NewResourceMetrics() - rm.SetSchemaUrl(conventions.SchemaURL) - ils := rm.ScopeMetrics().AppendEmpty() - ils.Scope().SetName("go.opentelemetry.io/collector") - ils.Scope().SetVersion(mb.buildInfo.Version) - ils.Metrics().EnsureCapacity(mb.metricsCapacity) - mb.metricDefaultMetric.emit(ils.Metrics()) - mb.metricDefaultMetricToBeRemoved.emit(ils.Metrics()) - mb.metricOptionalMetric.emit(ils.Metrics()) - mb.metricOptionalMetricEmptyUnit.emit(ils.Metrics()) - - for _, op := range rmo { - op(rm) - } - if ils.Metrics().Len() > 0 { - mb.updateCapacity(rm) - rm.MoveTo(mb.metricsBuffer.ResourceMetrics().AppendEmpty()) - } -} - -// Emit returns all the metrics accumulated by the metrics builder and updates the internal state to be ready for -// recording another set of metrics. This function will be responsible for applying all the transformations required to -// produce metric representation defined in metadata and user config, e.g. delta or cumulative. -func (mb *MetricsBuilder) Emit(rmo ...ResourceMetricsOption) pmetric.Metrics { - mb.EmitForResource(rmo...) - metrics := mb.metricsBuffer - mb.metricsBuffer = pmetric.NewMetrics() - return metrics -} - -// RecordDefaultMetricDataPoint adds a data point to default.metric metric. -func (mb *MetricsBuilder) RecordDefaultMetricDataPoint(ts pcommon.Timestamp, val int64, stringAttrAttributeValue string, overriddenIntAttrAttributeValue int64, enumAttrAttributeValue AttributeEnumAttr, sliceAttrAttributeValue []any, mapAttrAttributeValue map[string]any) { - mb.metricDefaultMetric.recordDataPoint(mb.startTime, ts, val, stringAttrAttributeValue, overriddenIntAttrAttributeValue, enumAttrAttributeValue.String(), sliceAttrAttributeValue, mapAttrAttributeValue) -} - -// RecordDefaultMetricToBeRemovedDataPoint adds a data point to default.metric.to_be_removed metric. -func (mb *MetricsBuilder) RecordDefaultMetricToBeRemovedDataPoint(ts pcommon.Timestamp, val float64) { - mb.metricDefaultMetricToBeRemoved.recordDataPoint(mb.startTime, ts, val) -} - -// RecordOptionalMetricDataPoint adds a data point to optional.metric metric. -func (mb *MetricsBuilder) RecordOptionalMetricDataPoint(ts pcommon.Timestamp, val float64, stringAttrAttributeValue string, booleanAttrAttributeValue bool) { - mb.metricOptionalMetric.recordDataPoint(mb.startTime, ts, val, stringAttrAttributeValue, booleanAttrAttributeValue) -} - -// RecordOptionalMetricEmptyUnitDataPoint adds a data point to optional.metric.empty_unit metric. -func (mb *MetricsBuilder) RecordOptionalMetricEmptyUnitDataPoint(ts pcommon.Timestamp, val float64, stringAttrAttributeValue string, booleanAttrAttributeValue bool) { - mb.metricOptionalMetricEmptyUnit.recordDataPoint(mb.startTime, ts, val, stringAttrAttributeValue, booleanAttrAttributeValue) -} - -// Reset resets metrics builder to its initial state. It should be used when external metrics source is restarted, -// and metrics builder should update its startTime and reset it's internal state accordingly. -func (mb *MetricsBuilder) Reset(options ...metricBuilderOption) { - mb.startTime = pcommon.NewTimestampFromTime(time.Now()) - for _, op := range options { - op(mb) - } -} diff --git a/cmd/mdatagen/internal/metadata/generated_metrics_test.go b/cmd/mdatagen/internal/metadata/generated_metrics_test.go deleted file mode 100644 index 4860ac1ba2b..00000000000 --- a/cmd/mdatagen/internal/metadata/generated_metrics_test.go +++ /dev/null @@ -1,215 +0,0 @@ -// Code generated by mdatagen. DO NOT EDIT. - -package metadata - -import ( - "testing" - - "github.com/stretchr/testify/assert" - "go.uber.org/zap" - "go.uber.org/zap/zaptest/observer" - - "go.opentelemetry.io/collector/pdata/pcommon" - "go.opentelemetry.io/collector/pdata/pmetric" - "go.opentelemetry.io/collector/receiver/receivertest" -) - -type testConfigCollection int - -const ( - testSetDefault testConfigCollection = iota - testSetAll - testSetNone -) - -func TestMetricsBuilder(t *testing.T) { - tests := []struct { - name string - configSet testConfigCollection - }{ - { - name: "default", - configSet: testSetDefault, - }, - { - name: "all_set", - configSet: testSetAll, - }, - { - name: "none_set", - configSet: testSetNone, - }, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - start := pcommon.Timestamp(1_000_000_000) - ts := pcommon.Timestamp(1_000_001_000) - observedZapCore, observedLogs := observer.New(zap.WarnLevel) - settings := receivertest.NewNopCreateSettings() - settings.Logger = zap.New(observedZapCore) - mb := NewMetricsBuilder(loadMetricsBuilderConfig(t, test.name), settings, WithStartTime(start)) - - expectedWarnings := 0 - if test.configSet == testSetDefault { - assert.Equal(t, "[WARNING] Please set `enabled` field explicitly for `default.metric`: This metric will be disabled by default soon.", observedLogs.All()[expectedWarnings].Message) - expectedWarnings++ - } - if test.configSet == testSetDefault || test.configSet == testSetAll { - assert.Equal(t, "[WARNING] `default.metric.to_be_removed` should not be enabled: This metric is deprecated and will be removed soon.", observedLogs.All()[expectedWarnings].Message) - expectedWarnings++ - } - if test.configSet == testSetAll || test.configSet == testSetNone { - assert.Equal(t, "[WARNING] `optional.metric` should not be configured: This metric is deprecated and will be removed soon.", observedLogs.All()[expectedWarnings].Message) - expectedWarnings++ - } - if test.configSet == testSetAll || test.configSet == testSetNone { - assert.Equal(t, "[WARNING] `optional.metric.empty_unit` should not be configured: This metric is deprecated and will be removed soon.", observedLogs.All()[expectedWarnings].Message) - expectedWarnings++ - } - if test.configSet == testSetDefault { - assert.Equal(t, "[WARNING] Please set `enabled` field explicitly for `string.resource.attr_disable_warning`: This resource_attribute will be disabled by default soon.", observedLogs.All()[expectedWarnings].Message) - expectedWarnings++ - } - if test.configSet == testSetAll || test.configSet == testSetNone { - assert.Equal(t, "[WARNING] `string.resource.attr_remove_warning` should not be configured: This resource_attribute is deprecated and will be removed soon.", observedLogs.All()[expectedWarnings].Message) - expectedWarnings++ - } - if test.configSet == testSetDefault || test.configSet == testSetAll { - assert.Equal(t, "[WARNING] `string.resource.attr_to_be_removed` should not be enabled: This resource_attribute is deprecated and will be removed soon.", observedLogs.All()[expectedWarnings].Message) - expectedWarnings++ - } - - assert.Equal(t, expectedWarnings, observedLogs.Len()) - - defaultMetricsCount := 0 - allMetricsCount := 0 - - defaultMetricsCount++ - allMetricsCount++ - mb.RecordDefaultMetricDataPoint(ts, 1, "string_attr-val", 19, AttributeEnumAttrRed, []any{"slice_attr-item1", "slice_attr-item2"}, map[string]any{"key1": "map_attr-val1", "key2": "map_attr-val2"}) - - defaultMetricsCount++ - allMetricsCount++ - mb.RecordDefaultMetricToBeRemovedDataPoint(ts, 1) - - allMetricsCount++ - mb.RecordOptionalMetricDataPoint(ts, 1, "string_attr-val", true) - - allMetricsCount++ - mb.RecordOptionalMetricEmptyUnitDataPoint(ts, 1, "string_attr-val", true) - - rb := mb.NewResourceBuilder() - rb.SetMapResourceAttr(map[string]any{"key1": "map.resource.attr-val1", "key2": "map.resource.attr-val2"}) - rb.SetOptionalResourceAttr("optional.resource.attr-val") - rb.SetSliceResourceAttr([]any{"slice.resource.attr-item1", "slice.resource.attr-item2"}) - rb.SetStringEnumResourceAttrOne() - rb.SetStringResourceAttr("string.resource.attr-val") - rb.SetStringResourceAttrDisableWarning("string.resource.attr_disable_warning-val") - rb.SetStringResourceAttrRemoveWarning("string.resource.attr_remove_warning-val") - rb.SetStringResourceAttrToBeRemoved("string.resource.attr_to_be_removed-val") - res := rb.Emit() - metrics := mb.Emit(WithResource(res)) - - if test.configSet == testSetNone { - assert.Equal(t, 0, metrics.ResourceMetrics().Len()) - return - } - - assert.Equal(t, 1, metrics.ResourceMetrics().Len()) - rm := metrics.ResourceMetrics().At(0) - assert.Equal(t, res, rm.Resource()) - assert.Equal(t, 1, rm.ScopeMetrics().Len()) - ms := rm.ScopeMetrics().At(0).Metrics() - if test.configSet == testSetDefault { - assert.Equal(t, defaultMetricsCount, ms.Len()) - } - if test.configSet == testSetAll { - assert.Equal(t, allMetricsCount, ms.Len()) - } - validatedMetrics := make(map[string]bool) - for i := 0; i < ms.Len(); i++ { - switch ms.At(i).Name() { - case "default.metric": - assert.False(t, validatedMetrics["default.metric"], "Found a duplicate in the metrics slice: default.metric") - validatedMetrics["default.metric"] = true - assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type()) - assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len()) - assert.Equal(t, "Monotonic cumulative sum int metric enabled by default.", ms.At(i).Description()) - assert.Equal(t, "s", ms.At(i).Unit()) - assert.Equal(t, true, ms.At(i).Sum().IsMonotonic()) - assert.Equal(t, pmetric.AggregationTemporalityCumulative, ms.At(i).Sum().AggregationTemporality()) - dp := ms.At(i).Sum().DataPoints().At(0) - assert.Equal(t, start, dp.StartTimestamp()) - assert.Equal(t, ts, dp.Timestamp()) - assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) - assert.Equal(t, int64(1), dp.IntValue()) - attrVal, ok := dp.Attributes().Get("string_attr") - assert.True(t, ok) - assert.EqualValues(t, "string_attr-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("state") - assert.True(t, ok) - assert.EqualValues(t, 19, attrVal.Int()) - attrVal, ok = dp.Attributes().Get("enum_attr") - assert.True(t, ok) - assert.EqualValues(t, "red", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("slice_attr") - assert.True(t, ok) - assert.EqualValues(t, []any{"slice_attr-item1", "slice_attr-item2"}, attrVal.Slice().AsRaw()) - attrVal, ok = dp.Attributes().Get("map_attr") - assert.True(t, ok) - assert.EqualValues(t, map[string]any{"key1": "map_attr-val1", "key2": "map_attr-val2"}, attrVal.Map().AsRaw()) - case "default.metric.to_be_removed": - assert.False(t, validatedMetrics["default.metric.to_be_removed"], "Found a duplicate in the metrics slice: default.metric.to_be_removed") - validatedMetrics["default.metric.to_be_removed"] = true - assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type()) - assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len()) - assert.Equal(t, "[DEPRECATED] Non-monotonic delta sum double metric enabled by default.", ms.At(i).Description()) - assert.Equal(t, "s", ms.At(i).Unit()) - assert.Equal(t, false, ms.At(i).Sum().IsMonotonic()) - assert.Equal(t, pmetric.AggregationTemporalityDelta, ms.At(i).Sum().AggregationTemporality()) - dp := ms.At(i).Sum().DataPoints().At(0) - assert.Equal(t, start, dp.StartTimestamp()) - assert.Equal(t, ts, dp.Timestamp()) - assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType()) - assert.Equal(t, float64(1), dp.DoubleValue()) - case "optional.metric": - assert.False(t, validatedMetrics["optional.metric"], "Found a duplicate in the metrics slice: optional.metric") - validatedMetrics["optional.metric"] = true - assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) - assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) - assert.Equal(t, "[DEPRECATED] Gauge double metric disabled by default.", ms.At(i).Description()) - assert.Equal(t, "1", ms.At(i).Unit()) - dp := ms.At(i).Gauge().DataPoints().At(0) - assert.Equal(t, start, dp.StartTimestamp()) - assert.Equal(t, ts, dp.Timestamp()) - assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType()) - assert.Equal(t, float64(1), dp.DoubleValue()) - attrVal, ok := dp.Attributes().Get("string_attr") - assert.True(t, ok) - assert.EqualValues(t, "string_attr-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("boolean_attr") - assert.True(t, ok) - assert.EqualValues(t, true, attrVal.Bool()) - case "optional.metric.empty_unit": - assert.False(t, validatedMetrics["optional.metric.empty_unit"], "Found a duplicate in the metrics slice: optional.metric.empty_unit") - validatedMetrics["optional.metric.empty_unit"] = true - assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type()) - assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len()) - assert.Equal(t, "[DEPRECATED] Gauge double metric disabled by default.", ms.At(i).Description()) - assert.Equal(t, "", ms.At(i).Unit()) - dp := ms.At(i).Gauge().DataPoints().At(0) - assert.Equal(t, start, dp.StartTimestamp()) - assert.Equal(t, ts, dp.Timestamp()) - assert.Equal(t, pmetric.NumberDataPointValueTypeDouble, dp.ValueType()) - assert.Equal(t, float64(1), dp.DoubleValue()) - attrVal, ok := dp.Attributes().Get("string_attr") - assert.True(t, ok) - assert.EqualValues(t, "string_attr-val", attrVal.Str()) - attrVal, ok = dp.Attributes().Get("boolean_attr") - assert.True(t, ok) - assert.EqualValues(t, true, attrVal.Bool()) - } - } - }) - } -} diff --git a/cmd/mdatagen/internal/metadata/generated_resource.go b/cmd/mdatagen/internal/metadata/generated_resource.go deleted file mode 100644 index da69b3c0841..00000000000 --- a/cmd/mdatagen/internal/metadata/generated_resource.go +++ /dev/null @@ -1,92 +0,0 @@ -// Code generated by mdatagen. DO NOT EDIT. - -package metadata - -import ( - "go.opentelemetry.io/collector/pdata/pcommon" -) - -// ResourceBuilder is a helper struct to build resources predefined in metadata.yaml. -// The ResourceBuilder is not thread-safe and must not to be used in multiple goroutines. -type ResourceBuilder struct { - config ResourceAttributesConfig - res pcommon.Resource -} - -// NewResourceBuilder creates a new ResourceBuilder. This method should be called on the start of the application. -func NewResourceBuilder(rac ResourceAttributesConfig) *ResourceBuilder { - return &ResourceBuilder{ - config: rac, - res: pcommon.NewResource(), - } -} - -// SetMapResourceAttr sets provided value as "map.resource.attr" attribute. -func (rb *ResourceBuilder) SetMapResourceAttr(val map[string]any) { - if rb.config.MapResourceAttr.Enabled { - rb.res.Attributes().PutEmptyMap("map.resource.attr").FromRaw(val) - } -} - -// SetOptionalResourceAttr sets provided value as "optional.resource.attr" attribute. -func (rb *ResourceBuilder) SetOptionalResourceAttr(val string) { - if rb.config.OptionalResourceAttr.Enabled { - rb.res.Attributes().PutStr("optional.resource.attr", val) - } -} - -// SetSliceResourceAttr sets provided value as "slice.resource.attr" attribute. -func (rb *ResourceBuilder) SetSliceResourceAttr(val []any) { - if rb.config.SliceResourceAttr.Enabled { - rb.res.Attributes().PutEmptySlice("slice.resource.attr").FromRaw(val) - } -} - -// SetStringEnumResourceAttrOne sets "string.enum.resource.attr=one" attribute. -func (rb *ResourceBuilder) SetStringEnumResourceAttrOne() { - if rb.config.StringEnumResourceAttr.Enabled { - rb.res.Attributes().PutStr("string.enum.resource.attr", "one") - } -} - -// SetStringEnumResourceAttrTwo sets "string.enum.resource.attr=two" attribute. -func (rb *ResourceBuilder) SetStringEnumResourceAttrTwo() { - if rb.config.StringEnumResourceAttr.Enabled { - rb.res.Attributes().PutStr("string.enum.resource.attr", "two") - } -} - -// SetStringResourceAttr sets provided value as "string.resource.attr" attribute. -func (rb *ResourceBuilder) SetStringResourceAttr(val string) { - if rb.config.StringResourceAttr.Enabled { - rb.res.Attributes().PutStr("string.resource.attr", val) - } -} - -// SetStringResourceAttrDisableWarning sets provided value as "string.resource.attr_disable_warning" attribute. -func (rb *ResourceBuilder) SetStringResourceAttrDisableWarning(val string) { - if rb.config.StringResourceAttrDisableWarning.Enabled { - rb.res.Attributes().PutStr("string.resource.attr_disable_warning", val) - } -} - -// SetStringResourceAttrRemoveWarning sets provided value as "string.resource.attr_remove_warning" attribute. -func (rb *ResourceBuilder) SetStringResourceAttrRemoveWarning(val string) { - if rb.config.StringResourceAttrRemoveWarning.Enabled { - rb.res.Attributes().PutStr("string.resource.attr_remove_warning", val) - } -} - -// SetStringResourceAttrToBeRemoved sets provided value as "string.resource.attr_to_be_removed" attribute. -func (rb *ResourceBuilder) SetStringResourceAttrToBeRemoved(val string) { - if rb.config.StringResourceAttrToBeRemoved.Enabled { - rb.res.Attributes().PutStr("string.resource.attr_to_be_removed", val) - } -} - -// Emit returns the built resource and resets the internal builder state. -func (rb *ResourceBuilder) Emit() pcommon.Resource { - r := rb.res - rb.res = pcommon.NewResource() - return r -} diff --git a/cmd/mdatagen/internal/metadata/generated_resource_test.go b/cmd/mdatagen/internal/metadata/generated_resource_test.go deleted file mode 100644 index c0bde40a087..00000000000 --- a/cmd/mdatagen/internal/metadata/generated_resource_test.go +++ /dev/null @@ -1,82 +0,0 @@ -// Code generated by mdatagen. DO NOT EDIT. - -package metadata - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestResourceBuilder(t *testing.T) { - for _, test := range []string{"default", "all_set", "none_set"} { - t.Run(test, func(t *testing.T) { - cfg := loadResourceAttributesConfig(t, test) - rb := NewResourceBuilder(cfg) - rb.SetMapResourceAttr(map[string]any{"key1": "map.resource.attr-val1", "key2": "map.resource.attr-val2"}) - rb.SetOptionalResourceAttr("optional.resource.attr-val") - rb.SetSliceResourceAttr([]any{"slice.resource.attr-item1", "slice.resource.attr-item2"}) - rb.SetStringEnumResourceAttrOne() - rb.SetStringResourceAttr("string.resource.attr-val") - rb.SetStringResourceAttrDisableWarning("string.resource.attr_disable_warning-val") - rb.SetStringResourceAttrRemoveWarning("string.resource.attr_remove_warning-val") - rb.SetStringResourceAttrToBeRemoved("string.resource.attr_to_be_removed-val") - - res := rb.Emit() - assert.Equal(t, 0, rb.Emit().Attributes().Len()) // Second call should return empty Resource - - switch test { - case "default": - assert.Equal(t, 6, res.Attributes().Len()) - case "all_set": - assert.Equal(t, 8, res.Attributes().Len()) - case "none_set": - assert.Equal(t, 0, res.Attributes().Len()) - return - default: - assert.Failf(t, "unexpected test case: %s", test) - } - - val, ok := res.Attributes().Get("map.resource.attr") - assert.True(t, ok) - if ok { - assert.EqualValues(t, map[string]any{"key1": "map.resource.attr-val1", "key2": "map.resource.attr-val2"}, val.Map().AsRaw()) - } - val, ok = res.Attributes().Get("optional.resource.attr") - assert.Equal(t, test == "all_set", ok) - if ok { - assert.EqualValues(t, "optional.resource.attr-val", val.Str()) - } - val, ok = res.Attributes().Get("slice.resource.attr") - assert.True(t, ok) - if ok { - assert.EqualValues(t, []any{"slice.resource.attr-item1", "slice.resource.attr-item2"}, val.Slice().AsRaw()) - } - val, ok = res.Attributes().Get("string.enum.resource.attr") - assert.True(t, ok) - if ok { - assert.EqualValues(t, "one", val.Str()) - } - val, ok = res.Attributes().Get("string.resource.attr") - assert.True(t, ok) - if ok { - assert.EqualValues(t, "string.resource.attr-val", val.Str()) - } - val, ok = res.Attributes().Get("string.resource.attr_disable_warning") - assert.True(t, ok) - if ok { - assert.EqualValues(t, "string.resource.attr_disable_warning-val", val.Str()) - } - val, ok = res.Attributes().Get("string.resource.attr_remove_warning") - assert.Equal(t, test == "all_set", ok) - if ok { - assert.EqualValues(t, "string.resource.attr_remove_warning-val", val.Str()) - } - val, ok = res.Attributes().Get("string.resource.attr_to_be_removed") - assert.True(t, ok) - if ok { - assert.EqualValues(t, "string.resource.attr_to_be_removed-val", val.Str()) - } - }) - } -} diff --git a/cmd/mdatagen/internal/metadata/generated_status.go b/cmd/mdatagen/internal/metadata/generated_status.go deleted file mode 100644 index 7e332e5ba4a..00000000000 --- a/cmd/mdatagen/internal/metadata/generated_status.go +++ /dev/null @@ -1,29 +0,0 @@ -// Code generated by mdatagen. DO NOT EDIT. - -package metadata - -import ( - "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/trace" - - "go.opentelemetry.io/collector/component" -) - -var ( - Type = component.MustNewType("file") - scopeName = "go.opentelemetry.io/collector" -) - -const ( - TracesStability = component.StabilityLevelBeta - LogsStability = component.StabilityLevelDevelopment - MetricsStability = component.StabilityLevelStable -) - -func Meter(settings component.TelemetrySettings) metric.Meter { - return settings.MeterProvider.Meter(scopeName) -} - -func Tracer(settings component.TelemetrySettings) trace.Tracer { - return settings.TracerProvider.Tracer(scopeName) -} diff --git a/cmd/mdatagen/internal/metadata/testdata/config.yaml b/cmd/mdatagen/internal/metadata/testdata/config.yaml deleted file mode 100644 index 8283dc2dd70..00000000000 --- a/cmd/mdatagen/internal/metadata/testdata/config.yaml +++ /dev/null @@ -1,55 +0,0 @@ -default: -all_set: - metrics: - default.metric: - enabled: true - default.metric.to_be_removed: - enabled: true - optional.metric: - enabled: true - optional.metric.empty_unit: - enabled: true - resource_attributes: - map.resource.attr: - enabled: true - optional.resource.attr: - enabled: true - slice.resource.attr: - enabled: true - string.enum.resource.attr: - enabled: true - string.resource.attr: - enabled: true - string.resource.attr_disable_warning: - enabled: true - string.resource.attr_remove_warning: - enabled: true - string.resource.attr_to_be_removed: - enabled: true -none_set: - metrics: - default.metric: - enabled: false - default.metric.to_be_removed: - enabled: false - optional.metric: - enabled: false - optional.metric.empty_unit: - enabled: false - resource_attributes: - map.resource.attr: - enabled: false - optional.resource.attr: - enabled: false - slice.resource.attr: - enabled: false - string.enum.resource.attr: - enabled: false - string.resource.attr: - enabled: false - string.resource.attr_disable_warning: - enabled: false - string.resource.attr_remove_warning: - enabled: false - string.resource.attr_to_be_removed: - enabled: false diff --git a/cmd/mdatagen/metadata-sample.yaml b/cmd/mdatagen/metadata-sample.yaml deleted file mode 100644 index b9a5f8f6c90..00000000000 --- a/cmd/mdatagen/metadata-sample.yaml +++ /dev/null @@ -1,136 +0,0 @@ -# Sample metric metadata file with all available configurations. - -type: file - -sem_conv_version: 1.9.0 - -status: - class: receiver - stability: - development: [logs] - beta: [traces] - stable: [metrics] - distributions: [contrib] - warnings: - - Any additional information that should be brought to the consumer's attention - -resource_attributes: - string.resource.attr: - description: Resource attribute with any string value. - type: string - enabled: true - - string.enum.resource.attr: - description: Resource attribute with a known set of string values. - type: string - enum: [one, two] - enabled: true - - optional.resource.attr: - description: Explicitly disabled ResourceAttribute. - type: string - enabled: false - - slice.resource.attr: - description: Resource attribute with a slice value. - type: slice - enabled: true - - map.resource.attr: - description: Resource attribute with a map value. - type: map - enabled: true - - string.resource.attr_disable_warning: - description: Resource attribute with any string value. - type: string - enabled: true - warnings: - if_enabled_not_set: This resource_attribute will be disabled by default soon. - - string.resource.attr_remove_warning: - description: Resource attribute with any string value. - type: string - enabled: false - warnings: - if_configured: This resource_attribute is deprecated and will be removed soon. - - string.resource.attr_to_be_removed: - description: Resource attribute with any string value. - type: string - enabled: true - warnings: - if_enabled: This resource_attribute is deprecated and will be removed soon. - -attributes: - string_attr: - description: Attribute with any string value. - type: string - - overridden_int_attr: - name_override: state - description: Integer attribute with overridden name. - type: int - - enum_attr: - description: Attribute with a known set of string values. - type: string - enum: [red, green, blue] - - boolean_attr: - description: Attribute with a boolean value. - type: bool - - slice_attr: - description: Attribute with a slice value. - type: slice - - map_attr: - description: Attribute with a map value. - type: map - -metrics: - default.metric: - enabled: true - description: Monotonic cumulative sum int metric enabled by default. - extended_documentation: The metric will be become optional soon. - unit: s - sum: - value_type: int - monotonic: true - aggregation_temporality: cumulative - attributes: [string_attr, overridden_int_attr, enum_attr, slice_attr, map_attr] - warnings: - if_enabled_not_set: This metric will be disabled by default soon. - - optional.metric: - enabled: false - description: "[DEPRECATED] Gauge double metric disabled by default." - unit: 1 - gauge: - value_type: double - attributes: [string_attr, boolean_attr] - warnings: - if_configured: This metric is deprecated and will be removed soon. - - optional.metric.empty_unit: - enabled: false - description: "[DEPRECATED] Gauge double metric disabled by default." - unit: "" - gauge: - value_type: double - attributes: [string_attr, boolean_attr] - warnings: - if_configured: This metric is deprecated and will be removed soon. - - default.metric.to_be_removed: - enabled: true - description: "[DEPRECATED] Non-monotonic delta sum double metric enabled by default." - extended_documentation: The metric will be will be removed soon. - unit: s - sum: - value_type: double - monotonic: false - aggregation_temporality: delta - warnings: - if_enabled: This metric is deprecated and will be removed soon. diff --git a/connector/forwardconnector/package_test.go b/connector/forwardconnector/package_test.go deleted file mode 100644 index 54cc0fd73ce..00000000000 --- a/connector/forwardconnector/package_test.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package forwardconnector - -import ( - "testing" - - "go.uber.org/goleak" -) - -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m) -} diff --git a/examples/k8s/otel-config.yaml b/examples/k8s/otel-config.yaml index 7c73578ac3c..791af80fc55 100644 --- a/examples/k8s/otel-config.yaml +++ b/examples/k8s/otel-config.yaml @@ -195,7 +195,7 @@ spec: ports: - containerPort: 55679 # Default endpoint for ZPages. - containerPort: 4317 # Default endpoint for OpenTelemetry receiver. - - containerPort: 1.3.0 # Default endpoint for Jaeger gRPC receiver. + - containerPort: 14250 # Default endpoint for Jaeger gRPC receiver. - containerPort: 14268 # Default endpoint for Jaeger HTTP receiver. - containerPort: 9411 # Default endpoint for Zipkin receiver. - containerPort: 8888 # Default endpoint for querying metrics. diff --git a/exporter/debugexporter/package_test.go b/exporter/debugexporter/package_test.go deleted file mode 100644 index 320777f1ab8..00000000000 --- a/exporter/debugexporter/package_test.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package debugexporter - -import ( - "testing" - - "go.uber.org/goleak" -) - -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m) -} diff --git a/exporter/exportertest/package_test.go b/exporter/exportertest/package_test.go deleted file mode 100644 index 8fa8a72b85f..00000000000 --- a/exporter/exportertest/package_test.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package exportertest - -import ( - "testing" - - "go.uber.org/goleak" -) - -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m) -} diff --git a/exporter/internal/queue/queue_capacity.go b/exporter/internal/queue/queue_capacity.go deleted file mode 100644 index 1995febcd63..00000000000 --- a/exporter/internal/queue/queue_capacity.go +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package queue // import "go.opentelemetry.io/collector/exporter/internal/queue" - -import ( - "sync/atomic" -) - -type itemsCounter interface { - ItemsCount() int -} - -// Sizer is an interface that returns the size of the given element. -type Sizer[T any] interface { - SizeOf(T) uint64 -} - -// ItemsSizer is a Sizer implementation that returns the size of a queue element as the number of items it contains. -type ItemsSizer[T itemsCounter] struct{} - -func (is *ItemsSizer[T]) SizeOf(el T) uint64 { - return uint64(el.ItemsCount()) -} - -// RequestSizer is a Sizer implementation that returns the size of a queue element as one request. -type RequestSizer[T any] struct{} - -func (rs *RequestSizer[T]) SizeOf(T) uint64 { - return 1 -} - -type queueCapacityLimiter[T any] struct { - used *atomic.Uint64 - cap uint64 - sz Sizer[T] -} - -func (bcl queueCapacityLimiter[T]) Capacity() int { - return int(bcl.cap) -} - -func (bcl queueCapacityLimiter[T]) Size() int { - return int(bcl.used.Load()) -} - -func (bcl queueCapacityLimiter[T]) claim(el T) bool { - size := bcl.sizeOf(el) - if bcl.used.Add(size) > bcl.cap { - bcl.releaseSize(size) - return false - } - return true -} - -func (bcl queueCapacityLimiter[T]) release(el T) { - bcl.releaseSize(bcl.sizeOf(el)) -} - -func (bcl queueCapacityLimiter[T]) releaseSize(size uint64) { - bcl.used.Add(^(size - 1)) -} - -func (bcl queueCapacityLimiter[T]) sizeOf(el T) uint64 { - return bcl.sz.SizeOf(el) -} - -func newQueueCapacityLimiter[T any](sizer Sizer[T], capacity int) *queueCapacityLimiter[T] { - return &queueCapacityLimiter[T]{ - used: &atomic.Uint64{}, - cap: uint64(capacity), - sz: sizer, - } -} diff --git a/exporter/internal/queue/queue_capacity_test.go b/exporter/internal/queue/queue_capacity_test.go deleted file mode 100644 index 3dd6ad2b898..00000000000 --- a/exporter/internal/queue/queue_capacity_test.go +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package queue - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestRequestsCapacityLimiter(t *testing.T) { - rl := newQueueCapacityLimiter[fakeReq](&RequestSizer[fakeReq]{}, 2) - assert.Equal(t, 0, rl.Size()) - assert.Equal(t, 2, rl.Capacity()) - - req := fakeReq{itemsCount: 5} - - assert.True(t, rl.claim(req)) - assert.Equal(t, 1, rl.Size()) - - assert.True(t, rl.claim(req)) - assert.Equal(t, 2, rl.Size()) - - assert.False(t, rl.claim(req)) - assert.Equal(t, 2, rl.Size()) - - rl.release(req) - assert.Equal(t, 1, rl.Size()) -} - -func TestItemsCapacityLimiter(t *testing.T) { - rl := newQueueCapacityLimiter[fakeReq](&ItemsSizer[fakeReq]{}, 7) - assert.Equal(t, 0, rl.Size()) - assert.Equal(t, 7, rl.Capacity()) - - req := fakeReq{itemsCount: 3} - - assert.True(t, rl.claim(req)) - assert.Equal(t, 3, rl.Size()) - - assert.True(t, rl.claim(req)) - assert.Equal(t, 6, rl.Size()) - - assert.False(t, rl.claim(req)) - assert.Equal(t, 6, rl.Size()) - - rl.release(req) - assert.Equal(t, 3, rl.Size()) -} - -type fakeReq struct { - itemsCount int -} - -func (r fakeReq) ItemsCount() int { - return r.itemsCount -} diff --git a/exporter/loggingexporter/package_test.go b/exporter/loggingexporter/package_test.go deleted file mode 100644 index 0c1b40739cc..00000000000 --- a/exporter/loggingexporter/package_test.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package loggingexporter - -import ( - "testing" - - "go.uber.org/goleak" -) - -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m) -} diff --git a/exporter/otlpexporter/package_test.go b/exporter/otlpexporter/package_test.go deleted file mode 100644 index c5fb1007f5b..00000000000 --- a/exporter/otlpexporter/package_test.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package otlpexporter - -import ( - "testing" - - "go.uber.org/goleak" -) - -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m) -} diff --git a/exporter/otlphttpexporter/package_test.go b/exporter/otlphttpexporter/package_test.go deleted file mode 100644 index 07858386cc4..00000000000 --- a/exporter/otlphttpexporter/package_test.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package otlphttpexporter - -import ( - "testing" - - "go.uber.org/goleak" -) - -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m) -} diff --git a/extension/ballastextension/package_test.go b/extension/ballastextension/package_test.go deleted file mode 100644 index 9035e22edbc..00000000000 --- a/extension/ballastextension/package_test.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package ballastextension - -import ( - "testing" - - "go.uber.org/goleak" -) - -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m) -} diff --git a/extension/extensiontest/package_test.go b/extension/extensiontest/package_test.go deleted file mode 100644 index 22f7af4bd14..00000000000 --- a/extension/extensiontest/package_test.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package extensiontest - -import ( - "testing" - - "go.uber.org/goleak" -) - -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m) -} diff --git a/extension/zpagesextension/package_test.go b/extension/zpagesextension/package_test.go deleted file mode 100644 index 40ce0f11cc4..00000000000 --- a/extension/zpagesextension/package_test.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package zpagesextension - -import ( - "testing" - - "go.uber.org/goleak" -) - -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m) -} diff --git a/obsreport/obsreporttest/package_test.go b/obsreport/obsreporttest/package_test.go deleted file mode 100644 index 97b3f7f9210..00000000000 --- a/obsreport/obsreporttest/package_test.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package obsreporttest - -import ( - "testing" - - "go.uber.org/goleak" -) - -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m) -} diff --git a/processor/batchprocessor/package_test.go b/processor/batchprocessor/package_test.go deleted file mode 100644 index 58d64e47b57..00000000000 --- a/processor/batchprocessor/package_test.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package batchprocessor - -import ( - "testing" - - "go.uber.org/goleak" -) - -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m) -} diff --git a/processor/memorylimiterprocessor/package_test.go b/processor/memorylimiterprocessor/package_test.go deleted file mode 100644 index 77bee80493d..00000000000 --- a/processor/memorylimiterprocessor/package_test.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package memorylimiterprocessor - -import ( - "testing" - - "go.uber.org/goleak" -) - -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m) -} diff --git a/receiver/otlpreceiver/package_test.go b/receiver/otlpreceiver/package_test.go deleted file mode 100644 index 9d49b5c8f7b..00000000000 --- a/receiver/otlpreceiver/package_test.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package otlpreceiver - -import ( - "testing" - - "go.uber.org/goleak" -) - -// The IgnoreTopFunction call prevents catching the leak generated by opencensus -// defaultWorker.Start which at this time is part of the package's init call. -// See https://github.com/open-telemetry/opentelemetry-collector/issues/9165#issuecomment-1874836336 for more context. -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m, goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start")) -}