From 0a5f763fd9becbeb5313291f26def033f726907e Mon Sep 17 00:00:00 2001 From: wanjunlei Date: Mon, 26 Sep 2022 17:39:25 +0800 Subject: [PATCH] Support disable block viewer UI in compactor Signed-off-by: wanjunlei --- CHANGELOG.md | 1 + cmd/thanos/compact.go | 80 ++++++++++++++++++++++--------------------- cmd/thanos/config.go | 2 ++ 3 files changed, 44 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87f4b571f2a..51d2bf68f58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re - [#5650](https://github.com/thanos-io/thanos/pull/5650) Query Frontend: Add sharded queries metrics. - [#5658](https://github.com/thanos-io/thanos/pull/5658) Query Frontend: Introduce new optional parameters (`query-range.min-split-interval`, `query-range.max-split-interval`, `query-range.horizontal-shards`) to implement more dynamic horizontal query splitting. - [#5721](https://github.com/thanos-io/thanos/pull/5721) Store: Add metric `thanos_bucket_store_empty_postings_total` for number of empty postings when fetching series. +- [#5723](https://github.com/thanos-io/thanos/pull/5723) Compactor: Support disable block viewer UI. ### Changed diff --git a/cmd/thanos/compact.go b/cmd/thanos/compact.go index 6d81b32975a..762d9b313b3 100644 --- a/cmd/thanos/compact.go +++ b/cmd/thanos/compact.go @@ -509,28 +509,49 @@ func runCompact( }) if conf.wait { - r := route.New() - - ins := extpromhttp.NewInstrumentationMiddleware(reg, nil) - - global := ui.NewBucketUI(logger, conf.webConf.externalPrefix, conf.webConf.prefixHeaderName, component) - global.Register(r, ins) - - // Configure Request Logging for HTTP calls. - opts := []logging.Option{logging.WithDecider(func(_ string, _ error) logging.Decision { - return logging.NoLogCall - })} - logMiddleware := logging.NewHTTPServerMiddleware(logger, opts...) - api.Register(r.WithPrefix("/api/v1"), tracer, logger, ins, logMiddleware) + if !conf.webConf.disable { + r := route.New() + + ins := extpromhttp.NewInstrumentationMiddleware(reg, nil) + + global := ui.NewBucketUI(logger, conf.webConf.externalPrefix, conf.webConf.prefixHeaderName, component) + global.Register(r, ins) + + // Configure Request Logging for HTTP calls. + opts := []logging.Option{logging.WithDecider(func(_ string, _ error) logging.Decision { + return logging.NoLogCall + })} + logMiddleware := logging.NewHTTPServerMiddleware(logger, opts...) + api.Register(r.WithPrefix("/api/v1"), tracer, logger, ins, logMiddleware) + + // Separate fetcher for global view. + // TODO(bwplotka): Allow Bucket UI to visualize the state of the block as well. + f := baseMetaFetcher.NewMetaFetcher(extprom.WrapRegistererWithPrefix("thanos_bucket_ui", reg), nil, "component", "globalBucketUI") + f.UpdateOnChange(func(blocks []metadata.Meta, err error) { + api.SetGlobal(blocks, err) + }) - // Separate fetcher for global view. - // TODO(bwplotka): Allow Bucket UI to visualize the state of the block as well. - f := baseMetaFetcher.NewMetaFetcher(extprom.WrapRegistererWithPrefix("thanos_bucket_ui", reg), nil, "component", "globalBucketUI") - f.UpdateOnChange(func(blocks []metadata.Meta, err error) { - api.SetGlobal(blocks, err) - }) + srv.Handle("/", r) - srv.Handle("/", r) + g.Add(func() error { + iterCtx, iterCancel := context.WithTimeout(ctx, conf.blockViewerSyncBlockTimeout) + _, _, _ = f.Fetch(iterCtx) + iterCancel() + + // For /global state make sure to fetch periodically. + return runutil.Repeat(conf.blockViewerSyncBlockInterval, ctx.Done(), func() error { + return runutil.RetryWithLog(logger, time.Minute, ctx.Done(), func() error { + iterCtx, iterCancel := context.WithTimeout(ctx, conf.blockViewerSyncBlockTimeout) + defer iterCancel() + + _, _, err := f.Fetch(iterCtx) + return err + }) + }) + }, func(error) { + cancel() + }) + } // Periodically remove partial blocks and blocks marked for deletion // since one iteration potentially could take a long time. @@ -593,25 +614,6 @@ func runCompact( cancel() }) } - - g.Add(func() error { - iterCtx, iterCancel := context.WithTimeout(ctx, conf.blockViewerSyncBlockTimeout) - _, _, _ = f.Fetch(iterCtx) - iterCancel() - - // For /global state make sure to fetch periodically. - return runutil.Repeat(conf.blockViewerSyncBlockInterval, ctx.Done(), func() error { - return runutil.RetryWithLog(logger, time.Minute, ctx.Done(), func() error { - iterCtx, iterCancel := context.WithTimeout(ctx, conf.blockViewerSyncBlockTimeout) - defer iterCancel() - - _, _, err := f.Fetch(iterCtx) - return err - }) - }) - }, func(error) { - cancel() - }) } level.Info(logger).Log("msg", "starting compact node") diff --git a/cmd/thanos/config.go b/cmd/thanos/config.go index 9f055e27fa7..4fb16576493 100644 --- a/cmd/thanos/config.go +++ b/cmd/thanos/config.go @@ -154,6 +154,7 @@ func (sc *shipperConfig) registerFlag(cmd extkingpin.FlagClause) *shipperConfig } type webConfig struct { + disable bool routePrefix string externalPrefix string prefixHeaderName string @@ -161,6 +162,7 @@ type webConfig struct { } func (wc *webConfig) registerFlag(cmd extkingpin.FlagClause) *webConfig { + cmd.Flag("web.disable", "Disable Block Viewer UI.").Default("false").BoolVar(&wc.disable) cmd.Flag("web.route-prefix", "Prefix for API and UI endpoints. This allows thanos UI to be served on a sub-path. This option is analogous to --web.route-prefix of Prometheus."). Default("").StringVar(&wc.routePrefix)