Skip to content

Commit 02af93d

Browse files
authored
Merge pull request opendatahub-io#92 from gmfrasca/crstatus-metrics
Add CR Ready Status Metrics
2 parents c99a8ca + a84906b commit 02af93d

File tree

5 files changed

+128
-1
lines changed

5 files changed

+128
-1
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Data Science Pipeline stacks onto individual OCP namespaces.
1919
1. [Cleanup ODH Installation](#cleanup-odh-installation)
2020
2. [Cleanup Standalone Installation](#cleanup-standalone-installation)
2121
5. [Run tests](#run-tests)
22+
6. [Metrics](#metrics)
2223

2324
# Quickstart
2425

@@ -359,6 +360,17 @@ You can find a more permanent location to install `setup-envtest` into on your l
359360
`KUBEBUILDER_ASSETS` into your `.bashrc` or equivalent. By doing this you can always run `pre-commit run --all-files`
360361
without having to repeat these steps.
361362

363+
# Metrics
364+
365+
The Data Science Pipelines Operator exposes standard operator-sdk metrics for controller monitoring purposes.
366+
In addition to these metrics, DSPO also exposes several custom metrics for monitoring the status of the DataSciencePipelinesApplications that it owns.
367+
368+
They are as follows:
369+
- `data_science_pipelines_application_apiserver_ready` - Gauge that indicates if the DSPA's APIServer is in a Ready state (1 => Ready, 0 => Not Ready)
370+
- `data_science_pipelines_application_persistenceagent_ready` - Gauge that indicates if the DSPA's PersistenceAgent is in a Ready state (1 => Ready, 0 => Not Ready)
371+
- `data_science_pipelines_application_scheduledworkflow_ready` - Gauge that indicates if the DSPA's ScheduledWorkflow manager is in a Ready state (1 => Ready, 0 => Not Ready)
372+
- `data_science_pipelines_application_ready` - Gauge that indicates if the DSPA is in a fully Ready state (1 => Ready, 0 => Not Ready)
373+
362374
[cluster admin]: https://docs.openshift.com/container-platform/4.12/authentication/using-rbac.html#creating-cluster-admin_using-rbac
363375
[oc client]: https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/latest/openshift-client-linux.tar.gz
364376
[OCP Pipelines Operator]: https://docs.openshift.com/container-platform/4.12/cicd/pipelines/installing-pipelines.html#op-installing-pipelines-operator-in-web-console_installing-pipelines

controllers/dspipeline_controller.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,48 @@ func (r *DSPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
308308
return ctrl.Result{}, err
309309
}
310310

311+
r.PublishMetrics(dspa, apiServerReady, persistenceAgentReady, scheduledWorkflowReady, crReady)
312+
311313
return ctrl.Result{}, nil
312314
}
313315

316+
func (r *DSPAReconciler) PublishMetrics(dspa *dspav1alpha1.DataSciencePipelinesApplication,
317+
apiServerReady, persistenceAgentReady, scheduledWorkflowReady,
318+
crReady metav1.Condition) {
319+
r.Log.Info("Publishing Ready Metrics")
320+
if apiServerReady.Status == metav1.ConditionTrue {
321+
r.Log.Info("APIServer Ready")
322+
APIServerReadyMetric.WithLabelValues(dspa.Name, dspa.Namespace).Set(1)
323+
} else {
324+
r.Log.Info("APIServer Not Ready")
325+
APIServerReadyMetric.WithLabelValues(dspa.Name, dspa.Namespace).Set(0)
326+
}
327+
328+
if persistenceAgentReady.Status == metav1.ConditionTrue {
329+
r.Log.Info("PersistanceAgent Ready")
330+
PersistenceAgentReadyMetric.WithLabelValues(dspa.Name, dspa.Namespace).Set(1)
331+
} else {
332+
r.Log.Info("PersistanceAgent Not Ready")
333+
PersistenceAgentReadyMetric.WithLabelValues(dspa.Name, dspa.Namespace).Set(0)
334+
}
335+
336+
if scheduledWorkflowReady.Status == metav1.ConditionTrue {
337+
r.Log.Info("ScheduledWorkflow Ready")
338+
ScheduledWorkflowReadyMetric.WithLabelValues(dspa.Name, dspa.Namespace).Set(1)
339+
} else {
340+
r.Log.Info("ScheduledWorkflow Not Ready")
341+
ScheduledWorkflowReadyMetric.WithLabelValues(dspa.Name, dspa.Namespace).Set(0)
342+
}
343+
344+
if crReady.Status == metav1.ConditionTrue {
345+
r.Log.Info("CR Fully Ready")
346+
CrReadyMetric.WithLabelValues(dspa.Name, dspa.Namespace).Set(1)
347+
} else {
348+
r.Log.Info("CR Not Ready")
349+
CrReadyMetric.WithLabelValues(dspa.Name, dspa.Namespace).Set(0)
350+
}
351+
}
352+
314353
// SetupWithManager sets up the controller with the Manager.
315354
func (r *DSPAReconciler) SetupWithManager(mgr ctrl.Manager) error {
316355
return ctrl.NewControllerManagedBy(mgr).

controllers/metrics.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package controllers
18+
19+
import (
20+
"github.com/prometheus/client_golang/prometheus"
21+
"sigs.k8s.io/controller-runtime/pkg/metrics"
22+
)
23+
24+
// Prometheus metrics gauges
25+
var (
26+
APIServerReadyMetric = prometheus.NewGaugeVec(
27+
prometheus.GaugeOpts{
28+
Name: "data_science_pipelines_application_apiserver_ready",
29+
Help: "Data Science Pipelines Application - APIServer Ready Status",
30+
},
31+
[]string{
32+
"dspa_name",
33+
"namespace",
34+
},
35+
)
36+
PersistenceAgentReadyMetric = prometheus.NewGaugeVec(
37+
prometheus.GaugeOpts{
38+
Name: "data_science_pipelines_application_persistenceagent_ready",
39+
Help: "Data Science Pipelines Application - PersistenceAgent Ready Status",
40+
},
41+
[]string{
42+
"dspa_name",
43+
"namespace",
44+
},
45+
)
46+
ScheduledWorkflowReadyMetric = prometheus.NewGaugeVec(
47+
prometheus.GaugeOpts{
48+
Name: "data_science_pipelines_application_scheduledworkflow_ready",
49+
Help: "Data Science Pipelines Application - ScheduledWorkflow Ready Status",
50+
},
51+
[]string{
52+
"dspa_name",
53+
"namespace",
54+
},
55+
)
56+
CrReadyMetric = prometheus.NewGaugeVec(
57+
prometheus.GaugeOpts{
58+
Name: "data_science_pipelines_application_ready",
59+
Help: "Data Science Pipelines Application - CustomResource Ready Status",
60+
},
61+
[]string{
62+
"dspa_name",
63+
"namespace",
64+
},
65+
)
66+
)
67+
68+
// InitMetrics initialize prometheus metrics
69+
func InitMetrics() {
70+
metrics.Registry.MustRegister(APIServerReadyMetric,
71+
PersistenceAgentReadyMetric,
72+
ScheduledWorkflowReadyMetric,
73+
CrReadyMetric)
74+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/onsi/ginkgo/v2 v2.8.4
1212
github.com/onsi/gomega v1.27.1
1313
github.com/openshift/api v3.9.0+incompatible
14+
github.com/prometheus/client_golang v1.12.2
1415
github.com/spf13/viper v1.4.0
1516
go.uber.org/zap v1.21.0
1617
k8s.io/api v0.25.0
@@ -63,7 +64,6 @@ require (
6364
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
6465
github.com/pelletier/go-toml v1.2.0 // indirect
6566
github.com/pkg/errors v0.9.1 // indirect
66-
github.com/prometheus/client_golang v1.12.2 // indirect
6767
github.com/prometheus/client_model v0.2.0 // indirect
6868
github.com/prometheus/common v0.32.1 // indirect
6969
github.com/prometheus/procfs v0.7.3 // indirect

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ func init() {
5858

5959
utilruntime.Must(dspav1alpha1.AddToScheme(scheme))
6060
//+kubebuilder:scaffold:scheme
61+
62+
controllers.InitMetrics()
6163
}
6264

6365
func initConfig(configPath string) error {

0 commit comments

Comments
 (0)