From a5200bb13a7fba69637ef81a5211530ede9e0b40 Mon Sep 17 00:00:00 2001 From: Filippo Pacifici Date: Thu, 12 Mar 2026 17:36:19 -0700 Subject: [PATCH] feat(k8s): add service_name label to k8s macro resources Add `service` label to the labels dict in `pipeline_step.py` so that Deployment and ConfigMap resources include the service name, enabling service-level monitoring, alerting, and discovery in Sentry's infrastructure. Co-Authored-By: Claude Sonnet 4.6 --- sentry_streams_k8s/sentry_streams_k8s/pipeline_step.py | 1 + sentry_streams_k8s/tests/test_pipeline_step.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/sentry_streams_k8s/sentry_streams_k8s/pipeline_step.py b/sentry_streams_k8s/sentry_streams_k8s/pipeline_step.py index 4094466a..6c12a66e 100644 --- a/sentry_streams_k8s/sentry_streams_k8s/pipeline_step.py +++ b/sentry_streams_k8s/sentry_streams_k8s/pipeline_step.py @@ -382,6 +382,7 @@ def run(self, context: dict[str, Any]) -> dict[str, Any]: labels = { "pipeline-app": make_k8s_name(pipeline_module), "pipeline": make_k8s_name(pipeline_name), + "service": make_k8s_name(service_name), } configmap_name = make_k8s_name(f"{service_name}-pipeline-{pipeline_name}") diff --git a/sentry_streams_k8s/tests/test_pipeline_step.py b/sentry_streams_k8s/tests/test_pipeline_step.py index 2ba0861c..e8c89626 100644 --- a/sentry_streams_k8s/tests/test_pipeline_step.py +++ b/sentry_streams_k8s/tests/test_pipeline_step.py @@ -386,6 +386,7 @@ def test_run_generates_complete_manifests() -> None: # Validate deployment name assert deployment["metadata"]["name"] == "my-service-pipeline-profiles-0" assert deployment["metadata"]["labels"]["pipeline-app"] == "sbc-profiles" + assert deployment["metadata"]["labels"]["service"] == "my-service" assert ( deployment["spec"]["template"]["metadata"]["annotations"]["sidecar.istio.io/inject"] == "false" @@ -394,6 +395,7 @@ def test_run_generates_complete_manifests() -> None: selector = deployment["spec"]["selector"] assert selector["matchLabels"]["pipeline-app"] == "sbc-profiles" assert selector["matchLabels"]["pipeline"] == "profiles" + assert selector["matchLabels"]["service"] == "my-service" # Validate deployment has container containers = deployment["spec"]["template"]["spec"]["containers"] @@ -418,6 +420,7 @@ def test_run_generates_complete_manifests() -> None: assert configmap["metadata"]["name"] == "my-service-pipeline-profiles" assert configmap["metadata"]["labels"]["pipeline-app"] == "sbc-profiles" assert configmap["metadata"]["labels"]["pipeline"] == "profiles" + assert configmap["metadata"]["labels"]["service"] == "my-service" # Validate configmap data assert "pipeline_config.yaml" in configmap["data"] @@ -568,6 +571,7 @@ def test_run_with_base_templates() -> None: # Check that pipeline additions are present assert deployment["metadata"]["name"] == "my-service-pipeline-profiles-0" assert "pipeline" in deployment["metadata"]["labels"] + assert "service" in deployment["metadata"]["labels"] assert len(deployment["spec"]["template"]["spec"]["containers"]) == 1 assert ( len(deployment["spec"]["template"]["spec"]["volumes"]) == 2 @@ -1035,5 +1039,6 @@ def test_emergency_patch_overrides_final_deployment() -> None: # Verify pipeline additions are still present (not removed by emergency patch) assert deployment["metadata"]["name"] == "my-service-pipeline-profiles-0" assert deployment["metadata"]["labels"]["pipeline-app"] == "sbc-profiles" + assert deployment["metadata"]["labels"]["service"] == "my-service" assert len(deployment["spec"]["template"]["spec"]["containers"]) == 1 assert deployment["spec"]["template"]["spec"]["containers"][0]["name"] == "pipeline-consumer"