opentelemetry-collector/confmap
Evan Bradley 1c683a1da1
[chore][fileprovider] Add README file (#12506)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Use mdatagen for the file provider. This switches the package test to be
generated and adds an autogenerated section to the readme.

I've also populated the readme with basic usage information.
2025-02-27 12:44:11 +00:00
..
confmaptest [chore]: enable use-any rule from revive linter (#11926) 2024-12-17 08:43:20 +00:00
internal Update All go.opentelemetry.io/collector packages (#12418) 2025-02-18 05:46:56 +00:00
provider [chore][fileprovider] Add README file (#12506) 2025-02-27 12:44:11 +00:00
testdata [confmap] Fix expansion of escaped environment variables (#10716) 2024-07-24 14:18:54 -07:00
xconfmap [chore] Prepare release v1.26.0/v0.120.0 (#12412) 2025-02-18 00:10:21 +00:00
Makefile Split `confmap` into its own module (#6199) 2022-12-01 09:27:08 -08:00
README.md [chore] fix metadata.yaml (#12387) 2025-02-14 11:00:42 +00:00
confmap.go [chore] fix metadata.yaml (#12387) 2025-02-14 11:00:42 +00:00
confmap_test.go [chore]: enable partially thelper linter (#11895) 2024-12-17 08:42:49 +00:00
converter.go [confmap] Add logger to ConverterSettings (#10135) 2024-05-10 21:48:11 +02:00
doc_test.go [chore]: enable gofumpt linter in client, cmd, component, config and confmap (#11587) 2024-12-11 08:50:57 +00:00
expand.go [confmap] Mark `confmap.strictlyTypedInput` as stable (#10793) 2024-08-20 10:04:59 +02:00
expand_test.go [chore]: enable gofumpt linter in client, cmd, component, config and confmap (#11587) 2024-12-11 08:50:57 +00:00
generated_package_test.go [chore] fix metadata.yaml (#12387) 2025-02-14 11:00:42 +00:00
go.mod bump minimum supported go version to 1.23 (#12370) 2025-02-12 15:03:19 +00:00
go.sum fix(deps): update module github.com/stretchr/testify to v1.10.0 (#11751) 2024-11-26 11:09:39 -08:00
metadata.yaml [chore] fix metadata.yaml (#12387) 2025-02-14 11:00:42 +00:00
provider.go [confmap] Add error hint when invalid YAML was passed (#12180) 2025-02-25 10:05:21 +00:00
provider_test.go [confmap] Add error hint when invalid YAML was passed (#12180) 2025-02-25 10:05:21 +00:00
resolver.go [confmap] Set confmap.unifyEnvVarExpansion feature gate to stable (#10508) 2024-08-07 13:31:17 -07:00
resolver_test.go [chore]: enable partially thelper linter (#11895) 2024-12-17 08:42:49 +00:00

README.md

Confmap

Status
Stability stable: logs, metrics, traces
Issues Open issues Closed issues
Code Owners @mx-psi, @evan-bradley

High Level Design

Conf

The Conf represents the raw configuration for a service (e.g. OpenTelemetry Collector).

Provider

The Provider provides configuration, and allows to watch/monitor for changes. Any Provider has a <scheme> associated with it, and will provide configs for configURI that follow the ":<opaque_data>" format. This format is compatible with the URI definition (see RFC 3986). The <scheme> MUST be always included in the configURI. The scheme for any Provider MUST be at least 2 characters long to avoid conflicting with a driver-letter identifier as specified in file URI syntax.

Converter

The Converter allows implementing conversion logic for the provided configuration. One of the most common use-case is to migrate/transform the configuration after a backwards incompatible change.

Resolver

The Resolver handles the use of multiple Providers and Converters simplifying configuration parsing, monitoring for updates, and the overall life-cycle of the used config providers. The Resolver provides two main functionalities: Configuration Resolving and Watching for Updates.

Configuration Resolving

The Resolver receives as input a set of Providers, a list of Converters, and a list of configuration identifier configURI that will be used to generate the resulting, or effective, configuration in the form of a Conf, that can be used by code that is oblivious to the usage of Providers and Converters.

Providers are used to provide an entire configuration when the configURI is given directly to the Resolver, or an individual value (partial configuration) when the configURI is embedded into the Conf as a values using the syntax ${configURI}.

Limitation:

  • When embedding a ${configURI} the uri cannot contain dollar sign ("$") character unless it embeds another uri.
  • The number of URIs is limited to 100.
              Resolver                   Provider
   Resolve       │                          │
────────────────►│                          │
                 │                          │
              ┌─ │        Retrieve          │
              │  ├─────────────────────────►│
              │  │          Conf            │
              │  │◄─────────────────────────┤
  foreach     │  │                          │
  configURI   │  ├───┐                      │
              │  │   │Merge                 │
              │  │◄──┘                      │
              └─ │                          │
              ┌─ │        Retrieve          │
              │  ├─────────────────────────►│
              │  │    Partial Conf Value    │
              │  │◄─────────────────────────┤
  foreach     │  │                          │
  embedded    │  │                          │
  configURI   │  ├───┐                      │
              │  │   │Replace               │
              │  │◄──┘                      │
              └─ │                          │
                 │            Converter     │
              ┌─ │     Convert    │         │
              │  ├───────────────►│         │
    foreach   │  │                │         │
   Converter  │  │◄───────────────┤         │
              └─ │                          │
                 │                          │
◄────────────────┤                          │

The Resolve method proceeds in the following steps:

  1. Start with an empty "result" of Conf type.
  2. For each config URI retrieves individual configurations, and merges it into the "result".
  3. For each embedded config URI retrieves individual value, and replaces it into the "result".
  4. For each "Converter", call "Convert" for the "result".
  5. Return the "result", aka effective, configuration.

Watching for Updates

After the configuration was processed, the Resolver can be used as a single point to watch for updates in the configuration retrieved via the Provider used to retrieve the “initial” configuration and to generate the “effective” one.

         Resolver              Provider
            │                     │
   Watch    │                     │
───────────►│                     │
            │                     │
            .                     .
            .                     .
            .                     .
            │      onChange       │
            │◄────────────────────┤
◄───────────┤                     │

The Resolver does that by passing an onChange func to each Provider.Retrieve call and capturing all watch events.

Calling the onChange func from a provider triggers the collector to re-resolve new configuration:

         Resolver              Provider
            │                     │
   Watch    │                     │
───────────►│                     │
            │                     │
            .                     .
            .                     .
            .                     .
            │      onChange       │
            │◄────────────────────┤
◄───────────┤                     │
            |                     |
  Resolve   │                     │
───────────►│                     │
            │                     │
            │      Retrieve       │
            ├────────────────────►│
            │        Conf         │
            │◄────────────────────┤
◄───────────┤                     │

An example of a Provider with an onChange func that periodically gets notified can be found in provider_test.go as UpdatingProvider

Troubleshooting

Null Maps

Due to how our underlying merge library, koanf, behaves, configuration resolution will treat configuration such as

processors:

as null, which is a valid value. As a result if you have configuration A:

receivers:
    nop:

processors:
    nop:

exporters:
    nop:

extensions:
    nop:

service:
    extensions: [nop]
    pipelines:
        traces:
            receivers: [nop]
            processors: [nop]
            exporters: [nop]

and configuration B:

processors:

and do ./otelcorecol --config A.yaml --config B.yaml

The result will be an error:

Error: invalid configuration: service::pipelines::traces: references processor "nop" which is not configured
2024/06/10 14:37:14 collector server run finished with error: invalid configuration: service::pipelines::traces: references processor "nop" which is not configured

This happens because configuration B sets processors to null, removing the nop processor defined in configuration A, so the nop processor referenced in configuration A's pipeline no longer exists.

This situation can be remedied 2 ways:

  1. Use {} when you want to represent an empty map, such as processors: {} instead of processors:.
  2. Omit configuration like processors: from your configuration.