-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Web console: Display compaction status #10438
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,14 +18,19 @@ | |
|
|
||
| import { Button, Menu, Popover, Position } from '@blueprintjs/core'; | ||
| import { IconNames } from '@blueprintjs/icons'; | ||
| import React from 'react'; | ||
| import React, { useState } from 'react'; | ||
|
|
||
| type OpenState = 'open' | 'alt-open'; | ||
|
|
||
| export interface MoreButtonProps { | ||
| children: React.ReactNode; | ||
| children: React.ReactNode | React.ReactNode[]; | ||
| altExtra?: React.ReactNode; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about adding another snapshot test that sets the new |
||
| } | ||
|
|
||
| export const MoreButton = React.memo(function MoreButton(props: MoreButtonProps) { | ||
| const { children } = props; | ||
| const { children, altExtra } = props; | ||
|
|
||
| const [openState, setOpenState] = useState<OpenState | undefined>(); | ||
|
|
||
| let childCount = 0; | ||
| // Sadly React.Children.count does not ignore nulls correctly | ||
|
|
@@ -36,8 +41,18 @@ export const MoreButton = React.memo(function MoreButton(props: MoreButtonProps) | |
| return ( | ||
| <Popover | ||
| className="more-button" | ||
| content={<Menu>{children}</Menu>} | ||
| isOpen={Boolean(openState)} | ||
| content={ | ||
| <Menu> | ||
| {children} | ||
| {openState === 'alt-open' && altExtra} | ||
| </Menu> | ||
| } | ||
| position={Position.BOTTOM_LEFT} | ||
| onInteraction={(nextOpenState, e: any) => { | ||
| if (!e) return; // For some reason this function is always called twice once with e and once without | ||
| setOpenState(nextOpenState ? (e.altKey ? 'alt-open' : 'open') : undefined); | ||
| }} | ||
| > | ||
| <Button icon={IconNames.MORE} disabled={!childCount} /> | ||
| </Popover> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { | ||
| CompactionConfig, | ||
| CompactionStatus, | ||
| formatCompactionConfigAndStatus, | ||
| zeroCompactionStatus, | ||
| } from './compaction'; | ||
|
|
||
| describe('compaction', () => { | ||
| const BASIC_CONFIG: CompactionConfig = {}; | ||
| const ZERO_STATUS: CompactionStatus = { | ||
| dataSource: 'tbl', | ||
| scheduleStatus: 'RUNNING', | ||
| bytesAwaitingCompaction: 0, | ||
| bytesCompacted: 0, | ||
| bytesSkipped: 0, | ||
| segmentCountAwaitingCompaction: 0, | ||
| segmentCountCompacted: 0, | ||
| segmentCountSkipped: 0, | ||
| intervalCountAwaitingCompaction: 0, | ||
| intervalCountCompacted: 0, | ||
| intervalCountSkipped: 0, | ||
| }; | ||
|
|
||
| it('zeroCompactionStatus', () => { | ||
| expect(zeroCompactionStatus(ZERO_STATUS)).toEqual(true); | ||
|
|
||
| expect( | ||
| zeroCompactionStatus({ | ||
| dataSource: 'tbl', | ||
| scheduleStatus: 'RUNNING', | ||
| bytesAwaitingCompaction: 1, | ||
| bytesCompacted: 0, | ||
| bytesSkipped: 0, | ||
| segmentCountAwaitingCompaction: 0, | ||
| segmentCountCompacted: 0, | ||
| segmentCountSkipped: 0, | ||
| intervalCountAwaitingCompaction: 0, | ||
| intervalCountCompacted: 0, | ||
| intervalCountSkipped: 0, | ||
| }), | ||
| ).toEqual(false); | ||
| }); | ||
|
|
||
| it('formatCompactionConfigAndStatus', () => { | ||
| expect(formatCompactionConfigAndStatus(undefined, undefined)).toEqual('Not enabled'); | ||
|
|
||
| expect(formatCompactionConfigAndStatus(BASIC_CONFIG, undefined)).toEqual('Awaiting first run'); | ||
|
|
||
| expect(formatCompactionConfigAndStatus(undefined, ZERO_STATUS)).toEqual('Running'); | ||
|
|
||
| expect(formatCompactionConfigAndStatus(BASIC_CONFIG, ZERO_STATUS)).toEqual('Running'); | ||
|
|
||
| expect( | ||
| formatCompactionConfigAndStatus(BASIC_CONFIG, { | ||
| dataSource: 'tbl', | ||
| scheduleStatus: 'RUNNING', | ||
| bytesAwaitingCompaction: 0, | ||
| bytesCompacted: 100, | ||
| bytesSkipped: 0, | ||
| segmentCountAwaitingCompaction: 0, | ||
| segmentCountCompacted: 10, | ||
| segmentCountSkipped: 0, | ||
| intervalCountAwaitingCompaction: 0, | ||
| intervalCountCompacted: 10, | ||
| intervalCountSkipped: 0, | ||
| }), | ||
| ).toEqual('Fully compacted'); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| function capitalizeFirst(str: string): string { | ||
| return str.slice(0, 1).toUpperCase() + str.slice(1).toLowerCase(); | ||
| } | ||
|
|
||
| export interface CompactionStatus { | ||
| dataSource: string; | ||
| scheduleStatus: string; | ||
| bytesAwaitingCompaction: number; | ||
| bytesCompacted: number; | ||
| bytesSkipped: number; | ||
| segmentCountAwaitingCompaction: number; | ||
| segmentCountCompacted: number; | ||
| segmentCountSkipped: number; | ||
| intervalCountAwaitingCompaction: number; | ||
| intervalCountCompacted: number; | ||
| intervalCountSkipped: number; | ||
| } | ||
|
|
||
| export type CompactionConfig = Record<string, any>; | ||
|
|
||
| export function zeroCompactionStatus(compactionStatus: CompactionStatus): boolean { | ||
| return ( | ||
| !compactionStatus.bytesAwaitingCompaction && | ||
| !compactionStatus.bytesCompacted && | ||
| !compactionStatus.bytesSkipped && | ||
| !compactionStatus.segmentCountAwaitingCompaction && | ||
| !compactionStatus.segmentCountCompacted && | ||
| !compactionStatus.segmentCountSkipped && | ||
| !compactionStatus.intervalCountAwaitingCompaction && | ||
| !compactionStatus.intervalCountCompacted && | ||
| !compactionStatus.intervalCountSkipped | ||
| ); | ||
| } | ||
|
|
||
| export function formatCompactionConfigAndStatus( | ||
| compactionConfig: CompactionConfig | undefined, | ||
| compactionStatus: CompactionStatus | undefined, | ||
| ) { | ||
| if (compactionStatus) { | ||
| if (compactionStatus.bytesAwaitingCompaction === 0 && !zeroCompactionStatus(compactionStatus)) { | ||
| return 'Fully compacted'; | ||
| } else { | ||
| return capitalizeFirst(compactionStatus.scheduleStatus); | ||
| } | ||
| } else if (compactionConfig) { | ||
| return 'Awaiting first run'; | ||
| } else { | ||
| return 'Not enabled'; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -231,6 +231,10 @@ export function formatMegabytes(n: number): string { | |
| return numeral(n / 1048576).format('0,0.0'); | ||
| } | ||
|
|
||
| export function formatPercent(n: number): string { | ||
| return (n * 100).toFixed(2) + '%'; | ||
| } | ||
|
Comment on lines
+234
to
+236
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing unit test in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
|
||
| function pad2(str: string | number): string { | ||
| return ('00' + str).substr(-2); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no logical change here... just wanted to have less nesting