Skip to content

Commit

Permalink
fix: error with label values at Cardinality
Browse files Browse the repository at this point in the history
  • Loading branch information
jacovinus committed Dec 15, 2023
1 parent 6df4542 commit f4d17c9
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions packages/main/plugins/Cardinality/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export const getValuesArrayToString = (values: string[]): string => {
return values?.map((value) => `\"${value}\"`).join(",");
};

const labelsFreq = (arr: string[]) =>
arr.reduce((cnt, cur) => ((cnt[cur] = cnt[cur] + 1 || 1), cnt), {});

/**
*
* @param labelsArray
Expand All @@ -31,7 +34,26 @@ const getSeriesArraySelector = (labelsArray: string[]): string => {

let LabelsString = "{";
let labelslength = labelsArray.length;

let lsarray = [];
// generate labels array splitting by equals or non equals
for (let i = 0; i < labelslength; i++) {
const [label] = labelsArray[i].split(/(=|!=)/);
lsarray.push(label);
}
// check for frequency of same label
const labelsFrequency = labelsFreq(lsarray);

for (let i = 0; i < labelslength; i++) {
let currentLabel = lsarray[i];
// check if non equals label is hit and another one in the room is present
if (
labelsArray[i].includes("!=") &&
labelsFrequency[currentLabel] > 1
) {
continue;
}

const [lb, val] = labelsArray[i].split("=");

LabelsString += `${lb}=\"${val}\"`;
Expand Down Expand Up @@ -60,7 +82,10 @@ export const queryUpdater: QueryUpdater = {
return getSeriesSelector("__name__", query);
},
seriesCountByLabelName: ({ query }): string => {
return `{${query}!=""}`;
const queryStr = `{${query}!=""}`;
localStorage.setItem("labelValuePairs", `${query}!=`);

return queryStr;
},
seriesCountByFocusLabelValue: ({ query, focusLabel }): string => {
return getSeriesSelector(focusLabel, query);
Expand Down Expand Up @@ -229,7 +254,7 @@ export const useDataSourceData = (type: string) => {

const isAuth = authData.basicAuth.value;

let user_pass= {u: '', p:''}
let user_pass = { u: "", p: "" };

if (isAuth) {
let [user, password] = authData.fields.basicAuth;
Expand Down

0 comments on commit f4d17c9

Please sign in to comment.