From 0be3bf8eda98bb40fa881e3d1002bb686977d20f Mon Sep 17 00:00:00 2001 From: Andras Ferencz-Szabo Date: Thu, 17 Oct 2019 13:12:35 +0100 Subject: [PATCH] Add a new prometheus.ready_timeout CLI option to the sidecar The current timeout while the Prometheus instance is starting up is a constant 10 minutes. As reading the WAL can take a long time we would like to set a custom timeout value, so the Thanos sidecar container is not erroring out every 10 minutes. --- CHANGELOG.md | 4 ++++ cmd/thanos/sidecar.go | 11 +++++++---- docs/components/sidecar.md | 3 +++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc2db529d9c..c7c45a703b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ We use *breaking* word for marking changes that are not backward compatible (rel ## Unreleased +### Added + +- [#1660](https://github.com/thanos-io/thanos/pull/1660) Add a new `--prometheus.ready_timeout` CLI option to the sidecar to set how long to wait until Prometheus starts up. + ## [v0.8.1](https://github.com/thanos-io/thanos/releases/tag/v0.8.1) - 2019.10.14 ### Fixed diff --git a/cmd/thanos/sidecar.go b/cmd/thanos/sidecar.go index 403bce843e0..dfc2b4ac56b 100644 --- a/cmd/thanos/sidecar.go +++ b/cmd/thanos/sidecar.go @@ -32,8 +32,6 @@ import ( "gopkg.in/alecthomas/kingpin.v2" ) -const waitForExternalLabelsTimeout = 10 * time.Minute - func registerSidecar(m map[string]setupFunc, app *kingpin.Application) { cmd := app.Command(component.Sidecar.String(), "sidecar for Prometheus server") @@ -43,6 +41,9 @@ func registerSidecar(m map[string]setupFunc, app *kingpin.Application) { promURL := cmd.Flag("prometheus.url", "URL at which to reach Prometheus's API. For better performance use local network."). Default("http://localhost:9090").URL() + promReadyTimeout := cmd.Flag("prometheus.ready_timeout", "Maximum time to wait for the Prometheus instance to start up"). + Default("10m").Duration() + dataDir := cmd.Flag("tsdb.path", "Data directory of TSDB."). Default("./data").String() @@ -81,6 +82,7 @@ func registerSidecar(m map[string]setupFunc, app *kingpin.Application) { *clientCA, *httpBindAddr, *promURL, + *promReadyTimeout, *dataDir, objStoreConfig, rl, @@ -102,6 +104,7 @@ func runSidecar( clientCA string, httpBindAddr string, promURL *url.URL, + promReadyTimeout time.Duration, dataDir string, objStoreConfig *extflag.PathOrContent, reloader *reloader.Reloader, @@ -268,7 +271,7 @@ func runSidecar( g.Add(func() error { defer runutil.CloseWithLogOnErr(logger, bkt, "bucket client") - extLabelsCtx, cancel := context.WithTimeout(ctx, waitForExternalLabelsTimeout) + extLabelsCtx, cancel := context.WithTimeout(ctx, promReadyTimeout) defer cancel() if err := runutil.Retry(2*time.Second, extLabelsCtx.Done(), func() error { @@ -277,7 +280,7 @@ func runSidecar( } return nil }); err != nil { - return errors.Wrapf(err, "aborting as no external labels found after waiting %s", waitForExternalLabelsTimeout) + return errors.Wrapf(err, "aborting as no external labels found after waiting %s", promReadyTimeout) } var s *shipper.Shipper diff --git a/docs/components/sidecar.md b/docs/components/sidecar.md index 60699f125fb..a1d1a92112c 100644 --- a/docs/components/sidecar.md +++ b/docs/components/sidecar.md @@ -116,6 +116,9 @@ Flags: --prometheus.url=http://localhost:9090 URL at which to reach Prometheus's API. For better performance use local network. + --prometheus.ready_timeout=10m + Maximum time to wait for the Prometheus + instance to start up --tsdb.path="./data" Data directory of TSDB. --reloader.config-file="" Config file watched by the reloader. --reloader.config-envsubst-file=""