Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/make_stability_level_required.yaml
Original file line number Diff line number Diff line change
@@ -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: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: cmd/mdatagen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Make stability.level a required field for metrics

# One or more tracking issues or pull requests related to the change
issues: [14070]

# (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]
24 changes: 20 additions & 4 deletions cmd/mdatagen/internal/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func TestLoadMetadata(t *testing.T) {
Enabled: true,
Description: "Monotonic cumulative sum int metric enabled by default.",
ExtendedDocumentation: "The metric will be become optional soon.",
Stability: Stability{Level: component.StabilityLevelDevelopment},
Warnings: Warnings{
IfEnabledNotSet: "This metric will be disabled by default soon.",
},
Expand All @@ -264,6 +265,7 @@ func TestLoadMetadata(t *testing.T) {
Signal: Signal{
Enabled: false,
Description: "[DEPRECATED] Gauge double metric disabled by default.",
Stability: Stability{Level: component.StabilityLevelDeprecated},
Warnings: Warnings{
IfConfigured: "This metric is deprecated and will be removed soon.",
},
Expand All @@ -278,6 +280,7 @@ func TestLoadMetadata(t *testing.T) {
Signal: Signal{
Enabled: false,
Description: "[DEPRECATED] Gauge double metric disabled by default.",
Stability: Stability{Level: component.StabilityLevelDeprecated},
Warnings: Warnings{
IfConfigured: "This metric is deprecated and will be removed soon.",
},
Expand All @@ -294,6 +297,7 @@ func TestLoadMetadata(t *testing.T) {
Enabled: true,
Description: "[DEPRECATED] Non-monotonic delta sum double metric enabled by default.",
ExtendedDocumentation: "The metric will be removed soon.",
Stability: Stability{Level: component.StabilityLevelDeprecated},
Warnings: Warnings{
IfEnabled: "This metric is deprecated and will be removed soon.",
},
Expand All @@ -309,6 +313,7 @@ func TestLoadMetadata(t *testing.T) {
Signal: Signal{
Enabled: true,
Description: "Monotonic cumulative sum int metric with string input_type enabled by default.",
Stability: Stability{Level: component.StabilityLevelDevelopment},
Attributes: []AttributeName{"string_attr", "overridden_int_attr", "enum_attr", "slice_attr", "map_attr"},
},
Unit: strPtr("s"),
Expand Down Expand Up @@ -359,7 +364,7 @@ func TestLoadMetadata(t *testing.T) {
"batch_size_trigger_send": {
Signal: Signal{
Enabled: true,
Stability: Stability{Level: "deprecated", From: "v0.110.0"},
Stability: Stability{Level: component.StabilityLevelDeprecated, From: "v0.110.0"},
Description: "Number of times the batch was sent due to a size trigger",
},
Unit: strPtr("{times}"),
Expand All @@ -371,7 +376,7 @@ func TestLoadMetadata(t *testing.T) {
"request_duration": {
Signal: Signal{
Enabled: true,
Stability: Stability{Level: "alpha"},
Stability: Stability{Level: component.StabilityLevelAlpha},
Description: "Duration of request",
},
Unit: strPtr("s"),
Expand All @@ -383,7 +388,7 @@ func TestLoadMetadata(t *testing.T) {
"process_runtime_total_alloc_bytes": {
Signal: Signal{
Enabled: true,
Stability: Stability{Level: "stable"},
Stability: Stability{Level: component.StabilityLevelStable},
Description: "Cumulative bytes allocated for heap objects (see 'go doc runtime.MemStats.TotalAlloc')",
},
Unit: strPtr("By"),
Expand All @@ -398,7 +403,7 @@ func TestLoadMetadata(t *testing.T) {
"queue_length": {
Signal: Signal{
Enabled: true,
Stability: Stability{Level: "alpha"},
Stability: Stability{Level: component.StabilityLevelAlpha},
Description: "This metric is optional and therefore not initialized in NewTelemetryBuilder.",
ExtendedDocumentation: "For example this metric only exists if feature A is enabled.",
},
Expand All @@ -415,6 +420,7 @@ func TestLoadMetadata(t *testing.T) {
Signal: Signal{
Enabled: true,
Description: "Queue capacity - sync gauge example.",
Stability: Stability{Level: component.StabilityLevelDevelopment},
},
Unit: strPtr("{items}"),
Gauge: &Gauge{
Expand Down Expand Up @@ -513,6 +519,16 @@ func TestLoadMetadata(t *testing.T) {
want: Metadata{},
wantErr: "decoding failed due to the following error(s):\n\n'attributes[used_attr].type' invalid type: \"invalidtype\"",
},
{
name: "testdata/invalid_metric_stability.yaml",
want: Metadata{},
wantErr: "decoding failed due to the following error(s):\n\n'metrics[default.metric]' decoding failed due to the following error(s):\n\n'stability' decoding failed due to the following error(s):\n\n'level' unsupported stability level: \"development42\"",
},
{
name: "testdata/no_metric_stability.yaml",
want: Metadata{},
wantErr: "decoding failed due to the following error(s):\n\n'metrics[default.metric]' decoding failed due to the following error(s):\n\n'stability' missing required field: `stability.level`",
},
{
name: "testdata/~~this file doesn't exist~~.yaml",
wantErr: "unable to read the file file:testdata/~~this file doesn't exist~~.yaml",
Expand Down
22 changes: 16 additions & 6 deletions cmd/mdatagen/internal/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package internal // import "go.opentelemetry.io/collector/cmd/mdatagen/internal"
import (
"errors"
"fmt"
"strings"

"golang.org/x/text/cases"
"golang.org/x/text/language"
Expand Down Expand Up @@ -48,18 +47,26 @@ type Metric struct {
}

type Stability struct {
Level string `mapstructure:"level"`
From string `mapstructure:"from"`
Level component.StabilityLevel `mapstructure:"level"`
From string `mapstructure:"from"`
}

func (s Stability) String() string {
if s.Level == "" || strings.EqualFold(s.Level, component.StabilityLevelStable.String()) {
if s.Level == component.StabilityLevelUndefined ||
s.Level == component.StabilityLevelStable {
return ""
}
if s.From != "" {
return fmt.Sprintf(" [%s since %s]", s.Level, s.From)
return fmt.Sprintf(" [%s since %s]", s.Level.String(), s.From)
}
return fmt.Sprintf(" [%s]", s.Level)
return fmt.Sprintf(" [%s]", s.Level.String())
}

func (s *Stability) Unmarshal(parser *confmap.Conf) error {
if !parser.IsSet("level") {
return errors.New("missing required field: `stability.level`")
}
return parser.Unmarshal(s)
}

func (m *Metric) validate() error {
Expand Down Expand Up @@ -91,6 +98,9 @@ func (m *Metric) Unmarshal(parser *confmap.Conf) error {
if !parser.IsSet("enabled") {
return errors.New("missing required field: `enabled`")
}
if !parser.IsSet("stability") {
return errors.New("missing required field: `stability`")
}
return parser.Unmarshal(m)
}

Expand Down
30 changes: 15 additions & 15 deletions cmd/mdatagen/internal/sampleconnector/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ 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 |
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | Stability |
| ---- | ----------- | ---------- | ----------------------- | --------- | --------- |
| s | Sum | Int | Cumulative | true | Development |

#### Attributes

Expand All @@ -38,17 +38,17 @@ The metric will be become optional soon.

The metric will be removed soon.

| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| s | Sum | Double | Delta | false |
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | Stability |
| ---- | ----------- | ---------- | ----------------------- | --------- | --------- |
| s | Sum | Double | Delta | false | Deprecated |

### metric.input_type

Monotonic cumulative sum int metric with string input_type enabled by default.

| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| s | Sum | Int | Cumulative | true |
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | Stability |
| ---- | ----------- | ---------- | ----------------------- | --------- | --------- |
| s | Sum | Int | Cumulative | true | Development |

#### Attributes

Expand All @@ -74,9 +74,9 @@ metrics:

[DEPRECATED] Gauge double metric disabled by default.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| 1 | Gauge | Double |
| Unit | Metric Type | Value Type | Stability |
| ---- | ----------- | ---------- | --------- |
| 1 | Gauge | Double | Deprecated |

#### Attributes

Expand All @@ -90,9 +90,9 @@ metrics:

[DEPRECATED] Gauge double metric disabled by default.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| | Gauge | Double |
| Unit | Metric Type | Value Type | Stability |
| ---- | ----------- | ---------- | --------- |
| | Gauge | Double | Deprecated |

#### Attributes

Expand Down
10 changes: 10 additions & 0 deletions cmd/mdatagen/internal/sampleconnector/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ metrics:
enabled: true
description: Monotonic cumulative sum int metric enabled by default.
extended_documentation: The metric will be become optional soon.
stability:
level: development
unit: s
sum:
value_type: int
Expand All @@ -117,6 +119,8 @@ metrics:
enabled: true
description: "[DEPRECATED] Non-monotonic delta sum double metric enabled by default."
extended_documentation: The metric will be removed soon.
stability:
level: deprecated
unit: s
sum:
value_type: double
Expand All @@ -128,6 +132,8 @@ metrics:
metric.input_type:
enabled: true
description: Monotonic cumulative sum int metric with string input_type enabled by default.
stability:
level: development
unit: s
sum:
value_type: int
Expand All @@ -140,6 +146,8 @@ metrics:
optional.metric:
enabled: false
description: "[DEPRECATED] Gauge double metric disabled by default."
stability:
level: deprecated
unit: "1"
gauge:
value_type: double
Expand All @@ -150,6 +158,8 @@ metrics:
optional.metric.empty_unit:
enabled: false
description: "[DEPRECATED] Gauge double metric disabled by default."
stability:
level: deprecated
unit: ""
gauge:
value_type: double
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading