|
1 | 1 | package common
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "strconv" |
| 5 | + |
4 | 6 | "github.com/prometheus/client_golang/prometheus"
|
5 | 7 | "github.com/prometheus/client_golang/prometheus/promauto"
|
6 | 8 | "sigs.k8s.io/controller-runtime/pkg/metrics"
|
7 | 9 | )
|
8 | 10 |
|
9 | 11 | // Define all the prometheus counters for all clusters
|
10 | 12 | var (
|
11 |
| - clustersCreatedCount = promauto.NewCounterVec( |
12 |
| - prometheus.CounterOpts{ |
13 |
| - Name: "ray_operator_clusters_created_total", |
14 |
| - Help: "Counts number of clusters created", |
15 |
| - }, |
16 |
| - []string{"namespace"}, |
17 |
| - ) |
18 |
| - clustersDeletedCount = promauto.NewCounterVec( |
19 |
| - prometheus.CounterOpts{ |
20 |
| - Name: "ray_operator_clusters_deleted_total", |
21 |
| - Help: "Counts number of clusters deleted", |
22 |
| - }, |
23 |
| - []string{"namespace"}, |
24 |
| - ) |
25 |
| - clustersSuccessfulCount = promauto.NewCounterVec( |
26 |
| - prometheus.CounterOpts{ |
27 |
| - Name: "ray_operator_clusters_successful_total", |
28 |
| - Help: "Counts number of clusters successful", |
29 |
| - }, |
30 |
| - []string{"namespace"}, |
31 |
| - ) |
32 |
| - clustersFailedCount = promauto.NewCounterVec( |
| 13 | + rayClustersCreatedCounter = promauto.NewCounterVec( |
33 | 14 | prometheus.CounterOpts{
|
34 |
| - Name: "ray_operator_clusters_failed_total", |
35 |
| - Help: "Counts number of clusters failed", |
| 15 | + Name: "ray_clusters_created_total", |
| 16 | + Help: "The total number of RayClusters created", |
36 | 17 | },
|
37 |
| - []string{"namespace"}, |
| 18 | + []string{"namespace", "created_by_ray_job", "created_by_ray_service"}, |
38 | 19 | )
|
39 | 20 | )
|
40 | 21 |
|
41 | 22 | func init() {
|
42 | 23 | // Register custom metrics with the global prometheus registry
|
43 |
| - metrics.Registry.MustRegister(clustersCreatedCount, |
44 |
| - clustersDeletedCount, |
45 |
| - clustersSuccessfulCount, |
46 |
| - clustersFailedCount) |
47 |
| -} |
48 |
| - |
49 |
| -func CreatedClustersCounterInc(namespace string) { |
50 |
| - clustersCreatedCount.WithLabelValues(namespace).Inc() |
51 |
| -} |
52 |
| - |
53 |
| -// TODO: We don't handle the delete events in new reconciler mode, how to emit deletion metrics? |
54 |
| -func DeletedClustersCounterInc(namespace string) { |
55 |
| - clustersDeletedCount.WithLabelValues(namespace).Inc() |
56 |
| -} |
57 |
| - |
58 |
| -func SuccessfulClustersCounterInc(namespace string) { |
59 |
| - clustersSuccessfulCount.WithLabelValues(namespace).Inc() |
| 24 | + metrics.Registry.MustRegister(rayClustersCreatedCounter) |
60 | 25 | }
|
61 | 26 |
|
62 |
| -func FailedClustersCounterInc(namespace string) { |
63 |
| - clustersFailedCount.WithLabelValues(namespace).Inc() |
| 27 | +func CreatedRayClustersCounterInc(namespace string, createdByRayJob bool, createdByRayService bool) { |
| 28 | + rayClustersCreatedCounter.WithLabelValues(namespace, strconv.FormatBool(createdByRayJob), strconv.FormatBool(createdByRayService)).Inc() |
64 | 29 | }
|
0 commit comments