|
| 1 | +# Configuration of confmap Providers |
| 2 | + |
| 3 | +## Motivation |
| 4 | + |
| 5 | +The `confmap.Provider` interface is used by the Collector to retrieve map |
| 6 | +objects representing the Collector's configuration or a subset thereof. Sources |
| 7 | +of config may include locally-available information such as files on disk or |
| 8 | +environment variables, or may be remotely accessed over the network. In the |
| 9 | +process of obtaining configuration from a source, the user may wish to modify |
| 10 | +the behavior of how the source is obtained. |
| 11 | + |
| 12 | +For example, consider the case where the Collector obtains configuration over |
| 13 | +HTTP from an HTTP endpoint. A user may want to: |
| 14 | + |
| 15 | +1. Poll the HTTP endpoint for configuration at a configurable interval and |
| 16 | + reload the Collector service if the configuration changes. |
| 17 | +2. Authenticate the request to get configuration by including a header in the |
| 18 | + request. Additional headers may be necessary as part of this flow. |
| 19 | + |
| 20 | +This would produce a set of options like the following: |
| 21 | + |
| 22 | +- `poll-interval`: Sets an interval for the Provider to check the HTTP endpoint |
| 23 | + for changes. If the config has changed, the service will be reloaded. |
| 24 | +- `headers`: Specifies a map of headers to be put into the HTTP request to the |
| 25 | + server. |
| 26 | + |
| 27 | +## Current state |
| 28 | + |
| 29 | +No upstream Providers currently offer any configuration options. The exported |
| 30 | +interfaces are still able to change before the `confmap` module is declared |
| 31 | +stable, but avoiding breaking changes in the API would be preferable. |
| 32 | + |
| 33 | +## Desired state |
| 34 | + |
| 35 | +We would like the following features available to users to configure Providers: |
| 36 | + |
| 37 | +1. Global configuration of a certain type of Provider (`file`, `http`, etc.). |
| 38 | + This allows for users to express things such as "all files should be watched |
| 39 | + for changes" and "all HTTP requests should include authentication". |
| 40 | +2. Named configuration for a certain type of provider that can be applied to |
| 41 | + particular URIs. This will allow users to express things such as "some HTTP |
| 42 | + URLs should be watched for changes with a certain set of settings applied". |
| 43 | +3. Configuration options applied to specific URIs. |
| 44 | + |
| 45 | +## Resolution |
| 46 | + |
| 47 | +The `confmap` module APIs will not substantially change for 1.0. The following |
| 48 | +steps will be taken to ensure that configuration can be made to work post-1.0: |
| 49 | + |
| 50 | +1. Restrict URIs sufficiently to allow for extension after 1.0, e.g. restricting |
| 51 | + the scheme to allow for things like "named schemes" (`file/auth:`). |
| 52 | +2. Stabilize confmap Providers individually, so they can impose any desired |
| 53 | + restrictions on their own. |
| 54 | +3. Offer configuration as an optional interface for things like options that are |
| 55 | + applied to all instances of a Provider. |
| 56 | + |
| 57 | +## Possible technical solutions |
| 58 | + |
| 59 | +*NOTE*: This section is speculative and may not reflect the final implementation |
| 60 | +for providing options to confmap Providers. |
| 61 | + |
| 62 | +Providers are invoked through passing `--config` flags to the Collector binary |
| 63 | +or by using the braces syntax inside a Collector config file (`${scheme:uri}`). |
| 64 | +Each invocation contains a scheme specifying how to obtain config and URI |
| 65 | +specifying the config to be obtained. A single instance of a Provider is created |
| 66 | +for each scheme and is tasked with retrieving config for its scheme for each |
| 67 | +corresponding URI passed to the Collector. |
| 68 | + |
| 69 | +With the above in mind, we have the following places where it may make sense to |
| 70 | +support specifying options for Providers: |
| 71 | + |
| 72 | +1. Parts of the URI we are requesting. |
| 73 | +1. Separate flags to configure Providers per config URI. |
| 74 | +1. Use a separate config file that specifies config sources inside a map |
| 75 | + structure. |
| 76 | +1. Extend the Collector's config schema to support specifying additional places |
| 77 | + to obtain configuration. |
| 78 | + |
| 79 | +All of the above options are targeted toward configuring how specific URIs are |
| 80 | +resolved into config. To configure how a Provider resolves every URI it |
| 81 | +receives, we should consider how to extend the above options to be specified |
| 82 | +without a URI and to ensure the options are always applied to all URI |
| 83 | +resolutions. |
| 84 | + |
| 85 | +### Configure options inside the URI |
| 86 | + |
| 87 | +[RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986#section-3), which |
| 88 | +specifies the format of a URI, specifies the different parts of a URI and |
| 89 | +suggests two places where we could pass options to Providers: queries and |
| 90 | +fragments. |
| 91 | + |
| 92 | +#### Queries |
| 93 | + |
| 94 | +Breaking changes: |
| 95 | + |
| 96 | +- confmap Providers would have breaking changes since they would now consume |
| 97 | + unescaped URI queries. There would be no breaking changes to the confmap API. |
| 98 | + |
| 99 | +Advantages: |
| 100 | + |
| 101 | +- Explicitly intended to specify non-hierarchical data in a URI. |
| 102 | +- Often used for this purpose. |
| 103 | +- Fits into existing config URIs for URL-based Providers. |
| 104 | + |
| 105 | +Disadvantages: |
| 106 | + |
| 107 | +- Only allows easily specifying key-value pairs. |
| 108 | +- Query parameters are somewhat frequently used, which may extend to backend |
| 109 | + requests, and this may cause some churn for users who are unfamiliar that we |
| 110 | + would be consuming them. |
| 111 | + |
| 112 | +#### Fragments |
| 113 | + |
| 114 | +We could specify options in a query parameter-encoded string placed into the URI |
| 115 | +fragment. |
| 116 | + |
| 117 | +Breaking changes: |
| 118 | + |
| 119 | +- confmap Providers would have breaking changes since they would now consume |
| 120 | + fragments. There would be no breaking changes to the confmap API. |
| 121 | + |
| 122 | +Advantages: |
| 123 | + |
| 124 | +- Not likely to be used by config backends for any of our supported protocols, |
| 125 | + so has a low chance of conflict when using unescaped fragments. |
| 126 | +- Fits into existing config URIs for URL-based Providers. |
| 127 | + |
| 128 | +Disadvantages: |
| 129 | + |
| 130 | +- Even if fragments are likely not useful to backends, we are still preventing |
| 131 | + unescaped use in upstream Providers. |
| 132 | +- Doesn't conform to the spirit of how fragments should be used according to RFC |
| 133 | + 3986. |
| 134 | +- Only allows easily specifying key-value pairs. |
| 135 | + |
| 136 | +We could likely partially circumvent the key-value pair limitation by |
| 137 | +recursively calling confmap Providers to resolve files, env vars, HTTP URLs, |
| 138 | +etc. For example: |
| 139 | + |
| 140 | +```text |
| 141 | +https://config.com/config#refresh-interval=env:REFRESH_INTERVAL&headers=file:headers.yaml |
| 142 | +``` |
| 143 | + |
| 144 | +Using this strategy would also allow us to more easily get env vars and to get |
| 145 | +values from files for things like API tokens. |
| 146 | + |
| 147 | +### Separate flags to configure Providers per config URI |
| 148 | + |
| 149 | +Breaking changes: |
| 150 | + |
| 151 | +- Will need factory options if we provide config through a mechanism similar to |
| 152 | + `component.Factory`, along with making a Provider instance per URI. |
| 153 | +- Otherwise will need to break `confmap.Provider` interface to support providing |
| 154 | + options in `Retrieve`. |
| 155 | + |
| 156 | +Advantages: |
| 157 | + |
| 158 | +- Allows us to keep config URIs opaque. |
| 159 | +- Options live right next to config URIs on the command line. |
| 160 | + |
| 161 | +Disadvantages: |
| 162 | + |
| 163 | +- The flags would need to be placed in a certain position in the arguments list |
| 164 | + to specify which URI they apply to. |
| 165 | +- Configuring URIs present in files requires users to look in two places for |
| 166 | + each URI and is suboptimal UX. |
| 167 | +- Complicating the flags like this would be suboptimal UX. |
| 168 | + |
| 169 | +### Specify additional config sources inside the main Collector configuration |
| 170 | + |
| 171 | +This is a variant of providing a separate config source-only configuration file |
| 172 | +that instead puts those URIs and their options inside the main configuration |
| 173 | +file. |
| 174 | + |
| 175 | +API changes: |
| 176 | + |
| 177 | +- Need a way to specify options, either through a factory option, or an optional |
| 178 | + interface. |
| 179 | + |
| 180 | +Advantages: |
| 181 | + |
| 182 | +- Allows us to keep URIs opaque. |
| 183 | +- Map structures are easier to work with than command-line arguments for complex |
| 184 | + config. |
| 185 | + |
| 186 | +Disadvantages: |
| 187 | + |
| 188 | +- There are now two ways to include config inside a Collector config file. |
| 189 | +- Complicates the config schema and the config resolution process. |
0 commit comments