Commit Graph

37 Commits

Author SHA1 Message Date
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
Matthieu MOREL 564818fd7f
[chore]: fix testifylint rules (#12791)
#### Description

Fixes testifylint rules which where disabled with golangci-lint v2
upgrade

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-04-02 23:10:07 +00:00
Antoine Toulme 0fa0edb80c
[chore] unexport test structs (#12761)
A simple refactoring to unexport structs used in testing.
2025-03-31 15:36:15 +00:00
Matthew Sainsbury 7d3e03e500
[chore] replace deprecated tenv with usetesting (#12576)
#### Description
There are a bunch of warnings in the lint output about tenv being
deprecated, and moving to usetesting. Reference:
https://golangci-lint.run/usage/linters/#tenv

#### Link to tracking issue
none

#### Testing
Ran `make golint` and `make all`
<!--Describe the documentation added.-->

---------

Co-authored-by: Pablo Baeyens <pablo.baeyens@datadoghq.com>
2025-03-07 19:42:15 +00:00
Vihas Makwana 6e82944c1a
[confmap] - new feature flag for append merging strategy (#12097)
Koanf's default merging strategy currently overrides static values such
as slices, numbers, and strings. However, lists of components should be
treated as a special case. This pull request introduces a new command
line option to allow for merging lists instead of discarding the
existing ones.

With this new merging strategy:
- All the lists are merged rather than replaced.
- The merging logic is name-aware, meaning that if components with the
same name appear in both lists, they will only appear once in the final
merged list.

<!-- Issue number if applicable -->
#### Link to tracking issue
Related issues:
- https://github.com/open-telemetry/opentelemetry-collector/issues/8754
- https://github.com/open-telemetry/opentelemetry-collector/issues/8394
- https://github.com/open-telemetry/opentelemetry-collector/issues/10370

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

<!--Describe the documentation added.-->
#### Documentation
- Added under readme.


##### Example
Consider the following configs,

```yaml
# main.yaml
receivers:
  otlp/in:
processors:
  batch:
exporters:
  otlp/out:
extensions:
  file_storage:

service:
  pipelines:
    traces:
      receivers: [ otlp/in ]
      processors: [ batch ]
      exporters: [ otlp/out ]
  extensions: [ file_storage ]
```


```yaml
# extra_extension.yaml
extensions:
  healthcheckv2:

service:
  extensions: [ healthcheckv2 ]
```

If you run the collector with following command,
```
otelcol --config=main.yaml --config=extra_extension.yaml --feature-gates=-confmap.enableMergeAppendOption
```
then the final configuration after config resolution will look like
following:

```yaml
# main.yaml
receivers:
  otlp/in:
processors:
  batch:
exporters:
  otlp/out:
extensions:
  file_storage:
  healthcheckv2:

service:
  pipelines:
    traces:
      receivers: [ otlp/in ]
      processors: [ batch ]
      exporters: [ otlp/out ]
  extensions: [ file_storage, healthcheckv2 ]
```

For backward compatibly, the default behaviour is **not** to merge
lists. Users who want to explicitly merge lists can enable the command
line option.

Note: I’d appreciate your feedback on this 🙏
2025-03-04 09:56:22 +00:00
Matthieu MOREL 869eec38f3
[chore]: enable partially thelper linter (#11895)
#### Description

[Thelper](https://golangci-lint.run/usage/linters/#thelper) detects
tests helpers which is not start with t.Helper() method.

This only enables rules for naming and paramter order

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2024-12-17 08:42:49 +00:00
Matthieu MOREL 808fb7c260
[chore]: enable gofumpt linter in client, cmd, component, config and confmap (#11587)
#### Description

[gofumpt](https://golangci-lint.run/usage/linters/#gofumpt) is a
stricter format than gofmt, while being backwards compatible.

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2024-12-11 08:50:57 +00:00
Nathan Baulch 42e6304f65
Fix typos (#11348)
Just thought I'd contribute some typo fixes I stumbled upon. Nothing
controversial (hopefully), just 72 simple fixes.

Use the following command to get a quick and dirty summary of the
specific corrections made:
```shell
git diff HEAD^! --word-diff-regex='\w+' -U0 \
  | grep -E '\[\-.*\-\]\{\+.*\+\}' \
  | sed -r 's/.*\[\-(.*)\-\]\{\+(.*)\+\}.*/\1 \2/' \
  | sort | uniq -c | sort -n
```

FWIW, the top typos are:
* invokable (16)
* subsciption (15)
* decison (7)
* reques (3)
* dissallow (3)
* documenation (3)
* locahost (3)
* prerequistes (2)
* assinged (2)
* extenions (2)

---------

Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
2024-10-09 15:43:52 -07:00
Matthieu MOREL aba139c2cb
[chore]: use ErrorContains and EqualError (#11295)
#### Description

Testifylint doesn't support it yet. 
This replaces `Contains(t, err.Error()` by `ErrorContains(t, err` and
`Equal(t, err.Error()` by `EqualError(t, err`
As they both check for nil error it becomes useless to check it yourself
without having defined a custom message

<!-- Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> -->

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2024-09-28 08:06:09 -07:00
Matthieu MOREL 37f783308e
[chore]: enable require-error rule from testifylint (#11199)
#### Description

Testifylint is a linter that provides best practices with the use of
testify.

This PR enables
[require-error](https://github.com/Antonboom/testifylint?tab=readme-ov-file#require-error)
rule from [testifylint](https://github.com/Antonboom/testifylint)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2024-09-18 15:02:22 -07:00
Matthieu MOREL 2720f59f97
[chore]: enable error-nil and nil-compare rules from testifylint (#11120)
#### Description

Testifylint is a linter that provides best practices with the use of
testify.

This PR enables
[error-nil](https://github.com/Antonboom/testifylint?tab=readme-ov-file#error-nil)
and
[nil-compare](https://github.com/Antonboom/testifylint?tab=readme-ov-file#nil-compare)
rules from [testifylint](https://github.com/Antonboom/testifylint)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2024-09-10 14:34:29 -07:00
Pablo Baeyens 2beed98471
[confmap] Validate providers scheme when building a Resolver (#10786)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Validate providers schemes when building a Resolver.

I don't consider this a breaking change since the providers would be
useless if they don't follow this pattern.
2024-08-02 11:36:15 +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
Evan Bradley 91f13c309d
[confmap] Remove deprecated ResolverSettings fields (#10173)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

These fields were deprecated in v0.99.0 and aren't used in any upstream
repositories.

These appear to still be used in downstream distributions. If we want to
lengthen the deprecation period for these fields, I'll open a PR to
instead set a timeline for their removal.
2024-05-20 06:10:16 -07:00
Tyler Helmuth 1d52fb9c3c
[confmap] Add logger to ConverterSettings (#10135)
#### Description
Adds a Logger to ConverterSettings to enable logging from within
converters. Also update the expand converter to log a warning if the env
var is empty or missing.

#### Link to tracking issue
Closes
https://github.com/open-telemetry/opentelemetry-collector/issues/9162
Closes
https://github.com/open-telemetry/opentelemetry-collector/issues/5615

#### Testing

Unit tests and local testing


![image](https://github.com/open-telemetry/opentelemetry-collector/assets/12352919/af5dd1e2-62f9-4272-97c7-da57166ef07e)

```yaml
receivers:
  nop:

exporters:
  otlphttp:
    endpoint: http://0.0.0.0:4317
    headers:
      # Not set
      x-test: $TEMP3
  debug:
    # set to "detailed"
    verbosity: $TEMP

service:
  telemetry:
    logs:
      level: info
  pipelines:
    traces:
      receivers:
        - nop
      exporters:
        - otlphttp
        - debug
```

#### Documentation
Added godoc comments
2024-05-10 21:48:11 +02: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
Alex Boten 062d0a7ffc
[chore] remove unnecessary underscores (#9580)
As per feedback from my previous PR

Signed-off-by: Alex Boten <aboten@lightstep.com>
2024-02-13 13:34:53 -08:00
Alex Boten 4688461318
[chore] fix unused params (#9578)
Related to #9577

Signed-off-by: Alex Boten <aboten@lightstep.com>
2024-02-13 11:04:48 -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
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
Kshitij Patil 5c58fb38e4
replacing go.uber.org/atomic by sync/atomic (#7220)
replacing go.uber.org/atomic by sync/atomic
wrt issue #7160
2023-03-05 12:24:52 -08:00
Bogdan Drutu 105e5aede5
confmap: clear list of old closers (#7222)
Fixes https://github.com/open-telemetry/opentelemetry-collector/issues/7215

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2023-02-20 14:05:21 -08:00
Bogdan Drutu 202c030106
Add support for concatenating multiple embedded uris, or uris with other string parts (#7055)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2023-01-30 17:24:22 -08: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 776c6b3844
Fix support for concatenating envvars with colon (#6593)
* Fix support for concatenating envvars with colon

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>

* Update resolver.go

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2022-11-21 15:26:16 -08:00
Pablo Baeyens 6313054b64
[confmap] Fail fast on unsupported scheme (#6335) 2022-10-17 10:14:45 -07:00
Bogdan Drutu 77946260ea
Fix support for new line in config URI location (#6310)
Signed-off-by: Bogdan <bogdandrutu@gmail.com>

Signed-off-by: Bogdan <bogdandrutu@gmail.com>
2022-10-13 13:28:18 -07:00
Bogdan Drutu b15179e4da
Enable confmap expand feature (#6276)
Signed-off-by: Bogdan <bogdandrutu@gmail.com>

Signed-off-by: Bogdan <bogdandrutu@gmail.com>
2022-10-11 13:50:45 -07:00
Bogdan Drutu ff73e49f74
Disallow dollar sign in opaque value, allow recursive expansion to be implemented in the future (#6268)
Signed-off-by: Bogdan <bogdandrutu@gmail.com>

Signed-off-by: Bogdan <bogdandrutu@gmail.com>
2022-10-11 09:31:40 -07:00
Bogdan Drutu 01e4d0c886
[chore] refactor the URI parsing logic, use already parsed URIs (#6271)
Signed-off-by: Bogdan <bogdandrutu@gmail.com>

Signed-off-by: Bogdan <bogdandrutu@gmail.com>
2022-10-10 15:57:42 -07:00
Bogdan Drutu f1f04e1e61
Fix build because of a race condition between merged PRs (#5875)
Signed-off-by: Bogdan <bogdandrutu@gmail.com>
2022-08-09 11:01:28 -07:00
Bogdan Drutu b54eb17920
confmap.Resolver: Remove support for the old way of expanding env vars (#5863)
The new mechanism that allows embedding and expanding configs from all the Providers, does not doing it without explicitly specify the URI scheme.
If support for backwards compatibility is needed, continue to use the `expandconverter`.

Signed-off-by: Bogdan <bogdandrutu@gmail.com>
2022-08-09 10:18:43 -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 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
Bogdan Drutu 6fb884b2db
Fix small nits in confmap tests (#5473)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2022-06-03 10:53:57 -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 868a089679
Move service.mapResolver to confmap.Resolver (#5444)
The reason to do this is to allow alternative implementation of the service.ConfigProvider to re-use the resolver logic,
also to create an independent "confmap.Conf" resolver for other services/binaries to use.

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2022-06-02 15:20:39 -07:00