Skip to content

Commit

Permalink
Enhance MetricMonitorCriteria to support metric alias handling and im…
Browse files Browse the repository at this point in the history
…prove data processing logic
  • Loading branch information
simlarsen committed Dec 10, 2024
1 parent b26cf4e commit f575afa
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
54 changes: 48 additions & 6 deletions Common/Server/Utils/Monitor/Criteria/MetricMonitorCriteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export default class MetricMonitorCriteria {
dataToProcess: DataToProcess;
criteriaFilter: CriteriaFilter;
}): Promise<string | null> {

// Metric Monitoring Checks

let threshold: number | string | undefined | null =
Expand All @@ -21,11 +20,54 @@ export default class MetricMonitorCriteria {
const metricAggregaredResult: Array<AggregatedResult> =
(input.dataToProcess as MetricMonitorResponse).metricResult || [];

return CompareCriteria.compareCriteriaNumbers({
value: currentLogCount,
threshold: threshold as number,
criteriaFilter: input.criteriaFilter,
});
const metricAlias: string =
input.criteriaFilter.metricMonitorOptions?.metricAlias || "";

const aggregatedResult: AggregatedResult | undefined =
metricAggregaredResult && metricAggregaredResult.length > 0
? metricAggregaredResult[0]
: undefined;

if (metricAlias) {
// find the index of the alias in the dataToProcess.
const indexOfAlias = (
input.dataToProcess as MetricMonitorResponse
).metricViewConfig.queryConfigs.findIndex((queryConfig) => {
return queryConfig.metricAliasData?.metricVariable === metricAlias;
});

// now get the aggregated result for that alias
if (indexOfAlias !== -1) {
const aggregatedResultForAlias: AggregatedResult | undefined =
metricAggregaredResult[indexOfAlias];
if (aggregatedResultForAlias) {
const numbers: Array<number> = aggregatedResultForAlias.data.map(
(data) => {
return data.value;
},
);

return CompareCriteria.compareCriteriaNumbers({
value: numbers,
threshold: threshold as number,
criteriaFilter: input.criteriaFilter,
});
}
}
}

// if there's no alias then this is the default case
if (aggregatedResult) {
const numbers: Array<number> = aggregatedResult.data.map((data) => {
return data.value;
});

return CompareCriteria.compareCriteriaNumbers({
value: numbers,
threshold: threshold as number,
criteriaFilter: input.criteriaFilter,
});
}
}

return null;
Expand Down
1 change: 0 additions & 1 deletion Dashboard/src/Components/Form/Monitor/MonitorStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ const MonitorStepElement: FunctionComponent<ComponentProps> = (
}
};


const fetchTelemetryServices: PromiseVoidFunction =
async (): Promise<void> => {
const telemetryServicesResult: ListResult<TelemetryService> =
Expand Down

0 comments on commit f575afa

Please sign in to comment.