Skip to content

Commit

Permalink
[Metrics UI] Add back context variables with descriptions (elastic#67487
Browse files Browse the repository at this point in the history
)

* Add context variables for metric, value and threshold with descriptions

* Remove timestamp from this PR

* sentences are hard

* Fix lint rules

* Add more usage examples

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
phillipb and elasticmachine authored Jun 4, 2020
1 parent 97a72b3 commit a4549a7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ export const createMetricThresholdExecutor = (libs: InfraBackendLibs, alertId: s
group,
alertState: stateToAlertMessage[nextState],
reason,
value: mapToConditionsLookup(alertResults, (result) => result[group].currentValue),
threshold: mapToConditionsLookup(criteria, (c) => c.threshold),
metric: mapToConditionsLookup(criteria, (c) => c.metric),
});
}

Expand All @@ -352,3 +355,14 @@ export const FIRED_ACTIONS = {
defaultMessage: 'Fired',
}),
};

const mapToConditionsLookup = (
list: any[],
mapFn: (value: any, index: number, array: any[]) => unknown
) =>
list
.map(mapFn)
.reduce(
(result: Record<string, any>, value, i) => ({ ...result, [`condition${i}`]: value }),
{}
);
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ export function registerMetricThresholdAlertType(libs: InfraBackendLibs) {
}
);

const valueActionVariableDescription = i18n.translate(
'xpack.infra.metrics.alerting.threshold.alerting.valueActionVariableDescription',
{
defaultMessage:
'The value of the metric in the specified condition. Usage: (ctx.value.condition0, ctx.value.condition1, etc...).',
}
);

const metricActionVariableDescription = i18n.translate(
'xpack.infra.metrics.alerting.threshold.alerting.metricActionVariableDescription',
{
defaultMessage:
'The metric name in the specified condition. Usage: (ctx.metric.condition0, ctx.metric.condition1, etc...).',
}
);

const thresholdActionVariableDescription = i18n.translate(
'xpack.infra.metrics.alerting.threshold.alerting.thresholdActionVariableDescription',
{
defaultMessage:
'The threshold value of the metric for the specified condition. Usage: (ctx.threshold.condition0, ctx.threshold.condition1, etc...).',
}
);

return {
id: METRIC_THRESHOLD_ALERT_TYPE_ID,
name: 'Metric threshold',
Expand Down Expand Up @@ -82,6 +106,9 @@ export function registerMetricThresholdAlertType(libs: InfraBackendLibs) {
{ name: 'group', description: groupActionVariableDescription },
{ name: 'alertState', description: alertStateActionVariableDescription },
{ name: 'reason', description: reasonActionVariableDescription },
{ name: 'value', description: valueActionVariableDescription },
{ name: 'metric', description: metricActionVariableDescription },
{ name: 'threshold', description: thresholdActionVariableDescription },
],
},
producer: 'metrics',
Expand Down

0 comments on commit a4549a7

Please sign in to comment.