From 01df30ec4b77929d4110781289025ff2ad819a99 Mon Sep 17 00:00:00 2001 From: Naoki Kanatani Date: Fri, 21 Jul 2023 14:02:39 +0900 Subject: [PATCH] Add application related labels to deployment_status metric (#4520) Fixes: #4475 Signed-off-by: Naoki Kanatani --- pkg/app/piped/controller/controller.go | 2 +- pkg/app/piped/controller/controllermetrics/metrics.go | 10 ++++++---- pkg/app/piped/controller/planner.go | 2 +- pkg/app/piped/controller/scheduler.go | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/app/piped/controller/controller.go b/pkg/app/piped/controller/controller.go index d99eab7fea..76e057de3c 100644 --- a/pkg/app/piped/controller/controller.go +++ b/pkg/app/piped/controller/controller.go @@ -364,7 +364,7 @@ func (c *controller) syncPlanners(ctx context.Context) error { if pre, ok := pendingByApp[appID]; ok && !d.TriggerBefore(pre) { continue } - controllermetrics.UpdateDeploymentStatus(d.Id, d.Status, d.Kind, d.PlatformProvider) + controllermetrics.UpdateDeploymentStatus(d, d.Status) pendingByApp[appID] = d } diff --git a/pkg/app/piped/controller/controllermetrics/metrics.go b/pkg/app/piped/controller/controllermetrics/metrics.go index e4d4ef24df..d2f8c0e001 100644 --- a/pkg/app/piped/controller/controllermetrics/metrics.go +++ b/pkg/app/piped/controller/controllermetrics/metrics.go @@ -21,6 +21,8 @@ import ( const ( deploymentIDKey = "deployment" + applicationIDKey = "application_id" + applicationNameKey = "application_name" applicationKindKey = "application_kind" platformProviderKey = "platform_provider" deploymentStatusKey = "status" @@ -32,16 +34,16 @@ var ( Name: "deployment_status", Help: "The current status of deployment. 1 for current status, 0 for others.", }, - []string{deploymentIDKey, applicationKindKey, platformProviderKey, deploymentStatusKey}, + []string{deploymentIDKey, applicationIDKey, applicationNameKey, applicationKindKey, platformProviderKey, deploymentStatusKey}, ) ) -func UpdateDeploymentStatus(id string, status model.DeploymentStatus, applicationKind model.ApplicationKind, platformProvider string) { +func UpdateDeploymentStatus(d *model.Deployment, status model.DeploymentStatus) { for name, value := range model.DeploymentStatus_value { if model.DeploymentStatus(value) == status { - deploymentStatus.WithLabelValues(id, applicationKind.String(), platformProvider, name).Set(1) + deploymentStatus.WithLabelValues(d.Id, d.ApplicationId, d.ApplicationName, d.Kind.String(), d.PlatformProvider, name).Set(1) } else { - deploymentStatus.WithLabelValues(id, applicationKind.String(), platformProvider, name).Set(0) + deploymentStatus.WithLabelValues(d.Id, d.ApplicationId, d.ApplicationName, d.Kind.String(), d.PlatformProvider, name).Set(0) } } } diff --git a/pkg/app/piped/controller/planner.go b/pkg/app/piped/controller/planner.go index 94c5ac716d..580504144c 100644 --- a/pkg/app/piped/controller/planner.go +++ b/pkg/app/piped/controller/planner.go @@ -189,7 +189,7 @@ func (p *planner) Run(ctx context.Context) error { } defer func() { - controllermetrics.UpdateDeploymentStatus(p.deployment.Id, p.doneDeploymentStatus, p.deployment.Kind, p.deployment.PlatformProvider) + controllermetrics.UpdateDeploymentStatus(p.deployment, p.deployment.Status) }() planner, ok := p.plannerRegistry.Planner(p.deployment.Kind) diff --git a/pkg/app/piped/controller/scheduler.go b/pkg/app/piped/controller/scheduler.go index cb04e95d2d..91e0bf63a2 100644 --- a/pkg/app/piped/controller/scheduler.go +++ b/pkg/app/piped/controller/scheduler.go @@ -193,7 +193,7 @@ func (s *scheduler) Run(ctx context.Context) error { defer func() { s.doneTimestamp = s.nowFunc() s.doneDeploymentStatus = deploymentStatus - controllermetrics.UpdateDeploymentStatus(s.deployment.Id, deploymentStatus, s.deployment.Kind, s.deployment.PlatformProvider) + controllermetrics.UpdateDeploymentStatus(s.deployment, deploymentStatus) s.done.Store(true) }() @@ -209,7 +209,7 @@ func (s *scheduler) Run(ctx context.Context) error { if err != nil { return err } - controllermetrics.UpdateDeploymentStatus(s.deployment.Id, model.DeploymentStatus_DEPLOYMENT_RUNNING, s.deployment.Kind, s.deployment.PlatformProvider) + controllermetrics.UpdateDeploymentStatus(s.deployment, model.DeploymentStatus_DEPLOYMENT_RUNNING) } var (