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

feat: dynamic selectors with alert_foreign_logs_enricher #1600

Merged
merged 10 commits into from
Oct 21, 2024
15 changes: 15 additions & 0 deletions docs/playbook-reference/actions/event-enrichment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ These actions enrich Prometheus alerts and only support the :ref:`on_prometheus_

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

.. robusta-action:: playbooks.robusta_playbooks.alerts_integration.alert_foreign_logs_enricher

Here is an example using a dynamic selector that depends on the alert's labels

.. code-block:: yaml

customPlaybooks:
- actions:
- alert_foreign_logs_enricher:
label_selectors:
- "app=${labels.service}"
- "env=production"
triggers:
- on_prometheus_alert: {}

.. robusta-action:: playbooks.robusta_playbooks.alerts_integration.alert_definition_enricher

.. robusta-action:: playbooks.robusta_playbooks.alerts_integration.mention_enricher
Expand Down
14 changes: 14 additions & 0 deletions playbooks/robusta_playbooks/alerts_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,20 @@ class ForeignLogParams(LogEnricherParams):
title_override: Optional[str]


@action
def alert_foreign_logs_enricher(event: PrometheusKubernetesAlert, params: ForeignLogParams):
"""
Prometheus alert enricher to fetch and attach pod logs.

This action behaves the same as the foreign_logs_enricher.
The logs are fetched for the pod determined by the label selector field in the parameters.
The label selector field can use the format ${labels.XYZ} to reference any XYZ label present in the Prometheus alert.

"""
subject = event.get_subject()
params.label_selectors = [format_event_templated_string(subject, selector) for selector in params.label_selectors]
return foreign_logs_enricher(event, params)

@action
def foreign_logs_enricher(event: ExecutionBaseEvent, params: ForeignLogParams):
"""
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading