[ML] Alerting: Escape URL-like string from being displayed as links#226849
Conversation
…ng-strings-from-alert-context-messages
|
Pinging @elastic/ml-ui (:ml) |
|
Some concerns:
Looking at the default messageDon't we really just have a problem with Did you consider just wrapping these in backtics? I'm curious why there are single quotes around the values. They seem like they'd make the message kinda noisy. |
Hi! However, I've tested using backticks, and I don't think they produce good results (gmail client). For testing, I used Example 1:
Example 2:
|
|
I think it may be gmail auto-link-ifying, which is something I hadn't thought of. I sent myself an email with the gmail web ui, with the following text: |
|
@pmuellr @darnautov All testing was done without any escaping logic, only by manipulating the context message markdown. The default: Triple brackets: Double brackets with ticks Triple brackets with ticks It seems like the last one |
|
I guess the idea is going to be how to defeat auto-link-ification for field names, like And it seems like "surrounding" these doesn't always work - like with quotes or backtics, etc. I wonder if just suffixing or prefixing the values, at least in the template, might defeat it? So something like If we find something that works, we could use that in the default context message, and suggest that technique for other folks in the main doc for context variables (and this rule type as well). |
|
@pmuellr
|
|
I did some testing, and it appears appending Obviously not great, but it is good news that there's a common "autolinkify defeater". The text copy will of course be slightly odd looking, but likely better than linkified. If someone clicks the text in the email to select it, they might well pick up the hyphen, but hoping it would be obviously problematic wherever it might be used. I suspect there are more characters that can be used here. I was hoping I haven't tried with existing full URL values like you show with |
|
Hey, sorry for the late response, but I've tested proposed
WDYT? @darnautov @pmuellr |
I reckon it's fine for |
|
Ya, I think we want this just for the field NAME and not VALUE. With a |
Seems to me like a field name that was a valid URL the user would want to link to, is a bit of a stretch. Like, they had a field named
You could do this in both the constructed |
|
x-pack/platform/plugins/shared/ml/common/util/anomaly_description.ts
Outdated
Show resolved
Hide resolved
| Top influencers: | ||
| '{{#context.topInfluencers}}' | ||
| '{{influencer_field_name}}' = '{{influencer_field_value}}' ['{{score}}'] | ||
| '{{influencer_field_name}}-' = '{{influencer_field_value}}' ['{{score}}'] |
There was a problem hiding this comment.
Can we lose the = here? I think e.g.
IMO
customer_full_name.keyword- Sultan Al Bryan [4]
looks better than
customer_full_name.keyword- = Sultan Al Bryan [4]
There was a problem hiding this comment.
I don't have a strong opinion on this, I agree it looks a bit less odd.
WDYT @darnautov?
There was a problem hiding this comment.
agree, makes sense to use = (if it still breaks auto linkifying)
| Top records: | ||
| '{{#context.topRecords}}' | ||
| '{{function}}'('{{field_name}}') '{{by_field_value}}''{{over_field_value}}''{{partition_field_value}}' ['{{score}}']. Typical: '{{typical}}', Actual: '{{actual}}' | ||
| '{{function}}'('{{field_name}}-') '{{by_field_value}}''{{over_field_value}}''{{partition_field_value}}' ['{{score}}']. Typical: '{{typical}}', Actual: '{{actual}}' |
There was a problem hiding this comment.
Would dropping the brackets ( and ) improve the formatting here?
high_sum taxful_total_price- 'Wilhemina St. Ryan' [0]. Typical: $63.86, Actual: $200
maybe better than:
high_sum(taxful_total_price-) 'Wilhemina St. Ryan' [0]. Typical: $63.86, Actual: $200
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Async chunks
History
cc @rbrtj |
|
Starting backport for target branches: 9.2 |
…lastic#226849) Resolves elastic#202507 The PR aims to escape URL-like strings from being displayed as links, mainly in email clients. To achieve that, we append `-` hyphens after field_names. Here are the results of testing for: - Top records `field_name` = `service.name` - Top influencers `influencer_field_name` = `service.name` - Context message variables: `anomaly.entityName = service.name`, `partition_field_name = testing_it`, `correlated_by_field_value = correlated_by_field_value`, `by_field_name = testing.it`, `by_field_value = test_value`. I replaced some field values just because they're expected when constructing full context message, and I'm using mocked data. I think it covers all occurrences of possible URL-like field names in the alert message. <img width="1048" height="262" alt="image" src="https://github.com/user-attachments/assets/b16fff05-a0e9-4669-a8bd-8919ede95410" /> // Adjusted - removed `=` from top influencers - dropped `( )` from top records - Added a `.` dot after the `Actual` value results: <img width="859" height="238" alt="image" src="https://github.com/user-attachments/assets/a789ecec-3895-4307-b051-81d791d9bb98" /> (cherry picked from commit 2f9a43b)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…inks (#226849) (#237641) # Backport This will backport the following commits from `main` to `9.2`: - [[ML] Alerting: Escape URL-like string from being displayed as links (#226849)](#226849) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Robert Jaszczurek","email":"92210485+rbrtj@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-10-06T13:00:19Z","message":"[ML] Alerting: Escape URL-like string from being displayed as links (#226849)\n\nResolves https://github.com/elastic/kibana/issues/202507\nThe PR aims to escape URL-like strings from being displayed as links,\nmainly in email clients.\nTo achieve that, we append `-` hyphens after field_names.\n\nHere are the results of testing for:\n- Top records `field_name` = `service.name`\n- Top influencers `influencer_field_name` = `service.name`\n- Context message variables: `anomaly.entityName = service.name`,\n`partition_field_name = testing_it`, `correlated_by_field_value =\ncorrelated_by_field_value`, `by_field_name = testing.it`,\n`by_field_value = test_value`. I replaced some field values just because\nthey're expected when constructing full context message, and I'm using\nmocked data.\n\nI think it covers all occurrences of possible URL-like field names in\nthe alert message.\n\n<img width=\"1048\" height=\"262\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/b16fff05-a0e9-4669-a8bd-8919ede95410\"\n/>\n\n// Adjusted\n- removed `=` from top influencers\n- dropped `( )` from top records\n- Added a `.` dot after the `Actual` value\n results:\n<img width=\"859\" height=\"238\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/a789ecec-3895-4307-b051-81d791d9bb98\"\n/>","sha":"2f9a43bddfe8764e6af87aa3861593ea47bc8ab2","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","Team:ML","backport:version","v9.2.0","v9.3.0"],"title":"[ML] Alerting: Escape URL-like string from being displayed as links","number":226849,"url":"https://github.com/elastic/kibana/pull/226849","mergeCommit":{"message":"[ML] Alerting: Escape URL-like string from being displayed as links (#226849)\n\nResolves https://github.com/elastic/kibana/issues/202507\nThe PR aims to escape URL-like strings from being displayed as links,\nmainly in email clients.\nTo achieve that, we append `-` hyphens after field_names.\n\nHere are the results of testing for:\n- Top records `field_name` = `service.name`\n- Top influencers `influencer_field_name` = `service.name`\n- Context message variables: `anomaly.entityName = service.name`,\n`partition_field_name = testing_it`, `correlated_by_field_value =\ncorrelated_by_field_value`, `by_field_name = testing.it`,\n`by_field_value = test_value`. I replaced some field values just because\nthey're expected when constructing full context message, and I'm using\nmocked data.\n\nI think it covers all occurrences of possible URL-like field names in\nthe alert message.\n\n<img width=\"1048\" height=\"262\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/b16fff05-a0e9-4669-a8bd-8919ede95410\"\n/>\n\n// Adjusted\n- removed `=` from top influencers\n- dropped `( )` from top records\n- Added a `.` dot after the `Actual` value\n results:\n<img width=\"859\" height=\"238\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/a789ecec-3895-4307-b051-81d791d9bb98\"\n/>","sha":"2f9a43bddfe8764e6af87aa3861593ea47bc8ab2"}},"sourceBranch":"main","suggestedTargetBranches":["9.2"],"targetPullRequestStates":[{"branch":"9.2","label":"v9.2.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/226849","number":226849,"mergeCommit":{"message":"[ML] Alerting: Escape URL-like string from being displayed as links (#226849)\n\nResolves https://github.com/elastic/kibana/issues/202507\nThe PR aims to escape URL-like strings from being displayed as links,\nmainly in email clients.\nTo achieve that, we append `-` hyphens after field_names.\n\nHere are the results of testing for:\n- Top records `field_name` = `service.name`\n- Top influencers `influencer_field_name` = `service.name`\n- Context message variables: `anomaly.entityName = service.name`,\n`partition_field_name = testing_it`, `correlated_by_field_value =\ncorrelated_by_field_value`, `by_field_name = testing.it`,\n`by_field_value = test_value`. I replaced some field values just because\nthey're expected when constructing full context message, and I'm using\nmocked data.\n\nI think it covers all occurrences of possible URL-like field names in\nthe alert message.\n\n<img width=\"1048\" height=\"262\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/b16fff05-a0e9-4669-a8bd-8919ede95410\"\n/>\n\n// Adjusted\n- removed `=` from top influencers\n- dropped `( )` from top records\n- Added a `.` dot after the `Actual` value\n results:\n<img width=\"859\" height=\"238\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/a789ecec-3895-4307-b051-81d791d9bb98\"\n/>","sha":"2f9a43bddfe8764e6af87aa3861593ea47bc8ab2"}}]}] BACKPORT--> Co-authored-by: Robert Jaszczurek <92210485+rbrtj@users.noreply.github.com>
…lastic#226849) Resolves elastic#202507 The PR aims to escape URL-like strings from being displayed as links, mainly in email clients. To achieve that, we append `-` hyphens after field_names. Here are the results of testing for: - Top records `field_name` = `service.name` - Top influencers `influencer_field_name` = `service.name` - Context message variables: `anomaly.entityName = service.name`, `partition_field_name = testing_it`, `correlated_by_field_value = correlated_by_field_value`, `by_field_name = testing.it`, `by_field_value = test_value`. I replaced some field values just because they're expected when constructing full context message, and I'm using mocked data. I think it covers all occurrences of possible URL-like field names in the alert message. <img width="1048" height="262" alt="image" src="https://github.com/user-attachments/assets/b16fff05-a0e9-4669-a8bd-8919ede95410" /> // Adjusted - removed `=` from top influencers - dropped `( )` from top records - Added a `.` dot after the `Actual` value results: <img width="859" height="238" alt="image" src="https://github.com/user-attachments/assets/a789ecec-3895-4307-b051-81d791d9bb98" />















Resolves #202507
The PR aims to escape URL-like strings from being displayed as links, mainly in email clients.
To achieve that, we append
-hyphens after field_names.Here are the results of testing for:
field_name=service.nameinfluencer_field_name=service.nameanomaly.entityName = service.name,partition_field_name = testing_it,correlated_by_field_value = correlated_by_field_value,by_field_name = testing.it,by_field_value = test_value. I replaced some field values just because they're expected when constructing full context message, and I'm using mocked data.I think it covers all occurrences of possible URL-like field names in the alert message.
// Adjusted
=from top influencers( )from top records.dot after theActualvalueresults: