Skip to content

Commit

Permalink
fix(slo): preview data no response error (elastic#167909)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelemme authored and dej611 committed Oct 17, 2023
1 parent de4b807 commit a940952
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function useGetPreviewData(isValid: boolean, indicator: Indicator): UseGe
}
);

return response;
return Array.isArray(response) ? response : [];
},
retry: false,
refetchOnWindowFocus: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import {
KQLCustomIndicator,
MetricCustomIndicator,
} from '@kbn/slo-schema';
import { assertNever } from '@kbn/std';
import { APMTransactionDurationIndicator } from '../../domain/models';
import { computeSLI } from '../../domain/services';
import { InvalidQueryError } from '../../errors';
import {
GetHistogramIndicatorAggregation,
GetCustomMetricIndicatorAggregation,
GetHistogramIndicatorAggregation,
} from './aggregations';

export class GetPreviewData {
Expand Down Expand Up @@ -299,19 +300,24 @@ export class GetPreviewData {
}

public async execute(params: GetPreviewDataParams): Promise<GetPreviewDataResponse> {
switch (params.indicator.type) {
case 'sli.apm.transactionDuration':
return this.getAPMTransactionDurationPreviewData(params.indicator);
case 'sli.apm.transactionErrorRate':
return this.getAPMTransactionErrorPreviewData(params.indicator);
case 'sli.kql.custom':
return this.getCustomKQLPreviewData(params.indicator);
case 'sli.histogram.custom':
return this.getHistogramPreviewData(params.indicator);
case 'sli.metric.custom':
return this.getCustomMetricPreviewData(params.indicator);
default:
return [];
try {
const type = params.indicator.type;
switch (type) {
case 'sli.apm.transactionDuration':
return this.getAPMTransactionDurationPreviewData(params.indicator);
case 'sli.apm.transactionErrorRate':
return this.getAPMTransactionErrorPreviewData(params.indicator);
case 'sli.kql.custom':
return this.getCustomKQLPreviewData(params.indicator);
case 'sli.histogram.custom':
return this.getHistogramPreviewData(params.indicator);
case 'sli.metric.custom':
return this.getCustomMetricPreviewData(params.indicator);
default:
assertNever(type);
}
} catch (err) {
return [];
}
}
}
Expand Down

0 comments on commit a940952

Please sign in to comment.