hashicorp / consul

Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
https://www.consul.io
Other
28.39k stars 4.43k forks source link

How to bootstrap prepared queries #1956

Open johntdyer opened 8 years ago

johntdyer commented 8 years ago

I would like to bootstrap a cluster to "start" with some prepared queries but the docs only show adding them via the rest API. Is there a way to pre-seed them ? Is there also a way to back them up ?

johntdyer commented 8 years ago

Any chance anyone has an idea on this ?

slackpad commented 8 years ago

Hi @johntdyer similar to K/V, prepared queries belong to the cluster and not any individual agent, so they cannot be configured as part of an agent's config file. If you wanted to pre-seed them you'd need to script that outside of Consul with something like curl or using one of the Consul API clients. We have future plans for a better backup system on https://github.com/hashicorp/consul/issues/1254, which would include prepared queries. Most existing backup solutions only persist K/V, so at present the best way to back up your query definitions would be to save off a GET to /v1/query using a management token which will enumerate all defined queries in one request.

johntdyer commented 8 years ago

Are queries idempotent ? Could I run a check looking for a missing query and then readd it incase it somehow ended up "mIssing"?

slackpad commented 8 years ago

You could run a check and add a missing query, but it's a little tricky because you can't control the ID when you create a query. I'm assuming you are giving your queries a Name in which case the first attempt to create a query with that name will go through and subsequent ones will fail.

Not sure if you are creating queries for a bunch of different services, but perhaps prepared query templates might help you here by defining a single query with a pattern that applies to multiple services; this is new for 0.6.4.

slackpad commented 7 years ago

See https://github.com/hashicorp/consul/issues/717#issuecomment-298770072 for a possible implementation idea for this.

pearkes commented 5 years ago

Just wanted to drop a note for future readers that the Consul Terraform Provider supports a prepared_query resource that can potentially provide a nice workflow to bootstrap and manage prepared queries, but isn't a direct solution for this ask.