@@ -20,6 +20,7 @@ import (
2020 "time"
2121
2222 "github.com/prometheus/client_golang/prometheus"
23+ corev1 "k8s.io/api/core/v1"
2324 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425 "sigs.k8s.io/controller-runtime/pkg/metrics"
2526
@@ -254,6 +255,10 @@ var (
254255 // +metricsdoc:group=cohort
255256 // +metricsdoc:labels=cohort="the name of the Cohort",flavor="the resource flavor name",resource="the resource name",replica_role="one of `leader`, `follower`, or `standalone`"
256257 CohortSubtreeQuota * prometheus.GaugeVec
258+
259+ // +metricsdoc:group=cohort
260+ // +metricsdoc:labels=cohort="the name of the Cohort",flavor="the resource flavor name",resource="the resource name",replica_role="one of `leader`, `follower`, or `standalone`"
261+ CohortSubtreeResourceUsage * prometheus.GaugeVec
257262)
258263
259264func trackGaugeVec (g * prometheus.GaugeVec ) * prometheus.GaugeVec {
@@ -728,6 +733,14 @@ If the Cohort has a weight of zero and is borrowing, this will return NaN.`,
728733 Help : `Reports the cohort's nominal quota aggregated within the cohort's subtree. The values are reported per resource and flavor` ,
729734 }, []string {"cohort" , "flavor" , "resource" , "replica_role" },
730735 ))
736+
737+ CohortSubtreeResourceUsage = trackGaugeVec (prometheus .NewGaugeVec (
738+ prometheus.GaugeOpts {
739+ Subsystem : constants .KueueName ,
740+ Name : "cohort_subtree_resource_usage" ,
741+ Help : `Reports the cohort's resource usage aggregated within the cohort's subtree. The values are reported per resource and flavor` ,
742+ }, []string {"cohort" , "flavor" , "resource" , "replica_role" },
743+ ))
731744}
732745
733746func init () {
@@ -916,6 +929,7 @@ func ClearLocalQueueMetrics(lq LocalQueueReference) {
916929func ClearCohortMetrics (cohortName string ) {
917930 CohortSubtreeQuota .DeletePartialMatch (prometheus.Labels {"cohort" : cohortName })
918931 CohortWeightedShare .DeletePartialMatch (prometheus.Labels {"cohort" : cohortName })
932+ CohortSubtreeResourceUsage .DeletePartialMatch (prometheus.Labels {"cohort" : cohortName })
919933}
920934
921935func ReportClusterQueueStatus (cqName kueue.ClusterQueueReference , cqStatus ClusterQueueStatus , customLabelValues []string , tracker * roletracker.RoleTracker ) {
@@ -965,23 +979,35 @@ func ReportClusterQueueQuotas(cohort kueue.CohortReference, queue, flavor, resou
965979 ClusterQueueResourceLendingLimit .WithLabelValues (labels ... ).Set (lending )
966980}
967981
968- func ReportCohortSubtreeQuota (cohort kueue.CohortReference , flavor , resource string , quota float64 , tracker * roletracker.RoleTracker ) {
969- CohortSubtreeQuota .WithLabelValues (string (cohort ), flavor , resource , roletracker .GetRole (tracker )).Set (quota )
982+ func ReportCohortSubtreeQuota (cohort kueue.CohortReference , flavor kueue. ResourceFlavorReference , resource corev1. ResourceName , quota int64 , tracker * roletracker.RoleTracker ) {
983+ CohortSubtreeQuota .WithLabelValues (string (cohort ), string ( flavor ), string ( resource ) , roletracker .GetRole (tracker )).Set (float64 ( quota ) )
970984}
971985
972- func ClearCohortSubtreeQuota (cohort kueue.CohortReference , flavor , resource string ) {
973- lbls := prometheus.Labels {
974- "cohort" : string (cohort ),
975- }
986+ func cohortPartialMatchLabels (cohort kueue.CohortReference , flavor , resource string ) prometheus.Labels {
987+ lbls := prometheus.Labels {"cohort" : string (cohort )}
976988 if len (flavor ) != 0 {
977989 lbls ["flavor" ] = flavor
978990 }
979991 if len (resource ) != 0 {
980992 lbls ["resource" ] = resource
981993 }
994+ return lbls
995+ }
996+
997+ func ClearCohortSubtreeQuota (cohort kueue.CohortReference , flavor kueue.ResourceFlavorReference , resource corev1.ResourceName ) {
998+ lbls := cohortPartialMatchLabels (cohort , string (flavor ), string (resource ))
982999 CohortSubtreeQuota .DeletePartialMatch (lbls )
9831000}
9841001
1002+ func ReportCohortSubtreeResourceUsage (cohort kueue.CohortReference , flavor kueue.ResourceFlavorReference , resource corev1.ResourceName , usage int64 , tracker * roletracker.RoleTracker ) {
1003+ CohortSubtreeResourceUsage .WithLabelValues (string (cohort ), string (flavor ), string (resource ), roletracker .GetRole (tracker )).Set (float64 (usage ))
1004+ }
1005+
1006+ func ClearCohortSubtreeResourceUsage (cohort kueue.CohortReference , flavor kueue.ResourceFlavorReference , resource corev1.ResourceName ) {
1007+ lbls := cohortPartialMatchLabels (cohort , string (flavor ), string (resource ))
1008+ CohortSubtreeResourceUsage .DeletePartialMatch (lbls )
1009+ }
1010+
9851011func ReportClusterQueueResourceReservations (cohort kueue.CohortReference , queue , flavor , resource string , usage float64 , customLabelValues []string , tracker * roletracker.RoleTracker ) {
9861012 labels := append ([]string {string (cohort ), queue , flavor , resource , roletracker .GetRole (tracker )}, customLabelValues ... )
9871013 ClusterQueueResourceReservations .WithLabelValues (labels ... ).Set (usage )
@@ -1146,6 +1172,7 @@ func Register() {
11461172 ClusterQueueWeightedShare ,
11471173 CohortWeightedShare ,
11481174 CohortSubtreeQuota ,
1175+ CohortSubtreeResourceUsage ,
11491176 )
11501177 if features .Enabled (features .LocalQueueMetrics ) {
11511178 RegisterLQMetrics ()
0 commit comments