Skip to content

Commit

Permalink
Support disable block viewer UI in compactor
Browse files Browse the repository at this point in the history
Signed-off-by: wanjunlei <wanjunlei@kubesphere.io>
  • Loading branch information
wanjunlei committed Sep 26, 2022
1 parent abaef5b commit 0a5f763
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 39 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
80 changes: 41 additions & 39 deletions cmd/thanos/compact.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions cmd/thanos/config.go
Expand Up @@ -154,13 +154,15 @@ func (sc *shipperConfig) registerFlag(cmd extkingpin.FlagClause) *shipperConfig
}

type webConfig struct {
disable bool
routePrefix string
externalPrefix string
prefixHeaderName string
disableCORS bool
}

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)
Expand Down

0 comments on commit 0a5f763

Please sign in to comment.