Commit Graph

14 Commits

Author SHA1 Message Date
Evan Bradley 511f0464b6
[chore][confmap] Move functionality to the internal package (#13555)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Move substantial amounts of confmap's functionality to the internal
package. This allows us to share the functionality with xconfmap and
therefore add experimental functionality to confmap without risking
breaking changes.

I'm not a huge fan of the added indirection this introduces, but I think
this is a fairly standard pattern, is fairly straightforward to trace
from the top-level package down (e.g. confmap.Conf -> internal.Conf),
and is probably the simplest way to accomplish this.

<!-- Issue number if applicable -->
#### Link to tracking issue

Likely required for
https://github.com/open-telemetry/opentelemetry-collector/issues/13421
2025-08-06 16:10:54 +00: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 6f2729780d
[confmap] Remove original representation if invalid (#10795)
<!--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 -->

Removes original string representation if invalid.

#### Link to tracking issue

Fixes #10787

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

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

Added e2e test cases
2024-08-05 13:07:26 +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
Tyler Helmuth 3caaf168fc
[confmap] Allow more recursion and URI expansions (#10712)
#### Description
Bumps the limit of how much recursion we allow. This check is also
gating non-recursive expansions. We probably could separate these
concerns, but thats work that isn't really worthwhile, a simple constant
bump is simple and will cover most users. For the rest, there are
workarounds.

<!-- Issue number if applicable -->
#### Link to tracking issue
Fixes
https://github.com/open-telemetry/opentelemetry-collector/issues/10617
2024-07-24 10:13:14 +02:00
Pablo Baeyens 75aeab0f1d
[chore] Rename internal/featuregates to internal/globalgates (#10614)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Fixes #10569. However, I think it's fine to just close the issue as
wontfix and not do this.
2024-07-15 16:11:37 +02:00
Tyler Helmuth 637b1f42fc
[confmap] Fix bug where expand didn't honor escaping (#10560)
#### Description

When we promoted `confmap.unifyEnvVarExpansion` to beta, we found that
the new expansion logic in `confmap` wasn't handling escaping of `$$`
like it is supposed to. This PR fixes that bug, but adding escaping
logic for `$$`.

@azunna1 this fixes the bug you mentioned in
https://github.com/open-telemetry/opentelemetry-collector/pull/10435
around the metricstransformprocessor:

```yaml
  metricstransform:
    transforms:
      - include: '^k8s\.(.*)\.(.*)$$'
        match_type: regexp
        action: update
        new_name: 'kubernetes.$${1}.$${2}'
      - include: '^container_([0-9A-Za-z]+)_([0-9A-Za-z]+)_.*'
        match_type: regexp
        action: update
        new_name: 'container.$${1}.$${2}'
```

#### Testing
Added new unit tests explicitly for escaping logic
2024-07-10 07:17:41 -07:00
Pablo Baeyens b127da0890
[chore] Make internal/featuregates into a module, move confmap fg there (#10532)
#### Description

Create new internal module `internal/featuregates`.

This will be useful for importing feature gates while not creating a
dependency cycle.

I intend to use this for importing `confmap.strictlyTypedInput` in
`otelcol` in a follow up PR.
2024-07-05 09:17:05 -07: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
Tyler Helmuth 65d59d1401
[confmap] remove bool logic from expandURI (#10403)
expandURI can always be viewed as changing the value as long as no error
is returned.
2024-06-13 21:04:40 +02:00
Tyler Helmuth eaab76e46d
[confmap] Add ability to set default provider (#10182)
#### Description
This PR adds support for expanding `${}` syntax when no schema is
provided by allowing Resolver to use a default provider.

In a followup PR I'll update otelcol with a feature gate that allow
switching between a default envProvider and the expandconverter.

#### Link to tracking issue
Related to
https://github.com/open-telemetry/opentelemetry-collector/issues/10161
Related to
https://github.com/open-telemetry/opentelemetry-collector/issues/7111

#### Testing
Added unit tests

#### Documentation
Added godoc strings

---------

Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
2024-05-29 15:39:53 -07:00
Bogdan Drutu 0a9c4ffe64
[chore] cleanup tostring function, remove unclear uri parameter (#10244)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2024-05-28 10:54:42 -07: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
Mackenzie fe508cfe83
confmap: Add support for nested URIs (#7504)
* confmap: Add support for nested URIs

Addresses #7117.

This PR adds support for nesting URIs, e.g.
```
test: "${http://example.com/?os=${env:OS}}"
```
**Breaking change:**
In the case of an InvalidScheme, error `invalid uri: "g_c_s:VALUE"` will be thrown. Previously, no error was thrown (see [test case](https://github.com/open-telemetry/opentelemetry-collector/blob/v0.74.0/confmap/resolver_test.go#L623-L625)).

Other than the above, there will be no breaking changes. Although the parser now provides the ability to understand why parsing a URI fails (e.g. missing opening `${`), no errors will be thrown to preserve the previous behaviour.

The old way to expand env vars (e.g. `${HOST}`) is not supported in nested URIs, as expanding the old way is done in a converter. This has been documented.

* add issue # to changelog

* address feedback

* address feedback

* address feedback

* Address feedback: change expandStringURI & preserve comment

* Address feedback: move recursion to findURI

* Address feedback: avoid duplicate calls to findURI

* Update confmap/expand.go

Co-authored-by: Bogdan Drutu <lazy@splunk.com>

* Address Feedback

* remove unused errURILimit

* update findURI documentation

* fix test

* Update confmap/expand.go

* Address feedback: remove named return values

---------

Co-authored-by: Bogdan Drutu <lazy@splunk.com>
2023-04-15 12:47:19 -07:00