Skip to content

Commit

Permalink
Fixed crash on clean tenant
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Perez committed Jan 23, 2021
1 parent d091119 commit 793e65c
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions portal-ui/src/screens/Console/Dashboard/Prometheus/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,10 @@ export const panelsConfiguration: IDashboardPanel[] = [
];

const calculateMainValue = (elements: any[], metricCalc: string) => {
if(elements.length === 0) {
return ["", "0"];
}

switch (metricCalc) {
case "mean":
const sumValues = elements.reduce((accumulator, currValue) => {
Expand Down Expand Up @@ -583,7 +587,12 @@ export const getWidgetsWithValue = (payload: any[]) => {
case widgetType.singleValue:
if (typeOfPayload === "stat" || typeOfPayload === "singlestat") {
// We sort values & get the last value
const elements = get(payloadData, "targets[0].result[0].values", []);
let elements = get(payloadData, "targets[0].result[0].values", []);

if(elements === null) {
elements = [];
}

const metricCalc = get(
payloadData,
"options.reduceOptions.calcs[0]",
Expand All @@ -604,16 +613,23 @@ export const getWidgetsWithValue = (payload: any[]) => {
break;
case widgetType.pieChart:
if (typeOfPayload === "gauge") {
const chartSeries = get(payloadData, "targets[0].result", []);
let chartSeries = get(payloadData, "targets[0].result", []);

if(chartSeries === null) {
chartSeries = [];
}

const metricCalc = get(
payloadData,
"options.reduceOptions.calcs[0]",
"lastNotNull"
);

const valuesArray = chartSeries.length > 0 ? chartSeries[0].values : [];

const totalValues = calculateMainValue(
chartSeries[0].values,
metricCalc
valuesArray,
metricCalc
);

const values = chartSeries.map((elementValue: any) => {
Expand Down Expand Up @@ -738,7 +754,12 @@ export const getWidgetsWithValue = (payload: any[]) => {
break;
case widgetType.barChart:
if (typeOfPayload === "bargauge") {
const chartBars = get(payloadData, "targets[0].result", []);
let chartBars = get(payloadData, "targets[0].result", []);

if(chartBars === null) {
chartBars = [];
}

const sortFunction = (value1: any[], value2: any[]) =>
value1[0] - value2[0];

Expand All @@ -756,7 +777,7 @@ export const getWidgetsWithValue = (payload: any[]) => {
const elements = get(metricTake, "values", []);

const sortResult = elements.sort(sortFunction);
const lastValue = sortResult[sortResult.length - 1];
const lastValue = sortResult[sortResult.length - 1] || ["", "0"];

return {
name: structureItem.displayTag,
Expand All @@ -773,7 +794,7 @@ export const getWidgetsWithValue = (payload: any[]) => {
const elements = get(elementValue, "values", []);

const sortResult = elements.sort(sortFunction);
const lastValue = sortResult[sortResult.length - 1];
const lastValue = sortResult[sortResult.length - 1] || ["", "0"];
return { name: metricName, a: parseInt(lastValue[1]) };
});
}
Expand Down

0 comments on commit 793e65c

Please sign in to comment.