From 74656069bd284e01aa4f358da477307512aa0f29 Mon Sep 17 00:00:00 2001 From: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> Date: Thu, 24 Aug 2023 12:22:29 +0530 Subject: [PATCH 1/6] adding flags Signed-off-by: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> --- cmd/thanos/compact.go | 3 ++ cmd/thanos/tools_bucket.go | 17 ++++--- 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 ++- 6 files changed, 59 insertions(+), 37 deletions(-) diff --git a/cmd/thanos/compact.go b/cmd/thanos/compact.go index 711e38daec..7ab7e05639 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 9a31444f0e..754a639517 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/pkg/api/blocks/v1.go b/pkg/api/blocks/v1.go index 515c4623f7..c0da07d9bb 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 23bf869dea..076205e9c6 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 7e4573df41..6d28565b96 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 }) => { Download meta.json - - { - setModalAction('DELETION'); - setDetailValue(''); - }} - > - Mark Deletion - - - - { - setModalAction('NO_COMPACTION'); - setDetailValue(''); - }} - > - Mark No Compaction - - + {!disableAdminOperations && ( + + + { + setModalAction('DELETION'); + setDetailValue(''); + }} + > + Mark Deletion + + + + { + setModalAction('NO_COMPACTION'); + setDetailValue(''); + }} + > + Mark No Compaction + + + + )} 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 30252a912c..081d157d73 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} /> - + > ) : ( From b5614ff3fbe7eefca9b636bf6124c55adc38c5fe Mon Sep 17 00:00:00 2001 From: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> Date: Thu, 24 Aug 2023 12:25:14 +0530 Subject: [PATCH 2/6] adding docs Signed-off-by: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> --- docs/components/compact.md | 3 +++ docs/components/tools.md | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/components/compact.md b/docs/components/compact.md index 958ea07b21..d210dd55a8 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 3c552bf3a9..1ae507be20 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" @@ -823,7 +826,7 @@ Flags: --rewrite.to-relabel-config-file= Path to YAML file that contains relabel configs that will be applied to blocks - --tmp.dir="/tmp/thanos-rewrite" + --tmp.dir="/var/folders/yn/c6y00yq11klbr1pk_92j61580000gn/T/thanos-rewrite" Working directory for temporary files --tracing.config= Alternative to 'tracing.config-file' flag From 3b35461bb0dc9977df32d61279b97a05ecc0121c Mon Sep 17 00:00:00 2001 From: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> Date: Thu, 24 Aug 2023 12:30:52 +0530 Subject: [PATCH 3/6] fixing tools.md Signed-off-by: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> --- docs/components/tools.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/components/tools.md b/docs/components/tools.md index 1ae507be20..cbd78414ca 100644 --- a/docs/components/tools.md +++ b/docs/components/tools.md @@ -826,7 +826,7 @@ Flags: --rewrite.to-relabel-config-file= Path to YAML file that contains relabel configs that will be applied to blocks - --tmp.dir="/var/folders/yn/c6y00yq11klbr1pk_92j61580000gn/T/thanos-rewrite" + --tmp.dir="/var/folders/thanos-rewrite" Working directory for temporary files --tracing.config= Alternative to 'tracing.config-file' flag From 24d11dc7cc8553f46e5a5175e8906012f116afc8 Mon Sep 17 00:00:00 2001 From: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> Date: Thu, 24 Aug 2023 12:33:00 +0530 Subject: [PATCH 4/6] fixing tools.md Signed-off-by: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> --- docs/components/tools.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/components/tools.md b/docs/components/tools.md index cbd78414ca..ce34c4446f 100644 --- a/docs/components/tools.md +++ b/docs/components/tools.md @@ -826,7 +826,7 @@ Flags: --rewrite.to-relabel-config-file= Path to YAML file that contains relabel configs that will be applied to blocks - --tmp.dir="/var/folders/thanos-rewrite" + --tmp.dir="/tmp/thanos-rewrite" Working directory for temporary files --tracing.config= Alternative to 'tracing.config-file' flag From 5c4121e161382c92af2b090ef4249d9f5f30f3dd Mon Sep 17 00:00:00 2001 From: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> Date: Thu, 24 Aug 2023 12:43:20 +0530 Subject: [PATCH 5/6] adding changelog Signed-off-by: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5719bcfb35..20f8086032 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,9 @@ 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. @@ -1645,4 +1648,4 @@ Initial version to have a stable reference before [gossip protocol removal](docs - Compact / Downsample offline commands. - Bucket commands. - Downsampling support for UI. -- Grafana dashboards for Thanos components. +- Grafana dashboards for Thanos components. \ No newline at end of file From bb708ff5fe4c487f3b4f690f379c0811e4f76567 Mon Sep 17 00:00:00 2001 From: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> Date: Thu, 24 Aug 2023 13:28:40 +0530 Subject: [PATCH 6/6] fixing changelog Signed-off-by: Harsh Pratap Singh <119954739+harsh-ps-2003@users.noreply.github.com> --- CHANGELOG.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20f8086032..9fe2801b3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,9 +44,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 - +- [#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. @@ -1648,4 +1646,4 @@ Initial version to have a stable reference before [gossip protocol removal](docs - Compact / Downsample offline commands. - Bucket commands. - Downsampling support for UI. -- Grafana dashboards for Thanos components. \ No newline at end of file +- Grafana dashboards for Thanos components.