-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ui: Fix Block Viewer for Compactor and Store #3098
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -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, | ||
}, | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels weird from perspective on components that does not have global 🤔 Also I think it's on purpose that in code we talk about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree it is weird. But in our last 1:1, me, @squat, and @GiedriusS discussed and decided to go with this. As we have the same API but different needs in different components (Bucket viewer: a global view of blocks, Compactor: both global and loaded and Store: loaded only) we came up with two solutions:
The first solution is more generic but it requires us to modify logic for all of the API packages. Also, it would result in some weird endpoints like |
||
} | ||
|
||
// 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) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this, as it's fixing the release directly. But that's ok I will adjust it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!