Skip to content

Commit 31ccccf

Browse files
authored
feat: dynamic selectors with alert_foreign_logs_enricher (#1600)
* feat: dynamic selectors with alert_foreign_logs_enricher * feat: improve label parsing fallback and add documentation * test: small tweaks to unit test * fix: improve selector test and fix incorrect parsing issue * test: reenable commented out tests * chore: refactor locator parsing code * fix: incorrect import in playbooks and update docs * fix: revert some unnecessary changes to documentation generation * fix: restore unechanged files
1 parent 5e9f5e4 commit 31ccccf

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

docs/playbook-reference/actions/event-enrichment.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,21 @@ These actions enrich Prometheus alerts and only support the :ref:`on_prometheus_
128128

129129
.. robusta-action:: playbooks.robusta_playbooks.alerts_integration.foreign_logs_enricher
130130

131+
.. robusta-action:: playbooks.robusta_playbooks.alerts_integration.alert_foreign_logs_enricher
132+
133+
Here is an example using a dynamic selector that depends on the alert's labels
134+
135+
.. code-block:: yaml
136+
137+
customPlaybooks:
138+
- actions:
139+
- alert_foreign_logs_enricher:
140+
label_selectors:
141+
- "app=${labels.service}"
142+
- "env=production"
143+
triggers:
144+
- on_prometheus_alert: {}
145+
131146
.. robusta-action:: playbooks.robusta_playbooks.alerts_integration.alert_definition_enricher
132147

133148
.. robusta-action:: playbooks.robusta_playbooks.alerts_integration.mention_enricher

playbooks/robusta_playbooks/alerts_integration.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,20 @@ class ForeignLogParams(LogEnricherParams):
455455
title_override: Optional[str]
456456

457457

458+
@action
459+
def alert_foreign_logs_enricher(event: PrometheusKubernetesAlert, params: ForeignLogParams):
460+
"""
461+
Prometheus alert enricher to fetch and attach pod logs.
462+
463+
This action behaves the same as the foreign_logs_enricher.
464+
The logs are fetched for the pod determined by the label selector field in the parameters.
465+
The label selector field can use the format ${labels.XYZ} to reference any XYZ label present in the Prometheus alert.
466+
467+
"""
468+
subject = event.get_subject()
469+
params.label_selectors = [format_event_templated_string(subject, selector) for selector in params.label_selectors]
470+
return foreign_logs_enricher(event, params)
471+
458472
@action
459473
def foreign_logs_enricher(event: ExecutionBaseEvent, params: ForeignLogParams):
460474
"""
145 KB
Loading

0 commit comments

Comments
 (0)