Currently supported watches by Consul [1]:
- key - Watch a specific KV pair
- keyprefix - Watch a prefix in the KV store
- services - Watch the list of available services
- nodes - Watch the list of nodes
- service- Watch the instances of a service
- checks - Watch the value of health checks
- event - Watch for custom user events
Watches are driven by Consul itself. This means that consul either executes command or sends request to API endpoint. For our cause the API endpoint is the choice. Http handler options are:
{
"path": "https://localhost:8000/watch",
"method": "POST",
"header": { "x-foo": ["bar", "baz"] },
"timeout": "10s",
"tls_skip_verify": false
}
As an MVP let's implement just keyprefix as from property source it makes most sense atm.
- Use watches over HTTP handlers
- Create management
WatchesEndpoint
endpoint inio.micronaut.discovery.consul.endpoint
package - Basically for every watch type there would be specific method that handles watch specific payload
- Have for every watch type Bean annotated with @ConfigurationProperties("endpoints.consul.watches.keyprefix")
- Have for every watch type Bean that based on (@Requires) configuration and (@Requires) ConsulClient registers the watches
Depends on type of watches.
Motivation:
- user can manually specify prefixes of configuration to watch
- by providing some keywords like:
all
we can autoregister either all existing AppContext configuration or do some filering in microservice - this can basically allow to implement feature toggles (altough I registered some
Toggleable
annotation but didn't find documentation for it)
Two possible approaches:
- Create or replace PropertySource and refresh environment -> AFAIK will cause recreation of all beans??
- Do it like with
/refresh
management endpoint where refresh is called but after that RefresEvent is emitted
endpoints:
consul:
enabled: true/false
sensitive: true/false
watches:
<watch-type>:
sensitive: true/false
<watch-type-specific-config>
keyprefix:
prefixes:
- <prefix_1>
- <prefix_2>
- <prefix_N>
[1] https://www.consul.io/docs/agent/watches.html#watch-types
io.micronaut.discovery.consul.endpoint
->io.micronaut.discovery.consul.management