Skip to content

Commit

Permalink
Add application related labels to deployment_status metric (#4520)
Browse files Browse the repository at this point in the history
Fixes: #4475

Signed-off-by: Naoki Kanatani <[email protected]>
  • Loading branch information
kanata2 authored Jul 21, 2023
1 parent 824f9c0 commit 01df30e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/app/piped/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/app/piped/controller/controllermetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (

const (
deploymentIDKey = "deployment"
applicationIDKey = "application_id"
applicationNameKey = "application_name"
applicationKindKey = "application_kind"
platformProviderKey = "platform_provider"
deploymentStatusKey = "status"
Expand All @@ -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)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/piped/controller/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/piped/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}()

Expand All @@ -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 (
Expand Down

0 comments on commit 01df30e

Please sign in to comment.