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

Clowdapp Dependency metrics #936

Merged
merged 7 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
40 changes: 40 additions & 0 deletions controllers/cloud.redhat.com/clowdapp_reconciliation.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,41 @@ func (r *ClowdAppReconciliation) stopMetrics() (ctrl.Result, error) {
return ctrl.Result{}, nil
}

func reportDependencies(ctx context.Context, pClient client.Client, o *crd.ClowdApp) (ctrl.Result, error) {
// get parent clowdapp name
var appName string = o.Name
var dependencies []string

// get dependencies and optional dependencies
dependencies = append(dependencies, o.Spec.Dependencies...)
dependencies = append(dependencies, o.Spec.OptionalDependencies...)

applist := crd.ClowdAppList{}

err := pClient.List(ctx, &applist, client.MatchingFields{"spec.envName": o.Spec.EnvName})

if err != nil {
return ctrl.Result{}, err
}

// for each dependency
for _, dependency := range dependencies {
// get child clowdapp with name of dependency
for _, app := range applist.Items {
if app.Name == dependency {
// report child clowdapp availability
if app.Status.Ready {
dependencyMetrics.With(prometheus.Labels{"app": appName, "dependency": dependency}).Set(1.0)
} else {
dependencyMetrics.With(prometheus.Labels{"app": appName, "dependency": dependency}).Set(0.0)
}
}
}
}

return ctrl.Result{}, nil
}

func (r *ClowdAppReconciliation) setPresentAndManagedApps() (ctrl.Result, error) {
presentApps[r.app.GetIdent()] = true

Expand Down Expand Up @@ -358,6 +393,11 @@ func (r *ClowdAppReconciliation) deletedUnusedResources() (ctrl.Result, error) {
}

func (r *ClowdAppReconciliation) setReconciliationSuccessful() (ctrl.Result, error) {
_, err := reportDependencies(r.ctx, r.client, r.app)
if err != nil {
r.log.Info("Error during depency metric reporting", "err", err)
}

if setClowdStatusErr := SetClowdAppConditions(r.ctx, r.client, r.app, crd.ReconciliationSuccessful, r.oldStatus, nil); setClowdStatusErr != nil {
r.log.Info("Set status error", "err", setClowdStatusErr)
return ctrl.Result{Requeue: true}, setClowdStatusErr
Expand Down
8 changes: 8 additions & 0 deletions controllers/cloud.redhat.com/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ var (
},
[]string{"app", "env"},
)
dependencyMetrics = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "clowder_dependency_availability",
Help: "Clowder dependency availability",
},
[]string{"app", "dependency"},
)
)

func init() {
Expand All @@ -108,5 +115,6 @@ func init() {
presentAppsMetric,
presentEnvsMetric,
reconciliationMetrics,
dependencyMetrics,
)
}
Loading