Skip to content

Commit ab33d4b

Browse files
authored
[mdatagen] make stability a required field (#14070)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description With the completion of open-telemetry/opentelemetry-collector-contrib#42809 we can move on and make the `stability` field required for metrics so as new metrics from now on should explicitly define their stability. We still need to work-on/finalise the guidelines for moving metrics through stability levels but this is covered by #13910. <!-- Issue number if applicable --> #### Link to tracking issue Fixes # <!--Describe what testing was performed and which tests were added.--> #### Testing Tuned <!--Describe the documentation added.--> #### Documentation Tuned --------- Signed-off-by: ChrsMark <[email protected]>
1 parent 507664f commit ab33d4b

File tree

58 files changed

+537
-333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+537
-333
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: cmd/mdatagen
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Make stability.level a required field for metrics
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [14070]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [user]

cmd/mdatagen/internal/loader_test.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ func TestLoadMetadata(t *testing.T) {
248248
Enabled: true,
249249
Description: "Monotonic cumulative sum int metric enabled by default.",
250250
ExtendedDocumentation: "The metric will be become optional soon.",
251+
Stability: Stability{Level: component.StabilityLevelDevelopment},
251252
Warnings: Warnings{
252253
IfEnabledNotSet: "This metric will be disabled by default soon.",
253254
},
@@ -264,6 +265,7 @@ func TestLoadMetadata(t *testing.T) {
264265
Signal: Signal{
265266
Enabled: false,
266267
Description: "[DEPRECATED] Gauge double metric disabled by default.",
268+
Stability: Stability{Level: component.StabilityLevelDeprecated},
267269
Warnings: Warnings{
268270
IfConfigured: "This metric is deprecated and will be removed soon.",
269271
},
@@ -278,6 +280,7 @@ func TestLoadMetadata(t *testing.T) {
278280
Signal: Signal{
279281
Enabled: false,
280282
Description: "[DEPRECATED] Gauge double metric disabled by default.",
283+
Stability: Stability{Level: component.StabilityLevelDeprecated},
281284
Warnings: Warnings{
282285
IfConfigured: "This metric is deprecated and will be removed soon.",
283286
},
@@ -294,6 +297,7 @@ func TestLoadMetadata(t *testing.T) {
294297
Enabled: true,
295298
Description: "[DEPRECATED] Non-monotonic delta sum double metric enabled by default.",
296299
ExtendedDocumentation: "The metric will be removed soon.",
300+
Stability: Stability{Level: component.StabilityLevelDeprecated},
297301
Warnings: Warnings{
298302
IfEnabled: "This metric is deprecated and will be removed soon.",
299303
},
@@ -309,6 +313,7 @@ func TestLoadMetadata(t *testing.T) {
309313
Signal: Signal{
310314
Enabled: true,
311315
Description: "Monotonic cumulative sum int metric with string input_type enabled by default.",
316+
Stability: Stability{Level: component.StabilityLevelDevelopment},
312317
Attributes: []AttributeName{"string_attr", "overridden_int_attr", "enum_attr", "slice_attr", "map_attr"},
313318
},
314319
Unit: strPtr("s"),
@@ -359,7 +364,7 @@ func TestLoadMetadata(t *testing.T) {
359364
"batch_size_trigger_send": {
360365
Signal: Signal{
361366
Enabled: true,
362-
Stability: Stability{Level: "deprecated", From: "v0.110.0"},
367+
Stability: Stability{Level: component.StabilityLevelDeprecated, From: "v0.110.0"},
363368
Description: "Number of times the batch was sent due to a size trigger",
364369
},
365370
Unit: strPtr("{times}"),
@@ -371,7 +376,7 @@ func TestLoadMetadata(t *testing.T) {
371376
"request_duration": {
372377
Signal: Signal{
373378
Enabled: true,
374-
Stability: Stability{Level: "alpha"},
379+
Stability: Stability{Level: component.StabilityLevelAlpha},
375380
Description: "Duration of request",
376381
},
377382
Unit: strPtr("s"),
@@ -383,7 +388,7 @@ func TestLoadMetadata(t *testing.T) {
383388
"process_runtime_total_alloc_bytes": {
384389
Signal: Signal{
385390
Enabled: true,
386-
Stability: Stability{Level: "stable"},
391+
Stability: Stability{Level: component.StabilityLevelStable},
387392
Description: "Cumulative bytes allocated for heap objects (see 'go doc runtime.MemStats.TotalAlloc')",
388393
},
389394
Unit: strPtr("By"),
@@ -398,7 +403,7 @@ func TestLoadMetadata(t *testing.T) {
398403
"queue_length": {
399404
Signal: Signal{
400405
Enabled: true,
401-
Stability: Stability{Level: "alpha"},
406+
Stability: Stability{Level: component.StabilityLevelAlpha},
402407
Description: "This metric is optional and therefore not initialized in NewTelemetryBuilder.",
403408
ExtendedDocumentation: "For example this metric only exists if feature A is enabled.",
404409
},
@@ -415,6 +420,7 @@ func TestLoadMetadata(t *testing.T) {
415420
Signal: Signal{
416421
Enabled: true,
417422
Description: "Queue capacity - sync gauge example.",
423+
Stability: Stability{Level: component.StabilityLevelDevelopment},
418424
},
419425
Unit: strPtr("{items}"),
420426
Gauge: &Gauge{
@@ -513,6 +519,16 @@ func TestLoadMetadata(t *testing.T) {
513519
want: Metadata{},
514520
wantErr: "decoding failed due to the following error(s):\n\n'attributes[used_attr].type' invalid type: \"invalidtype\"",
515521
},
522+
{
523+
name: "testdata/invalid_metric_stability.yaml",
524+
want: Metadata{},
525+
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\"",
526+
},
527+
{
528+
name: "testdata/no_metric_stability.yaml",
529+
want: Metadata{},
530+
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`",
531+
},
516532
{
517533
name: "testdata/~~this file doesn't exist~~.yaml",
518534
wantErr: "unable to read the file file:testdata/~~this file doesn't exist~~.yaml",

cmd/mdatagen/internal/metric.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package internal // import "go.opentelemetry.io/collector/cmd/mdatagen/internal"
66
import (
77
"errors"
88
"fmt"
9-
"strings"
109

1110
"golang.org/x/text/cases"
1211
"golang.org/x/text/language"
@@ -48,18 +47,26 @@ type Metric struct {
4847
}
4948

5049
type Stability struct {
51-
Level string `mapstructure:"level"`
52-
From string `mapstructure:"from"`
50+
Level component.StabilityLevel `mapstructure:"level"`
51+
From string `mapstructure:"from"`
5352
}
5453

5554
func (s Stability) String() string {
56-
if s.Level == "" || strings.EqualFold(s.Level, component.StabilityLevelStable.String()) {
55+
if s.Level == component.StabilityLevelUndefined ||
56+
s.Level == component.StabilityLevelStable {
5757
return ""
5858
}
5959
if s.From != "" {
60-
return fmt.Sprintf(" [%s since %s]", s.Level, s.From)
60+
return fmt.Sprintf(" [%s since %s]", s.Level.String(), s.From)
6161
}
62-
return fmt.Sprintf(" [%s]", s.Level)
62+
return fmt.Sprintf(" [%s]", s.Level.String())
63+
}
64+
65+
func (s *Stability) Unmarshal(parser *confmap.Conf) error {
66+
if !parser.IsSet("level") {
67+
return errors.New("missing required field: `stability.level`")
68+
}
69+
return parser.Unmarshal(s)
6370
}
6471

6572
func (m *Metric) validate() error {
@@ -91,6 +98,9 @@ func (m *Metric) Unmarshal(parser *confmap.Conf) error {
9198
if !parser.IsSet("enabled") {
9299
return errors.New("missing required field: `enabled`")
93100
}
101+
if !parser.IsSet("stability") {
102+
return errors.New("missing required field: `stability`")
103+
}
94104
return parser.Unmarshal(m)
95105
}
96106

cmd/mdatagen/internal/sampleconnector/documentation.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ Monotonic cumulative sum int metric enabled by default.
1818
1919
The metric will be become optional soon.
2020
21-
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
22-
| ---- | ----------- | ---------- | ----------------------- | --------- |
23-
| s | Sum | Int | Cumulative | true |
21+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | Stability |
22+
| ---- | ----------- | ---------- | ----------------------- | --------- | --------- |
23+
| s | Sum | Int | Cumulative | true | Development |
2424
2525
#### Attributes
2626
@@ -38,17 +38,17 @@ The metric will be become optional soon.
3838
3939
The metric will be removed soon.
4040
41-
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
42-
| ---- | ----------- | ---------- | ----------------------- | --------- |
43-
| s | Sum | Double | Delta | false |
41+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | Stability |
42+
| ---- | ----------- | ---------- | ----------------------- | --------- | --------- |
43+
| s | Sum | Double | Delta | false | Deprecated |
4444
4545
### metric.input_type
4646
4747
Monotonic cumulative sum int metric with string input_type enabled by default.
4848
49-
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
50-
| ---- | ----------- | ---------- | ----------------------- | --------- |
51-
| s | Sum | Int | Cumulative | true |
49+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | Stability |
50+
| ---- | ----------- | ---------- | ----------------------- | --------- | --------- |
51+
| s | Sum | Int | Cumulative | true | Development |
5252
5353
#### Attributes
5454
@@ -74,9 +74,9 @@ metrics:
7474
7575
[DEPRECATED] Gauge double metric disabled by default.
7676
77-
| Unit | Metric Type | Value Type |
78-
| ---- | ----------- | ---------- |
79-
| 1 | Gauge | Double |
77+
| Unit | Metric Type | Value Type | Stability |
78+
| ---- | ----------- | ---------- | --------- |
79+
| 1 | Gauge | Double | Deprecated |
8080
8181
#### Attributes
8282
@@ -90,9 +90,9 @@ metrics:
9090
9191
[DEPRECATED] Gauge double metric disabled by default.
9292
93-
| Unit | Metric Type | Value Type |
94-
| ---- | ----------- | ---------- |
95-
| | Gauge | Double |
93+
| Unit | Metric Type | Value Type | Stability |
94+
| ---- | ----------- | ---------- | --------- |
95+
| | Gauge | Double | Deprecated |
9696
9797
#### Attributes
9898

cmd/mdatagen/internal/sampleconnector/metadata.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ metrics:
103103
enabled: true
104104
description: Monotonic cumulative sum int metric enabled by default.
105105
extended_documentation: The metric will be become optional soon.
106+
stability:
107+
level: development
106108
unit: s
107109
sum:
108110
value_type: int
@@ -117,6 +119,8 @@ metrics:
117119
enabled: true
118120
description: "[DEPRECATED] Non-monotonic delta sum double metric enabled by default."
119121
extended_documentation: The metric will be removed soon.
122+
stability:
123+
level: deprecated
120124
unit: s
121125
sum:
122126
value_type: double
@@ -128,6 +132,8 @@ metrics:
128132
metric.input_type:
129133
enabled: true
130134
description: Monotonic cumulative sum int metric with string input_type enabled by default.
135+
stability:
136+
level: development
131137
unit: s
132138
sum:
133139
value_type: int
@@ -140,6 +146,8 @@ metrics:
140146
optional.metric:
141147
enabled: false
142148
description: "[DEPRECATED] Gauge double metric disabled by default."
149+
stability:
150+
level: deprecated
143151
unit: "1"
144152
gauge:
145153
value_type: double
@@ -150,6 +158,8 @@ metrics:
150158
optional.metric.empty_unit:
151159
enabled: false
152160
description: "[DEPRECATED] Gauge double metric disabled by default."
161+
stability:
162+
level: deprecated
153163
unit: ""
154164
gauge:
155165
value_type: double

cmd/mdatagen/internal/samplefactoryreceiver/internal/metadata/generated_telemetry.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)