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

[Prometheus] Add ray_clusters_created_total metric #3204

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

win5923
Copy link
Contributor

@win5923 win5923 commented Mar 17, 2025

Why are these changes needed?

Add ray_clusters_created_total metric to track the total number of RayClusters created.

Metric Name Type Description Labels
ray_clusters_created_total Counter The total number of ray clusters created - created_by_ray_job: true/false
- created_by_ray_service: true/false
- namespace

Manual test:

$ k apply -f config/samples/ray-cluster.sample.yaml
$ k apply -f config/samples/ray-service.sample.yaml
$ k apply -f config/samples/ray-job.sample.yaml
$ k apply -f config/samples/ray-job.sample.yaml

$ k apply -f config/samples/ray-job.sample.yaml -n test

image

Related issue number

Closes #3175

Checks

  • I've made sure the tests are passing.
  • Testing Strategy
    • Unit tests
    • Manual tests
    • This PR is not tested :(

@win5923 win5923 changed the title [Prometheus] Add ray_clusters_created_total metric [Prometheus] Add ray_clusters_created_total metric Mar 18, 2025
@win5923
Copy link
Contributor Author

win5923 commented Mar 19, 2025

@troychiu PTAL, thx

@win5923 win5923 force-pushed the metrics/ray_clusters_created_total branch 7 times, most recently from 9976c1b to 92e7b83 Compare March 25, 2025 16:29
@win5923 win5923 force-pushed the metrics/ray_clusters_created_total branch 4 times, most recently from c446b4a to 6fa17fc Compare April 5, 2025 15:43
@@ -734,6 +739,19 @@ func (r *RayClusterReconciler) reconcilePods(ctx context.Context, instance *rayv
} else if len(headPods.Items) == 0 {
// Create head Pod if it does not exist.
logger.Info("reconcilePods: Found 0 head Pods; creating a head Pod for the RayCluster.")

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should increment after successfully create the head pod to avoid incrementing multiple times?

Copy link
Contributor Author

@win5923 win5923 Apr 8, 2025

Choose a reason for hiding this comment

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

Fixed. thx

Copy link
Member

Choose a reason for hiding this comment

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

It's still possible to be counted multiple times. KubeRay is possible to delete the head Pod if the restart policy is Never.

@@ -734,6 +739,19 @@ func (r *RayClusterReconciler) reconcilePods(ctx context.Context, instance *rayv
} else if len(headPods.Items) == 0 {
// Create head Pod if it does not exist.
logger.Info("reconcilePods: Found 0 head Pods; creating a head Pod for the RayCluster.")

if r.EnableMetrics {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to have a function in metrics.go handle EnableMetrics in a general way?


if r.EnableMetrics {
creatorCRDType := getCreatorCRDType(*instance)
// Increment the counter for ray_clusters_created_total metric based on the creator CRD type.
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we can move these checkings to ray_cluster_metrics.go to simplify the operator's logic?

Copy link
Contributor

Choose a reason for hiding this comment

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

or maybe still in this file but move to a function? What do you think it's better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a function called emitRayClusterMetrics in raycluster_controller.go. It takes a metric name and decides which metric to emit based on that.
WDYT?

@win5923 win5923 force-pushed the metrics/ray_clusters_created_total branch 2 times, most recently from a4290f9 to 8baf776 Compare April 8, 2025 15:30
@win5923 win5923 requested a review from troychiu April 8, 2025 15:32
@win5923 win5923 force-pushed the metrics/ray_clusters_created_total branch from 8baf776 to ef1a740 Compare April 8, 2025 15:45
"sigs.k8s.io/controller-runtime/pkg/metrics"
)

var rayClustersCreatedCounter = prometheus.NewCounterVec(
Copy link
Member

Choose a reason for hiding this comment

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

It's better not to use package-level variable. Can you open another PR first to improve it by:

  • ray_cluster_metric.go
type RayClusterMetricCollector struct {
	// Metrics
        rayClusterCreatedTotal: ...
}

func NewRayClusterMetricCollector(...) ... {

}
  • main.go: Initialize the collectors if this feature is enabled. Pass the collectors into controllers.

Example:

@@ -734,6 +739,19 @@ func (r *RayClusterReconciler) reconcilePods(ctx context.Context, instance *rayv
} else if len(headPods.Items) == 0 {
// Create head Pod if it does not exist.
logger.Info("reconcilePods: Found 0 head Pods; creating a head Pod for the RayCluster.")

Copy link
Member

Choose a reason for hiding this comment

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

It's still possible to be counted multiple times. KubeRay is possible to delete the head Pod if the restart policy is Never.

@win5923 win5923 force-pushed the metrics/ray_clusters_created_total branch from 151382b to 34ba8b5 Compare April 9, 2025 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature][metrics] ray_clusters_created_total
3 participants