Commit Graph

30 Commits

Author SHA1 Message Date
7h3-3mp7y-m4n 64088871ef
refactor: replace sigs.k8s.io/yaml with go.yaml.in/yaml (#13309)
<!-- Issue number if applicable -->
#### Link to tracking issue
Fixes #13308 

### Summary
This PR replaces the YAML parsing library `sigs.k8s.io/yaml` with
`go.yaml.in/yaml`.

---------

Signed-off-by: 7h3-3mp7y-m4n <emailtorash@gmail.com>
2025-07-01 16:39:47 +00:00
Antoine Toulme 829157cef7
[chore] add checkapi to tools (#12954)
Adds checkapi to the tools and a make target to run it.

Fixes #12360

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
2025-05-05 15:52:16 +00:00
Alex Boten 582fbbe3fa
update yaml dependency (#12838)
#### Description

This updates replace gopkg.in/yaml.v3 with sigs.k8s.io/yaml

#### Link to tracking issue
Fixes #12827

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
2025-04-15 14:52:19 +00:00
Antoine Toulme b3e68c3756
[chore] prevent unkeyed literal initialization (#12762)
This relates to
https://github.com/open-telemetry/opentelemetry-collector/issues/12360

Co-authored-by: Andrzej Stencel <andrzej.stencel@elastic.co>
2025-04-15 08:18:07 +00:00
Pablo Baeyens e7f071d43c
[confmap] Add error hint when invalid YAML was passed (#12180)
<!--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 -->

Add error hint field to surface YAML parsing errors. This only surfaces
the error for top-level URIs but it's a step in the right direction.

Error when passing a file with contents `[invalid:,` as the config:

Before:
```
retrieved value (type=string) cannot be used as a Conf
```

After: 
```
retrieved value (type=string) cannot be used as a Conf: assuming string type since contents are not valid YAML: yaml: line 1: did not find expected node content
```

#### Link to tracking issue
Updates #12000

<!--Describe what testing was performed and which tests were added.-->
#### Testing

<!--Describe the documentation added.-->
#### Documentation

<!--Please delete paragraphs that you did not use before submitting.-->
2025-02-25 10:05:21 +00:00
Matthew Sainsbury 96ba827bb0
doc: add detail to confmap watcher (#12150)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
I tried to improve the docs on watchers based on the issue below
<!-- Issue number if applicable -->
#### Link to tracking issue
Fixes #12115


<!--Describe the documentation added.-->
#### Documentation
Clarified some code comments that were incorrect (there's no
Retrieved.Get method) and included a new code sample for a Provider that
uses the watcher func
<!--Please delete paragraphs that you did not use before submitting.-->
2025-01-28 15:00:06 +00:00
Iris Grace Endozo 431fd11c8f
[confmap] Support expansion for environment variables with time formats (#11241)
#### Description

This addresses
https://github.com/open-telemetry/opentelemetry-collector/issues/10659.
In https://github.com/open-telemetry/opentelemetry-collector/pull/10800
we removed restrictions on the types that can be allowed if expanded but
in our case, this still fails because of the checks existing in
`provider.checkRawConfType()`

This adds `time.Time` as a type in the `provider.checkRawConfType()`
instead of removing it completely.

#### Link to tracking issue
Fixes
https://github.com/open-telemetry/opentelemetry-collector/issues/10659

<!--Describe what testing was performed and which tests were added.-->
#### Testing
- added a test case to handle time formats in provider.go and expand.go
- added an e2e test case to handle time formats
2024-09-26 22:27:58 -07:00
Bogdan Drutu 8027d80aef
Avoid public APIs with internal params in custom Options (#11054)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2024-09-17 13:08:41 -07:00
Pablo Baeyens e477c3a348
[confmap] Mark `confmap.strictlyTypedInput` as stable (#10793)
<!--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
2024-08-20 10:04:59 +02:00
Pablo Baeyens 93cbae436a
[confmap] Allow using any type as a string (#10800)
<!--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>
2024-08-05 17:51:55 +02:00
Pablo Baeyens 78df5c7243
[confmap] Use values as string if YAML is invalid (#10794)
<!--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 -->

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

<!--Describe what testing was performed and which tests were added.-->
#### Testing

<!--Describe the documentation added.-->

Added test case for this.
2024-08-05 10:15:46 +02:00
Pablo Baeyens 0001db2759
[confmap] Store original string in confmap.Conf (#10618)
<!--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 -->

- Adds new `expandedValue` struct that holds the original string
representation if available for values resolved from a provider.
- Removes any mention of `expandedValue` in the public API by adding a
`sanitize` step before returning any `Get`s or `ToStringMap`s.
- Adds new decoding hook that checks if the target field is of `string`
type and uses the string representation in that case.



#### Link to tracking issue

Fixes #10605, Fixes #10405, Fixes #10659

<!--Describe what testing was performed and which tests were added.-->
#### Testing

<!--Describe the documentation added.-->

This changes the behavior in some cases, I update the test cases.

#### Documentation

<!--Please delete paragraphs that you did not use before submitting.-->

| ENV value | ${ENV} before unification | ${ENV} in v0.105.0 (also
${env:ENV} before unification) | Value after this PR |

|----------------------------|----------------------------|---------------------------------------------------------|----------------------------|
| foo\nbar | foo\nbar | foo bar | foo\nbar |
| 1111:1111:1111:1111:1111:: | 1111:1111:1111:1111:1111:: | **Error** |
1111:1111:1111:1111:1111:: |
| "0123" | "0123" | 0123 | "0123" |
2024-07-25 10:06:08 +02:00
Pablo Baeyens e8a911bbdb
[confmap] Allow using map[string]any as string (#10615)
<!--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 -->

Allow using strings parseable in YAML as `map[string]any` in inline
position

#### Link to tracking issue

Relates to #10605 (does not fix it since it's not in inline position)
2024-07-16 17:25:20 +02:00
Pablo Baeyens 7a3c35cb77
[confmap] Add strict type validation under a feature gate (#10400)
#### Description

<!-- Issue number if applicable -->

- Add `confmap.strictlyTypedInput` feature gate that introduces stricter
type checks when resolving configuration
- Make `confmap.NewRetrievedFromYAML` function public so that external
providers have consistent behavior when resolving YAML
- Adds `confmap.Retrieved.AsString` method to retrieve string
representation for retrieved values

#### Link to tracking issue

Relates to #9854, updates #8565, #9532
2024-06-17 13:29:35 +02:00
Antoine Toulme d55d04226e
[chore] remove TODO from confmap code (#10278)
Remove a TODO comment on confmap/provider.go related to ChangeEvent.
This struct is used extensively in providers that rely on changes such
as:

https://github.com/signalfx/splunk-otel-collector/blob/main/internal/configsource/etcd2configsource/source.go#L84
2024-05-31 10:28:50 -07:00
Evan Bradley 2108ae88f5
[confmap] Add converter and provider settings to confmap.ResolverSettings (#9516)
**Description:**

Follows
https://github.com/open-telemetry/opentelemetry-collector/pull/9443,
relates to
https://github.com/open-telemetry/opentelemetry-collector/pull/9513.

This builds on
https://github.com/open-telemetry/opentelemetry-collector/pull/9228 to
demonstrate the concept.

This shows one way of extending the otelcol APIs to allow passing
converters and providers from the builder with the new settings structs
for each type.

I think this approach has a few advantages:
1. This follows our pattern of passing in "factory" functions instead of
instances to the object that actually uses the instances.
2. Makes the API more declarative: the settings specify which modules to
instantiate and which settings to instantiate them with, but don't
require the caller to actually do this.
3. Compared to the current state, this allows us to update the config at
different layers. A distribution's `main.go` file can specify the
providers/converters it wants and leave the settings to be created by
`otelcol.Collector`.

The primary drawbacks I see here are:
1. This is a little more opinionated since you don't have access to the
converter/provider instances or control how they are instantiated. I
think this is acceptable and provides good encapsulation.
2. The scheme->provider map can now only be specified by the providers'
schemes, which is how it is currently done by default. I would want to
hear what use cases we see for more complex control here that
necessitates using schemes not specified by the providers.

cc @mx-psi

---------

Co-authored-by: Evan Bradley <evan-bradley@users.noreply.github.com>
2024-04-18 18:01:01 +02:00
Ankit Patel 4f1a8936d2
Log when Environment Provider tries to pull unset or empty env var (#9837)
**Description:** 
Creates a logger in the confmap.ProviderSettings and uses it to log when
there is a missing or blank environment variable referenced in config.
For now the noop logger is used everywhere except tests.

**Link to tracking Issue:**
[5615](https://github.com/open-telemetry/opentelemetry-collector/issues/5615)

**Testing:** 
I wrote unit tests that ensured 

1. logging occurred when an environment variable was unset 
2. logging occcured when the env var was empty.  
3. there was no log when an env var was used correctly

I also started the otel collector with the sample config - and added an
env var reference in the sample config. I then inserted a print
statement next to each log call to see whether my code paths were hit in
the live application. I then went through the 3 cases mentioned above
and ensured that logging behavior was accurate.
2024-04-04 14:11:16 +02:00
Pablo Baeyens 11d8d52523
[confmap] Pass ConverterSettings and ProviderSettings to converters and providers (#9443)
**Description:** 

For both #5615 and #9162 we need to be able to log during the confmap
resolution.

My proposed solution is to pass a `*zap.Logger` to converters and
providers during initialization. These components can then use this to
log any warnings they need. This PR does the first step: being able to
pass anything to converters and providers during initialization.

The obvious alternative to this is to change the interface of
`confmap.Provider` and `confmap.Converter` to pass any warnings in an
explicit struct. I think the `*zap.Logger` alternative is more natural
for developers of providers and converters: you just use a logger like
everywhere else in the Collector.

One problem for the Collector usage of `confmap` is: How does one pass a
`*zap.Logger` before knowing how a `*zap.Logger` should be configured? I
think we can work around this by:
1. Passing a special 'deferred' Logger that just stores the warnings
without actually logging them (we can use something like
`zaptest/observer` for this)
2. Resolving configuration
3. Building a `*zap.Logger` with said configuration
4. Logging the entries stored in (1) with the logger from (3) (using
`zaptest/observer` we can do that by taking the `zapcore.Core` out of
the logger and manually writing)

**We don't actually need ProviderSettings today, just ConverterSettings,
but I think it can still be useful.**

**Link to tracking Issue:** Relates to #5615 and #9162

---------

Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
2024-02-01 05:48:52 -08:00
Alex Boten 80d704deb4
[chore] use license shortform (#7694)
* [chore] use license shortform

To remain consistent w/ contrib repo, see https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/22052

Signed-off-by: Alex Boten <aboten@lightstep.com>

* make goporto

Signed-off-by: Alex Boten <aboten@lightstep.com>

---------

Signed-off-by: Alex Boten <aboten@lightstep.com>
2023-05-18 13:11:17 -07:00
Sean Marciniak 2f0adc4344
[Provider] Include user friendly error (#7430)
* Adding error update in provider

* Adding changelog entry
2023-03-27 12:29:28 -07:00
Bogdan Drutu a2f0153679
[chore] replace the usage of interface{} with any (#7053)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2023-01-30 15:01:25 -08:00
Bogdan Drutu 121257178e
Enforce scheme name restrictions to all confmap.Provider implementations. (#5861)
Currently was documented that the format should be compatible with the URI definition (see https://datatracker.ietf.org/doc/html/rfc3986),
but the scheme name restriction was not copied from the RFC, and no tests to enforce. This PR clearly documents the characters allowed in the scheme name and add confmaptest helper func to test for valid scheme names.

Signed-off-by: Bogdan <bogdandrutu@gmail.com>
2022-08-09 10:17:42 -07:00
Bogdan Drutu 0b8698504c
Breaking Change: Change confmap.Provider to return pointer to Retrieved. (#5839)
This change makes implementations cleaner, since they can return `nil, err` in case of an error instead of a zero initialized Retrieved.

This is a breaking change, but there are very very few implementation of the Provider, so it should be safe to just break it.

Signed-off-by: Bogdan <bogdandrutu@gmail.com>
2022-08-09 08:40:20 -07:00
Bogdan Drutu 6f336e9a42
Use pointer for Retrieved.Close, consistency with all the other funcs (#5838)
Signed-off-by: Bogdan <bogdandrutu@gmail.com>
2022-08-05 13:26:06 -07:00
Bogdan Drutu 1c1a668faf
Add support in the confmap.Resolver to expand embedded config URIs inside configuration. (#4742)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2022-08-04 14:01:53 -07:00
Alex Boten f513448463
add go 1.19 to tests (#5791)
Adding the latest version of go to the tests run by CI. To pass the tests, the following changes were required:
- run make genpdata
- fix test certificates to address errors caused by the rejection of duplicate extensions in TLS handshakes
2022-08-03 09:55:10 -07:00
Bogdan Drutu c9913c3cc4
remove code deprecated in v0.53.0 (#5505)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2022-06-09 10:04:53 -07:00
Bogdan Drutu 086cc6891a
Deprecate confmap.Received.AsMap in favor of confmap.Received.AsConf (#5465)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2022-06-03 05:13:35 -07:00
Bogdan Drutu e0cf05e6dc
Replace NewRetrievedFromMap with NewRetrieved (#5468)
It is ok to change NewRetrievedFromMap to NewRetrieved since it was just moved, not yet released. This is a step towards supporting providing any value type.

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2022-06-03 04:38:02 -07:00
Bogdan Drutu 3356863030
Move config.Map to its own package which does not depend on any component concept (#5237)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2022-05-31 10:51:24 -07:00