Skip to content
Closed
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
14 changes: 13 additions & 1 deletion ui/src/features/common/analysis-modal/transforms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import {
metricStatusLabel,
metricSubstatus,
printableCloudWatchQuery,
printableDatadogQuery
printableDatadogQuery,
transformMeasurements
} from './transforms';
import { AnalysisStatus, FunctionalStatus } from './types';

Expand Down Expand Up @@ -559,4 +560,15 @@ describe('analysis modal transforms', () => {
tableValue: { latency: null, cpuUsage: null }
});
});

test('transformMeasurements() with a non-JSON string measurement value', () => {
// a provider may return a plain string (e.g. "kargo") that is not valid JSON;
// this should not throw -- the value is placed in the table as-is
expect(transformMeasurements([], [{ value: 'kargo' }])).toEqual({
chartable: false,
min: 0,
max: null,
measurements: [{ value: 'kargo', chartValue: null, tableValue: 'kargo' }]
});
});
});
12 changes: 11 additions & 1 deletion ui/src/features/common/analysis-modal/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,17 @@ const transformMeasurementValue = (
};
}

const parsedValue = JSON.parse(value);
let parsedValue;
try {
parsedValue = JSON.parse(value);
} catch {
// value is a plain string (not JSON) -- not chartable
return {
canChart: false,
chartValue: null,
tableValue: value
};
}

// single number measurement value
if (isFiniteNumber(parsedValue)) {
Expand Down