diff --git a/.chloggen/mdatagen-add-attribute-semconv-refs.yaml b/.chloggen/mdatagen-add-attribute-semconv-refs.yaml new file mode 100644 index 00000000000..d501ed5549b --- /dev/null +++ b/.chloggen/mdatagen-add-attribute-semconv-refs.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. receiver/otlp) +component: cmd/mdatagen + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add semconv reference for attributes + +# One or more tracking issues or pull requests related to the change +issues: [13297] + +# (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: + +# 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: [user] diff --git a/.github/workflows/utils/cspell.json b/.github/workflows/utils/cspell.json index a50d13eb099..5c396a5b652 100644 --- a/.github/workflows/utils/cspell.json +++ b/.github/workflows/utils/cspell.json @@ -464,6 +464,8 @@ "subpackages", "swiatekm", "syft", + "systemcputime", + "systemdiskio", "tailsampling", "tchannel", "telemetrygen", @@ -498,6 +500,7 @@ "unmarshal", "unmarshalling", "unmarshalls", + "unreclaimable", "unredacted", "unshallow", "unstarted", diff --git a/cmd/mdatagen/internal/loader.go b/cmd/mdatagen/internal/loader.go index df5cc1ce510..28d511a13dc 100644 --- a/cmd/mdatagen/internal/loader.go +++ b/cmd/mdatagen/internal/loader.go @@ -62,6 +62,10 @@ func LoadMetadata(filePath string) (Metadata, error) { md.GeneratedPackageName = "metadata" } + if err := md.expandSemConvRefs(); err != nil { + return md, err + } + if err := md.Validate(); err != nil { return md, err } diff --git a/cmd/mdatagen/internal/loader_test.go b/cmd/mdatagen/internal/loader_test.go index 27c24655f81..a18494e7a24 100644 --- a/cmd/mdatagen/internal/loader_test.go +++ b/cmd/mdatagen/internal/loader_test.go @@ -183,6 +183,14 @@ func TestLoadMetadata(t *testing.T) { }, Attributes: map[AttributeName]Attribute{ + "cpu": { + Description: "Logical CPU number starting at 0.", + Type: ValueType{ + ValueType: pcommon.ValueTypeStr, + }, + FullName: "cpu", + RequirementLevel: AttributeRequirementLevelRecommended, + }, "enum_attr": { Description: "Attribute with a known set of string values.", NameOverride: "", @@ -275,6 +283,18 @@ func TestLoadMetadata(t *testing.T) { FullName: "required_string_attr", RequirementLevel: AttributeRequirementLevelRequired, }, + "state": { + Description: "Breakdown of memory usage by type.", + Enum: []string{"buffered", "cached", "inactive", "free", "slab_reclaimable", "slab_unreclaimable", "used"}, + Type: ValueType{ + ValueType: pcommon.ValueTypeStr, + }, + FullName: "state", + RequirementLevel: AttributeRequirementLevelRecommended, + SemanticConvention: &SemanticConvention{ + SemanticConventionRef: "https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/registry/attributes/system.md#system-memory-state", + }, + }, }, Metrics: map[MetricName]Metric{ "default.metric": { @@ -330,6 +350,7 @@ func TestLoadMetadata(t *testing.T) { SemanticConvention: &SemanticConvention{SemanticConventionRef: "https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/system/system-metrics.md#metric-systemcputime"}, Description: "Monotonic cumulative sum int metric enabled by default.", ExtendedDocumentation: "The metric will be become optional soon.", + Attributes: []AttributeName{"cpu"}, }, Unit: strPtr("s"), Sum: &Sum{ @@ -338,6 +359,20 @@ func TestLoadMetadata(t *testing.T) { Mono: Mono{Monotonic: true}, }, }, + "system.memory.usage": { + Signal: Signal{ + Enabled: true, + Stability: component.StabilityLevelDevelopment, + Description: "Bytes of memory in use.", + Attributes: []AttributeName{"state"}, + }, + Unit: strPtr("By"), + Sum: &Sum{ + MetricValueType: MetricValueType{pmetric.NumberDataPointValueTypeInt}, + AggregationTemporality: AggregationTemporality{Aggregation: pmetric.AggregationTemporalityCumulative}, + Mono: Mono{Monotonic: false}, + }, + }, "optional.metric": { Signal: Signal{ Enabled: false, @@ -629,7 +664,7 @@ func TestLoadMetadata(t *testing.T) { { name: "testdata/invalid_metric_semconvref.yaml", want: Metadata{}, - wantErr: "metric \"default.metric\": invalid semantic-conventions URL: want https://github.com/open-telemetry/semantic-conventions/blob/v1.37.2/*#metric-defaultmetric, got \"https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/system/system-metrics.md#metric-systemcputime\"", + wantErr: "metric \"default.metric\": invalid semantic-conventions URL: want https://github.com/open-telemetry/semantic-conventions/blob/v1.37.2/*#metric-defaultmetric, got \"https://github.com/open-telemetry/semantic-conventions/blob/v1.37.2/docs/system/system-metrics.md#metric-systemcputime\"", }, { name: "testdata/no_metric_stability.yaml", @@ -646,6 +681,16 @@ func TestLoadMetadata(t *testing.T) { want: Metadata{}, wantErr: "config type must be \"object\", got \"string\"", }, + { + name: "testdata/invalid_metric_semconv_url_full.yaml", + want: Metadata{}, + wantErr: "metric \"default.metric\", use relative path for URL, not the full URL", + }, + { + name: "testdata/invalid_attribute_semconv_url_full.yaml", + want: Metadata{}, + wantErr: "attribute \"used_attr\", use relative path for URL, not the full URL", + }, { name: "testdata/~~this file doesn't exist~~.yaml", wantErr: "unable to read the file file:testdata/~~this file doesn't exist~~.yaml", diff --git a/cmd/mdatagen/internal/metadata.go b/cmd/mdatagen/internal/metadata.go index 9c552f0319a..a4b9aa42527 100644 --- a/cmd/mdatagen/internal/metadata.go +++ b/cmd/mdatagen/internal/metadata.go @@ -18,6 +18,8 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" ) +const semConvURL = "https://github.com/open-telemetry/semantic-conventions/blob" + type Metadata struct { // Type of the component. Type string `mapstructure:"type"` @@ -581,6 +583,8 @@ type Attribute struct { Warnings Warnings `mapstructure:"warnings"` // RequirementLevel defines the requirement level of the attribute. RequirementLevel AttributeRequirementLevel `mapstructure:"requirement_level"` + // The semantic convention reference of the attribute. + SemanticConvention *SemanticConvention `mapstructure:"semantic_convention"` } // IsConditional returns true if the attribute is conditionally required. @@ -785,3 +789,39 @@ type FeatureGate struct { // ReferenceURL is the URL with contextual information about the feature gate. ReferenceURL string `mapstructure:"reference_url"` } + +func (md *Metadata) expandSemConvRefs() error { + for k, v := range md.Attributes { + if v.SemanticConvention != nil { + if strings.HasPrefix(v.SemanticConvention.SemanticConventionRef, "http") { + return fmt.Errorf("attribute %q, use relative path for URL, not the full URL", k) + } + url := fmt.Sprintf( + "%s/v%s/docs/registry/attributes/%s", + semConvURL, + md.SemConvVersion, + v.SemanticConvention.SemanticConventionRef, + ) + v.SemanticConvention.SemanticConventionRef = url + } + md.Attributes[k] = v + } + + for k, v := range md.Metrics { + if v.SemanticConvention != nil { + if strings.HasPrefix(v.SemanticConvention.SemanticConventionRef, "http") { + return fmt.Errorf("metric %q, use relative path for URL, not the full URL", k) + } + url := fmt.Sprintf( + "%s/v%s/docs/%s", + semConvURL, + md.SemConvVersion, + v.SemanticConvention.SemanticConventionRef, + ) + v.SemanticConvention.SemanticConventionRef = url + } + md.Metrics[k] = v + } + + return nil +} diff --git a/cmd/mdatagen/internal/sampleconnector/documentation.md b/cmd/mdatagen/internal/sampleconnector/documentation.md index 3708e08948e..0dd4b5c07ec 100644 --- a/cmd/mdatagen/internal/sampleconnector/documentation.md +++ b/cmd/mdatagen/internal/sampleconnector/documentation.md @@ -24,13 +24,13 @@ The metric will be become optional soon. #### Attributes -| Name | Description | Values | Requirement Level | -| ---- | ----------- | ------ | -------- | -| string_attr | Attribute with any string value. | Any Str | Recommended | -| state | Integer attribute with overridden name. | Any Int | Recommended | -| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` | Recommended | -| slice_attr | Attribute with a slice value. | Any Slice | Recommended | -| map_attr | Attribute with a map value. | Any Map | Recommended | +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| string_attr | Attribute with any string value. | Any Str | Recommended | - | +| state | Integer attribute with overridden name. | Any Int | Recommended | - | +| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` | Recommended | - | +| slice_attr | Attribute with a slice value. | Any Slice | Recommended | - | +| map_attr | Attribute with a map value. | Any Map | Recommended | - | ### default.metric.to_be_removed @@ -54,13 +54,13 @@ Monotonic cumulative sum int metric with string input_type enabled by default. #### Attributes -| Name | Description | Values | Requirement Level | -| ---- | ----------- | ------ | -------- | -| string_attr | Attribute with any string value. | Any Str | Recommended | -| state | Integer attribute with overridden name. | Any Int | Recommended | -| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` | Recommended | -| slice_attr | Attribute with a slice value. | Any Slice | Recommended | -| map_attr | Attribute with a map value. | Any Map | Recommended | +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| string_attr | Attribute with any string value. | Any Str | Recommended | - | +| state | Integer attribute with overridden name. | Any Int | Recommended | - | +| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` | Recommended | - | +| slice_attr | Attribute with a slice value. | Any Slice | Recommended | - | +| map_attr | Attribute with a map value. | Any Map | Recommended | - | ### reaggregate.metric @@ -72,10 +72,10 @@ Metric for testing spatial reaggregation #### Attributes -| Name | Description | Values | Requirement Level | -| ---- | ----------- | ------ | -------- | -| string_attr | Attribute with any string value. | Any Str | Recommended | -| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| string_attr | Attribute with any string value. | Any Str | Recommended | - | +| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | - | ## Optional Metrics @@ -99,11 +99,11 @@ metrics: #### Attributes -| Name | Description | Values | Requirement Level | -| ---- | ----------- | ------ | -------- | -| string_attr | Attribute with any string value. | Any Str | Recommended | -| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | -| boolean_attr2 | Another attribute with a boolean value. | Any Bool | Recommended | +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| string_attr | Attribute with any string value. | Any Str | Recommended | - | +| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | - | +| boolean_attr2 | Another attribute with a boolean value. | Any Bool | Recommended | - | ### optional.metric.empty_unit @@ -117,23 +117,23 @@ metrics: #### Attributes -| Name | Description | Values | Requirement Level | -| ---- | ----------- | ------ | -------- | -| string_attr | Attribute with any string value. | Any Str | Recommended | -| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| string_attr | Attribute with any string value. | Any Str | Recommended | - | +| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | - | ## 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 | +| Name | Description | Values | Enabled | Semantic Convention | +| ---- | ----------- | ------ | ------- | ------------------- | +| 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 | - | ## Entities diff --git a/cmd/mdatagen/internal/sampleentityreceiver/documentation.md b/cmd/mdatagen/internal/sampleentityreceiver/documentation.md index 5530a6cf657..9dfd9af9da2 100644 --- a/cmd/mdatagen/internal/sampleentityreceiver/documentation.md +++ b/cmd/mdatagen/internal/sampleentityreceiver/documentation.md @@ -30,9 +30,9 @@ Current phase of the pod #### Attributes -| Name | Description | Values | Requirement Level | -| ---- | ----------- | ------ | -------- | -| phase | The phase of the pod (Pending, Running, Succeeded, Failed, Unknown) | Str: ``Pending``, ``Running``, ``Succeeded``, ``Failed``, ``Unknown`` | Recommended | +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| phase | The phase of the pod (Pending, Running, Succeeded, Failed, Unknown) | Str: ``Pending``, ``Running``, ``Succeeded``, ``Failed``, ``Unknown`` | Recommended | - | ### k8s.replicaset.desired @@ -44,13 +44,13 @@ Number of desired replicas ## Resource Attributes -| Name | Description | Values | Enabled | -| ---- | ----------- | ------ | ------- | -| k8s.namespace.name | The name of the Kubernetes Namespace | Any Str | true | -| k8s.pod.name | The name of the Kubernetes Pod | Any Str | true | -| k8s.pod.uid | The UID of the Kubernetes Pod | Any Str | true | -| k8s.replicaset.name | The name of the Kubernetes ReplicaSet | Any Str | true | -| k8s.replicaset.uid | The UID of the Kubernetes ReplicaSet | Any Str | true | +| Name | Description | Values | Enabled | Semantic Convention | +| ---- | ----------- | ------ | ------- | ------------------- | +| k8s.namespace.name | The name of the Kubernetes Namespace | Any Str | true | - | +| k8s.pod.name | The name of the Kubernetes Pod | Any Str | true | - | +| k8s.pod.uid | The UID of the Kubernetes Pod | Any Str | true | - | +| k8s.replicaset.name | The name of the Kubernetes ReplicaSet | Any Str | true | - | +| k8s.replicaset.uid | The UID of the Kubernetes ReplicaSet | Any Str | true | - | ## Entities diff --git a/cmd/mdatagen/internal/sampleprocessor/documentation.md b/cmd/mdatagen/internal/sampleprocessor/documentation.md index 5c1d70aa3d5..abf2301469a 100644 --- a/cmd/mdatagen/internal/sampleprocessor/documentation.md +++ b/cmd/mdatagen/internal/sampleprocessor/documentation.md @@ -4,13 +4,13 @@ ## 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 | +| Name | Description | Values | Enabled | Semantic Convention | +| ---- | ----------- | ------ | ------- | ------------------- | +| 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/samplereceiver/config.schema.json b/cmd/mdatagen/internal/samplereceiver/config.schema.json index 7a75f8e81e3..5e27c3c2f1a 100644 --- a/cmd/mdatagen/internal/samplereceiver/config.schema.json +++ b/cmd/mdatagen/internal/samplereceiver/config.schema.json @@ -253,6 +253,60 @@ "description": "SystemCPUTimeMetricConfig provides config for the system.cpu.time metric.", "type": "object", "properties": { + "aggregation_strategy": { + "type": "string", + "default": "sum", + "enum": [ + "sum", + "avg", + "min", + "max" + ] + }, + "attributes": { + "type": "array", + "default": [ + "cpu" + ], + "items": { + "type": "string", + "enum": [ + "cpu" + ] + } + }, + "enabled": { + "type": "boolean", + "default": true + } + } + }, + "system.memory.usage": { + "description": "SystemMemoryUsageMetricConfig provides config for the system.memory.usage metric.", + "type": "object", + "properties": { + "aggregation_strategy": { + "type": "string", + "default": "sum", + "enum": [ + "sum", + "avg", + "min", + "max" + ] + }, + "attributes": { + "type": "array", + "default": [ + "state" + ], + "items": { + "type": "string", + "enum": [ + "state" + ] + } + }, "enabled": { "type": "boolean", "default": true diff --git a/cmd/mdatagen/internal/samplereceiver/documentation.md b/cmd/mdatagen/internal/samplereceiver/documentation.md index 972446f8154..6180b3ba106 100644 --- a/cmd/mdatagen/internal/samplereceiver/documentation.md +++ b/cmd/mdatagen/internal/samplereceiver/documentation.md @@ -26,16 +26,16 @@ The metric will be become optional soon. #### Attributes -| Name | Description | Values | Requirement Level | -| ---- | ----------- | ------ | -------- | -| string_attr | Attribute with any string value. | Any Str | Recommended | -| state | Integer attribute with overridden name. | Any Int | Recommended | -| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` | Recommended | -| slice_attr | Attribute with a slice value. | Any Slice | Recommended | -| map_attr | Attribute with a map value. | Any Map | Recommended | -| conditional_int_attr | A conditional attribute with an integer value | Any Int | Conditionally Required | -| conditional_string_attr | A conditional attribute with any string value | Any Str | Conditionally Required | -| opt_in_bool_attr | An opt-in attribute with a boolean value | Any Bool | Opt-In | +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| string_attr | Attribute with any string value. | Any Str | Recommended | - | +| state | Integer attribute with overridden name. | Any Int | Recommended | - | +| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` | Recommended | - | +| slice_attr | Attribute with a slice value. | Any Slice | Recommended | - | +| map_attr | Attribute with a map value. | Any Map | Recommended | - | +| conditional_int_attr | A conditional attribute with an integer value | Any Int | Conditionally Required | - | +| conditional_string_attr | A conditional attribute with any string value | Any Str | Conditionally Required | - | +| opt_in_bool_attr | An opt-in attribute with a boolean value | Any Bool | Opt-In | - | ### default.metric.to_be_removed @@ -59,13 +59,13 @@ Monotonic cumulative sum int metric with string input_type enabled by default. #### Attributes -| Name | Description | Values | Requirement Level | -| ---- | ----------- | ------ | -------- | -| string_attr | Attribute with any string value. | Any Str | Recommended | -| state | Integer attribute with overridden name. | Any Int | Recommended | -| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` | Recommended | -| slice_attr | Attribute with a slice value. | Any Slice | Recommended | -| map_attr | Attribute with a map value. | Any Map | Recommended | +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| string_attr | Attribute with any string value. | Any Str | Recommended | - | +| state | Integer attribute with overridden name. | Any Int | Recommended | - | +| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` | Recommended | - | +| slice_attr | Attribute with a slice value. | Any Slice | Recommended | - | +| map_attr | Attribute with a map value. | Any Map | Recommended | - | ### reaggregate.metric @@ -77,10 +77,10 @@ Metric for testing spatial reaggregation #### Attributes -| Name | Description | Values | Requirement Level | -| ---- | ----------- | ------ | -------- | -| string_attr | Attribute with any string value. | Any Str | Recommended | -| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| string_attr | Attribute with any string value. | Any Str | Recommended | - | +| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | - | ### reaggregate.metric.with_required @@ -92,11 +92,11 @@ Metric for testing spatial reaggregation with required attributes #### Attributes -| Name | Description | Values | Requirement Level | -| ---- | ----------- | ------ | -------- | -| required_string_attr | A required attribute with a string value | Any Str | Required | -| string_attr | Attribute with any string value. | Any Str | Recommended | -| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| required_string_attr | A required attribute with a string value | Any Str | Required | - | +| string_attr | Attribute with any string value. | Any Str | Recommended | - | +| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | - | ### system.cpu.time @@ -108,6 +108,26 @@ The metric will be become optional soon. | ---- | ----------- | ---------- | ----------------------- | --------- | --------- | ------------------- | | s | Sum | Int | Cumulative | true | Beta | [system.cpu.time](https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/system/system-metrics.md#metric-systemcputime) | +#### Attributes + +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| cpu | Logical CPU number starting at 0. | Any Str | Recommended | - | + +### system.memory.usage + +Bytes of memory in use. + +| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | Stability | +| ---- | ----------- | ---------- | ----------------------- | --------- | --------- | +| By | Sum | Int | Cumulative | false | Development | + +#### Attributes + +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| state | Breakdown of memory usage by type. | Str: ``buffered``, ``cached``, ``inactive``, ``free``, ``slab_reclaimable``, ``slab_unreclaimable``, ``used`` | Recommended | [state](https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/registry/attributes/system.md#system-memory-state) | + ## Optional Metrics The following metrics are not emitted by default. Each of them can be enabled by applying the following configuration: @@ -130,12 +150,12 @@ metrics: #### Attributes -| Name | Description | Values | Requirement Level | -| ---- | ----------- | ------ | -------- | -| string_attr | Attribute with any string value. | Any Str | Recommended | -| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | -| boolean_attr2 | Another attribute with a boolean value. | Any Bool | Recommended | -| conditional_string_attr | A conditional attribute with any string value | Any Str | Conditionally Required | +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| string_attr | Attribute with any string value. | Any Str | Recommended | - | +| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | - | +| boolean_attr2 | Another attribute with a boolean value. | Any Bool | Recommended | - | +| conditional_string_attr | A conditional attribute with any string value | Any Str | Conditionally Required | - | ### optional.metric.empty_unit @@ -149,10 +169,10 @@ metrics: #### Attributes -| Name | Description | Values | Requirement Level | -| ---- | ----------- | ------ | -------- | -| string_attr | Attribute with any string value. | Any Str | Recommended | -| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| string_attr | Attribute with any string value. | Any Str | Recommended | - | +| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | - | ## Default Events @@ -170,16 +190,16 @@ Example event enabled by default. #### 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 | -| conditional_int_attr | A conditional attribute with an integer value | Any Int | -| conditional_string_attr | A conditional attribute with any string value | Any Str | -| opt_in_bool_attr | An opt-in attribute with a boolean value | Any Bool | +| Name | Description | Values | Semantic Convention | +| ---- | ----------- | ------ | ------------------- | +| 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 | - | +| conditional_int_attr | A conditional attribute with an integer value | Any Int | - | +| conditional_string_attr | A conditional attribute with any string value | Any Str | - | +| opt_in_bool_attr | An opt-in attribute with a boolean value | Any Bool | - | ### default.event.to_be_removed @@ -189,13 +209,13 @@ The event will be removed soon. #### 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 | +| Name | Description | Values | Semantic Convention | +| ---- | ----------- | ------ | ------------------- | +| 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 | - | ## Optional Events @@ -215,25 +235,25 @@ The event will be renamed soon. #### Attributes -| Name | Description | Values | -| ---- | ----------- | ------ | -| string_attr | Attribute with any string value. | Any Str | -| boolean_attr | Attribute with a boolean value. | Any Bool | -| boolean_attr2 | Another attribute with a boolean value. | Any Bool | -| conditional_string_attr | A conditional attribute with any string value | Any Str | +| Name | Description | Values | Semantic Convention | +| ---- | ----------- | ------ | ------------------- | +| string_attr | Attribute with any string value. | Any Str | - | +| boolean_attr | Attribute with a boolean value. | Any Bool | - | +| boolean_attr2 | Another attribute with a boolean value. | Any Bool | - | +| conditional_string_attr | A conditional attribute with any string value | Any Str | - | ## 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 | +| Name | Description | Values | Enabled | Semantic Convention | +| ---- | ----------- | ------ | ------- | ------------------- | +| 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 | - | ## Internal Telemetry diff --git a/cmd/mdatagen/internal/samplereceiver/internal/metadata/config.schema.yaml b/cmd/mdatagen/internal/samplereceiver/internal/metadata/config.schema.yaml index 2fc71dc2e4e..e450414f5de 100644 --- a/cmd/mdatagen/internal/samplereceiver/internal/metadata/config.schema.yaml +++ b/cmd/mdatagen/internal/samplereceiver/internal/metadata/config.schema.yaml @@ -191,6 +191,45 @@ $defs: enabled: type: boolean default: true + aggregation_strategy: + type: string + enum: + - "sum" + - "avg" + - "min" + - "max" + default: "sum" + attributes: + type: array + items: + type: string + enum: + - "cpu" + default: + - "cpu" + system.memory.usage: + description: "SystemMemoryUsageMetricConfig provides config for the system.memory.usage metric." + type: object + properties: + enabled: + type: boolean + default: true + aggregation_strategy: + type: string + enum: + - "sum" + - "avg" + - "min" + - "max" + default: "sum" + attributes: + type: array + items: + type: string + enum: + - "state" + default: + - "state" events_config: description: EventsConfig provides config for sample events. type: object diff --git a/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_config.go b/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_config.go index cd7fc3bbacd..c2a88d153a6 100644 --- a/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_config.go +++ b/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_config.go @@ -339,10 +339,20 @@ func (ms *ReaggregateMetricWithRequiredMetricConfig) Validate() error { return nil } +// SystemCPUTimeMetricAttributeKey specifies the key of an attribute for the system.cpu.time metric. +type SystemCPUTimeMetricAttributeKey string + +const ( + SystemCPUTimeMetricAttributeKeyCpu SystemCPUTimeMetricAttributeKey = "cpu" +) + // SystemCPUTimeMetricConfig provides config for the system.cpu.time metric. type SystemCPUTimeMetricConfig struct { Enabled bool `mapstructure:"enabled"` enabledSetByUser bool + + AggregationStrategy string `mapstructure:"aggregation_strategy"` + EnabledAttributes []SystemCPUTimeMetricAttributeKey `mapstructure:"attributes"` } func (ms *SystemCPUTimeMetricConfig) Unmarshal(parser *confmap.Conf) error { @@ -359,6 +369,72 @@ func (ms *SystemCPUTimeMetricConfig) Unmarshal(parser *confmap.Conf) error { return nil } +func (ms *SystemCPUTimeMetricConfig) Validate() error { + for _, val := range ms.EnabledAttributes { + switch val { + case SystemCPUTimeMetricAttributeKeyCpu: + default: + return fmt.Errorf("metric system.cpu.time doesn't have an attribute %v, valid attributes: [cpu]", val) + } + } + + switch ms.AggregationStrategy { + case AggregationStrategySum, AggregationStrategyAvg, AggregationStrategyMin, AggregationStrategyMax: + default: + return fmt.Errorf("invalid aggregation strategy %q, valid strategies: [%s, %s, %s, %s]", ms.AggregationStrategy, AggregationStrategySum, AggregationStrategyAvg, AggregationStrategyMin, AggregationStrategyMax) + } + + return nil +} + +// SystemMemoryUsageMetricAttributeKey specifies the key of an attribute for the system.memory.usage metric. +type SystemMemoryUsageMetricAttributeKey string + +const ( + SystemMemoryUsageMetricAttributeKeyState SystemMemoryUsageMetricAttributeKey = "state" +) + +// SystemMemoryUsageMetricConfig provides config for the system.memory.usage metric. +type SystemMemoryUsageMetricConfig struct { + Enabled bool `mapstructure:"enabled"` + enabledSetByUser bool + + AggregationStrategy string `mapstructure:"aggregation_strategy"` + EnabledAttributes []SystemMemoryUsageMetricAttributeKey `mapstructure:"attributes"` +} + +func (ms *SystemMemoryUsageMetricConfig) 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 +} + +func (ms *SystemMemoryUsageMetricConfig) Validate() error { + for _, val := range ms.EnabledAttributes { + switch val { + case SystemMemoryUsageMetricAttributeKeyState: + default: + return fmt.Errorf("metric system.memory.usage doesn't have an attribute %v, valid attributes: [state]", val) + } + } + + switch ms.AggregationStrategy { + case AggregationStrategySum, AggregationStrategyAvg, AggregationStrategyMin, AggregationStrategyMax: + default: + return fmt.Errorf("invalid aggregation strategy %q, valid strategies: [%s, %s, %s, %s]", ms.AggregationStrategy, AggregationStrategySum, AggregationStrategyAvg, AggregationStrategyMin, AggregationStrategyMax) + } + + return nil +} + // MetricsConfig provides config for sample metrics. type MetricsConfig struct { DefaultMetric DefaultMetricMetricConfig `mapstructure:"default.metric"` @@ -369,6 +445,7 @@ type MetricsConfig struct { ReaggregateMetric ReaggregateMetricMetricConfig `mapstructure:"reaggregate.metric"` ReaggregateMetricWithRequired ReaggregateMetricWithRequiredMetricConfig `mapstructure:"reaggregate.metric.with_required"` SystemCPUTime SystemCPUTimeMetricConfig `mapstructure:"system.cpu.time"` + SystemMemoryUsage SystemMemoryUsageMetricConfig `mapstructure:"system.memory.usage"` } func DefaultMetricsConfig() MetricsConfig { @@ -407,7 +484,14 @@ func DefaultMetricsConfig() MetricsConfig { EnabledAttributes: []ReaggregateMetricWithRequiredMetricAttributeKey{ReaggregateMetricWithRequiredMetricAttributeKeyRequiredStringAttr, ReaggregateMetricWithRequiredMetricAttributeKeyStringAttr, ReaggregateMetricWithRequiredMetricAttributeKeyBooleanAttr}, }, SystemCPUTime: SystemCPUTimeMetricConfig{ - Enabled: true, + Enabled: true, + AggregationStrategy: AggregationStrategySum, + EnabledAttributes: []SystemCPUTimeMetricAttributeKey{SystemCPUTimeMetricAttributeKeyCpu}, + }, + SystemMemoryUsage: SystemMemoryUsageMetricConfig{ + Enabled: true, + AggregationStrategy: AggregationStrategySum, + EnabledAttributes: []SystemMemoryUsageMetricAttributeKey{SystemMemoryUsageMetricAttributeKeyState}, }, } } diff --git a/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_config_test.go b/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_config_test.go index d7e413f3b34..e7183c852f7 100644 --- a/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_config_test.go +++ b/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_config_test.go @@ -61,7 +61,14 @@ func TestMetricsBuilderConfig(t *testing.T) { EnabledAttributes: []ReaggregateMetricWithRequiredMetricAttributeKey{ReaggregateMetricWithRequiredMetricAttributeKeyRequiredStringAttr, ReaggregateMetricWithRequiredMetricAttributeKeyStringAttr, ReaggregateMetricWithRequiredMetricAttributeKeyBooleanAttr}, }, SystemCPUTime: SystemCPUTimeMetricConfig{ - Enabled: true, + Enabled: true, + AggregationStrategy: AggregationStrategySum, + EnabledAttributes: []SystemCPUTimeMetricAttributeKey{SystemCPUTimeMetricAttributeKeyCpu}, + }, + SystemMemoryUsage: SystemMemoryUsageMetricConfig{ + Enabled: true, + AggregationStrategy: AggregationStrategySum, + EnabledAttributes: []SystemMemoryUsageMetricAttributeKey{SystemMemoryUsageMetricAttributeKeyState}, }, }, ResourceAttributes: ResourceAttributesConfig{ @@ -114,7 +121,14 @@ func TestMetricsBuilderConfig(t *testing.T) { EnabledAttributes: []ReaggregateMetricWithRequiredMetricAttributeKey{ReaggregateMetricWithRequiredMetricAttributeKeyRequiredStringAttr, ReaggregateMetricWithRequiredMetricAttributeKeyStringAttr, ReaggregateMetricWithRequiredMetricAttributeKeyBooleanAttr}, }, SystemCPUTime: SystemCPUTimeMetricConfig{ - Enabled: false, + Enabled: false, + AggregationStrategy: AggregationStrategySum, + EnabledAttributes: []SystemCPUTimeMetricAttributeKey{SystemCPUTimeMetricAttributeKeyCpu}, + }, + SystemMemoryUsage: SystemMemoryUsageMetricConfig{ + Enabled: false, + AggregationStrategy: AggregationStrategySum, + EnabledAttributes: []SystemMemoryUsageMetricAttributeKey{SystemMemoryUsageMetricAttributeKeyState}, }, }, ResourceAttributes: ResourceAttributesConfig{ @@ -133,7 +147,7 @@ func TestMetricsBuilderConfig(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { cfg := loadMetricsBuilderConfig(t, tt.name) - diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(DefaultMetricMetricConfig{}, DefaultMetricToBeRemovedMetricConfig{}, MetricInputTypeMetricConfig{}, OptionalMetricMetricConfig{}, OptionalMetricEmptyUnitMetricConfig{}, ReaggregateMetricMetricConfig{}, ReaggregateMetricWithRequiredMetricConfig{}, SystemCPUTimeMetricConfig{}, ResourceAttributeConfig{})) + diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(DefaultMetricMetricConfig{}, DefaultMetricToBeRemovedMetricConfig{}, MetricInputTypeMetricConfig{}, OptionalMetricMetricConfig{}, OptionalMetricEmptyUnitMetricConfig{}, ReaggregateMetricMetricConfig{}, ReaggregateMetricWithRequiredMetricConfig{}, SystemCPUTimeMetricConfig{}, SystemMemoryUsageMetricConfig{}, ResourceAttributeConfig{})) require.Emptyf(t, diff, "Config mismatch (-expected +actual):\n%s", diff) }) } diff --git a/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics.go b/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics.go index e047d97c69a..ba841883af3 100644 --- a/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics.go +++ b/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics.go @@ -54,6 +54,52 @@ var MapAttributeEnumAttr = map[string]AttributeEnumAttr{ "blue": AttributeEnumAttrBlue, } +// AttributeState specifies the value state attribute. +type AttributeState int + +const ( + _ AttributeState = iota + AttributeStateBuffered + AttributeStateCached + AttributeStateInactive + AttributeStateFree + AttributeStateSlabReclaimable + AttributeStateSlabUnreclaimable + AttributeStateUsed +) + +// String returns the string representation of the AttributeState. +func (av AttributeState) String() string { + switch av { + case AttributeStateBuffered: + return "buffered" + case AttributeStateCached: + return "cached" + case AttributeStateInactive: + return "inactive" + case AttributeStateFree: + return "free" + case AttributeStateSlabReclaimable: + return "slab_reclaimable" + case AttributeStateSlabUnreclaimable: + return "slab_unreclaimable" + case AttributeStateUsed: + return "used" + } + return "" +} + +// MapAttributeState is a helper map of string to AttributeState attribute value. +var MapAttributeState = map[string]AttributeState{ + "buffered": AttributeStateBuffered, + "cached": AttributeStateCached, + "inactive": AttributeStateInactive, + "free": AttributeStateFree, + "slab_reclaimable": AttributeStateSlabReclaimable, + "slab_unreclaimable": AttributeStateSlabUnreclaimable, + "used": AttributeStateUsed, +} + var MetricsInfo = metricsInfo{ DefaultMetric: metricInfo{ Name: "default.metric", @@ -79,6 +125,9 @@ var MetricsInfo = metricsInfo{ SystemCPUTime: metricInfo{ Name: "system.cpu.time", }, + SystemMemoryUsage: metricInfo{ + Name: "system.memory.usage", + }, } type metricsInfo struct { @@ -90,6 +139,7 @@ type metricsInfo struct { ReaggregateMetric metricInfo ReaggregateMetricWithRequired metricInfo SystemCPUTime metricInfo + SystemMemoryUsage metricInfo } type metricInfo struct { @@ -760,9 +810,10 @@ func newMetricReaggregateMetricWithRequired(cfg ReaggregateMetricWithRequiredMet } type metricSystemCPUTime struct { - data pmetric.Metric // data buffer for generated metric. - config SystemCPUTimeMetricConfig // metric config provided by user. - capacity int // max observed number of data points added to the metric. + data pmetric.Metric // data buffer for generated metric. + config SystemCPUTimeMetricConfig // metric config provided by user. + capacity int // max observed number of data points added to the metric. + aggDataPoints []int64 // slice containing number of aggregated datapoints at each index } // init fills system.cpu.time metric with initial data. @@ -773,16 +824,49 @@ func (m *metricSystemCPUTime) init() { m.data.SetEmptySum() m.data.Sum().SetIsMonotonic(true) m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) + m.aggDataPoints = m.aggDataPoints[:0] } -func (m *metricSystemCPUTime) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64) { +func (m *metricSystemCPUTime) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, cpuAttributeValue string) { if !m.config.Enabled { return } - dp := m.data.Sum().DataPoints().AppendEmpty() + + dp := pmetric.NewNumberDataPoint() dp.SetStartTimestamp(start) dp.SetTimestamp(ts) + if slices.Contains(m.config.EnabledAttributes, SystemCPUTimeMetricAttributeKeyCpu) { + dp.Attributes().PutStr("cpu", cpuAttributeValue) + } + + var s string + dps := m.data.Sum().DataPoints() + for i := 0; i < dps.Len(); i++ { + dpi := dps.At(i) + if dp.Attributes().Equal(dpi.Attributes()) && dp.StartTimestamp() == dpi.StartTimestamp() && dp.Timestamp() == dpi.Timestamp() { + switch s = m.config.AggregationStrategy; s { + case AggregationStrategySum, AggregationStrategyAvg: + dpi.SetIntValue(dpi.IntValue() + val) + m.aggDataPoints[i] += 1 + return + case AggregationStrategyMin: + if dpi.IntValue() > val { + dpi.SetIntValue(val) + } + return + case AggregationStrategyMax: + if dpi.IntValue() < val { + dpi.SetIntValue(val) + } + return + } + } + } + dp.SetIntValue(val) + m.aggDataPoints = append(m.aggDataPoints, 1) + dp.MoveTo(dps.AppendEmpty()) } // updateCapacity saves max length of data point slices that will be used for the slice capacity. @@ -795,6 +879,11 @@ func (m *metricSystemCPUTime) updateCapacity() { // emit appends recorded metric data to a metrics slice and prepares it for recording another set of data points. func (m *metricSystemCPUTime) emit(metrics pmetric.MetricSlice) { if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 { + if m.config.AggregationStrategy == AggregationStrategyAvg { + for i, aggCount := range m.aggDataPoints { + m.data.Sum().DataPoints().At(i).SetIntValue(m.data.Sum().DataPoints().At(i).IntValue() / aggCount) + } + } m.updateCapacity() m.data.MoveTo(metrics.AppendEmpty()) m.init() @@ -811,6 +900,97 @@ func newMetricSystemCPUTime(cfg SystemCPUTimeMetricConfig) metricSystemCPUTime { return m } +type metricSystemMemoryUsage struct { + data pmetric.Metric // data buffer for generated metric. + config SystemMemoryUsageMetricConfig // metric config provided by user. + capacity int // max observed number of data points added to the metric. + aggDataPoints []int64 // slice containing number of aggregated datapoints at each index +} + +// init fills system.memory.usage metric with initial data. +func (m *metricSystemMemoryUsage) init() { + m.data.SetName("system.memory.usage") + m.data.SetDescription("Bytes of memory in use.") + m.data.SetUnit("By") + m.data.SetEmptySum() + m.data.Sum().SetIsMonotonic(false) + m.data.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) + m.data.Sum().DataPoints().EnsureCapacity(m.capacity) + m.aggDataPoints = m.aggDataPoints[:0] +} + +func (m *metricSystemMemoryUsage) recordDataPoint(start pcommon.Timestamp, ts pcommon.Timestamp, val int64, stateAttributeValue string) { + if !m.config.Enabled { + return + } + + dp := pmetric.NewNumberDataPoint() + dp.SetStartTimestamp(start) + dp.SetTimestamp(ts) + if slices.Contains(m.config.EnabledAttributes, SystemMemoryUsageMetricAttributeKeyState) { + dp.Attributes().PutStr("state", stateAttributeValue) + } + + var s string + dps := m.data.Sum().DataPoints() + for i := 0; i < dps.Len(); i++ { + dpi := dps.At(i) + if dp.Attributes().Equal(dpi.Attributes()) && dp.StartTimestamp() == dpi.StartTimestamp() && dp.Timestamp() == dpi.Timestamp() { + switch s = m.config.AggregationStrategy; s { + case AggregationStrategySum, AggregationStrategyAvg: + dpi.SetIntValue(dpi.IntValue() + val) + m.aggDataPoints[i] += 1 + return + case AggregationStrategyMin: + if dpi.IntValue() > val { + dpi.SetIntValue(val) + } + return + case AggregationStrategyMax: + if dpi.IntValue() < val { + dpi.SetIntValue(val) + } + return + } + } + } + + dp.SetIntValue(val) + m.aggDataPoints = append(m.aggDataPoints, 1) + dp.MoveTo(dps.AppendEmpty()) +} + +// updateCapacity saves max length of data point slices that will be used for the slice capacity. +func (m *metricSystemMemoryUsage) 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 *metricSystemMemoryUsage) emit(metrics pmetric.MetricSlice) { + if m.config.Enabled && m.data.Sum().DataPoints().Len() > 0 { + if m.config.AggregationStrategy == AggregationStrategyAvg { + for i, aggCount := range m.aggDataPoints { + m.data.Sum().DataPoints().At(i).SetIntValue(m.data.Sum().DataPoints().At(i).IntValue() / aggCount) + } + } + m.updateCapacity() + m.data.MoveTo(metrics.AppendEmpty()) + m.init() + } +} + +func newMetricSystemMemoryUsage(cfg SystemMemoryUsageMetricConfig) metricSystemMemoryUsage { + m := metricSystemMemoryUsage{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 { @@ -829,6 +1009,7 @@ type MetricsBuilder struct { metricReaggregateMetric metricReaggregateMetric metricReaggregateMetricWithRequired metricReaggregateMetricWithRequired metricSystemCPUTime metricSystemCPUTime + metricSystemMemoryUsage metricSystemMemoryUsage } // MetricBuilderOption applies changes to default metrics builder. @@ -883,6 +1064,7 @@ func NewMetricsBuilder(mbc MetricsBuilderConfig, settings receiver.Settings, opt metricReaggregateMetric: newMetricReaggregateMetric(mbc.Metrics.ReaggregateMetric), metricReaggregateMetricWithRequired: newMetricReaggregateMetricWithRequired(mbc.Metrics.ReaggregateMetricWithRequired), metricSystemCPUTime: newMetricSystemCPUTime(mbc.Metrics.SystemCPUTime), + metricSystemMemoryUsage: newMetricSystemMemoryUsage(mbc.Metrics.SystemMemoryUsage), resourceAttributeIncludeFilter: make(map[string]filter.Filter), resourceAttributeExcludeFilter: make(map[string]filter.Filter), } @@ -1012,6 +1194,7 @@ func (mb *MetricsBuilder) EmitForResource(options ...ResourceMetricsOption) { mb.metricReaggregateMetric.emit(ils.Metrics()) mb.metricReaggregateMetricWithRequired.emit(ils.Metrics()) mb.metricSystemCPUTime.emit(ils.Metrics()) + mb.metricSystemMemoryUsage.emit(ils.Metrics()) for _, op := range options { op.apply(rm) @@ -1084,8 +1267,13 @@ func (mb *MetricsBuilder) RecordReaggregateMetricWithRequiredDataPoint(ts pcommo } // RecordSystemCPUTimeDataPoint adds a data point to system.cpu.time metric. -func (mb *MetricsBuilder) RecordSystemCPUTimeDataPoint(ts pcommon.Timestamp, val int64) { - mb.metricSystemCPUTime.recordDataPoint(mb.startTime, ts, val) +func (mb *MetricsBuilder) RecordSystemCPUTimeDataPoint(ts pcommon.Timestamp, val int64, cpuAttributeValue string) { + mb.metricSystemCPUTime.recordDataPoint(mb.startTime, ts, val, cpuAttributeValue) +} + +// RecordSystemMemoryUsageDataPoint adds a data point to system.memory.usage metric. +func (mb *MetricsBuilder) RecordSystemMemoryUsageDataPoint(ts pcommon.Timestamp, val int64, stateAttributeValue AttributeState) { + mb.metricSystemMemoryUsage.recordDataPoint(mb.startTime, ts, val, stateAttributeValue.String()) } // Reset resets metrics builder to its initial state. It should be used when external metrics source is restarted, diff --git a/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics_test.go b/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics_test.go index 866e3caacde..5c1f298560b 100644 --- a/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics_test.go +++ b/cmd/mdatagen/internal/samplereceiver/internal/metadata/generated_metrics_test.go @@ -74,6 +74,8 @@ func TestMetricsBuilder(t *testing.T) { aggMap["OptionalMetricEmptyUnit"] = mb.metricOptionalMetricEmptyUnit.config.AggregationStrategy aggMap["ReaggregateMetric"] = mb.metricReaggregateMetric.config.AggregationStrategy aggMap["ReaggregateMetricWithRequired"] = mb.metricReaggregateMetricWithRequired.config.AggregationStrategy + aggMap["SystemCPUTime"] = mb.metricSystemCPUTime.config.AggregationStrategy + aggMap["SystemMemoryUsage"] = mb.metricSystemMemoryUsage.config.AggregationStrategy expectedWarnings := 0 if tt.metricsSet == testDataSetDefault { @@ -157,7 +159,17 @@ func TestMetricsBuilder(t *testing.T) { defaultMetricsCount++ allMetricsCount++ - mb.RecordSystemCPUTimeDataPoint(ts, 1) + mb.RecordSystemCPUTimeDataPoint(ts, 1, "cpu-val") + if tt.name == "reaggregate_set" { + mb.RecordSystemCPUTimeDataPoint(ts, 3, "cpu-val-2") + } + + defaultMetricsCount++ + allMetricsCount++ + mb.RecordSystemMemoryUsageDataPoint(ts, 1, AttributeStateBuffered) + if tt.name == "reaggregate_set" { + mb.RecordSystemMemoryUsageDataPoint(ts, 3, AttributeStateCached) + } rb := mb.NewResourceBuilder() rb.SetMapResourceAttr(map[string]any{"key1": "map.resource.attr-val1", "key2": "map.resource.attr-val2"}) @@ -177,6 +189,8 @@ func TestMetricsBuilder(t *testing.T) { assert.Empty(t, mb.metricOptionalMetricEmptyUnit.aggDataPoints) assert.Empty(t, mb.metricReaggregateMetric.aggDataPoints) assert.Empty(t, mb.metricReaggregateMetricWithRequired.aggDataPoints) + assert.Empty(t, mb.metricSystemCPUTime.aggDataPoints) + assert.Empty(t, mb.metricSystemMemoryUsage.aggDataPoints) } if tt.expectEmpty { @@ -548,19 +562,93 @@ func TestMetricsBuilder(t *testing.T) { assert.False(t, ok) } case "system.cpu.time": - assert.False(t, validatedMetrics["system.cpu.time"], "Found a duplicate in the metrics slice: system.cpu.time") - validatedMetrics["system.cpu.time"] = true - assert.Equal(t, pmetric.MetricTypeSum, mi.Type()) - assert.Equal(t, 1, mi.Sum().DataPoints().Len()) - assert.Equal(t, "Monotonic cumulative sum int metric enabled by default.", mi.Description()) - assert.Equal(t, "s", mi.Unit()) - assert.True(t, mi.Sum().IsMonotonic()) - assert.Equal(t, pmetric.AggregationTemporalityCumulative, mi.Sum().AggregationTemporality()) - dp := mi.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()) + if tt.name != "reaggregate_set" { + assert.False(t, validatedMetrics["system.cpu.time"], "Found a duplicate in the metrics slice: system.cpu.time") + validatedMetrics["system.cpu.time"] = true + assert.Equal(t, pmetric.MetricTypeSum, mi.Type()) + assert.Equal(t, 1, mi.Sum().DataPoints().Len()) + assert.Equal(t, "Monotonic cumulative sum int metric enabled by default.", mi.Description()) + assert.Equal(t, "s", mi.Unit()) + assert.True(t, mi.Sum().IsMonotonic()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, mi.Sum().AggregationTemporality()) + dp := mi.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()) + cpuAttrVal, ok := dp.Attributes().Get("cpu") + assert.True(t, ok) + assert.Equal(t, "cpu-val", cpuAttrVal.Str()) + } else { + assert.False(t, validatedMetrics["system.cpu.time"], "Found a duplicate in the metrics slice: system.cpu.time") + validatedMetrics["system.cpu.time"] = true + assert.Equal(t, pmetric.MetricTypeSum, mi.Type()) + assert.Equal(t, 1, mi.Sum().DataPoints().Len()) + assert.Equal(t, "Monotonic cumulative sum int metric enabled by default.", mi.Description()) + assert.Equal(t, "s", mi.Unit()) + assert.True(t, mi.Sum().IsMonotonic()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, mi.Sum().AggregationTemporality()) + dp := mi.Sum().DataPoints().At(0) + assert.Equal(t, start, dp.StartTimestamp()) + assert.Equal(t, ts, dp.Timestamp()) + assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) + switch aggMap["system.cpu.time"] { + case "sum": + assert.Equal(t, int64(4), dp.IntValue()) + case "avg": + assert.Equal(t, int64(2), dp.IntValue()) + case "min": + assert.Equal(t, int64(1), dp.IntValue()) + case "max": + assert.Equal(t, int64(3), dp.IntValue()) + } + _, ok := dp.Attributes().Get("cpu") + assert.False(t, ok) + } + case "system.memory.usage": + if tt.name != "reaggregate_set" { + assert.False(t, validatedMetrics["system.memory.usage"], "Found a duplicate in the metrics slice: system.memory.usage") + validatedMetrics["system.memory.usage"] = true + assert.Equal(t, pmetric.MetricTypeSum, mi.Type()) + assert.Equal(t, 1, mi.Sum().DataPoints().Len()) + assert.Equal(t, "Bytes of memory in use.", mi.Description()) + assert.Equal(t, "By", mi.Unit()) + assert.False(t, mi.Sum().IsMonotonic()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, mi.Sum().AggregationTemporality()) + dp := mi.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()) + stateAttrVal, ok := dp.Attributes().Get("state") + assert.True(t, ok) + assert.Equal(t, "buffered", stateAttrVal.Str()) + } else { + assert.False(t, validatedMetrics["system.memory.usage"], "Found a duplicate in the metrics slice: system.memory.usage") + validatedMetrics["system.memory.usage"] = true + assert.Equal(t, pmetric.MetricTypeSum, mi.Type()) + assert.Equal(t, 1, mi.Sum().DataPoints().Len()) + assert.Equal(t, "Bytes of memory in use.", mi.Description()) + assert.Equal(t, "By", mi.Unit()) + assert.False(t, mi.Sum().IsMonotonic()) + assert.Equal(t, pmetric.AggregationTemporalityCumulative, mi.Sum().AggregationTemporality()) + dp := mi.Sum().DataPoints().At(0) + assert.Equal(t, start, dp.StartTimestamp()) + assert.Equal(t, ts, dp.Timestamp()) + assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType()) + switch aggMap["system.memory.usage"] { + case "sum": + assert.Equal(t, int64(4), dp.IntValue()) + case "avg": + assert.Equal(t, int64(2), dp.IntValue()) + case "min": + assert.Equal(t, int64(1), dp.IntValue()) + case "max": + assert.Equal(t, int64(3), dp.IntValue()) + } + _, ok := dp.Attributes().Get("state") + assert.False(t, ok) + } } } }) diff --git a/cmd/mdatagen/internal/samplereceiver/internal/metadata/testdata/config.yaml b/cmd/mdatagen/internal/samplereceiver/internal/metadata/testdata/config.yaml index 023835c76d0..c4a72f672c7 100644 --- a/cmd/mdatagen/internal/samplereceiver/internal/metadata/testdata/config.yaml +++ b/cmd/mdatagen/internal/samplereceiver/internal/metadata/testdata/config.yaml @@ -23,6 +23,10 @@ all_set: attributes: ["required_string_attr","string_attr","boolean_attr"] system.cpu.time: enabled: true + attributes: ["cpu"] + system.memory.usage: + enabled: true + attributes: ["state"] events: default.event: enabled: true @@ -71,6 +75,10 @@ reaggregate_set: attributes: ["required_string_attr"] system.cpu.time: enabled: true + attributes: [] + system.memory.usage: + enabled: true + attributes: [] events: default.event: enabled: true @@ -119,6 +127,10 @@ none_set: attributes: ["required_string_attr","string_attr","boolean_attr"] system.cpu.time: enabled: false + attributes: ["cpu"] + system.memory.usage: + enabled: false + attributes: ["state"] events: default.event: enabled: false diff --git a/cmd/mdatagen/internal/samplereceiver/metadata.yaml b/cmd/mdatagen/internal/samplereceiver/metadata.yaml index c036705d2bc..2a4e76cfac6 100644 --- a/cmd/mdatagen/internal/samplereceiver/metadata.yaml +++ b/cmd/mdatagen/internal/samplereceiver/metadata.yaml @@ -120,6 +120,10 @@ attributes: type: string requirement_level: conditionally_required + cpu: + description: Logical CPU number starting at 0. + type: string + enum_attr: description: Attribute with a known set of string values. type: string @@ -148,6 +152,13 @@ attributes: description: Attribute with a slice value. type: slice + state: + description: Breakdown of memory usage by type. + type: string + enum: [buffered, cached, inactive, free, slab_reclaimable, slab_unreclaimable, used] + semantic_convention: + ref: system.md#system-memory-state + string_attr: description: Attribute with any string value. type: string @@ -300,8 +311,20 @@ metrics: value_type: int monotonic: true aggregation_temporality: cumulative + attributes: [cpu] semantic_convention: - ref: https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/system/system-metrics.md#metric-systemcputime + ref: system/system-metrics.md#metric-systemcputime + + system.memory.usage: + enabled: true + description: Bytes of memory in use. + unit: By + stability: development + sum: + value_type: int + aggregation_temporality: cumulative + monotonic: false + attributes: [state] telemetry: metrics: diff --git a/cmd/mdatagen/internal/samplescraper/documentation.md b/cmd/mdatagen/internal/samplescraper/documentation.md index dc0ab8c93aa..8e5c809031b 100644 --- a/cmd/mdatagen/internal/samplescraper/documentation.md +++ b/cmd/mdatagen/internal/samplescraper/documentation.md @@ -24,13 +24,13 @@ The metric will be become optional soon. #### Attributes -| Name | Description | Values | Requirement Level | -| ---- | ----------- | ------ | -------- | -| string_attr | Attribute with any string value. | Any Str | Recommended | -| state | Integer attribute with overridden name. | Any Int | Recommended | -| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` | Recommended | -| slice_attr | Attribute with a slice value. | Any Slice | Recommended | -| map_attr | Attribute with a map value. | Any Map | Recommended | +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| string_attr | Attribute with any string value. | Any Str | Recommended | - | +| state | Integer attribute with overridden name. | Any Int | Recommended | - | +| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` | Recommended | - | +| slice_attr | Attribute with a slice value. | Any Slice | Recommended | - | +| map_attr | Attribute with a map value. | Any Map | Recommended | - | ### default.metric.to_be_removed @@ -54,13 +54,13 @@ Monotonic cumulative sum int metric with string input_type enabled by default. #### Attributes -| Name | Description | Values | Requirement Level | -| ---- | ----------- | ------ | -------- | -| string_attr | Attribute with any string value. | Any Str | Recommended | -| state | Integer attribute with overridden name. | Any Int | Recommended | -| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` | Recommended | -| slice_attr | Attribute with a slice value. | Any Slice | Recommended | -| map_attr | Attribute with a map value. | Any Map | Recommended | +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| string_attr | Attribute with any string value. | Any Str | Recommended | - | +| state | Integer attribute with overridden name. | Any Int | Recommended | - | +| enum_attr | Attribute with a known set of string values. | Str: ``red``, ``green``, ``blue`` | Recommended | - | +| slice_attr | Attribute with a slice value. | Any Slice | Recommended | - | +| map_attr | Attribute with a map value. | Any Map | Recommended | - | ### reaggregate.metric @@ -72,10 +72,10 @@ Metric for testing spatial reaggregation #### Attributes -| Name | Description | Values | Requirement Level | -| ---- | ----------- | ------ | -------- | -| string_attr | Attribute with any string value. | Any Str | Recommended | -| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| string_attr | Attribute with any string value. | Any Str | Recommended | - | +| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | - | ### system.cpu.time @@ -109,11 +109,11 @@ metrics: #### Attributes -| Name | Description | Values | Requirement Level | -| ---- | ----------- | ------ | -------- | -| string_attr | Attribute with any string value. | Any Str | Recommended | -| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | -| boolean_attr2 | Another attribute with a boolean value. | Any Bool | Recommended | +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| string_attr | Attribute with any string value. | Any Str | Recommended | - | +| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | - | +| boolean_attr2 | Another attribute with a boolean value. | Any Bool | Recommended | - | ### optional.metric.empty_unit @@ -127,20 +127,20 @@ metrics: #### Attributes -| Name | Description | Values | Requirement Level | -| ---- | ----------- | ------ | -------- | -| string_attr | Attribute with any string value. | Any Str | Recommended | -| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | +| string_attr | Attribute with any string value. | Any Str | Recommended | - | +| boolean_attr | Attribute with a boolean value. | Any Bool | Recommended | - | ## 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 | +| Name | Description | Values | Enabled | Semantic Convention | +| ---- | ----------- | ------ | ------- | ------------------- | +| 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/samplescraper/metadata.yaml b/cmd/mdatagen/internal/samplescraper/metadata.yaml index ee027216ca2..ebdc1478f94 100644 --- a/cmd/mdatagen/internal/samplescraper/metadata.yaml +++ b/cmd/mdatagen/internal/samplescraper/metadata.yaml @@ -223,4 +223,4 @@ metrics: monotonic: true aggregation_temporality: cumulative semantic_convention: - ref: https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/system/system-metrics.md#metric-systemcputime + ref: system/system-metrics.md#metric-systemcputime diff --git a/cmd/mdatagen/internal/templates/documentation.md.tmpl b/cmd/mdatagen/internal/templates/documentation.md.tmpl index 73cadff8c20..9c78fd905fc 100644 --- a/cmd/mdatagen/internal/templates/documentation.md.tmpl +++ b/cmd/mdatagen/internal/templates/documentation.md.tmpl @@ -28,12 +28,12 @@ #### Attributes -| Name | Description | Values | Requirement Level | -| ---- | ----------- | ------ | -------- | +| Name | Description | Values | Requirement Level | Semantic Convention | +| ---- | ----------- | ------ | ----------------- | ------------------- | {{- range $metric.Attributes }} {{- $attribute := . | attributeInfo }} | {{ $attribute.Name }} | {{ $attribute.Description }} | -{{- if $attribute.Enum }} {{ $attribute.Type }}: ``{{ stringsJoin $attribute.Enum "``, ``" }}``{{ else }} Any {{ $attribute.Type }}{{ end }} | {{ $attribute.RequirementLevel }} | +{{- if $attribute.Enum }} {{ $attribute.Type }}: ``{{ stringsJoin $attribute.Enum "``, ``" }}``{{ else }} Any {{ $attribute.Type }}{{ end }} | {{ $attribute.RequirementLevel }} |{{ if $attribute.SemanticConvention }} [{{ $attribute.Name }}]({{ $attribute.SemanticConvention.SemanticConventionRef }}) |{{ else }} - |{{ end }} {{- end }} {{- end }} @@ -58,12 +58,12 @@ #### Attributes -| Name | Description | Values | -| ---- | ----------- | ------ | +| Name | Description | Values | Semantic Convention | +| ---- | ----------- | ------ | ------------------- | {{- range $event.Attributes }} {{- $attribute := . | attributeInfo }} | {{ $attribute.Name }} | {{ $attribute.Description }} | -{{- if $attribute.Enum }} {{ $attribute.Type }}: ``{{ stringsJoin $attribute.Enum "``, ``" }}``{{ else }} Any {{ $attribute.Type }}{{ end }} | +{{- if $attribute.Enum }} {{ $attribute.Type }}: ``{{ stringsJoin $attribute.Enum "``, ``" }}``{{ else }} Any {{ $attribute.Type }}{{ end }} |{{ if $attribute.SemanticConvention }} [{{ $attribute.Name }}]({{ $attribute.SemanticConvention.SemanticConventionRef }}) |{{ else }} - |{{ end }} {{- end }} {{- end }} @@ -106,12 +106,12 @@ #### Attributes -| Name | Description | Values | -| ---- | ----------- | ------ | +| Name | Description | Values | Semantic Convention | +| ---- | ----------- | ------ | ------------------- | {{- range $metric.Attributes }} {{- $attribute := . | attributeInfo }} | {{ $attribute.Name }} | {{ $attribute.Description }} | -{{- if $attribute.Enum }} {{ $attribute.Type }}: ``{{ stringsJoin $attribute.Enum "``, ``" }}``{{ else }} Any {{ $attribute.Type }}{{ end }} | +{{- if $attribute.Enum }} {{ $attribute.Type }}: ``{{ stringsJoin $attribute.Enum "``, ``" }}``{{ else }} Any {{ $attribute.Type }}{{ end }} |{{ if $attribute.SemanticConvention }} [{{ $attribute.Name }}]({{ $attribute.SemanticConvention.SemanticConventionRef }}) |{{ else }} - |{{ end }} {{- end }} {{- end }} @@ -220,11 +220,11 @@ events: ## Resource Attributes -| Name | Description | Values | Enabled | -| ---- | ----------- | ------ | ------- | +| Name | Description | Values | Enabled | Semantic Convention | +| ---- | ----------- | ------ | ------- | ------------------- | {{- range $attributeName, $attribute := .ResourceAttributes }} | {{ $attributeName }} | {{ $attribute.Description }} | -{{- if $attribute.Enum }} {{ $attribute.Type }}: ``{{ stringsJoin $attribute.Enum "``, ``" }}``{{ else }} Any {{ $attribute.Type }}{{ end }} | {{ $attribute.Enabled }} | +{{- if $attribute.Enum }} {{ $attribute.Type }}: ``{{ stringsJoin $attribute.Enum "``, ``" }}``{{ else }} Any {{ $attribute.Type }}{{ end }} | {{ $attribute.Enabled }} |{{ if $attribute.SemanticConvention }} [{{ $attributeName }}]({{ $attribute.SemanticConvention.SemanticConventionRef }}) |{{ else }} - |{{ end }} {{- end }} {{- end }} diff --git a/cmd/mdatagen/internal/testdata/invalid_attribute_semconv_url_full.yaml b/cmd/mdatagen/internal/testdata/invalid_attribute_semconv_url_full.yaml new file mode 100644 index 00000000000..478729e9b22 --- /dev/null +++ b/cmd/mdatagen/internal/testdata/invalid_attribute_semconv_url_full.yaml @@ -0,0 +1,28 @@ +type: metricreceiver + +sem_conv_version: 1.38.0 + +status: + class: receiver + stability: + development: [logs] + beta: [traces] + stable: [metrics] + +attributes: + used_attr: + description: Used attribute. + type: string + semantic_convention: + ref: https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/registry/attributes/system.md#system-memory-state + +metrics: + metric: + enabled: true + description: Metric. + stability: development + unit: "1" + gauge: + value_type: double + attributes: [used_attr] + diff --git a/cmd/mdatagen/internal/testdata/invalid_metric_semconv_url_full.yaml b/cmd/mdatagen/internal/testdata/invalid_metric_semconv_url_full.yaml new file mode 100644 index 00000000000..29dd50bcccc --- /dev/null +++ b/cmd/mdatagen/internal/testdata/invalid_metric_semconv_url_full.yaml @@ -0,0 +1,28 @@ +type: metricreceiver + +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 + +sem_conv_version: 1.37.2 + +metrics: + default.metric: + enabled: true + description: Monotonic cumulative sum int metric enabled by default. + extended_documentation: The metric will be become optional soon. + stability: development + semantic_convention: + ref: https://github.com/open-telemetry/semantic-conventions/blob/v1.37.2/docs/system/system-metrics.md#metric-systemcputime + unit: s + sum: + value_type: int + monotonic: true + aggregation_temporality: cumulative + diff --git a/cmd/mdatagen/internal/testdata/invalid_metric_semconvref.yaml b/cmd/mdatagen/internal/testdata/invalid_metric_semconvref.yaml index 0f431e8deae..78300033545 100644 --- a/cmd/mdatagen/internal/testdata/invalid_metric_semconvref.yaml +++ b/cmd/mdatagen/internal/testdata/invalid_metric_semconvref.yaml @@ -19,7 +19,7 @@ metrics: extended_documentation: The metric will be become optional soon. stability: development semantic_convention: - ref: https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/system/system-metrics.md#metric-systemcputime + ref: system/system-metrics.md#metric-systemcputime unit: s sum: value_type: int diff --git a/cmd/mdatagen/internal/testdata/with_underscore_in_semconv_ref_anchor_tag.yaml b/cmd/mdatagen/internal/testdata/with_underscore_in_semconv_ref_anchor_tag.yaml index df19b0a5e12..22d3a8d8f14 100644 --- a/cmd/mdatagen/internal/testdata/with_underscore_in_semconv_ref_anchor_tag.yaml +++ b/cmd/mdatagen/internal/testdata/with_underscore_in_semconv_ref_anchor_tag.yaml @@ -18,7 +18,7 @@ metrics: description: Time disk spent activated.. stability: development semantic_convention: - ref: https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/system/system-metrics.md#metric-systemdiskio_time + ref: system/system-metrics.md#metric-systemdiskio_time unit: s sum: value_type: double diff --git a/cmd/mdatagen/metadata-schema.yaml b/cmd/mdatagen/metadata-schema.yaml index 721d200ccfb..7203babd4b2 100644 --- a/cmd/mdatagen/metadata-schema.yaml +++ b/cmd/mdatagen/metadata-schema.yaml @@ -171,6 +171,13 @@ resource_attributes: # A warning that will be displayed if the resource_attribute is configured by user in any way. # Should be used for deprecated optional resource_attributes that will be removed soon. if_configured: + # Optional: the reference to a semantic convention + # Relative path to the semantic convention definition (e.g., "system.md#system-memory-state") + # The full URL is constructed using sem_conv_version: {base}/v{version}/docs/registry/attributes/{ref} + # An example of a full url is: https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/registry/attributes/system.md#system-memory-state + semantic_convention: + ref: + # Optional: array of entity definitions. Entities organize resource attributes into logical entities # with identity and description attributes. @@ -219,6 +226,12 @@ attributes: # - recommended (default behavior): the attribute is included by default but can be disabled via configuration. # - opt_in: the attribute is not included unless explicitly enabled in user config. requirement_level: + # Optional: the reference to a semantic convention + # Relative path to the semantic convention definition (e.g., "system.md#system-memory-state") + # The full URL is constructed using sem_conv_version: {base}/v{version}/docs/registry/attributes/{ref} + # An example of a full url is: https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/registry/attributes/system.md#system-memory-state + semantic_convention: + ref: # Optional: map of metric names with the key being the metric name and value # being described below. @@ -270,6 +283,9 @@ metrics: # Required: migration note note: # Optional: the reference to a semantic convention + # Relative path to the semantic convention definition (e.g., "system/system-metrics.md#metric-systemcputime") + # The full URL is constructed using sem_conv_version: {base}/v{version}/docs/{ref} + # An example of a full url is: https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/system/system-metrics.md#metric-systemcputime semantic_convention: ref: diff --git a/receiver/receiverhelper/documentation.md b/receiver/receiverhelper/documentation.md index 34e51c3108c..d4ec146c1ee 100644 --- a/receiver/receiverhelper/documentation.md +++ b/receiver/receiverhelper/documentation.md @@ -112,9 +112,9 @@ The number of requests performed. #### Attributes -| Name | Description | Values | -| ---- | ----------- | ------ | -| outcome | The outcome of receiver requests | Str: ``success``, ``refused``, ``failure`` | +| Name | Description | Values | Semantic Convention | +| ---- | ----------- | ------ | ------------------- | +| outcome | The outcome of receiver requests | Str: ``success``, ``refused``, ``failure`` | - | ## Feature Gates