Skip to content

Commit 4314042

Browse files
Merge remote-tracking branch 'origin/main' into mdatagen_config_libs
2 parents cb82199 + 5a2da78 commit 4314042

114 files changed

Lines changed: 1455 additions & 513 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
change_type: bug_fix
2+
component: pkg/service
3+
note: Fix Prometheus config defaults mismatch when host is explicitly set in telemetry configuration.
4+
subtext: |
5+
When users explicitly configured the telemetry metrics section (e.g. to change the host),
6+
the Prometheus exporter boolean fields (WithoutScopeInfo, WithoutUnits, WithoutTypeSuffix)
7+
defaulted to nil/false instead of true, causing metric name format changes compared to the
8+
implicit default configuration. This fix applies the correct defaults during config unmarshaling.
9+
issues: [13867]
10+
change_logs: [user]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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. receiver/otlp)
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: Add `go_struct.ignore_default` flag to suppress default value generation for individual config fields.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [15156]
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+
Setting `go_struct.ignore_default: true` on a config field causes mdatagen to omit that field's default
20+
from the generated `createDefaultConfig` function, emitting `nil` for pointer fields
21+
and `configoptional.None` for optional fields.
22+
23+
# Optional: The change log or logs in which this entry should be included.
24+
# e.g. '[user]' or '[user, api]'
25+
# Include 'user' if the change is relevant to end users.
26+
# Include 'api' if there is a change to a library API.
27+
# Default: '[user]'
28+
change_logs: [api]
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. receiver/otlp)
7+
component: pkg/pdata
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "`pcommon.Value.AsString` no longer HTML-escapes `<`, `>`, and `&` inside `ValueTypeMap` and `ValueTypeSlice` values, matching the behavior already used for `ValueTypeStr`."
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [14662]
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, api]

.github/workflows/codeql-analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ jobs:
3939

4040
# Initializes the CodeQL tools for scanning.
4141
- name: Initialize CodeQL
42-
uses: github/codeql-action/init@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4.35.2
42+
uses: github/codeql-action/init@e46ed2cbd01164d986452f91f178727624ae40d7 # v4.35.3
4343
with:
4444
languages: go
4545

4646
- name: Autobuild
47-
uses: github/codeql-action/autobuild@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4.35.2
47+
uses: github/codeql-action/autobuild@e46ed2cbd01164d986452f91f178727624ae40d7 # v4.35.3
4848

4949
- name: Perform CodeQL Analysis
50-
uses: github/codeql-action/analyze@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4.35.2
50+
uses: github/codeql-action/analyze@e46ed2cbd01164d986452f91f178727624ae40d7 # v4.35.3

.github/workflows/go-benchmarks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ on:
77
pull_request:
88
workflow_dispatch:
99

10+
permissions: read-all
11+
1012
jobs:
1113
benchmarks:
1214
name: Run benchmarks

.github/workflows/scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ jobs:
6464

6565
# Upload the results to GitHub's code scanning dashboard.
6666
- name: "Upload to code-scanning"
67-
uses: github/codeql-action/upload-sarif@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4.35.2
67+
uses: github/codeql-action/upload-sarif@e46ed2cbd01164d986452f91f178727624ae40d7 # v4.35.3
6868
with:
6969
sarif_file: results.sarif

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ Working with the project sources requires the following tools:
231231
2. [Go](https://go.dev/) (version 1.25 and up)
232232
3. [GNU Make](https://www.gnu.org/software/make/)
233233
4. [Docker](https://www.docker.com/)
234+
5. [OpenSSL Library](https://openssl-library.org/) (for the `config/configtls` component)
234235

235236
## Repository Setup
236237

cmd/mdatagen/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ require (
5656
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
5757
github.com/felixge/httpsnoop v1.0.4 // indirect
5858
github.com/foxboron/go-tpm-keyfiles v0.0.0-20251226215517-609e4778396f // indirect
59-
github.com/fsnotify/fsnotify v1.9.0 // indirect
59+
github.com/fsnotify/fsnotify v1.10.1 // indirect
6060
github.com/go-logr/logr v1.4.3 // indirect
6161
github.com/go-logr/stdr v1.2.2 // indirect
6262
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
@@ -67,7 +67,7 @@ require (
6767
github.com/hashicorp/go-version v1.9.0 // indirect
6868
github.com/inconshreveable/mousetrap v1.1.0 // indirect
6969
github.com/json-iterator/go v1.1.12 // indirect
70-
github.com/klauspost/compress v1.18.5 // indirect
70+
github.com/klauspost/compress v1.18.6 // indirect
7171
github.com/knadh/koanf/maps v0.1.2 // indirect
7272
github.com/knadh/koanf/providers/confmap v1.0.0 // indirect
7373
github.com/knadh/koanf/v2 v2.3.4 // indirect
@@ -103,7 +103,7 @@ require (
103103
golang.org/x/sync v0.20.0 // indirect
104104
golang.org/x/sys v0.43.0 // indirect
105105
google.golang.org/genproto/googleapis/rpc v0.0.0-20260406210006-6f92a3bedf2d // indirect
106-
google.golang.org/grpc v1.80.0 // indirect
106+
google.golang.org/grpc v1.81.0 // indirect
107107
google.golang.org/protobuf v1.36.11 // indirect
108108
gopkg.in/yaml.v3 v3.0.1 // indirect
109109
)

cmd/mdatagen/go.sum

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

cmd/mdatagen/internal/cfggen/generation.go

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func NewCfgFns(rootPackage, componentPackage string) map[string]any {
2525
}
2626
imports, err := ExtractImports(cfg, rootPackage, componentPackage)
2727
if err != nil {
28-
return []string{}
28+
panic(err)
2929
}
3030
return imports
3131
},
@@ -202,7 +202,10 @@ func collectImports(md *ConfigMetadata, imports map[string]bool, rootPackage, co
202202

203203
if md.GoType != "" {
204204
ref, err := ResolveGoTypeRef(md.GoType, rootPackage, componentPackage)
205-
if err == nil && ref.ImportPath != "" {
205+
if err != nil {
206+
return fmt.Errorf("failed to resolve import for custom type %q: %w", md.GoType, err)
207+
}
208+
if ref.ImportPath != "" {
206209
imports[ref.ImportPath] = true
207210
}
208211
}
@@ -217,11 +220,17 @@ func collectImports(md *ConfigMetadata, imports map[string]bool, rootPackage, co
217220

218221
if md.ResolvedFrom != "" {
219222
ref, err := ResolveGoTypeRef(md.ResolvedFrom, rootPackage, componentPackage)
220-
if err == nil && ref.ImportPath != "" {
223+
if err != nil {
224+
return fmt.Errorf("failed to resolve import for reference %q: %w", md.ResolvedFrom, err)
225+
}
226+
if ref.ImportPath != "" {
221227
imports[ref.ImportPath] = true
222228
}
223229
refDesc := NewRef(md.ResolvedFrom)
224230
if !refDesc.isInternal() {
231+
if err := collectCustomDefaultImports(md, md.Default, imports, rootPackage, componentPackage); err != nil {
232+
return err
233+
}
225234
return nil
226235
}
227236
}
@@ -271,6 +280,42 @@ func collectImports(md *ConfigMetadata, imports map[string]bool, rootPackage, co
271280
return nil
272281
}
273282

283+
func collectCustomDefaultImports(md *ConfigMetadata, defaultValue any, imports map[string]bool, rootPackage, componentPackage string) error {
284+
if md == nil || md.GoStruct.IgnoreDefault {
285+
return nil
286+
}
287+
288+
switch typedValue := defaultValue.(type) {
289+
case map[string]any:
290+
if md.AdditionalProperties != nil {
291+
return nil
292+
}
293+
for key, value := range typedValue {
294+
prop := md.Properties[key]
295+
if prop == nil {
296+
continue
297+
}
298+
if err := collectImports(prop, imports, rootPackage, componentPackage); err != nil {
299+
return err
300+
}
301+
if err := collectCustomDefaultImports(prop, value, imports, rootPackage, componentPackage); err != nil {
302+
return err
303+
}
304+
}
305+
case []any:
306+
if md.Items == nil || md.Items.Type != "object" {
307+
return nil
308+
}
309+
for _, item := range typedValue {
310+
if err := collectCustomDefaultImports(md.Items, item, imports, rootPackage, componentPackage); err != nil {
311+
return err
312+
}
313+
}
314+
}
315+
316+
return nil
317+
}
318+
274319
func hasValidators(md *ConfigMetadata) bool {
275320
return md.GoStruct.CustomValidator != nil || // custom validation
276321
len(md.Required) > 0 || // required validation
@@ -458,8 +503,10 @@ func generateValidatorName(propName string, desc *CustomValidatorConfig) string
458503
}
459504

460505
func MapCustomDefaults(schema *ConfigMetadata, defaultValue any, rootPackage, componentPackage string) []string {
506+
if schema.GoStruct.IgnoreDefault {
507+
return nil
508+
}
461509
exps := make([]string, 0)
462-
463510
switch typedValue := defaultValue.(type) {
464511
case map[string]any:
465512
// is nested struct
@@ -493,12 +540,25 @@ func MapCustomDefaults(schema *ConfigMetadata, defaultValue any, rootPackage, co
493540
}
494541

495542
func FormatDefaultValue(md *ConfigMetadata, name string, defaultValue any, rootPackage, componentPackage string) string {
543+
if md.GoStruct.IgnoreDefault || (defaultValue == nil && !hasDefaultValue(md)) {
544+
if md.IsPointer {
545+
return "nil"
546+
}
547+
if md.IsOptional {
548+
t, _ := resolveGoType(md, name, rootPackage, componentPackage)
549+
return fmt.Sprintf("configoptional.None[%s]()", t)
550+
}
551+
return ""
552+
}
496553
exp := formatSimpleValue(md, name, defaultValue, rootPackage, componentPackage)
497554
if md.IsPointer {
498-
exp = "&" + exp
555+
return "&" + exp
499556
}
500557
if md.IsOptional {
501-
exp = fmt.Sprintf("configoptional.Some(%s)", exp)
558+
if md.Type == "object" && md.Properties != nil {
559+
return fmt.Sprintf("configoptional.Default(%s)", exp)
560+
}
561+
return fmt.Sprintf("configoptional.Some(%s)", exp)
502562
}
503563
return exp
504564
}
@@ -514,16 +574,19 @@ func FormatBaseValue(md *ConfigMetadata, name string, defaultValue any, rootPack
514574
func WrapDefaultValue(md *ConfigMetadata, varName string) string {
515575
exp := varName
516576
if md.IsPointer {
517-
exp = "&" + exp
577+
return "&" + exp
518578
}
519579
if md.IsOptional {
520-
exp = fmt.Sprintf("configoptional.Some(%s)", exp)
580+
if md.Type == "object" && md.Properties != nil {
581+
return fmt.Sprintf("configoptional.Default(%s)", exp)
582+
}
583+
return fmt.Sprintf("configoptional.Some(%s)", exp)
521584
}
522585
return exp
523586
}
524587

525588
func hasDefaultValue(md *ConfigMetadata) bool {
526-
if md.Default != nil {
589+
if !md.GoStruct.IgnoreDefault && md.Default != nil {
527590
return true
528591
}
529592
for _, prop := range md.Properties {
@@ -569,8 +632,8 @@ func formatSimpleValue(md *ConfigMetadata, name string, defaultValue any, rootPa
569632
return ""
570633
}
571634

572-
// do not process further if "default" attribute not defined
573-
if defaultValue == nil {
635+
// do not process further if "ignore_default" attribute set
636+
if md.GoStruct.IgnoreDefault {
574637
return ""
575638
}
576639

0 commit comments

Comments
 (0)