From 59d4ebc109db59151f626ecf18876c437791655f Mon Sep 17 00:00:00 2001 From: Alex <33497058+bexsoft@users.noreply.github.com> Date: Thu, 20 May 2021 19:42:39 -0500 Subject: [PATCH] Fixed issue with graphs that are not showing series correctly (#763) Co-authored-by: Benjamin Perez --- .../Console/Dashboard/Prometheus/utils.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/portal-ui/src/screens/Console/Dashboard/Prometheus/utils.ts b/portal-ui/src/screens/Console/Dashboard/Prometheus/utils.ts index 0167260c7..7c56e1b01 100644 --- a/portal-ui/src/screens/Console/Dashboard/Prometheus/utils.ts +++ b/portal-ui/src/screens/Console/Dashboard/Prometheus/utils.ts @@ -727,13 +727,27 @@ const constructLabelNames = (metrics: any, legendFormat: string) => { const keysToReplace = Object.keys(metrics); const expToReplace = new RegExp(`{{(${keysToReplace.join("|")})}}`, "g"); - const replacedLegend = legendFormat.replace(expToReplace, (matchItem) => { + let replacedLegend = legendFormat.replace(expToReplace, (matchItem) => { const nwMatchItem = matchItem.replace(/({{|}})/g, ""); return metrics[nwMatchItem]; }); + const countVarsOpen = (replacedLegend.match(/{{/g) || []).length; + const countVarsClose = (replacedLegend.match(/}}/g) || []).length; + + let cleanLegend = replacedLegend.replace(/{{(.*?)}}/g, ""); + + if (countVarsOpen === countVarsClose && countVarsOpen !== 0 && countVarsClose !== 0) { + + keysToReplace.forEach((element) => { + replacedLegend = replacedLegend.replace(element, metrics[element]); + }) + + cleanLegend = replacedLegend; + } + // In case not all the legends were replaced, we remove the placeholders. - return replacedLegend.replace(/{{(.*?)}}/g, ""); + return cleanLegend; }; export const getWidgetsWithValue = (payload: any[]) => {