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

Add --disable-admin-operations flag in Compactor UI and Bucket UI #6604

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ff9612d
adding flags
harsh-ps-2003 Aug 10, 2023
9096d15
Merge branch 'main' into addingflags
harsh-ps-2003 Aug 10, 2023
dae9fbc
adding changes requested in code review
harsh-ps-2003 Aug 11, 2023
35c2658
components/query: add a paragraph about filter (#6607)
GiedriusS Aug 11, 2023
bd1c4cb
cache: remove unnecessary nil check (#6603)
Juneezee Aug 11, 2023
a76bd25
fixing docs ci
harsh-ps-2003 Aug 12, 2023
7458b34
fixing docs ci
harsh-ps-2003 Aug 12, 2023
5a54e3c
fixing runbook docs Signed-off-by: Harsh Pratap Singh <119954739+hars…
harsh-ps-2003 Aug 12, 2023
ae25455
fixing docs
harsh-ps-2003 Aug 12, 2023
50db859
cleaning white noise Signed-off-by: Harsh Pratap Singh <119954739+har…
harsh-ps-2003 Aug 12, 2023
c10e213
fixing mixin
harsh-ps-2003 Aug 13, 2023
394ef36
Bump go4.org/intern to fix build on go1.21 (#6609)
jonjohnsonjr Aug 13, 2023
e57f82a
Updates busybox SHA (#6614)
github-actions[bot] Aug 15, 2023
e37a913
Update objstore and promql-engine to latest (#6618)
saswatamcode Aug 16, 2023
9a7e8d0
store/bucket: wait until chunk loading ends in Close() (#6582)
GiedriusS Aug 16, 2023
ae665ab
CHANGELOG: Mark v0.32 as in progress (#6617)
saswatamcode Aug 16, 2023
14b27c5
Vertical shard binary expression using metric name when no matching l…
yeya24 Aug 16, 2023
680772b
store: fix missing flush when handling pushed down queries (#6612)
MichaHoffmann Aug 17, 2023
d8a6064
Handle warnings from remote engines (#6619)
fpetkovski Aug 18, 2023
e8aab6e
Bug fix in quickstart (#6628)
Vanshikav123 Aug 18, 2023
d5d92c8
fixing docs Signed-off-by: Harsh Pratap Singh <119954739+harsh-ps-200…
harsh-ps-2003 Aug 22, 2023
e746386
Revert "fixing docs" Signed-off-by: Harsh Pratap Singh <119954739+har…
harsh-ps-2003 Aug 22, 2023
69adc1a
Revert "fixing mixin" Signed-off-by: Harsh Pratap Singh <119954739+ha…
harsh-ps-2003 Aug 22, 2023
b614c7c
Revert "cleaning white noise" Signed-off-by: Harsh Pratap Singh <1199…
harsh-ps-2003 Aug 22, 2023
dfa6093
Revert "fixing docs" Signed-off-by: Harsh Pratap Singh <119954739+har…
harsh-ps-2003 Aug 22, 2023
f52b6e0
Revert "fixing runbook docs"
harsh-ps-2003 Aug 22, 2023
1222e87
Revert "fixing docs ci"
harsh-ps-2003 Aug 22, 2023
af9dd43
Revert "fixing docs ci"
harsh-ps-2003 Aug 22, 2023
89d9c40
fixing docs ci
harsh-ps-2003 Aug 22, 2023
61e6cb1
fixing docs Signed-off-by: Harsh Pratap Singh <119954739+harsh-ps-200…
harsh-ps-2003 Aug 22, 2023
e7e0689
fixing tools.md
harsh-ps-2003 Aug 22, 2023
3b9a02e
adding Changelog
harsh-ps-2003 Aug 22, 2023
4020bc4
Merge branch 'main' into addingflags
harsh-ps-2003 Aug 22, 2023
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
3 changes: 3 additions & 0 deletions cmd/thanos/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ type compactConfig struct {
skipBlockWithOutOfOrderChunks bool
progressCalculateInterval time.Duration
filterConf *store.FilterConfig
disableAdminOperations bool
}

func (cc *compactConfig) registerFlag(cmd extkingpin.FlagClause) {
Expand Down Expand Up @@ -786,4 +787,6 @@ func (cc *compactConfig) registerFlag(cmd extkingpin.FlagClause) {
cc.webConf.registerFlag(cmd)

cmd.Flag("bucket-web-label", "External block label to use as group title in the bucket web UI").StringVar(&cc.label)

cmd.Flag("disable-admin-operations", "Restrict access to Block Mark deletion and no compaction").Default("false").BoolVar(&cc.disableAdminOperations)
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 make description a bit clearer.

Suggested change
cmd.Flag("disable-admin-operations", "Restrict access to Block Mark deletion and no compaction").Default("false").BoolVar(&cc.disableAdminOperations)
cmd.Flag("disable-admin-operations", "Disable UI/API admin operations like marking blocks for deletion and no compaction.").Default("false").BoolVar(&cc.disableAdminOperations)

}
17 changes: 10 additions & 7 deletions cmd/thanos/tools_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ type bucketLsConfig struct {
}

type bucketWebConfig struct {
webRoutePrefix string
webExternalPrefix string
webPrefixHeaderName string
webDisableCORS bool
interval time.Duration
label string
timeout time.Duration
webRoutePrefix string
webExternalPrefix string
webPrefixHeaderName string
webDisableCORS bool
interval time.Duration
label string
timeout time.Duration
disableAdminOperations bool
}

type bucketReplicateConfig struct {
Expand Down Expand Up @@ -203,6 +204,8 @@ func (tbc *bucketWebConfig) registerBucketWebFlag(cmd extkingpin.FlagClause) *bu
cmd.Flag("timeout", "Timeout to download metadata from remote storage").Default("5m").DurationVar(&tbc.timeout)

cmd.Flag("label", "External block label to use as group title").StringVar(&tbc.label)

cmd.Flag("disable-admin-operations", "Restrict access to Block Mark deletion and no compaction").Default("false").BoolVar(&tbc.disableAdminOperations)
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Suggested change
cmd.Flag("disable-admin-operations", "Restrict access to Block Mark deletion and no compaction").Default("false").BoolVar(&tbc.disableAdminOperations)
cmd.Flag("disable-admin-operations", "Disable UI/API admin operations like marking blocks for deletion and no compaction.").Default("false").BoolVar(&tbc.disableAdminOperations)

return tbc
}

Expand Down
22 changes: 14 additions & 8 deletions pkg/api/blocks/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ 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
disableCORS bool
bkt objstore.Bucket
baseAPI *api.BaseAPI
logger log.Logger
globalBlocksInfo *BlocksInfo
loadedBlocksInfo *BlocksInfo
disableCORS bool
bkt objstore.Bucket
disableAdminOperations bool
}

type BlocksInfo struct {
Expand Down Expand Up @@ -61,6 +62,7 @@ func parse(s string) ActionType {

// NewBlocksAPI creates a simple API to be used by Thanos Block Viewer.
func NewBlocksAPI(logger log.Logger, disableCORS bool, label string, flagsMap map[string]string, bkt objstore.Bucket) *BlocksAPI {
disableAdminOperations := flagsMap["disable-admin-operations"] == "true"
return &BlocksAPI{
baseAPI: api.NewBaseAPI(logger, disableCORS, flagsMap),
logger: logger,
Expand All @@ -72,8 +74,9 @@ func NewBlocksAPI(logger log.Logger, disableCORS bool, label string, flagsMap ma
Blocks: []metadata.Meta{},
Label: label,
},
disableCORS: disableCORS,
bkt: bkt,
disableCORS: disableCORS,
bkt: bkt,
disableAdminOperations: disableAdminOperations,
}
}

Expand All @@ -87,6 +90,9 @@ func (bapi *BlocksAPI) Register(r *route.Router, tracer opentracing.Tracer, logg
}

func (bapi *BlocksAPI) markBlock(r *http.Request) (interface{}, []error, *api.ApiError, func()) {
if bapi.disableAdminOperations {
return nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: errors.New("Admin operations are disabled")}, func() {}
}
idParam := r.FormValue("id")
actionParam := r.FormValue("action")
detailParam := r.FormValue("detail")
Expand Down
49 changes: 29 additions & 20 deletions pkg/ui/react-app/src/thanos/pages/blocks/BlockDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import styles from './blocks.module.css';
import moment from 'moment';
import { Button, Modal, ModalBody, Form, Input, ModalHeader, ModalFooter } from 'reactstrap';
import { download } from './helpers';
import { FlagMap } from '../../../pages/flags/Flags';
import { useFetch } from '../../../hooks/useFetch';

export interface BlockDetailsProps {
block: Block | undefined;
Expand Down Expand Up @@ -40,6 +42,9 @@ export const BlockDetails: FC<BlockDetailsProps> = ({ block, selectBlock }) => {
}
};

const { response: flagsRes } = useFetch<FlagMap>(`/api/v1/status/flags`);
const disableAdminOperations = flagsRes?.data?.['disable-admin-operations'] || false;
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 actually call this in BlocksContent and pass it to BlocksDetails as a prop, that way we won't be calling this every time we open a block detail page. This also won't change from block to block.


return (
<div className={`${styles.blockDetails} ${block && styles.open}`}>
{block && (
Expand Down Expand Up @@ -100,26 +105,30 @@ export const BlockDetails: FC<BlockDetailsProps> = ({ block, selectBlock }) => {
<Button>Download meta.json</Button>
</a>
</div>
<div style={{ marginTop: '12px' }}>
<Button
onClick={() => {
setModalAction('DELETION');
setDetailValue('');
}}
>
Mark Deletion
</Button>
</div>
<div style={{ marginTop: '12px' }}>
<Button
onClick={() => {
setModalAction('NO_COMPACTION');
setDetailValue('');
}}
>
Mark No Compaction
</Button>
</div>
{!disableAdminOperations && (
<div style={{ marginTop: '12px' }}>
<Button
onClick={() => {
setModalAction('DELETION');
setDetailValue('');
}}
>
Mark Deletion
</Button>
</div>
)}
{!disableAdminOperations && (
Copy link
Member

Choose a reason for hiding this comment

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

We can probably render both buttons, under a single conditional?

<div style={{ marginTop: '12px' }}>
<Button
onClick={() => {
setModalAction('NO_COMPACTION');
setDetailValue('');
}}
>
Mark No Compaction
</Button>
</div>
)}
<Modal isOpen={!!modalAction}>
<ModalBody>
<ModalHeader toggle={() => setModalAction('')}>
Expand Down