Skip to content
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

Compact: Display Planned and Running Compactions #7590

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

amandaguan-ag
Copy link

@amandaguan-ag amandaguan-ag commented Aug 2, 2024

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

Changes

planned blocks
image

Verification

Signed-off-by: amandaguan-ag <amandaguan1314@gmail.com>
…tching planned blocks

Signed-off-by: amandaguan-ag <amandaguan1314@gmail.com>
…ndicator, and Blocks component with API integration

Signed-off-by: amandaguan-ag <amandaguan1314@gmail.com>
Signed-off-by: amandaguan-ag <amandaguan1314@gmail.com>
@pull-request-size pull-request-size bot added size/L and removed size/M labels Aug 8, 2024
Copy link
Member

@saswatamcode saswatamcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Some feedback

}

metasByMinTime := []*metadata.Meta{&mockBlocks[0], &mockBlocks[1]}
plannedMetas, err := bapi.planner.Plan(context.TODO(), metasByMinTime, nil, nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we define bapi.planner anywhere?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just defined bapi.planner in the BlocksAPI struct

.bin/gopls Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably shouldn't be committing these? :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add these files in .gitignore, i got these files everytime i run make react-app

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is your GOBIN set to? I think this causes issues

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my says /Users/amandaguan/Desktop/Epicodus/thanos/.bin, as instructed by CONTRIBUTING.md

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, those are older instructions, usually don't need to.

pkg/api/blocks/v1.go Outdated Show resolved Hide resolved
Comment on lines 271 to 274
if (globalBlocksLoading || planLoading) return <div>Loading...</div>;
if (globalBlocksError) return <UncontrolledAlert color="danger">{globalBlocksError.toString()}</UncontrolledAlert>;
if (planError) return <UncontrolledAlert color="danger">{planError.toString()}</UncontrolledAlert>;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we need this, I think the WithStatusIndicator handles this for us?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. withStatusIndicator HOC will be handling the loading and error states, i will remove the redundant checks


if (err) {
return (
<UncontrolledAlert color="danger">{err.toString()}</UncontrolledAlert>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably done with status indicator already?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will look in withStatusIndicator for this one. I see BlocksContent also has this direct handling

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see withStatusIndicator is handling error in general and Displaying an error message (. I will take off from PlanBlocksContent and maybe from BlocksContent

key={key}
data={blocksPool[key]}
title={`Plan View - ${key}`}
selectBlock={() => { }} // No-op function if selection is not applicable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why no-op here?

isLoading={isLoading}
/>
<div>
<h2>Planned Blocks</h2>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think...this would make sense as a separate page rather than a component above the Global Blocks screen?

…ithStatusIndicator HOC should be handling the loading and error states
The selectBlock function is passed down to SourceView where it can be invoked, typically through some user interaction like clicking on a block.
    - Add new routes for Global Blocks and Planned Blocks in App.tsx
    - Update navigation configuration to include links to new pages
    - Create GlobalBlocks and PlannedBlocks components
    - Implement separate views for global and planned blocks
    - Ensure proper routing and prop passing for new components

    This commit introduces dedicated pages for viewing Global Blocks and
    Planned Blocks, improving the organization and accessibility of block
    information in the Thanos UI.
    Signed-off-by: amandaguan-ag <amandaguan1314@gmail.com>
Signed-off-by: amandaguan-ag <amandaguan1314@gmail.com>
    Signed-off-by: amandaguan-ag <amandaguan1314@gmail.com>
    Signed-off-by: amandaguan-ag <amandaguan1314@gmail.com>
@amandaguan-ag amandaguan-ag force-pushed the ag-compact-plan-ui branch 2 times, most recently from c461c53 to 28ec713 Compare August 15, 2024 15:26
This commit introduces the `UpdateOnPlanned` method in the `tsdbBasedPlanner` struct, allowing for dynamic updates of planned block metadata. The callback mechanism is integrated into the compaction process to handle planned blocks efficiently.

The main changes include:
- Definition and implementation of `UpdateOnPlanned` in `tsdbBasedPlanner`.
- Adjustment in `runCompact` to instantiate `tsdbPlanner` at the beginning of the function, ensuring accessibility throughout the compaction process and avoiding repeated declaration.
- Use of `UpdateOnPlanned` to set planned blocks via the API, enhancing the flexibility and responsiveness of block management.

By moving the `tsdbPlanner` instantiation earlier in `runCompact`, we avoid duplication and enhance code clarity, ensuring the planner is accessible where needed without multiple initializations.

Signed-off-by: amandaguan-ag<amandaguan1314@gmail.com>
Signed-off-by: amandaguan-ag <amandaguan1314@gmail.com>
@@ -1135,6 +1140,9 @@ func (cg *Group) compact(ctx context.Context, dir string, planner Planner, comp
var toCompact []*metadata.Meta
if err := tracing.DoInSpanWithErr(ctx, "compaction_planning", func(ctx context.Context) (e error) {
toCompact, e = planner.Plan(ctx, cg.metasByMinTime, errChan, cg.extensions)
planner.UpdateOnPlanned(func(metas []metadata.Meta, err error) {
level.Info(cg.logger).Log("msg", "planner updated", "metas", len(metas), "err", err)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

planner.UpdateOnPlanned(func(blocks []metadata.Meta, err error) {
api.SetPlanned(blocks, err)
})

// SetPlanned updates the plan blocks' metadata in the API.
func (bapi *BlocksAPI) SetPlanned(blocks []metadata.Meta, err error) {

bapi.plannedBlocksInfo.set(blocks, err)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be a append operation

@@ -53,6 +54,10 @@ func (p *tsdbBasedPlanner) Plan(_ context.Context, metasByMinTime []*metadata.Me
return p.plan(p.noCompBlocksFunc(), metasByMinTime)
}

func (p *tsdbBasedPlanner) UpdateOnPlanned(f func([]metadata.Meta, error)) {
p.updateOnPlanned = f
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateOnPlanned needs to be called from somewhere..to figure out.

Also, let's do this on the planner interface instead?

@@ -25,6 +25,7 @@ type tsdbBasedPlanner struct {
ranges []int64

noCompBlocksFunc func() map[ulid.ULID]*metadata.NoCompactMark
updateOnPlanned func([]metadata.Meta, error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe listener instead of updateOnPlanned?

@@ -288,6 +295,7 @@ func runCompact(
cf.UpdateOnChange(func(blocks []metadata.Meta, err error) {
api.SetLoaded(blocks, err)
})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should pass in blocksAPI.SetPlanned into UpdateOnPlanned callback?

@@ -1135,6 +1140,9 @@ func (cg *Group) compact(ctx context.Context, dir string, planner Planner, comp
var toCompact []*metadata.Meta
if err := tracing.DoInSpanWithErr(ctx, "compaction_planning", func(ctx context.Context) (e error) {
toCompact, e = planner.Plan(ctx, cg.metasByMinTime, errChan, cg.extensions)
planner.UpdateOnPlanned(func(metas []metadata.Meta, err error) {
level.Info(cg.logger).Log("msg", "planner updated", "metas", len(metas), "err", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SetPlanned over here?

@@ -1135,6 +1140,9 @@ func (cg *Group) compact(ctx context.Context, dir string, planner Planner, comp
var toCompact []*metadata.Meta
if err := tracing.DoInSpanWithErr(ctx, "compaction_planning", func(ctx context.Context) (e error) {
toCompact, e = planner.Plan(ctx, cg.metasByMinTime, errChan, cg.extensions)
planner.UpdateOnPlanned(func(metas []metadata.Meta, err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call this on group level, and get plans of every group, and set it once

1. Add BlocksAPI to Compact method

2. Update BlocksAPI initialization
   - Return plannedBlocksInfo in BlocksAPI constructor

3. Enhance compact package
   - Add blocksAPI parameter to Group.compact method

This change improves the integration of BlocksAPI with the compaction
process.

Signed-off-by: [amandaguan-ag] <amandaguan1314@gmail.com>
1. Introduce `blocksAPI` fields to the `BucketCompactor` struct.
2. Implement logic to retrieve metas for the current group and convert them into `[]metadata.Meta`.
3. Invoke `Syncer.SetPlanned` prior to compaction to update the syncer's state.
4. Invoke `BlocksAPI.SetPlanned` to synchronize the API with the planned metas.

These updates enhance the tracking and management of planned compactions, streamlining the overall process and ensuring that external systems are informed of upcoming compactions.

Signed-off-by: [amandaguan-ag] <amandaguan1314@gmail.com>
groupMetas := g.Metas()

// Delete before merge: Convert []*metadata.Meta to []metadata.Meta
plannedMetas := make([]metadata.Meta, len(groupMetas))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think we are just setting blocks of the group, instead of the planned blocks? We need planner.Plan output

}

// Delete before merge: Call Syncer.SetPlanned before compaction
if err := c.sy.SetPlanned(plannedMetas); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be overriden on each group

@@ -1475,7 +1490,33 @@ func (c *BucketCompactor) Compact(ctx context.Context, v1 *v1.BlocksAPI) (rerr e
go func() {
defer wg.Done()
for g := range groupChan {
shouldRerunGroup, _, err := g.Compact(workCtx, c.compactDir, c.planner, c.comp, c.blockDeletableChecker, c.compactionLifecycleCallback, v1)
// Delete before merge: Get the metas for the current group
groupMetas := g.Metas()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do i need change the source from g to planner.plan, move out not for group

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read go routine, and channels ->concurrency

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants