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
Draft
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6ceb3b7
feat(test): Add sleep delay and browser opening for e2einteractive data
amandaguan-ag Aug 2, 2024
112bc0d
feat(blocksAPI): Add plannedBlocksInfo, plannedLock, and route for fe…
amandaguan-ag Aug 2, 2024
1dca384
feat(ui): Add placeholders for PlanBlocksContent, PlanViewWithStatusI…
amandaguan-ag Aug 2, 2024
e7c15bf
chore(build): Update auto-generated React build files
amandaguan-ag Aug 2, 2024
dbe5d56
Add mock data and simply list out planned blocks
amandaguan-ag Aug 8, 2024
d43a456
TODO: fix bapi.planner undefined (type *BlocksAPI has no field or met…
amandaguan-ag Aug 8, 2024
c6cf932
TODO: fix Type 'Block[][]' is not assignable to type 'BlocksPool'.
amandaguan-ag Aug 8, 2024
71b94c6
planner is passed as an argument to the NewBlocksAPI function and the…
amandaguan-ag Aug 8, 2024
72942d0
simplify the Blocks component by removing the redundant checks, The w…
amandaguan-ag Aug 8, 2024
2a486c9
add useState to manage the selected block.
amandaguan-ag Aug 8, 2024
f9777dc
remove SetPlanned placeholder
amandaguan-ag Aug 9, 2024
3c7b555
feat(api): Add mock data for planned blocks
amandaguan-ag Aug 12, 2024
f343a47
remove planner
amandaguan-ag Aug 13, 2024
a039136
Add Global and Planned Blocks pages
amandaguan-ag Aug 13, 2024
08592ae
Update auto-generated React build files
amandaguan-ag Aug 13, 2024
ea98f7c
fix prettier error
amandaguan-ag Aug 13, 2024
394d56e
Move GlobalBlocks and PlannedBlocks components to the blocks directory
amandaguan-ag Aug 13, 2024
7c46fc2
Update auto-generated React build files
amandaguan-ag Aug 13, 2024
28ec713
fix comment indent
amandaguan-ag Aug 13, 2024
97e0886
feat: Add UpdateOnPlanned callback support to tsdbBasedPlanner
amandaguan-ag Aug 15, 2024
06cfa3a
define the UpdateOnPlanned method on the Planner interface, rather th…
amandaguan-ag Aug 20, 2024
87134d3
call UpdateOnPlanned after each Plan call.
amandaguan-ag Aug 20, 2024
ee15442
Replace mock data with plannedBlocksInfo
amandaguan-ag Aug 21, 2024
ac2253a
compact: Add BlocksAPI and improve logging
amandaguan-ag Aug 23, 2024
2f19b48
Enhance BucketCompactor with tracking and synchronization features
amandaguan-ag Aug 26, 2024
2c7d008
update compact_e2e_test with api field in NewBucketCompactor
amandaguan-ag Aug 27, 2024
82a07e7
replace g.Metas() with planner.Plan
amandaguan-ag Aug 29, 2024
b4ffc90
accumulate all the planned metas from all groups before calling SetPl…
amandaguan-ag Aug 29, 2024
1046dfa
add mergeFunc to NewBucketCompactor
amandaguan-ag Aug 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .bin/gopls
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.

Binary file not shown.
Binary file added .bin/gotesplit-v0.2.1
Binary file not shown.
Binary file added .bin/staticcheck
Binary file not shown.
2 changes: 2 additions & 0 deletions .bingo/gotesplit.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
github.com/Songmu/gotesplit v0.2.1 h1:qJFvR75nJpeKyMQFwyDtFrcc6zDWhrHAkks7DvM8oLo=
github.com/Songmu/gotesplit v0.2.1/go.mod h1:sVBfmLT26b1H5VhUpq8cRhCVK75GAmW9c8r2NiK0gzk=
github.com/jstemmer/go-junit-report v1.0.0 h1:8X1gzZpR+nVQLAht+L/foqOeX2l9DTZoaIPbEQHxsds=
github.com/jstemmer/go-junit-report v1.0.0/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 h1:w8s32wxx3sY+OjLlv9qltkLU5yvJzxjjgiHWLjdIcw4=
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
14 changes: 8 additions & 6 deletions cmd/thanos/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ func runCompact(
consistencyDelayMetaFilter := block.NewConsistencyDelayMetaFilter(logger, conf.consistencyDelay, extprom.WrapRegistererWithPrefix("thanos_", reg))
timePartitionMetaFilter := block.NewTimePartitionMetaFilter(conf.filterConf.MinTime, conf.filterConf.MaxTime)

levels, err := compactions.levels(conf.maxCompactionLevel)
if err != nil {
return errors.Wrap(err, "get compaction levels")
}

tsdbPlanner := compact.NewPlanner(logger, levels, noCompactMarkerFilter)

var blockLister block.Lister
switch syncStrategy(conf.blockListStrategy) {
case concurrentDiscovery:
Expand Down Expand Up @@ -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?

sy, err = compact.NewMetaSyncer(
logger,
reg,
Expand All @@ -303,11 +311,6 @@ func runCompact(
}
}

levels, err := compactions.levels(conf.maxCompactionLevel)
if err != nil {
return errors.Wrap(err, "get compaction levels")
}

if conf.maxCompactionLevel < compactions.maxLevel() {
level.Warn(logger).Log("msg", "Max compaction level is lower than should be", "current", conf.maxCompactionLevel, "default", compactions.maxLevel())
}
Expand Down Expand Up @@ -371,7 +374,6 @@ func runCompact(
)
var planner compact.Planner

tsdbPlanner := compact.NewPlanner(logger, levels, noCompactMarkerFilter)
largeIndexFilterPlanner := compact.WithLargeTotalIndexSizeFilter(
tsdbPlanner,
insBkt,
Expand Down
35 changes: 28 additions & 7 deletions pkg/api/blocks/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ import (

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

globalLock, loadedLock sync.Mutex
disableCORS bool
bkt objstore.Bucket
disableAdminOperations bool
disableCORS bool
bkt objstore.Bucket
disableAdminOperations bool
}

type BlocksInfo struct {
Expand Down Expand Up @@ -90,6 +91,7 @@ func (bapi *BlocksAPI) Register(r *route.Router, tracer opentracing.Tracer, logg

r.Get("/blocks", instr("blocks", bapi.blocks))
r.Post("/blocks/mark", instr("blocks_mark", bapi.markBlock))
r.Get("/blocks/plan", instr("blocks_plan", bapi.plannedBlocks))
}

func (bapi *BlocksAPI) markBlock(r *http.Request) (interface{}, []error, *api.ApiError, func()) {
Expand Down Expand Up @@ -146,6 +148,19 @@ func (bapi *BlocksAPI) blocks(r *http.Request) (interface{}, []error, *api.ApiEr
return bapi.globalBlocksInfo, nil, nil, func() {}
}

func (bapi *BlocksAPI) plannedBlocks(r *http.Request) (interface{}, []error, *api.ApiError, func()) {
ctx := r.Context()


select {
case <-ctx.Done():
return nil, []error{ctx.Err()}, nil, func() {}
default:
}

return bapi.plannedBlocksInfo, nil, nil, func() {}
}

func (b *BlocksInfo) set(blocks []metadata.Meta, err error) {
if err != nil {
// Last view is maintained.
Expand Down Expand Up @@ -174,3 +189,9 @@ func (bapi *BlocksAPI) SetLoaded(blocks []metadata.Meta, err error) {

bapi.loadedBlocksInfo.set(blocks, err)
}

// SetPlanned updates the plan blocks' metadata in the API.
func (bapi *BlocksAPI) SetPlanned(blocks []metadata.Meta, err error) {
amandaguan-ag marked this conversation as resolved.
Show resolved Hide resolved

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

}
8 changes: 8 additions & 0 deletions pkg/compact/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,11 @@ type Planner interface {
// Plan returns a list of blocks that should be compacted into single one.
// The blocks can be overlapping. The provided metadata has to be ordered by minTime.
Plan(ctx context.Context, metasByMinTime []*metadata.Meta, errChan chan error, extensions any) ([]*metadata.Meta, error)
UpdateOnPlanned(f func([]metadata.Meta, error))
}

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

type BlockDeletableChecker interface {
Expand Down Expand Up @@ -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

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?

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)
})

})
return e
}); err != nil {
return false, nil, errors.Wrap(err, "plan compaction")
Expand Down
1 change: 1 addition & 0 deletions pkg/compact/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?

}

var _ Planner = &tsdbBasedPlanner{}
Expand Down
5 changes: 4 additions & 1 deletion pkg/ui/react-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { QueryParamProvider } from 'use-query-params';
import useMedia from 'use-media';

import { Alerts, Config, Flags, Rules, ServiceDiscovery, Status, Targets, TSDBStatus, PanelList, NotFound } from './pages';
import { GlobalBlocks, PlannedBlocks } from './thanos/pages/blocks/Blocks';
import PathPrefixProps from './types/PathPrefixProps';
import ThanosComponentProps from './thanos/types/ThanosComponentProps';
import Navigation from './thanos/Navbar';
Expand All @@ -17,7 +18,7 @@ const defaultRouteConfig: { [component: string]: string } = {
query: '/graph',
rule: '/alerts',
bucket: '/blocks',
compact: '/loaded',
compact: '/global-blocks',
store: '/loaded',
};

Expand Down Expand Up @@ -61,6 +62,8 @@ const App: FC<PathPrefixProps & ThanosComponentProps> = ({ pathPrefix, thanosCom
<Stores path="/stores" pathPrefix={pathPrefix} />
<Blocks path="/blocks" pathPrefix={pathPrefix} />
<Blocks path="/loaded" pathPrefix={pathPrefix} view="loaded" />
<GlobalBlocks path="/global-blocks" pathPrefix={pathPrefix} />
<PlannedBlocks path="/planned-blocks" pathPrefix={pathPrefix} />
<NotFound pathPrefix={pathPrefix} default defaultRoute={defaultRouteConfig[thanosComponent]} />
</Router>
</QueryParamProvider>
Expand Down
3 changes: 2 additions & 1 deletion pkg/ui/react-app/src/thanos/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ const navConfig: { [component: string]: (NavConfig | NavDropDown)[] } = {
},
],
compact: [
{ name: 'Global Blocks', uri: '/blocks' },
{ name: 'Global Blocks', uri: '/global-blocks' },
{ name: 'Planned Blocks', uri: '/planned-blocks' },
{ name: 'Loaded Blocks', uri: '/loaded' },
{
name: 'Status',
Expand Down
9 changes: 8 additions & 1 deletion pkg/ui/react-app/src/thanos/pages/blocks/Blocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ interface BlocksProps {

export const Blocks: FC<RouteComponentProps & PathPrefixProps & BlocksProps> = ({ pathPrefix = '', view = 'global' }) => {
const { response, error, isLoading } = useFetch<BlockListProps>(
`${pathPrefix}/api/v1/blocks${view ? '?view=' + view : ''}`
`${pathPrefix}/api/v1/blocks${view === 'planned' ? '/plan' : view ? '?view=' + view : ''}`
);
const { status: responseStatus } = response;
const badResponse = responseStatus !== 'success' && responseStatus !== 'start fetching';
Expand All @@ -221,5 +221,12 @@ export const Blocks: FC<RouteComponentProps & PathPrefixProps & BlocksProps> = (
/>
);
};
export const GlobalBlocks: React.FC<RouteComponentProps & PathPrefixProps> = ({ pathPrefix }) => {
return <Blocks view="global" pathPrefix={pathPrefix} />;
};

export const PlannedBlocks: React.FC<RouteComponentProps & PathPrefixProps> = ({ pathPrefix }) => {
return <Blocks view="planned" pathPrefix={pathPrefix} />;
};

export default Blocks;
12 changes: 6 additions & 6 deletions pkg/ui/static/react/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"files": {
"main.css": "./static/css/main.17d667f4.css",
"main.js": "./static/js/main.20f9b436.js",
"main.css": "./static/css/main.0cc3dff0.css",
"main.js": "./static/js/main.39be79f4.js",
"static/media/codicon.ttf": "./static/media/codicon.b3726f0165bf67ac6849.ttf",
"index.html": "./index.html",
"static/media/index.cjs": "./static/media/index.cd351d7c31d0d3fccf96.cjs",
"main.17d667f4.css.map": "./static/css/main.17d667f4.css.map",
"main.20f9b436.js.map": "./static/js/main.20f9b436.js.map"
"main.0cc3dff0.css.map": "./static/css/main.0cc3dff0.css.map",
"main.39be79f4.js.map": "./static/js/main.39be79f4.js.map"
},
"entrypoints": [
"static/css/main.17d667f4.css",
"static/js/main.20f9b436.js"
"static/css/main.0cc3dff0.css",
"static/js/main.39be79f4.js"
]
}
2 changes: 1 addition & 1 deletion pkg/ui/static/react/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><script>const GLOBAL_PATH_PREFIX="{{ pathPrefix }}"</script><script>const THANOS_COMPONENT="{{ .Component }}",THANOS_QUERY_URL="{{ .queryURL }}",THANOS_TENANT_HEADER="{{ .tenantHeader }}",THANOS_DEFAULT_TENANT="{{ .defaultTenant }}",THANOS_DISPLAY_TENANT_BOX="{{ .displayTenantBox }}"</script><link rel="manifest" href="./manifest.json"/><title>Thanos | Highly available Prometheus setup</title><script defer="defer" src="./static/js/main.20f9b436.js"></script><link href="./static/css/main.17d667f4.css" rel="stylesheet"></head><body class="bootstrap"><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><script>const GLOBAL_PATH_PREFIX="{{ pathPrefix }}"</script><script>const THANOS_COMPONENT="{{ .Component }}",THANOS_QUERY_URL="{{ .queryURL }}",THANOS_TENANT_HEADER="{{ .tenantHeader }}",THANOS_DEFAULT_TENANT="{{ .defaultTenant }}",THANOS_DISPLAY_TENANT_BOX="{{ .displayTenantBox }}"</script><link rel="manifest" href="./manifest.json"/><title>Thanos | Highly available Prometheus setup</title><script defer="defer" src="./static/js/main.39be79f4.js"></script><link href="./static/css/main.0cc3dff0.css" rel="stylesheet"></head><body class="bootstrap"><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
6 changes: 6 additions & 0 deletions pkg/ui/static/react/static/css/main.0cc3dff0.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/ui/static/react/static/css/main.0cc3dff0.css.map

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions pkg/ui/static/react/static/css/main.17d667f4.css

This file was deleted.

1 change: 0 additions & 1 deletion pkg/ui/static/react/static/css/main.17d667f4.css.map

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions test/e2e/compact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/efficientgo/e2e"
e2edb "github.com/efficientgo/e2e/db"
e2einteractive "github.com/efficientgo/e2e/interactive"
e2emon "github.com/efficientgo/e2e/monitoring"
"github.com/efficientgo/e2e/monitoring/matchers"
"github.com/go-kit/log"
Expand Down Expand Up @@ -692,6 +693,9 @@ func testCompactWithStoreGateway(t *testing.T, penaltyDedup bool) {
c := cFuture.Init(bktConfig, nil, extArgs...)
testutil.Ok(t, e2e.StartAndWaitReady(c))

testutil.Ok(t, e2einteractive.OpenInBrowser("http://"+c.Endpoint("http")))
time.Sleep(5 * time.Minute)

// NOTE: We cannot assert on intermediate `thanos_blocks_meta_` metrics as those are gauge and change dynamically due to many
// compaction groups. Wait for at least first compaction iteration (next is in 5m).
testutil.Ok(t, c.WaitSumMetrics(e2emon.Greater(0), "thanos_compact_iterations_total"))
Expand Down
Loading