-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
481 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React, { FC } from 'react'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { faTimes } from '@fortawesome/free-solid-svg-icons'; | ||
import { Block } from './block'; | ||
import styles from './blocks.module.css'; | ||
import moment from 'moment'; | ||
|
||
interface BlockDetailsProps { | ||
block: Block | undefined; | ||
selectBlock: React.Dispatch<React.SetStateAction<Block | undefined>>; | ||
} | ||
|
||
export const BlockDetails: FC<BlockDetailsProps> = ({ block, selectBlock }) => { | ||
return ( | ||
<div className={`${styles.blockDetails} ${block && styles.open}`}> | ||
{block && ( | ||
<> | ||
<div className={styles.detailsTop}> | ||
<p>{block.ulid}</p> | ||
<button className={styles.closeBtn} onClick={(): void => selectBlock(undefined)}> | ||
<FontAwesomeIcon icon={faTimes} /> | ||
</button> | ||
</div> | ||
<hr /> | ||
<div> | ||
<b>Start Time:</b> {moment.unix(block.minTime / 1000).format('LLL')} | ||
</div> | ||
<div> | ||
<b>End Time:</b> {moment.unix(block.maxTime / 1000).format('LLL')} | ||
</div> | ||
<div> | ||
<b>Duration:</b> {moment.duration(block.maxTime - block.minTime, 'ms').humanize()} | ||
</div> | ||
<hr /> | ||
<div> | ||
<b>Series:</b> {block.stats.numSeries} | ||
</div> | ||
<div> | ||
<b>Samples:</b> {block.stats.numSamples} | ||
</div> | ||
<div> | ||
<b>Chunks:</b> {block.stats.numChunks} | ||
</div> | ||
<hr /> | ||
<div> | ||
<b>Resolution:</b> {block.thanos.downsample.resolution} | ||
</div> | ||
<div> | ||
<b>Level:</b> {block.compaction.level} | ||
</div> | ||
<div> | ||
<b>Source:</b> {block.thanos.source} | ||
</div> | ||
<hr /> | ||
<div> | ||
<b>Labels:</b> | ||
<ul> | ||
{Object.entries(block.thanos.labels).map(([key, value]) => ( | ||
<li key={key}> | ||
<b>{key}: </b> | ||
{value} | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
</> | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React, { FC } from 'react'; | ||
import { Block } from './block'; | ||
import styles from './blocks.module.css'; | ||
|
||
interface BlockSpanProps { | ||
block: Block; | ||
gridMinTime: number; | ||
gridMaxTime: number; | ||
selectBlock: React.Dispatch<React.SetStateAction<Block | undefined>>; | ||
} | ||
|
||
export const BlockSpan: FC<BlockSpanProps> = ({ block, gridMaxTime, gridMinTime, selectBlock }) => { | ||
const viewWidth = gridMaxTime - gridMinTime; | ||
const spanWidth = ((block.maxTime - block.minTime) / viewWidth) * 100; | ||
const spanOffset = ((block.minTime - gridMinTime) / viewWidth) * 100; | ||
|
||
return ( | ||
<button | ||
onClick={(): void => selectBlock(block)} | ||
className={styles.blockSpan} | ||
style={{ | ||
width: `${spanWidth}%`, | ||
left: `${spanOffset}%`, | ||
}} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React, { FC, useMemo, useState } from 'react'; | ||
import { RouteComponentProps } from '@reach/router'; | ||
import { Alert } from 'reactstrap'; | ||
import { withStatusIndicator } from '../../../components/withStatusIndicator'; | ||
import { useFetch } from '../../../hooks/useFetch'; | ||
import PathPrefixProps from '../../../types/PathPrefixProps'; | ||
import { Block } from './block'; | ||
import { SourceView } from './SourceView'; | ||
import { BlockDetails } from './BlockDetails'; | ||
import { sortBlocks } from './helpers'; | ||
import styles from './blocks.module.css'; | ||
|
||
export interface BlockListProps { | ||
blocks: Block[]; | ||
err: string | null; | ||
label: string; | ||
refreshedAt: string; | ||
} | ||
|
||
export const BlocksContent: FC<{ data: BlockListProps }> = ({ data }) => { | ||
const [selectedBlock, selectBlock] = useState<Block>(); | ||
|
||
const { blocks, label } = data; | ||
|
||
const blockPools = useMemo(() => sortBlocks(blocks, label), [blocks, label]); | ||
const [gridMinTime, gridMaxTime] = useMemo(() => { | ||
let gridMinTime = blocks[0].minTime; | ||
let gridMaxTime = blocks[0].maxTime; | ||
blocks.forEach(block => { | ||
if (block.minTime < gridMinTime) { | ||
gridMinTime = block.minTime; | ||
} | ||
if (block.maxTime > gridMaxTime) { | ||
gridMaxTime = block.maxTime; | ||
} | ||
}); | ||
return [gridMinTime, gridMaxTime]; | ||
}, [blocks]); | ||
|
||
return ( | ||
<> | ||
{blocks.length > 0 ? ( | ||
<div className={styles.container}> | ||
<div className={styles.grid}> | ||
{Object.keys(blockPools).map(pk => ( | ||
<SourceView | ||
key={pk} | ||
data={blockPools[pk]} | ||
title={pk} | ||
selectBlock={selectBlock} | ||
gridMinTime={gridMinTime} | ||
gridMaxTime={gridMaxTime} | ||
/> | ||
))} | ||
</div> | ||
<BlockDetails selectBlock={selectBlock} block={selectedBlock} /> | ||
</div> | ||
) : ( | ||
<Alert color="warning">No blocks found.</Alert> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
const BlocksWithStatusIndicator = withStatusIndicator(BlocksContent); | ||
|
||
export const Blocks: FC<RouteComponentProps & PathPrefixProps> = ({ pathPrefix = '' }) => { | ||
const { response, error, isLoading } = useFetch<BlockListProps>(`${pathPrefix}/api/v1/blocks`); | ||
const { status: responseStatus } = response; | ||
const badResponse = responseStatus !== 'success' && responseStatus !== 'start fetching'; | ||
|
||
return ( | ||
<BlocksWithStatusIndicator | ||
data={response.data} | ||
error={badResponse ? new Error(responseStatus) : error} | ||
isLoading={isLoading} | ||
/> | ||
); | ||
}; | ||
|
||
export default Blocks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React, { FC } from 'react'; | ||
import { Block, BlocksPool } from './block'; | ||
import { BlockSpan } from './BlockSpan'; | ||
import styles from './blocks.module.css'; | ||
|
||
const BlocksRow: FC<{ | ||
blocks: Block[]; | ||
gridMinTime: number; | ||
gridMaxTime: number; | ||
selectBlock: React.Dispatch<React.SetStateAction<Block | undefined>>; | ||
}> = ({ blocks, gridMinTime, gridMaxTime, selectBlock }) => { | ||
return ( | ||
<div className={styles.row}> | ||
{blocks.map<JSX.Element>(b => ( | ||
<BlockSpan selectBlock={selectBlock} block={b} gridMaxTime={gridMaxTime} gridMinTime={gridMinTime} key={b.ulid} /> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export const SourceView: FC<{ | ||
data: BlocksPool; | ||
title: string; | ||
gridMinTime: number; | ||
gridMaxTime: number; | ||
selectBlock: React.Dispatch<React.SetStateAction<Block | undefined>>; | ||
}> = ({ data, title, gridMaxTime, gridMinTime, selectBlock }) => { | ||
return ( | ||
<> | ||
<div className={styles.source}> | ||
<div className={styles.title}> | ||
<h4>{title}</h4> | ||
</div> | ||
<div className={styles.rowsContainer}> | ||
{Object.keys(data).map(k => ( | ||
<BlocksRow | ||
selectBlock={selectBlock} | ||
blocks={data[k]} | ||
key={k} | ||
gridMaxTime={gridMaxTime} | ||
gridMinTime={gridMinTime} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
<hr /> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export interface Block { | ||
compaction: { | ||
level: number; | ||
sources: string[]; | ||
parents?: { | ||
maxTime: number; | ||
minTime: number; | ||
ulid: string; | ||
}[]; | ||
}; | ||
maxTime: number; | ||
minTime: number; | ||
stats: { | ||
numChunks: number; | ||
numSamples: number; | ||
numSeries: number; | ||
}; | ||
thanos: { | ||
downsample: { | ||
resolution: number; | ||
}; | ||
labels: LabelSet; | ||
source: string; | ||
}; | ||
ulid: string; | ||
version: number; | ||
} | ||
|
||
export interface LabelSet { | ||
[labelName: string]: string; | ||
} | ||
|
||
export interface BlocksPool { | ||
[key: string]: Block[]; | ||
} |
Oops, something went wrong.