Skip to content

Commit

Permalink
ui: Fix Block Viewer for Compactor and Store (thanos-io#3098)
Browse files Browse the repository at this point in the history
* ui: Fix Block viewer for Compactor and Store

Signed-off-by: Prem Kumar <[email protected]>

* Add an entry in CHANGELOG.md

Signed-off-by: Prem Kumar <[email protected]>

* ui: react: Fixed tests for Blocks

Signed-off-by: Prem Kumar <[email protected]>
Signed-off-by: Kemal Akkoyun <[email protected]>
  • Loading branch information
onprem authored and kakkoyun committed Sep 7, 2020
1 parent a060c41 commit f02d941
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 92 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ We use *breaking :warning:* word for marking changes that are not backward compa

:warning: **WARNING** :warning: Thanos Rule's `/api/v1/rules` endpoint no longer returns the old, deprecated `partial_response_strategy`. The old, deprecated value has been fixed to `WARN` for quite some time. _Please_ use `partialResponseStrategy`.

:warning: **WARNING** :warning: The `sse_encryption` value is now deprecated in favour of `sse_config`. If you used `sse_encryption`, the migration strategy is to set up the following block:

```yaml
* [#3095](https://github.com/thanos-io/thanos/pull/3095) Rule: update manager when all rule files are removed.
* [#3098](https://github.com/thanos-io/thanos/pull/3098) ui: Fix Block Viewer for Compactor and Store

---
sse_config:
Expand Down
19 changes: 12 additions & 7 deletions cmd/thanos/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,12 @@ func runCompact(
compactorView := ui.NewBucketUI(
logger,
conf.label,
path.Join(conf.webConf.externalPrefix, "/loaded"),
conf.webConf.externalPrefix,
conf.webConf.prefixHeaderName,
"/loaded",
component,
)
api := blocksAPI.NewBlocksAPI(logger, conf.label, flagsMap)
var sy *compact.Syncer
{
// Make sure all compactor meta syncs are done through Syncer.SyncMeta for readability.
Expand All @@ -227,7 +230,10 @@ func runCompact(
duplicateBlocksFilter,
}, []block.MetadataModifier{block.NewReplicaLabelRemover(logger, conf.dedupReplicaLabels)},
)
cf.UpdateOnChange(compactorView.Set)
cf.UpdateOnChange(func(blocks []metadata.Meta, err error) {
compactorView.Set(blocks, err)
api.SetLoaded(blocks, err)
})
sy, err = compact.NewSyncer(
logger,
reg,
Expand Down Expand Up @@ -393,12 +399,11 @@ func runCompact(
r := route.New()

ins := extpromhttp.NewInstrumentationMiddleware(reg)
compactorView.Register(r, ins)
compactorView.Register(r, true, ins)

global := ui.NewBucketUI(logger, conf.label, path.Join(conf.webConf.externalPrefix, "/global"), conf.webConf.prefixHeaderName)
global.Register(r, ins)
global := ui.NewBucketUI(logger, conf.label, conf.webConf.externalPrefix, conf.webConf.prefixHeaderName, "/global", component)
global.Register(r, false, ins)

api := blocksAPI.NewBlocksAPI(logger, conf.label, flagsMap)
// Configure Request Logging for HTTP calls.
opts := []logging.Option{logging.WithDecider(func() logging.Decision {
return logging.NoLogCall
Expand All @@ -411,7 +416,7 @@ func runCompact(
f := baseMetaFetcher.NewMetaFetcher(extprom.WrapRegistererWithPrefix("thanos_bucket_ui", reg), nil, nil, "component", "globalBucketUI")
f.UpdateOnChange(func(blocks []metadata.Meta, err error) {
global.Set(blocks, err)
api.Set(blocks, err)
api.SetGlobal(blocks, err)
})

srv.Handle("/", r)
Expand Down
26 changes: 22 additions & 4 deletions cmd/thanos/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package main
import (
"context"
"fmt"
"path"
"time"

"github.com/go-kit/kit/log"
Expand All @@ -17,13 +16,16 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/common/route"
blocksAPI "github.com/thanos-io/thanos/pkg/api/blocks"
"github.com/thanos-io/thanos/pkg/block"
"github.com/thanos-io/thanos/pkg/block/metadata"
"github.com/thanos-io/thanos/pkg/component"
"github.com/thanos-io/thanos/pkg/extflag"
"github.com/thanos-io/thanos/pkg/extkingpin"
"github.com/thanos-io/thanos/pkg/extprom"
extpromhttp "github.com/thanos-io/thanos/pkg/extprom/http"
"github.com/thanos-io/thanos/pkg/gate"
"github.com/thanos-io/thanos/pkg/logging"
"github.com/thanos-io/thanos/pkg/model"
"github.com/thanos-io/thanos/pkg/objstore/client"
"github.com/thanos-io/thanos/pkg/prober"
Expand Down Expand Up @@ -149,6 +151,7 @@ func registerStore(app *extkingpin.App) {
*webPrefixHeaderName,
*postingOffsetsInMemSampling,
cachingBucketConfig,
getFlagsMap(cmd.Model().Flags),
)
})
}
Expand Down Expand Up @@ -180,6 +183,7 @@ func runStore(
externalPrefix, prefixHeader string,
postingOffsetsInMemSampling int,
cachingBucketConfig *extflag.PathOrContent,
flagsMap map[string]string,
) error {
grpcProbe := prober.NewGRPC()
httpProbe := prober.NewHTTP()
Expand Down Expand Up @@ -363,9 +367,23 @@ func runStore(
// Add bucket UI for loaded blocks.
{
r := route.New()
compactorView := ui.NewBucketUI(logger, "", path.Join(externalPrefix, "/loaded"), prefixHeader)
compactorView.Register(r, extpromhttp.NewInstrumentationMiddleware(reg))
metaFetcher.UpdateOnChange(compactorView.Set)
ins := extpromhttp.NewInstrumentationMiddleware(reg)

compactorView := ui.NewBucketUI(logger, "", externalPrefix, prefixHeader, "/loaded", component)
compactorView.Register(r, true, ins)

// Configure Request Logging for HTTP calls.
opts := []logging.Option{logging.WithDecider(func() logging.Decision {
return logging.NoLogCall
})}
logMiddleware := logging.NewHTTPServerMiddleware(logger, opts...)
api := blocksAPI.NewBlocksAPI(logger, "", flagsMap)
api.Register(r.WithPrefix("/api/v1"), tracer, logger, ins, logMiddleware)

metaFetcher.UpdateOnChange(func(blocks []metadata.Meta, err error) {
compactorView.Set(blocks, err)
api.SetLoaded(blocks, err)
})
srv.Handle("/", r)
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/thanos/tools_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ func registerBucketWeb(app extkingpin.AppClause, objStoreConfig *extflag.PathOrC
router := route.New()
ins := extpromhttp.NewInstrumentationMiddleware(reg)

bucketUI := ui.NewBucketUI(logger, *label, *webExternalPrefix, *webPrefixHeaderName)
bucketUI.Register(router, ins)
bucketUI := ui.NewBucketUI(logger, *label, *webExternalPrefix, *webPrefixHeaderName, "", component.Bucket)
bucketUI.Register(router, true, ins)

flagsMap := getFlagsMap(cmd.Flags())

Expand Down Expand Up @@ -393,7 +393,7 @@ func registerBucketWeb(app extkingpin.AppClause, objStoreConfig *extflag.PathOrC
}
fetcher.UpdateOnChange(func(blocks []metadata.Meta, err error) {
bucketUI.Set(blocks, err)
api.Set(blocks, err)
api.SetGlobal(blocks, err)
})

ctx, cancel := context.WithCancel(context.Background())
Expand Down
42 changes: 30 additions & 12 deletions pkg/api/blocks/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (

// BlocksAPI is a very simple API used by Thanos Block Viewer.
type BlocksAPI struct {
baseAPI *api.BaseAPI
logger log.Logger
blocksInfo *BlocksInfo
baseAPI *api.BaseAPI
logger log.Logger
globalBlocksInfo *BlocksInfo
loadedBlocksInfo *BlocksInfo
}

type BlocksInfo struct {
Expand All @@ -35,7 +36,11 @@ func NewBlocksAPI(logger log.Logger, label string, flagsMap map[string]string) *
return &BlocksAPI{
baseAPI: api.NewBaseAPI(logger, flagsMap),
logger: logger,
blocksInfo: &BlocksInfo{
globalBlocksInfo: &BlocksInfo{
Blocks: []metadata.Meta{},
Label: label,
},
loadedBlocksInfo: &BlocksInfo{
Blocks: []metadata.Meta{},
Label: label,
},
Expand All @@ -51,19 +56,32 @@ func (bapi *BlocksAPI) Register(r *route.Router, tracer opentracing.Tracer, logg
}

func (bapi *BlocksAPI) blocks(r *http.Request) (interface{}, []error, *api.ApiError) {
return bapi.blocksInfo, nil, nil
viewParam := r.URL.Query().Get("view")
if viewParam == "loaded" {
return bapi.loadedBlocksInfo, nil, nil
}
return bapi.globalBlocksInfo, nil, nil
}

// Set updates the blocks' metadata in the API.
func (bapi *BlocksAPI) Set(blocks []metadata.Meta, err error) {
func (b *BlocksInfo) set(blocks []metadata.Meta, err error) {
if err != nil {
// Last view is maintained.
bapi.blocksInfo.RefreshedAt = time.Now()
bapi.blocksInfo.Err = err
b.RefreshedAt = time.Now()
b.Err = err
return
}

bapi.blocksInfo.RefreshedAt = time.Now()
bapi.blocksInfo.Blocks = blocks
bapi.blocksInfo.Err = err
b.RefreshedAt = time.Now()
b.Blocks = blocks
b.Err = err
}

// SetGlobal updates the global blocks' metadata in the API.
func (bapi *BlocksAPI) SetGlobal(blocks []metadata.Meta, err error) {
bapi.globalBlocksInfo.set(blocks, err)
}

// SetLoaded updates the local blocks' metadata in the API.
func (bapi *BlocksAPI) SetLoaded(blocks []metadata.Meta, err error) {
bapi.loadedBlocksInfo.set(blocks, err)
}
Loading

0 comments on commit f02d941

Please sign in to comment.