From ba4e9f31581cb46a65b1af5e1a51591e5a9fb0a9 Mon Sep 17 00:00:00 2001 From: Harsh Pratap Singh Date: Mon, 28 Aug 2023 12:07:37 +0530 Subject: [PATCH] Add `--disable-admin-operations` flag in Compactor UI and Bucket UI (#6646) * adding flags Signed-off-by: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> * adding docs Signed-off-by: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> * fixing tools.md Signed-off-by: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> * fixing tools.md Signed-off-by: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> * adding changelog Signed-off-by: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> * fixing changelog Signed-off-by: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> --------- Signed-off-by: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> --- CHANGELOG.md | 1 + cmd/thanos/compact.go | 3 ++ cmd/thanos/tools_bucket.go | 17 ++++--- docs/components/compact.md | 3 ++ docs/components/tools.md | 3 ++ pkg/api/blocks/v1.go | 22 +++++---- .../thanos/pages/blocks/BlockDetails.test.tsx | 1 + .../src/thanos/pages/blocks/BlockDetails.tsx | 47 ++++++++++--------- .../src/thanos/pages/blocks/Blocks.tsx | 6 ++- 9 files changed, 66 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf15dbcabff..3663a078d10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re - [#6264](https://github.com/thanos-io/thanos/pull/6264) Query: Add Thanos logo in navbar - [#6234](https://github.com/thanos-io/thanos/pull/6234) Query: Add ability to switch between `thanos` and `prometheus` engines dynamically via UI and API. - [#6346](https://github.com/thanos-io/thanos/pull/6346) Query: Add ability to generate SQL-like query explanations when `thanos` engine is used. +- [#6646](https://github.com/thanos-io/thanos/pull/6646) Compact and Bucket: Add `--disable-admin-operations` flag in Compactor UI and Bucket UI ### Fixed - [#6503](https://github.com/thanos-io/thanos/pull/6503) *: Change the engine behind `ContentPathReloader` to be completely independent of any filesystem concept. This effectively fixes this configuration reload when used with Kubernetes ConfigMaps, Secrets, or other volume mounts. diff --git a/cmd/thanos/compact.go b/cmd/thanos/compact.go index 711e38daec4..7ab7e056398 100644 --- a/cmd/thanos/compact.go +++ b/cmd/thanos/compact.go @@ -678,6 +678,7 @@ type compactConfig struct { skipBlockWithOutOfOrderChunks bool progressCalculateInterval time.Duration filterConf *store.FilterConfig + disableAdminOperations bool } func (cc *compactConfig) registerFlag(cmd extkingpin.FlagClause) { @@ -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", "Disable UI/API admin operations like marking blocks for deletion and no compaction.").Default("false").BoolVar(&cc.disableAdminOperations) } diff --git a/cmd/thanos/tools_bucket.go b/cmd/thanos/tools_bucket.go index 9a31444f0e8..754a6395179 100644 --- a/cmd/thanos/tools_bucket.go +++ b/cmd/thanos/tools_bucket.go @@ -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 { @@ -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", "Disable UI/API admin operations like marking blocks for deletion and no compaction.").Default("false").BoolVar(&tbc.disableAdminOperations) return tbc } diff --git a/docs/components/compact.md b/docs/components/compact.md index 958ea07b21d..d210dd55a83 100644 --- a/docs/components/compact.md +++ b/docs/components/compact.md @@ -355,6 +355,9 @@ Flags: block loaded, or compactor is ignoring the deletion because it's compacting the block at the same time. + --disable-admin-operations + Disable UI/API admin operations like marking + blocks for deletion and no compaction. --downsample.concurrency=1 Number of goroutines to use when downsampling blocks. diff --git a/docs/components/tools.md b/docs/components/tools.md index 3c552bf3a90..ce34c4446fa 100644 --- a/docs/components/tools.md +++ b/docs/components/tools.md @@ -210,6 +210,9 @@ usage: thanos tools bucket web [] Web interface for remote storage bucket. Flags: + --disable-admin-operations + Disable UI/API admin operations like marking + blocks for deletion and no compaction. -h, --help Show context-sensitive help (also try --help-long and --help-man). --http-address="0.0.0.0:10902" diff --git a/pkg/api/blocks/v1.go b/pkg/api/blocks/v1.go index 515c4623f75..c0da07d9bbf 100644 --- a/pkg/api/blocks/v1.go +++ b/pkg/api/blocks/v1.go @@ -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 { @@ -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, @@ -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, } } @@ -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") diff --git a/pkg/ui/react-app/src/thanos/pages/blocks/BlockDetails.test.tsx b/pkg/ui/react-app/src/thanos/pages/blocks/BlockDetails.test.tsx index 23bf869dea9..076205e9c64 100644 --- a/pkg/ui/react-app/src/thanos/pages/blocks/BlockDetails.test.tsx +++ b/pkg/ui/react-app/src/thanos/pages/blocks/BlockDetails.test.tsx @@ -15,6 +15,7 @@ describe('BlockDetails', () => { selectBlock: (): void => { // do nothing }, + disableAdminOperations: false, }; window.URL.createObjectURL = jest.fn(); const blockDetails = mount(); diff --git a/pkg/ui/react-app/src/thanos/pages/blocks/BlockDetails.tsx b/pkg/ui/react-app/src/thanos/pages/blocks/BlockDetails.tsx index 7e4573df414..6d28565b966 100644 --- a/pkg/ui/react-app/src/thanos/pages/blocks/BlockDetails.tsx +++ b/pkg/ui/react-app/src/thanos/pages/blocks/BlockDetails.tsx @@ -8,9 +8,10 @@ import { download } from './helpers'; export interface BlockDetailsProps { block: Block | undefined; selectBlock: React.Dispatch>; + disableAdminOperations: boolean; } -export const BlockDetails: FC = ({ block, selectBlock }) => { +export const BlockDetails: FC = ({ block, selectBlock, disableAdminOperations }) => { const [modalAction, setModalAction] = useState(''); const [detailValue, setDetailValue] = useState(null); @@ -100,26 +101,30 @@ export const BlockDetails: FC = ({ block, selectBlock }) => { -
- -
-
- -
+ {!disableAdminOperations && ( +
+
+ +
+
+ +
+
+ )} setModalAction('')}> diff --git a/pkg/ui/react-app/src/thanos/pages/blocks/Blocks.tsx b/pkg/ui/react-app/src/thanos/pages/blocks/Blocks.tsx index 30252a912c5..081d157d73e 100644 --- a/pkg/ui/react-app/src/thanos/pages/blocks/Blocks.tsx +++ b/pkg/ui/react-app/src/thanos/pages/blocks/Blocks.tsx @@ -14,6 +14,7 @@ import { sortBlocks, getBlockByUlid, getFilteredBlockPools } from './helpers'; import styles from './blocks.module.css'; import TimeRange from './TimeRange'; import Checkbox from '../../../components/Checkbox'; +import { FlagMap } from '../../../pages/flags/Flags'; export interface BlockListProps { blocks: Block[]; @@ -74,6 +75,9 @@ export const BlocksContent: FC<{ data: BlockListProps }> = ({ data }) => { const filteredBlocks = useMemo(() => getBlockByUlid(blocks, blockSearch), [blocks, blockSearch]); const filteredBlockPools = useMemo(() => getFilteredBlockPools(blockPools, filteredBlocks), [filteredBlocks, blockPools]); + const { response: flagsRes } = useFetch(`/api/v1/status/flags`); + const disableAdminOperations = flagsRes?.data?.['disable-admin-operations'] === 'true' || false; + const setViewTime = (times: number[]): void => { setQuery({ 'min-time': times[0], @@ -180,7 +184,7 @@ export const BlocksContent: FC<{ data: BlockListProps }> = ({ data }) => { onChange={setViewTime} /> - + ) : (