Alerting: Update warning message for Telegram parse_mode and default to empty value (#89630)

This commit is contained in:
Tom Ratcliffe 2024-06-27 10:33:40 +01:00 committed by GitHub
parent 8e1c4919c7
commit 86d41b1e23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 9 deletions

View File

@ -5,7 +5,8 @@ import * as React from 'react';
import { Controller, FieldErrors, FieldValues, useFormContext } from 'react-hook-form'; import { Controller, FieldErrors, FieldValues, useFormContext } from 'react-hook-form';
import { GrafanaTheme2, SelectableValue } from '@grafana/data'; import { GrafanaTheme2, SelectableValue } from '@grafana/data';
import { Alert, Button, Field, Select, useStyles2 } from '@grafana/ui'; import { Alert, Button, Field, Select, Text, useStyles2 } from '@grafana/ui';
import { Trans, t } from 'app/core/internationalization';
import { useUnifiedAlertingSelector } from '../../../hooks/useUnifiedAlertingSelector'; import { useUnifiedAlertingSelector } from '../../../hooks/useUnifiedAlertingSelector';
import { ChannelValues, CommonSettingsComponentType } from '../../../types/receiver-form'; import { ChannelValues, CommonSettingsComponentType } from '../../../types/receiver-form';
@ -125,7 +126,10 @@ export function ChannelSubForm<R extends ChannelValues>({
const notifier = notifiers.find(({ dto: { type } }) => type === selectedType); const notifier = notifiers.find(({ dto: { type } }) => type === selectedType);
const isTelegram = selectedType === 'telegram'; const isTelegram = selectedType === 'telegram';
const isParseModeNone = parse_mode === 'None'; // Grafana AM takes "None" value and maps to an empty string,
// Cloud AM takes no value at all
const isParseModeNone = parse_mode === 'None' || !parse_mode;
const showTelegramWarning = isTelegram && !isParseModeNone;
// if there are mandatory options defined, optional options will be hidden by a collapse // if there are mandatory options defined, optional options will be hidden by a collapse
// if there aren't mandatory options, all options will be shown without collapse // if there aren't mandatory options, all options will be shown without collapse
const mandatoryOptions = notifier?.dto.options.filter((o) => o.required); const mandatoryOptions = notifier?.dto.options.filter((o) => o.required);
@ -191,13 +195,20 @@ export function ChannelSubForm<R extends ChannelValues>({
</div> </div>
{notifier && ( {notifier && (
<div className={styles.innerContent}> <div className={styles.innerContent}>
{isTelegram && !isParseModeNone && ( {showTelegramWarning && (
<Alert <Alert
title="Telegram messages are limited to 4096 UTF-8 characters. title={t(
If you use a `parse_mode` other than 'None', truncation may result in an invalid message, causing the notification to fail. 'alerting.contact-points.telegram.parse-mode-warning-title',
For longer messages, we recommend using an alternative contact method." 'Telegram messages are limited to 4096 UTF-8 characters.'
)}
severity="warning" severity="warning"
></Alert> >
<Trans i18nKey="alerting.contact-points.telegram.parse-mode-warning-body">
If you use a <Text variant="code">parse_mode</Text> option other than <Text variant="code">None</Text>,
truncation may result in an invalid message, causing the notification to fail. For longer messages, we
recommend using an alternative contact method.
</Trans>
</Alert>
)} )}
<ChannelOptions<R> <ChannelOptions<R>
defaultValues={defaultValues} defaultValues={defaultValues}

View File

@ -420,12 +420,16 @@ export const cloudNotifierTypes: Array<NotifierDTO<CloudNotifierType>> = [
}), }),
option('parse_mode', 'Parse mode', 'Parse mode for telegram message', { option('parse_mode', 'Parse mode', 'Parse mode for telegram message', {
element: 'select', element: 'select',
defaultValue: { label: 'MarkdownV2', value: 'MarkdownV2' }, // If we've set '' on the API, then the Select won't populate with the correct value,
// so the easiest way to fix this is to set the default value to ''
defaultValue: { label: 'None', value: '' },
selectOptions: [ selectOptions: [
// Note that the value for Cloud AM is '',
// and for Grafana AM it is 'None'
{ label: 'None', value: '' },
{ label: 'MarkdownV2', value: 'MarkdownV2' }, { label: 'MarkdownV2', value: 'MarkdownV2' },
{ label: 'Markdown', value: 'Markdown' }, { label: 'Markdown', value: 'Markdown' },
{ label: 'HTML', value: 'HTML' }, { label: 'HTML', value: 'HTML' },
{ label: 'plain text', value: '' },
], ],
}), }),
httpConfigOption, httpConfigOption,

View File

@ -55,6 +55,14 @@
}, },
"pause": "Pause evaluation" "pause": "Pause evaluation"
}, },
"alerting": {
"contact-points": {
"telegram": {
"parse-mode-warning-body": "If you use a <1>parse_mode</1> option other than <3>None</3>, truncation may result in an invalid message, causing the notification to fail. For longer messages, we recommend using an alternative contact method.",
"parse-mode-warning-title": "Telegram messages are limited to 4096 UTF-8 characters."
}
}
},
"annotations": { "annotations": {
"empty-state": { "empty-state": {
"button-title": "Add annotation query", "button-title": "Add annotation query",

View File

@ -55,6 +55,14 @@
}, },
"pause": "Päūşę ęväľūäŧįőʼn" "pause": "Päūşę ęväľūäŧįőʼn"
}, },
"alerting": {
"contact-points": {
"telegram": {
"parse-mode-warning-body": "Ĩƒ yőū ūşę ä <1>päřşę_mőđę</1> őpŧįőʼn őŧĥęř ŧĥäʼn <3>Ńőʼnę</3>, ŧřūʼnčäŧįőʼn mäy řęşūľŧ įʼn äʼn įʼnväľįđ męşşäģę, čäūşįʼnģ ŧĥę ʼnőŧįƒįčäŧįőʼn ŧő ƒäįľ. Főř ľőʼnģęř męşşäģęş, ŵę řęčőmmęʼnđ ūşįʼnģ äʼn äľŧęřʼnäŧįvę čőʼnŧäčŧ męŧĥőđ.",
"parse-mode-warning-title": "Ŧęľęģřäm męşşäģęş äřę ľįmįŧęđ ŧő 4096 ŮŦF-8 čĥäřäčŧęřş."
}
}
},
"annotations": { "annotations": {
"empty-state": { "empty-state": {
"button-title": "Åđđ äʼnʼnőŧäŧįőʼn qūęřy", "button-title": "Åđđ äʼnʼnőŧäŧįőʼn qūęřy",