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

Refine metrics #1338

Merged
merged 2 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ import {
processRawData,
PromMatrixData,
QueryOptions,
resolveQueryTemplate
resolveQueryTemplate,
TransformNullValue
} from '@lib/utils/prometheus'
import { AxiosPromise } from 'axios'
import { ReqConfig } from '@lib/types'
Expand Down Expand Up @@ -96,6 +97,7 @@ export interface IMetricChartProps {
queries: IQueryOption[]
unit?: string
type: GraphType
nullValue?: TransformNullValue

height?: number

Expand Down Expand Up @@ -126,7 +128,8 @@ export default function MetricChart({
height = 200,
onRangeChange,
onLoadingStateChange,
getMetrics
getMetrics,
nullValue = TransformNullValue.NULL
}: IMetricChartProps) {
const chartRef = useRef<Chart>(null)
const chartContainerRef = useRef<HTMLDivElement>(null)
Expand Down Expand Up @@ -204,10 +207,23 @@ export default function MetricChart({
if (data === null) {
return
}

// transform data according to nullValue config
const transformedData =
nullValue === TransformNullValue.AS_ZERO
? data.map((d) => {
if (d[1] !== null) {
return d
}
d[1] = 0
return d
})
: data

sd.push({
id: `${queryIdx}_${seriesIdx}`,
name: format(queries[queryIdx].name, promResult.metric),
data,
data: transformedData,
color: queries[queryIdx].color
})
})
Expand Down
5 changes: 5 additions & 0 deletions ui/packages/tidb-dashboard-lib/src/utils/prometheus/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ export type MatrixOrVectorResult =
| PromMatrixData['result'][0]
| PromVectorData['result'][0]

export enum TransformNullValue {
NULL = 'null',
AS_ZERO = 'as_zero'
}

// Our customized types

export interface QueryOptions {
Expand Down