Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 11 commits into from
Jun 4, 2020
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