Skip to content

Commit

Permalink
Merge branch 'master' into json-change-tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
arikalon1 authored Jan 9, 2025
2 parents 6df8a32 + 6a8baca commit 986f30b
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 53 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/test-poetry-lock.yaml

This file was deleted.

9 changes: 9 additions & 0 deletions .github/workflows/test_robusta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ name: Test robusta with pytest
on: [push, pull_request, workflow_dispatch]

jobs:
check:
name: Pre-commit checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/[email protected]

run_tests:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
58 changes: 34 additions & 24 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
repos:
- repo: https://github.com/ambv/black
rev: 22.3.0
hooks:
- id: black
language_version: python3
args: [--config=pyproject.toml]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
- repo: https://github.com/python-poetry/poetry
rev: 1.8.5
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: poetry-check
- id: poetry-lock
pass_filenames: false
args:
- --no-update

# - repo: https://github.com/ambv/black
# rev: 22.3.0
# hooks:
# - id: black
# language_version: python3
# args: [--config=pyproject.toml]

- repo: https://github.com/MarcoGorelli/absolufy-imports
rev: v0.3.1
hooks:
- id: absolufy-imports
# - repo: https://github.com/pre-commit/pre-commit-hooks
# rev: v3.3.0
# hooks:
# - id: trailing-whitespace
# - id: end-of-file-fixer

- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
args: [--config=.flake8]
# - repo: https://github.com/MarcoGorelli/absolufy-imports
# rev: v0.3.1
# hooks:
# - id: absolufy-imports

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: [--settings-path=pyproject.toml]
# - repo: https://github.com/pycqa/flake8
# rev: 5.0.4
# hooks:
# - id: flake8
# args: [--config=.flake8]

# - repo: https://github.com/pycqa/isort
# rev: 5.12.0
# hooks:
# - id: isort
# args: [--settings-path=pyproject.toml]

# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.790
Expand Down
2 changes: 1 addition & 1 deletion docs/how-it-works/architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Alternatively, you can :ref:`integrate an existing Prometheus with Robusta <Inte
Web UI (Optional)
^^^^^^^^^^^^^^^^^^^^^^

The Robusta `SaaS platform <http://home.robusta.dev/ui?from=docs>`_ provides a single pane of glass for all your alerts and clusters.
The Robusta `SaaS platform <http://home.robusta.dev/?from=docs>`_ provides a single pane of glass for all your alerts and clusters.

On commercial plans, the UI is available for self-hosting in your own environment.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ To investigate you look at the event log:
Aha! "1 node(s) didn't match Pod's node affinity/selector." ALRIGHT!

.. note::
You can see this event on an informative timeline in `Robusta UI <http://home.robusta.dev/ui?from=docs>`_. Check it out!
You can see this event on an informative timeline in `Robusta UI <http://home.robusta.dev/?from=docs>`_. Check it out!

Wait, what does it mean? 😖 (Hint: Check the YAML config for the spoiler)

Expand Down
12 changes: 6 additions & 6 deletions playbooks/robusta_playbooks/event_enrichments.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def event_resource_events(event: EventChangeEvent):
return
obj = event.obj.regarding
events_table = get_resource_events_table(
"*Related Events*",
"Related Events",
obj.kind,
obj.name,
obj.namespace,
Expand Down Expand Up @@ -245,7 +245,7 @@ def resource_events_enricher(event: KubernetesResourceEvent, params: ExtendedEve
[
EventsBlock(
events=events_row,
table_name=f"*{kind} events:*",
table_name=f"{kind} Events",
column_renderers={"time": RendererType.DATETIME},
headers=["reason", "type", "time", "kind", "name", "message"],
rows=rows,
Expand All @@ -269,7 +269,7 @@ def pod_events_enricher(event: PodEvent, params: EventEnricherParams):
return

events_table_block = get_resource_events_table(
"*Pod events:*",
"Pod Events",
pod.kind,
pod.metadata.name,
pod.metadata.namespace,
Expand All @@ -292,7 +292,7 @@ def enrich_pod_with_node_events(event: PodEvent, params: EventEnricherParams):
"""
pod = event.get_pod()
events_table_block = get_resource_events_table(
"*Node events:*",
"Node Events",
kind="Node",
name=pod.spec.nodeName,
included_types=params.included_types,
Expand Down Expand Up @@ -325,7 +325,7 @@ def deployment_events_enricher(event: DeploymentEvent, params: ExtendedEventEnri
selected_pods = pods if len(pods) <= params.max_pods else pods[: params.max_pods]
for pod in selected_pods:
events_table_block = get_resource_events_table(
f"*Pod events for {pod.metadata.name}:*",
f"Pod events for {pod.metadata.name}",
"Pod",
pod.metadata.name,
pod.metadata.namespace,
Expand All @@ -341,7 +341,7 @@ def deployment_events_enricher(event: DeploymentEvent, params: ExtendedEventEnri
)
else:
events_table_block = get_resource_events_table(
"*Deployment events:*",
"Deployment Events",
dep.kind,
dep.metadata.name,
dep.metadata.namespace,
Expand Down
77 changes: 77 additions & 0 deletions playbooks/robusta_playbooks/kubectl_enrichments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import logging
import os
import uuid

from hikaru.model.rel_1_26 import Container, PodSpec
from robusta.api import (
RUNNER_SERVICE_ACCOUNT,
ExecutionBaseEvent,
FileBlock,
MarkdownBlock,
PodRunningParams,
RobustaJob,
action,
)
from robusta.utils.parsing import format_event_templated_string

IMAGE: str = os.getenv("KUBECTL_IMAGE_OVERRIDE", f"bitnami/kubectl:latest")


class KubectlParams(PodRunningParams):
"""
:var kubectl_command: The full kubectl command to run, formatted as a shell command string.
:var description: A description of the command ran.
:var timeout: The maximum time (in seconds) to wait for the kubectl command to complete. Default is 3600 seconds.
"""

command: str = None
description: str = None
timeout: int = 3600


@action
def kubectl_command(event: ExecutionBaseEvent, params: KubectlParams):
"""
Runs a custom kubectl command inside a Kubernetes pod using a Job.
"""

subject = event.get_subject()
formatted_kubectl_command = format_event_templated_string(subject, params.command)
logging.info(f"kubectl_command running '{params.description}'")
logging.debug(f"kubectl_command: '{formatted_kubectl_command}'")

spec = PodSpec(
serviceAccountName=RUNNER_SERVICE_ACCOUNT,
containers=[
Container(
name="kubectl",
image=IMAGE,
imagePullPolicy="Always",
command=["/bin/sh", "-c"],
args=[formatted_kubectl_command]
)
],
restartPolicy="Never",
)

try:
kubectl_response = RobustaJob.run_simple_job_spec(
spec,
f"robusta-kubectl-command-{str(uuid.uuid4())}",
params.timeout,
custom_annotations=params.custom_annotations,
ttl_seconds_after_finished=43200, # 12 hours
delete_job_post_execution=True,
process_name=False,
)
descriptiont_text = params.description if params.description else "Kubectl Command"
event.add_enrichment(
[
MarkdownBlock(f"*{formatted_kubectl_command}*"),
FileBlock(f"kubectl.txt", kubectl_response.encode()),
], title=descriptiont_text
)
except Exception:
logging.exception("Error running kubectl command")


4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ types-toml = "^0.10.2"
types-tabulate = "^0.8.10"

[tool.poetry.extras]
all = ["Flask", "grafana-api", "watchdog", "dulwich", "better-exceptions", "CairoSVG", "tabulate", "kafka-python", "prometheus-api-client", "supabase", "datadog-api-client", "tinycss", "cssselect", "rsa", "sentry-sdk", "poetry-core"]
all = ["Flask", "grafana-api", "watchdog", "better-exceptions", "CairoSVG", "tabulate", "kafka-python", "prometheus-api-client", "supabase", "datadog-api-client", "sentry-sdk", "poetry-core"]

[tool.poetry.group.dev.dependencies]
sphinx-jinja = { git = "https://github.com/robusta-dev/sphinx-jinja.git" }
Expand Down

0 comments on commit 986f30b

Please sign in to comment.