From 86d41b1e235d4012bc07d352eecd0c71329a9aea Mon Sep 17 00:00:00 2001 From: Tom Ratcliffe Date: Thu, 27 Jun 2024 10:33:40 +0100 Subject: [PATCH] Alerting: Update warning message for Telegram parse_mode and default to empty value (#89630) --- .../receivers/form/ChannelSubForm.tsx | 25 +++++++++++++------ .../cloud-alertmanager-notifier-types.ts | 8 ++++-- public/locales/en-US/grafana.json | 8 ++++++ public/locales/pseudo-LOCALE/grafana.json | 8 ++++++ 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/public/app/features/alerting/unified/components/receivers/form/ChannelSubForm.tsx b/public/app/features/alerting/unified/components/receivers/form/ChannelSubForm.tsx index c3650654a41..b9f5c32374e 100644 --- a/public/app/features/alerting/unified/components/receivers/form/ChannelSubForm.tsx +++ b/public/app/features/alerting/unified/components/receivers/form/ChannelSubForm.tsx @@ -5,7 +5,8 @@ import * as React from 'react'; import { Controller, FieldErrors, FieldValues, useFormContext } from 'react-hook-form'; 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 { ChannelValues, CommonSettingsComponentType } from '../../../types/receiver-form'; @@ -125,7 +126,10 @@ export function ChannelSubForm({ const notifier = notifiers.find(({ dto: { type } }) => type === selectedType); 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 aren't mandatory options, all options will be shown without collapse const mandatoryOptions = notifier?.dto.options.filter((o) => o.required); @@ -191,13 +195,20 @@ export function ChannelSubForm({ {notifier && (
- {isTelegram && !isParseModeNone && ( + {showTelegramWarning && ( + > + + If you use a parse_mode option other than None, + truncation may result in an invalid message, causing the notification to fail. For longer messages, we + recommend using an alternative contact method. + + )} defaultValues={defaultValues} diff --git a/public/app/features/alerting/unified/utils/cloud-alertmanager-notifier-types.ts b/public/app/features/alerting/unified/utils/cloud-alertmanager-notifier-types.ts index 0ff45bb14e9..27b19c8d3fe 100644 --- a/public/app/features/alerting/unified/utils/cloud-alertmanager-notifier-types.ts +++ b/public/app/features/alerting/unified/utils/cloud-alertmanager-notifier-types.ts @@ -420,12 +420,16 @@ export const cloudNotifierTypes: Array> = [ }), option('parse_mode', 'Parse mode', 'Parse mode for telegram message', { 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: [ + // Note that the value for Cloud AM is '', + // and for Grafana AM it is 'None' + { label: 'None', value: '' }, { label: 'MarkdownV2', value: 'MarkdownV2' }, { label: 'Markdown', value: 'Markdown' }, { label: 'HTML', value: 'HTML' }, - { label: 'plain text', value: '' }, ], }), httpConfigOption, diff --git a/public/locales/en-US/grafana.json b/public/locales/en-US/grafana.json index afbd474048c..f695c4d2c64 100644 --- a/public/locales/en-US/grafana.json +++ b/public/locales/en-US/grafana.json @@ -55,6 +55,14 @@ }, "pause": "Pause evaluation" }, + "alerting": { + "contact-points": { + "telegram": { + "parse-mode-warning-body": "If you use a <1>parse_mode option other than <3>None, 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": { "empty-state": { "button-title": "Add annotation query", diff --git a/public/locales/pseudo-LOCALE/grafana.json b/public/locales/pseudo-LOCALE/grafana.json index c3eb128f08d..5041043b211 100644 --- a/public/locales/pseudo-LOCALE/grafana.json +++ b/public/locales/pseudo-LOCALE/grafana.json @@ -55,6 +55,14 @@ }, "pause": "Päūşę ęväľūäŧįőʼn" }, + "alerting": { + "contact-points": { + "telegram": { + "parse-mode-warning-body": "Ĩƒ yőū ūşę ä <1>päřşę_mőđę őpŧįőʼn őŧĥęř ŧĥäʼn <3>Ńőʼnę, ŧřūʼ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": { "empty-state": { "button-title": "Åđđ äʼnʼnőŧäŧįőʼn qūęřy",