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

Add application related labels to deployment_status metric #4520

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kentakozuka should it p.doneDeploymentStatus instead? 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out!
Let me fix it 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry... 😢

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No prob. It was my fault too.

}()

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