| 1 |
# Confmap |
| 2 |
|
| 3 |
<!-- status autogenerated section --> |
| 4 |
| Status | | |
| 5 |
| ------------- |-----------| |
| 6 |
| Stability | [stable]: logs, metrics, traces | |
| 7 |
| Issues | [](https://github.com/open-telemetry/opentelemetry-collector/issues?q=is%3Aopen+is%3Aissue+label%3Apkg%2Fconfmap) [](https://github.com/open-telemetry/opentelemetry-collector/issues?q=is%3Aclosed+is%3Aissue+label%3Apkg%2Fconfmap) | |
| 8 |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@mx-psi](https://www.github.com/mx-psi), [@evan-bradley](https://www.github.com/evan-bradley) | |
| 9 |
|
| 10 |
[stable]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#stable |
| 11 |
<!-- end autogenerated section --> |
| 12 |
|
| 13 |
# High Level Design |
| 14 |
|
| 15 |
## Conf |
| 16 |
|
| 17 |
The [Conf](confmap.go) represents the raw configuration for a service (e.g. OpenTelemetry Collector). |
| 18 |
|
| 19 |
## Provider |
| 20 |
|
| 21 |
The [Provider](provider.go) provides configuration, and allows to watch/monitor for changes. Any `Provider` |
| 22 |
has a `<scheme>` associated with it, and will provide configs for `configURI` that follow the "<scheme>:<opaque_data>" format. |
| 23 |
This format is compatible with the URI definition (see [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986)). |
| 24 |
The `<scheme>` MUST be always included in the `configURI`. The scheme for any `Provider` MUST be at least 2 |
| 25 |
characters long to avoid conflicting with a driver-letter identifier as specified in |
| 26 |
[file URI syntax](https://datatracker.ietf.org/doc/html/rfc8089#section-2). |
| 27 |
|
| 28 |
## Converter |
| 29 |
|
| 30 |
The [Converter](converter.go) allows implementing conversion logic for the provided configuration. One of the most |
| 31 |
common use-case is to migrate/transform the configuration after a backwards incompatible change. |
| 32 |
|
| 33 |
## Resolver |
| 34 |
|
| 35 |
The `Resolver` handles the use of multiple [Providers](#provider) and [Converters](#converter) |
| 36 |
simplifying configuration parsing, monitoring for updates, and the overall life-cycle of the used config providers. |
| 37 |
The `Resolver` provides two main functionalities: [Configuration Resolving](#configuration-resolving) and |
| 38 |
[Watching for Updates](#watching-for-updates). |
| 39 |
|
| 40 |
### Configuration Resolving |
| 41 |
|
| 42 |
The `Resolver` receives as input a set of `Providers`, a list of `Converters`, and a list of configuration identifier |
| 43 |
`configURI` that will be used to generate the resulting, or effective, configuration in the form of a `Conf`, |
| 44 |
that can be used by code that is oblivious to the usage of `Providers` and `Converters`. |
| 45 |
|
| 46 |
`Providers` are used to provide an entire configuration when the `configURI` is given directly to the `Resolver`, |
| 47 |
or an individual value (partial configuration) when the `configURI` is embedded into the `Conf` as a values using |
| 48 |
the syntax `${configURI}`. |
| 49 |
|
| 50 |
**Limitation:** |
| 51 |
- When embedding a `${configURI}` the uri cannot contain dollar sign ("$") character unless it embeds another uri. |
| 52 |
- The number of URIs is limited to 100. |
| 53 |
|
| 54 |
```terminal |
| 55 |
Resolver Provider |
| 56 |
Resolve │ │ |
| 57 |
────────────────►│ │ |
| 58 |
│ │ |
| 59 |
┌─ │ Retrieve │ |
| 60 |
│ ├─────────────────────────►│ |
| 61 |
│ │ Conf │ |
| 62 |
│ │◄─────────────────────────┤ |
| 63 |
foreach │ │ │ |
| 64 |
configURI │ ├───┐ │ |
| 65 |
│ │ │Merge │ |
| 66 |
│ │◄──┘ │ |
| 67 |
└─ │ │ |
| 68 |
┌─ │ Retrieve │ |
| 69 |
│ ├─────────────────────────►│ |
| 70 |
│ │ Partial Conf Value │ |
| 71 |
│ │◄─────────────────────────┤ |
| 72 |
foreach │ │ │ |
| 73 |
embedded │ │ │ |
| 74 |
configURI │ ├───┐ │ |
| 75 |
│ │ │Replace │ |
| 76 |
│ │◄──┘ │ |
| 77 |
└─ │ │ |
| 78 |
│ Converter │ |
| 79 |
┌─ │ Convert │ │ |
| 80 |
│ ├───────────────►│ │ |
| 81 |
foreach │ │ │ │ |
| 82 |
Converter │ │◄───────────────┤ │ |
| 83 |
└─ │ │ |
| 84 |
│ │ |
| 85 |
◄────────────────┤ │ |
| 86 |
``` |
| 87 |
|
| 88 |
The `Resolve` method proceeds in the following steps: |
| 89 |
|
| 90 |
1. Start with an empty "result" of `Conf` type. |
| 91 |
2. For each config URI retrieves individual configurations, and merges it into the "result". |
| 92 |
3. For each embedded config URI retrieves individual value, and replaces it into the "result". |
| 93 |
4. For each "Converter", call "Convert" for the "result". |
| 94 |
5. Return the "result", aka effective, configuration. |
| 95 |
|
| 96 |
#### (Experimental) Append merging strategy for lists |
| 97 |
|
| 98 |
You can opt-in to experimentally combine slices instead of discarding the existing ones by enabling the `confmap.enableMergeAppendOption` feature flag. Lists are appended in the order in which they appear in their configuration sources. |
| 99 |
This will **not** become the default in the future, we are still deciding how this should be configured and want your feedback on [this issue](https://github.com/open-telemetry/opentelemetry-collector/issues/8754). |
| 100 |
|
| 101 |
##### Example |
| 102 |
Consider the following configs, |
| 103 |
|
| 104 |
```yaml |
| 105 |
# main.yaml |
| 106 |
receivers: |
| 107 |
otlp/in: |
| 108 |
processors: |
| 109 |
attributes/example: |
| 110 |
actions: |
| 111 |
- key: key |
| 112 |
value: "value" |
| 113 |
action: upsert |
| 114 |
|
| 115 |
exporters: |
| 116 |
otlp/out: |
| 117 |
extensions: |
| 118 |
file_storage: |
| 119 |
|
| 120 |
service: |
| 121 |
pipelines: |
| 122 |
traces: |
| 123 |
receivers: [ otlp/in ] |
| 124 |
processors: [ attributes/example ] |
| 125 |
exporters: [ otlp/out ] |
| 126 |
extensions: [ file_storage ] |
| 127 |
``` |
| 128 |
|
| 129 |
|
| 130 |
```yaml |
| 131 |
# extra_extension.yaml |
| 132 |
extensions: |
| 133 |
healthcheckv2: |
| 134 |
|
| 135 |
service: |
| 136 |
extensions: [ healthcheckv2 ] |
| 137 |
pipelines: |
| 138 |
traces: |
| 139 |
``` |
| 140 |
|
| 141 |
If you run the Collector with following command, |
| 142 |
``` |
| 143 |
otelcol --config=main.yaml --config=extra_extension.yaml --feature-gates=confmap.enableMergeAppendOption |
| 144 |
``` |
| 145 |
then the final configuration after config resolution will look like following: |
| 146 |
|
| 147 |
```yaml |
| 148 |
# main.yaml |
| 149 |
receivers: |
| 150 |
otlp/in: |
| 151 |
processors: |
| 152 |
attributes/example: |
| 153 |
actions: |
| 154 |
- key: key |
| 155 |
value: "value" |
| 156 |
action: upsert |
| 157 |
exporters: |
| 158 |
otlp/out: |
| 159 |
extensions: |
| 160 |
file_storage: |
| 161 |
healthcheckv2: |
| 162 |
|
| 163 |
service: |
| 164 |
pipelines: |
| 165 |
traces: |
| 166 |
receivers: [ otlp/in ] |
| 167 |
processors: [ attributes/example ] |
| 168 |
exporters: [ otlp/out ] |
| 169 |
extensions: [ file_storage, healthcheckv2 ] |
| 170 |
``` |
| 171 |
|
| 172 |
Notice that the `service::extensions` list is a combination of both configurations. By default, the value of the last configuration source passed, `extra_extension`, would be used, so the extensions list would be: `service::extensions: [healthcheckv2]`. |
| 173 |
|
| 174 |
> [!NOTE] |
| 175 |
> By enabling this feature gate, all the lists in the given configuration will be merged. |
| 176 |
|
| 177 |
### Watching for Updates |
| 178 |
After the configuration was processed, the `Resolver` can be used as a single point to watch for updates in the |
| 179 |
configuration retrieved via the `Provider` used to retrieve the “initial” configuration and to generate the “effective” one. |
| 180 |
|
| 181 |
```terminal |
| 182 |
Resolver Provider |
| 183 |
│ │ |
| 184 |
Watch │ │ |
| 185 |
───────────►│ │ |
| 186 |
│ │ |
| 187 |
. . |
| 188 |
. . |
| 189 |
. . |
| 190 |
│ onChange │ |
| 191 |
│◄────────────────────┤ |
| 192 |
◄───────────┤ │ |
| 193 |
|
| 194 |
``` |
| 195 |
|
| 196 |
The `Resolver` does that by passing an `onChange` func to each `Provider.Retrieve` call and capturing all watch events. |
| 197 |
|
| 198 |
Calling the `onChange` func from a provider triggers the collector to re-resolve new configuration: |
| 199 |
|
| 200 |
```terminal |
| 201 |
Resolver Provider |
| 202 |
│ │ |
| 203 |
Watch │ │ |
| 204 |
───────────►│ │ |
| 205 |
│ │ |
| 206 |
. . |
| 207 |
. . |
| 208 |
. . |
| 209 |
│ onChange │ |
| 210 |
│◄────────────────────┤ |
| 211 |
◄───────────┤ │ |
| 212 |
| | |
| 213 |
Resolve │ │ |
| 214 |
───────────►│ │ |
| 215 |
│ │ |
| 216 |
│ Retrieve │ |
| 217 |
├────────────────────►│ |
| 218 |
│ Conf │ |
| 219 |
│◄────────────────────┤ |
| 220 |
◄───────────┤ │ |
| 221 |
``` |
| 222 |
|
| 223 |
An example of a `Provider` with an `onChange` func that periodically gets notified can be found in provider_test.go as UpdatingProvider |
| 224 |
|
| 225 |
## Troubleshooting |
| 226 |
|
| 227 |
### Null Maps |
| 228 |
|
| 229 |
Due to how our underlying merge library, [koanf](https://github.com/knadh/koanf), behaves, configuration resolution |
| 230 |
will treat configuration such as |
| 231 |
|
| 232 |
```yaml |
| 233 |
processors: |
| 234 |
``` |
| 235 |
|
| 236 |
as null, which is a valid value. As a result if you have configuration `A`: |
| 237 |
|
| 238 |
```yaml |
| 239 |
receivers: |
| 240 |
nop: |
| 241 |
|
| 242 |
processors: |
| 243 |
nop: |
| 244 |
|
| 245 |
exporters: |
| 246 |
nop: |
| 247 |
|
| 248 |
extensions: |
| 249 |
nop: |
| 250 |
|
| 251 |
service: |
| 252 |
extensions: [nop] |
| 253 |
pipelines: |
| 254 |
traces: |
| 255 |
receivers: [nop] |
| 256 |
processors: [nop] |
| 257 |
exporters: [nop] |
| 258 |
``` |
| 259 |
|
| 260 |
and configuration `B`: |
| 261 |
|
| 262 |
```yaml |
| 263 |
processors: |
| 264 |
``` |
| 265 |
|
| 266 |
and do `./otelcorecol --config A.yaml --config B.yaml` |
| 267 |
|
| 268 |
The result will be an error: |
| 269 |
|
| 270 |
``` |
| 271 |
Error: invalid configuration: service::pipelines::traces: references processor "nop" which is not configured |
| 272 |
2024/06/10 14:37:14 collector server run finished with error: invalid configuration: service::pipelines::traces: references processor "nop" which is not configured |
| 273 |
``` |
| 274 |
|
| 275 |
This happens because configuration `B` sets `processors` to null, removing the `nop` processor defined in configuration `A`, |
| 276 |
so the `nop` processor referenced in configuration `A`'s pipeline no longer exists. |
| 277 |
|
| 278 |
This situation can be remedied 2 ways: |
| 279 |
1. Use `{}` when you want to represent an empty map, such as `processors: {}` instead of `processors:`. |
| 280 |
2. Omit configuration like `processors:` from your configuration. |