From 81dbb29fa1db103a8f52e04f31471b9c665f8219 Mon Sep 17 00:00:00 2001 From: Kemal Akkoyun Date: Wed, 9 Dec 2020 15:52:55 +0300 Subject: [PATCH] Address review issues Signed-off-by: Kemal Akkoyun --- CHANGELOG.md | 5 ----- cmd/thanos/receive.go | 13 +++---------- pkg/extflag/pathorcontent.go | 9 +++++---- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2d38c656bf..b54f6e00720 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,13 +87,8 @@ Highlights: ### Added -<<<<<<< HEAD -- [#3114](https://github.com/thanos-io/thanos/pull/3114) Query Frontend: Added support for Memacached cache. - - **breaking** Renamed flag `log_queries_longer_than` to `log-queries-longer-than`. -======= - [#3114](https://github.com/thanos-io/thanos/pull/3114) Query Frontend: Added support for Memcached cache. - **breaking** Renamed flag `log_queries_longer_than` to `log-queries-longer-than`. ->>>>>>> dedc7164 (Add ability to consume content of the hashring directly) - [#3166](https://github.com/thanos-io/thanos/pull/3166) UIs: Added UI for passing a `storeMatch[]` parameter to queries. - [#3181](https://github.com/thanos-io/thanos/pull/3181) Logging: Added debug level logging for responses between 300-399 - [#3133](https://github.com/thanos-io/thanos/pull/3133) Query: Allowed passing a `storeMatch[]` to Labels APIs; Time range metadata based store filtering is supported on Labels APIs. diff --git a/cmd/thanos/receive.go b/cmd/thanos/receive.go index 2f4f64083b9..5a77b7f8a59 100644 --- a/cmd/thanos/receive.go +++ b/cmd/thanos/receive.go @@ -106,14 +106,6 @@ func registerReceive(app *extkingpin.App) { return errors.New("no external labels configured for receive, uniquely identifying external labels must be configured (ideally with `receive_` prefix); see https://thanos.io/tip/thanos/storage.md#external-labels for details.") } - var cw *receive.ConfigWatcher - if *hashringsFile != "" { - cw, err = receive.NewConfigWatcher(log.With(logger, "component", "config-watcher"), reg, *hashringsFile, *refreshInterval) - if err != nil { - return err - } - } - tsdbOpts := &tsdb.Options{ MinBlockDuration: int64(time.Duration(*tsdbMinBlockDuration) / time.Millisecond), MaxBlockDuration: int64(time.Duration(*tsdbMaxBlockDuration) / time.Millisecond), @@ -376,8 +368,8 @@ func runReceive( // watcher, we close the chan ourselves. updates := make(chan receive.Hashring, 1) - // The Hashrings config file path given initializing config watcher. - if configPath, err := hashringsFile.Path(); err != nil { + // The Hashrings config file path is given initializing config watcher. + if configPath, err := hashringsFile.Path(); err == nil && configPath != "" { cw, err := receive.NewConfigWatcher(log.With(logger, "component", "config-watcher"), reg, configPath, *refreshInterval) if err != nil { return errors.Wrap(err, "failed to initialize config watcher") @@ -397,6 +389,7 @@ func runReceive( cancel() }) } else { + // The Hashrings config file path is not given, so initialize using content.. configContent, err := hashringsFile.Content() if err != nil { return errors.Wrap(err, "failed to read hashrings configuration file") diff --git a/pkg/extflag/pathorcontent.go b/pkg/extflag/pathorcontent.go index b8455c385ac..bc2a50d58e2 100644 --- a/pkg/extflag/pathorcontent.go +++ b/pkg/extflag/pathorcontent.go @@ -44,7 +44,8 @@ func RegisterPathOrContent(cmd FlagClause, flagName string, help string, require } } -// Content returns the content of the file. Flag that specifies path has priority. +// Content returns the content of the file when given or directly the content that has passed to the flag. +// Flag that specifies path has priority. // It returns error if the content is empty and required flag is set to true. func (p *PathOrContent) Content() ([]byte, error) { fileFlagName := fmt.Sprintf("%s-file", p.flagName) @@ -71,9 +72,9 @@ func (p *PathOrContent) Content() ([]byte, error) { return content, nil } -// Path returns the path of the file. Flag that specifies path has priority. -// It returns error if the required flag is set to true and content is empty. -// It also returns errors if both a path and content are given. +// Path returns the path of the given file that has passed to the flag. +// It returns error if both a path and content are given. +// It returns error if the required flag is set to true and path is empty. func (p *PathOrContent) Path() (string, error) { fileFlagName := fmt.Sprintf("%s-file", p.flagName)