-
Notifications
You must be signed in to change notification settings - Fork 510
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_cluster_provisioned_duration_seconds
metric
#3212
Open
win5923
wants to merge
1
commit into
ray-project:master
Choose a base branch
from
win5923:metrics/ray_cluster_provisioned_duration_seconds
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+53
−47
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,33 @@ | ||
package common | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
"sigs.k8s.io/controller-runtime/pkg/metrics" | ||
) | ||
|
||
// Define all the prometheus counters for all clusters | ||
var ( | ||
clustersCreatedCount = promauto.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "ray_operator_clusters_created_total", | ||
Help: "Counts number of clusters created", | ||
}, | ||
[]string{"namespace"}, | ||
) | ||
clustersDeletedCount = promauto.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "ray_operator_clusters_deleted_total", | ||
Help: "Counts number of clusters deleted", | ||
}, | ||
[]string{"namespace"}, | ||
) | ||
clustersSuccessfulCount = promauto.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "ray_operator_clusters_successful_total", | ||
Help: "Counts number of clusters successful", | ||
}, | ||
[]string{"namespace"}, | ||
) | ||
clustersFailedCount = promauto.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "ray_operator_clusters_failed_total", | ||
Help: "Counts number of clusters failed", | ||
rayClusterProvisionedHistogram = promauto.NewHistogramVec( | ||
prometheus.HistogramOpts{ | ||
Name: "ray_cluster_provisioned_duration_seconds", | ||
Help: "The time from RayClusters created to all ray pods are ready for the first time (RayClusterProvisioned) in seconds", | ||
// It may not be applicable to all users, but default buckets cannot be used either. | ||
// For reference, see: https://github.com/prometheus/client_golang/blob/331dfab0cc853dca0242a0d96a80184087a80c1d/prometheus/histogram.go#L271 | ||
Buckets: []float64{30, 60, 120, 180, 240, 300, 600, 900, 1800, 3600}, | ||
}, | ||
[]string{"namespace"}, | ||
) | ||
) | ||
|
||
func init() { | ||
// Register custom metrics with the global prometheus registry | ||
metrics.Registry.MustRegister(clustersCreatedCount, | ||
clustersDeletedCount, | ||
clustersSuccessfulCount, | ||
clustersFailedCount) | ||
} | ||
|
||
func CreatedClustersCounterInc(namespace string) { | ||
clustersCreatedCount.WithLabelValues(namespace).Inc() | ||
} | ||
|
||
// TODO: We don't handle the delete events in new reconciler mode, how to emit deletion metrics? | ||
func DeletedClustersCounterInc(namespace string) { | ||
clustersDeletedCount.WithLabelValues(namespace).Inc() | ||
} | ||
|
||
func SuccessfulClustersCounterInc(namespace string) { | ||
clustersSuccessfulCount.WithLabelValues(namespace).Inc() | ||
metrics.Registry.MustRegister(rayClusterProvisionedHistogram) | ||
} | ||
|
||
func FailedClustersCounterInc(namespace string) { | ||
clustersFailedCount.WithLabelValues(namespace).Inc() | ||
// ObserveRayClusterProvisionedDuration observes the duration of RayCluster from creation to provisioned | ||
func ObserveRayClusterProvisionedDuration(namespace string, duration time.Duration) { | ||
rayClusterProvisionedHistogram.WithLabelValues(namespace).Observe(duration.Seconds()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package common | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus/testutil" | ||
) | ||
|
||
func TestObserveRayClusterProvisionedDuration(t *testing.T) { | ||
ObserveRayClusterProvisionedDuration("default", 2*time.Minute) | ||
|
||
metric := ` | ||
# HELP ray_cluster_provisioned_duration_seconds The time from RayClusters created to all ray pods are ready for the first time (RayClusterProvisioned) in seconds | ||
# TYPE ray_cluster_provisioned_duration_seconds histogram | ||
ray_cluster_provisioned_duration_seconds_bucket{namespace="default",le="30"} 0 | ||
ray_cluster_provisioned_duration_seconds_bucket{namespace="default",le="60"} 0 | ||
ray_cluster_provisioned_duration_seconds_bucket{namespace="default",le="120"} 1 | ||
ray_cluster_provisioned_duration_seconds_bucket{namespace="default",le="180"} 1 | ||
ray_cluster_provisioned_duration_seconds_bucket{namespace="default",le="240"} 1 | ||
ray_cluster_provisioned_duration_seconds_bucket{namespace="default",le="300"} 1 | ||
ray_cluster_provisioned_duration_seconds_bucket{namespace="default",le="600"} 1 | ||
ray_cluster_provisioned_duration_seconds_bucket{namespace="default",le="900"} 1 | ||
ray_cluster_provisioned_duration_seconds_bucket{namespace="default",le="1800"} 1 | ||
ray_cluster_provisioned_duration_seconds_bucket{namespace="default",le="3600"} 1 | ||
ray_cluster_provisioned_duration_seconds_sum{namespace="default"} 120 | ||
ray_cluster_provisioned_duration_seconds_count{namespace="default"} 1 | ||
` | ||
|
||
if err := testutil.CollectAndCompare(rayClusterProvisionedHistogram, strings.NewReader(metric), "ray_cluster_provisioned_duration_seconds"); err != nil { | ||
t.Errorf("unexpected collecting result:\n%s", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -734,12 +734,9 @@ 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.") | ||
common.CreatedClustersCounterInc(instance.Namespace) | ||
if err := r.createHeadPod(ctx, *instance); err != nil { | ||
common.FailedClustersCounterInc(instance.Namespace) | ||
return errstd.Join(utils.ErrFailedCreateHeadPod, err) | ||
} | ||
common.SuccessfulClustersCounterInc(instance.Namespace) | ||
} else if len(headPods.Items) > 1 { // This should never happen. This protects against the case that users manually create headpod. | ||
correctHeadPodName := instance.Name + "-head" | ||
headPodNames := make([]string, len(headPods.Items)) | ||
|
@@ -1336,6 +1333,11 @@ func (r *RayClusterReconciler) calculateStatus(ctx context.Context, instance *ra | |
Reason: rayv1.AllPodRunningAndReadyFirstTime, | ||
Message: "All Ray Pods are ready for the first time", | ||
}) | ||
|
||
// Record ray_cluster_provisioned_duration_seconds duration metric | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The metric should not be recorded in |
||
// Calculate the time between cluster creation and being fully provisioned | ||
provisionDuration := time.Since(instance.CreationTimestamp.Time) | ||
common.ObserveRayClusterProvisionedDuration(instance.Namespace, provisionDuration) | ||
} else { | ||
meta.SetStatusCondition(&newInstance.Status.Conditions, metav1.Condition{ | ||
Type: string(rayv1.RayClusterProvisioned), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what bucket ranges would be suitable for most users.