Skip to content

Commit

Permalink
Added flag for query addresses to ruler
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Valkov committed Oct 12, 2018
1 parent 7180ccc commit d6e4c5a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/thanos/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func registerRule(m map[string]setupFunc, app *kingpin.Application, name string)

objStoreConfig := regCommonObjStoreFlags(cmd, "")

queries := cmd.Flag("query", "Addresses of statically configured query API servers (repeatable).").
PlaceHolder("<query>").Strings()

filesToWatch := cmd.Flag("store.file-sd-config", "Path to file that contain addresses of query peers. The path can be a glob pattern (repeatable).").
PlaceHolder("<path>").Strings()

Expand All @@ -103,6 +106,15 @@ func registerRule(m map[string]setupFunc, app *kingpin.Application, name string)
WALFlushInterval: 30 * time.Second,
}

lookupQueries := map[string]struct{}{}
for _, q := range *queries {
if _, ok := lookupQueries[q]; ok {
return errors.Errorf("Address %s is duplicated for --query flag.", q)
}

lookupQueries[q] = struct{}{}
}

var filesd *file.Discovery
if len(*filesToWatch) > 0 {
conf := &file.SDConfig{
Expand Down Expand Up @@ -131,6 +143,7 @@ func registerRule(m map[string]setupFunc, app *kingpin.Application, name string)
tsdbOpts,
name,
alertQueryURL,
*queries,
filesd,
)
}
Expand Down Expand Up @@ -158,6 +171,7 @@ func runRule(
tsdbOpts *tsdb.Options,
component string,
alertQueryURL *url.URL,
queryAddrs []string,
fileSD *file.Discovery,
) error {
configSuccess := prometheus.NewGauge(prometheus.GaugeOpts{
Expand All @@ -176,6 +190,12 @@ func runRule(
reg.MustRegister(configSuccessTime)
reg.MustRegister(duplicatedQuery)

for _, addr := range queryAddrs {
if addr == "" {
return errors.New("static querier address cannot be empty")
}
}

db, err := tsdb.Open(dataDir, log.With(logger, "component", "tsdb"), reg, tsdbOpts)
if err != nil {
return errors.Wrap(err, "open TSDB")
Expand All @@ -197,6 +217,8 @@ func runRule(
// back or the context get canceled.
queryFn := func(ctx context.Context, q string, t time.Time) (promql.Vector, error) {
var addrs []string
// Add addresses from static flag
addrs = append(addrs, queryAddrs...)

// Add addresses from gossip
peers := peer.PeerStates(cluster.PeerTypeQuery)
Expand Down
2 changes: 2 additions & 0 deletions docs/components/rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ Flags:
--objstore.config=<bucket.config-yaml>
Alternative to 'objstore.config-file' flag.
Object store configuration in YAML.
--query=<query> ... Addresses of statically configured query API
servers (repeatable).
--store.file-sd-config=<path> ...
Path to file that contain addresses of query
peers. The path can be a glob pattern
Expand Down

0 comments on commit d6e4c5a

Please sign in to comment.