Skip to content

Conversation

@win5923
Copy link
Collaborator

@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
Collaborator 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
} 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
Collaborator

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
Collaborator 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.

// 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
Collaborator

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
Collaborator

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
Collaborator

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
Collaborator 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:

} 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
win5923 added 3 commits April 11, 2025 10:03
Signed-off-by: win5923 <ken89@kimo.com>
Signed-off-by: win5923 <ken89@kimo.com>
Signed-off-by: win5923 <ken89@kimo.com>
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