Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[confmap] Use values as string if YAML is invalid #10794

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

mx-psi
Copy link
Member

@mx-psi mx-psi commented Aug 2, 2024

Description

If YAML parsing fails, assume the user wanted to pass the value as a string.

This has the downside that the error messages are less informative: it will tell you it expected something other than a string instead of the YAML parser error.

A future improvement could be to pass these errors down as extra metadata up until the unmarshaling stage.

Link to tracking issue

Fixes #10759

Testing

Added test case for this.

@mx-psi mx-psi force-pushed the mx-psi/fix-invalid-yaml-string branch 2 times, most recently from ce31624 to cf4efcf Compare August 2, 2024 11:40
@mx-psi mx-psi force-pushed the mx-psi/fix-invalid-yaml-string branch from cf4efcf to 27c66f5 Compare August 2, 2024 11:42
@mx-psi mx-psi marked this pull request as ready for review August 2, 2024 11:48
@mx-psi mx-psi requested review from a team and TylerHelmuth August 2, 2024 11:48
Copy link

codecov bot commented Aug 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.70%. Comparing base (2beed98) to head (27c66f5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10794      +/-   ##
==========================================
- Coverage   91.70%   91.70%   -0.01%     
==========================================
  Files         406      406              
  Lines       18952    18955       +3     
==========================================
+ Hits        17380    17382       +2     
- Misses       1212     1213       +1     
  Partials      360      360              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@TylerHelmuth TylerHelmuth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test to replicate the issue in #10787

@TylerHelmuth
Copy link
Member

NVM, I see the second PR

@mx-psi mx-psi merged commit 78df5c7 into open-telemetry:main Aug 5, 2024
58 of 67 checks passed
@github-actions github-actions bot added this to the next release milestone Aug 5, 2024
mx-psi added a commit that referenced this pull request Aug 5, 2024
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Allows any type to be used as a string if the target field is a string
or the value is expanded in inline position. Inspired by #10794. This is
not a breaking change (previously we would return an error for these).

Some things that you can do after this PR that you couldn't do before
it:

1. Set `HOST` to `[2001:db8::8a2e:370:7334]` and use it in an endpoint:
```yaml
exporters:
  otlp:
    endpoint: http://${env:HOST}/api/v1/traces
```

2. Pass really big numbers as strings (e.g. `10000000000000000000`)

3. Pass `null` as a string.

<details>
<summary>Types that can be returned by our current YAML parser</summary>

Our current way of using the YAML parser has these types: `string`,
`nil`, `int`, `uint64`, `float64`, `map[any]any`, `map[string]any`,
`[]any`.

There is no documentation for this, but the following fuzzing test did
not find any failing cases after 20 minutes of continous run:

```go
package main

import (
	"testing"
	"gopkg.in/yaml.v3"
)

func FuzzTest(f *testing.F) {
	f.Fuzz(func(t *testing.T, data []byte){
		var b any
		err := yaml.Unmarshal([]byte(data), &b)
		if err != nil {
			return
		}

		switch b.(type) {
			case string, nil, int, uint64, float64, map[any]any, map[string]any, []any:
				return
			default:
			  t.Errorf("Unexpected type %T", b)
		}
	})	
}

```
</details>
mx-psi added a commit that referenced this pull request Aug 20, 2024
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

<!-- Issue number if applicable -->

Marks `confmap.strictlyTypedInput` as stable.

#### Link to tracking issue

Fixes #10552

Blocked by:
- #10794
- #10795
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Docker Secrets for Configuration Values
3 participants