Skip to content

Commit

Permalink
[8.x] [Obs Alerts table] Fix error on clicking alert reason message (e…
Browse files Browse the repository at this point in the history
…lastic#193693) (elastic#193718)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Obs Alerts table] Fix error on clicking alert reason message
(elastic#193693)](elastic#193693)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Bena
Kansara","email":"69037875+benakansara@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-09-23T13:08:15Z","message":"[Obs
Alerts table] Fix error on clicking alert reason message
(elastic#193693)\n\nResolves
https://github.com/elastic/kibana/issues/193692","sha":"2304fb67365325bfcb530d3fa2a658544d8a7016","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","ci:project-deploy-observability","Team:obs-ux-management","v8.16.0","backport:version"],"title":"[Obs
Alerts table] Fix error on clicking alert reason
message","number":193693,"url":"https://github.com/elastic/kibana/pull/193693","mergeCommit":{"message":"[Obs
Alerts table] Fix error on clicking alert reason message
(elastic#193693)\n\nResolves
https://github.com/elastic/kibana/issues/193692","sha":"2304fb67365325bfcb530d3fa2a658544d8a7016"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/193693","number":193693,"mergeCommit":{"message":"[Obs
Alerts table] Fix error on clicking alert reason message
(elastic#193693)\n\nResolves
https://github.com/elastic/kibana/issues/193692","sha":"2304fb67365325bfcb530d3fa2a658544d8a7016"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Bena Kansara <69037875+benakansara@users.noreply.github.com>
  • Loading branch information
2 people authored and neptunian committed Oct 1, 2024
1 parent d0614a3 commit b69eb0f
Showing 1 changed file with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ export const mapRuleParamsWithFlyout = (alert: TopAlert): FlyoutThresholdData[]
switch (ruleId) {
case OBSERVABILITY_THRESHOLD_RULE_TYPE_ID:
return observedValues.map((observedValue, metricIndex) => {
const criteria = ruleCriteria[metricIndex] as CustomMetricExpressionParams;
const criteria = Array.isArray(ruleCriteria)
? (ruleCriteria[metricIndex] as CustomMetricExpressionParams)
: (ruleCriteria as CustomMetricExpressionParams);
const fields = criteria.metrics.map((metric) => metric.field || 'COUNT_AGG');
const comparator = criteria.comparator;
const threshold = criteria.threshold;
Expand Down Expand Up @@ -118,12 +120,20 @@ export const mapRuleParamsWithFlyout = (alert: TopAlert): FlyoutThresholdData[]

case METRIC_THRESHOLD_ALERT_TYPE_ID:
return observedValues.map((observedValue, metricIndex) => {
const criteria = ruleCriteria[metricIndex] as BaseMetricExpressionParams & {
metric: string;
customMetrics: Array<{
field?: string;
}>;
};
const criteria = Array.isArray(ruleCriteria)
? (ruleCriteria[metricIndex] as BaseMetricExpressionParams & {
metric: string;
customMetrics: Array<{
field?: string;
}>;
})
: (ruleCriteria as BaseMetricExpressionParams & {
metric: string;
customMetrics: Array<{
field?: string;
}>;
});

let fields: string[] = [];
const metric = criteria.metric;
const customMetric = criteria.customMetrics;
Expand Down Expand Up @@ -157,14 +167,21 @@ export const mapRuleParamsWithFlyout = (alert: TopAlert): FlyoutThresholdData[]

case METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID:
return observedValues.map((observedValue, metricIndex) => {
const { threshold, customMetric, metric, comparator } = ruleCriteria[
metricIndex
] as BaseMetricExpressionParams & {
metric: string;
customMetric: {
field: string;
};
};
const criteria = Array.isArray(ruleCriteria)
? (ruleCriteria[metricIndex] as BaseMetricExpressionParams & {
metric: string;
customMetric: {
field: string;
};
})
: (ruleCriteria as BaseMetricExpressionParams & {
metric: string;
customMetric: {
field: string;
};
});

const { threshold, customMetric, metric, comparator } = criteria;
const metricField = customMetric?.field || metric;
const thresholdFormatted = threshold.map((thresholdToFormat) => {
if (
Expand Down

0 comments on commit b69eb0f

Please sign in to comment.