Skip to content

Commit 0630965

Browse files
authored
Merge branch 'main' into 13956
2 parents f4a8bae + 6f29b34 commit 0630965

File tree

66 files changed

+629
-336
lines changed

Some content is hidden

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

66 files changed

+629
-336
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: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: cmd/builder
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Set CGO_ENABLED=0 by default, add the `cgo_enabled` configuration to enable it."
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [10028]
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]
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: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: exporter/debug
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: add queue configuration
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [14101]
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: []
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/builder/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,14 @@ file for the following things after `go get`ing all components and calling
222222
The `--skip-strict-versioning` flag disables these versioning checks.
223223
This flag is available temporarily and
224224
**will be removed in a future minor version**.
225+
226+
### Cgo disabled by default
227+
228+
By default, the OpenTelemetry Collector binary is built with `CGO_ENABLED=0` in accordance with
229+
how the official OpenTelemetry Collector releases are built. This can be overridden by adding
230+
the following configuration option to the `dist` section of the builder configuration file:
231+
232+
```yaml
233+
dist:
234+
cgo_enabled: true
235+
```

cmd/builder/internal/builder/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type Distribution struct {
7373
Version string `mapstructure:"version"`
7474
BuildTags string `mapstructure:"build_tags"`
7575
DebugCompilation bool `mapstructure:"debug_compilation"`
76+
CGoEnabled bool `mapstructure:"cgo_enabled"`
7677
}
7778

7879
// Module represents a receiver, exporter, processor or extension for the distribution

cmd/builder/internal/builder/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ func runGoCommand(cfg *Config, args ...string) ([]byte, error) {
4040
cmd := exec.Command(cfg.Distribution.Go, args...)
4141
cmd.Dir = cfg.Distribution.OutputPath
4242

43+
cmd.Env = os.Environ()
44+
if cfg.Distribution.CGoEnabled {
45+
cmd.Env = append(cmd.Env, "CGO_ENABLED=1")
46+
} else {
47+
cmd.Env = append(cmd.Env, "CGO_ENABLED=0")
48+
}
49+
4350
var stdout, stderr bytes.Buffer
4451
cmd.Stdout = &stdout
4552
cmd.Stderr = &stderr
@@ -127,6 +134,9 @@ func Compile(cfg *Config) error {
127134
gcflags = cfg.GCFlags
128135
}
129136
}
137+
if cfg.Distribution.CGoEnabled {
138+
cfg.Logger.Info("Building with cgo enabled")
139+
}
130140

131141
args = append(args, "-ldflags="+ldflags, "-gcflags="+gcflags)
132142

cmd/builder/internal/builder/main_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,16 @@ func TestGenerateAndCompile(t *testing.T) {
327327
return cfg
328328
},
329329
},
330+
{
331+
name: "CGoEnabled set to true",
332+
cfgBuilder: func(t *testing.T) *Config {
333+
cfg := newTestConfig(t)
334+
cfg.Distribution.OutputPath = t.TempDir()
335+
cfg.Replaces = append(cfg.Replaces, replaces...)
336+
cfg.Distribution.CGoEnabled = true
337+
return cfg
338+
},
339+
},
330340
}
331341

332342
for _, tt := range testCases {

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

0 commit comments

Comments
 (0)