[Metrics UI] Add back context variables with descriptions (#67487)

* 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>
This commit is contained in:
Phillip Burch 2020-06-04 15:56:54 -05:00 committed by GitHub
parent 97a72b33c5
commit a4549a71ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View file

@ -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),
});
}
@ -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 }),
{}
);

View file

@ -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',
@ -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',