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

Bug 1866928: add support for Grafana valueMaps to monitoring dashboards #6328

Merged
merged 1 commit into from
Aug 14, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion frontend/public/components/monitoring/dashboards/single-stat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const SingleStat: React.FC<Props> = ({ panel, pollInterval, query }) => {
prefix,
prefixFontSize,
valueFontSize,
valueMaps,
} = panel;

const [error, setError] = React.useState<string>();
Expand All @@ -50,6 +51,12 @@ const SingleStat: React.FC<Props> = ({ panel, pollInterval, query }) => {

usePoll(tick, pollInterval, query);

const filteredVMs = valueMaps?.filter((vm) => vm.op === '=');
const valueMap =
value === undefined
? filteredVMs?.find((vm) => vm.value === 'null')
: filteredVMs?.find((vm) => vm.value === value);

if (isLoading) {
return <LoadingInline />;
}
Expand All @@ -60,7 +67,9 @@ const SingleStat: React.FC<Props> = ({ panel, pollInterval, query }) => {
return (
<Body>
{prefix && <span style={{ fontSize: prefixFontSize }}>{prefix}</span>}
<span style={{ fontSize: valueFontSize }}>{formatNumber(value, decimals, format)}</span>
<span style={{ fontSize: valueFontSize }}>
{valueMap ? valueMap.text : formatNumber(value, decimals, format)}
</span>
{postfix && <span style={{ fontSize: postfixFontSize }}>{postfix}</span>}
</Body>
);
Expand Down
7 changes: 7 additions & 0 deletions frontend/public/components/monitoring/dashboards/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ export type ColumnStyle = {
type: string;
};

type ValueMap = {
op: string;
text: string;
value: string;
};

export type Panel = {
breakpoint?: string;
decimals?: number;
Expand Down Expand Up @@ -37,4 +43,5 @@ export type Panel = {
type: string;
units?: string;
valueFontSize?: string;
valueMaps?: ValueMap[];
};