Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cmd/scheduler/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,21 @@ func (cc ClusterManagerCollector) Collect(ch chan<- prometheus.Metric) {
quotaUsedDesc := prometheus.NewDesc(
"hami_resource_quota_used",
"resourcequota usage for a certain device",
[]string{"namespace", "quota_name", "limit"}, nil,
[]string{"namespace", "quota_name"}, nil,
)
quotaLimitDesc := prometheus.NewDesc(
"hami_resource_quota_limit",
"Configured hard limit for a resource quota",
[]string{"namespace", "quota_name"}, nil,
)
for ns, val := range cc.metricsProvider.GetQuotaManager().GetResourceQuota() {
for quotaname, q := range *val {
if err := sendMetric(ch, quotaUsedDesc, prometheus.GaugeValue, float64(q.Used), ns, quotaname, fmt.Sprint(q.Limit)); err != nil {
if err := sendMetric(ch, quotaUsedDesc, prometheus.GaugeValue, float64(q.Used), ns, quotaname); err != nil {
klog.V(4).Infof("Failed to send quotaUsedDesc metric: %v", err)
}
if err := sendMetric(ch, quotaLimitDesc, prometheus.GaugeValue, float64(q.Limit), ns, quotaname); err != nil {
klog.V(4).Infof("Failed to send quotaLimitDesc metric: %v", err)
}
if legacy {
sendLegacyMetric(ch, legacyQuotaUsed, prometheus.GaugeValue, float64(q.Used), ns, quotaname, fmt.Sprint(q.Limit))
}
Expand Down
39 changes: 39 additions & 0 deletions cmd/scheduler/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,42 @@ nodeGPUMemoryPercentage{deviceidx="2",deviceuuid="normal-memory",nodeid="node-1"
t.Fatalf("unexpected collecting result:\n%s", err)
}
}

func TestQuotaMetricHasNoLimitLabel(t *testing.T) {
qm := device.NewQuotaManager()
qm.Quotas["test-namespace"] = &device.DeviceQuota{
"test-quota": &device.Quota{
Limit: 10,
Used: 3,
},
}

collector := ClusterManagerCollector{
ClusterManager: &ClusterManager{
LegacyMetrics: false,
},
metricsProvider: &fakeSchedulerMetricsProvider{
nodeUsage: map[string]*schedulerpkg.NodeUsage{},
quotaManager: qm,
podManager: device.NewPodManager(),
},
}

want := `
# HELP hami_resource_quota_limit Configured hard limit for a resource quota
# TYPE hami_resource_quota_limit gauge
hami_resource_quota_limit{namespace="test-namespace",quota_name="test-quota"} 10
# HELP hami_resource_quota_used resourcequota usage for a certain device
# TYPE hami_resource_quota_used gauge
hami_resource_quota_used{namespace="test-namespace",quota_name="test-quota"} 3
`

if err := promtestutil.CollectAndCompare(
collector,
strings.NewReader(want),
"hami_resource_quota_limit",
"hami_resource_quota_used",
); err != nil {
t.Fatalf("unexpected collecting result:\n%s", err)
}
}
1 change: 1 addition & 0 deletions cmd/vGPUmonitor/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package main

import (
"strings"

Check failure on line 20 in cmd/vGPUmonitor/metrics_test.go

View workflow job for this annotation

GitHub Actions / lint

"strings" imported and not used (typecheck)
"testing"

"github.com/prometheus/client_golang/prometheus"
Expand Down
Loading