Skip to content
Merged
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
7 changes: 4 additions & 3 deletions cmd/vGPUmonitor/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,17 @@ func sendLegacyMetric(ch chan<- prometheus.Metric, desc *prometheus.Desc, valueT
}
}

// Describe is implemented with DescribeByCollect. That's possible because the
// Collect method will always return the same two metrics with the same two
// descriptors.
// Describe sends all the metrics descriptors that the collector might use.
// These descriptors are used by the Prometheus registry to register the metrics.
func (cc ClusterManagerCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- hostGPUdesc
ch <- ctrvGPUdesc
ch <- ctrvGPUlimitdesc
ch <- hostGPUUtilizationdesc
ch <- ctrDeviceMemorydesc
ch <- ctrDeviceUtilizationdesc
ch <- ctrDeviceLastKernelDesc
Comment thread
archlitchi marked this conversation as resolved.
ch <- ctrDeviceMigInfo
Comment thread
archlitchi marked this conversation as resolved.
ch <- ctrDeviceMemoryContextDesc
ch <- ctrDeviceMemoryModuleDesc
ch <- ctrDeviceMemoryBufferDesc
Expand Down
70 changes: 70 additions & 0 deletions cmd/vGPUmonitor/metrics_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Copyright 2024 The HAMi Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main
Comment thread
coderabbitai[bot] marked this conversation as resolved.

import (
"testing"

"github.com/prometheus/client_golang/prometheus"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes/fake"

"github.com/Project-HAMi/HAMi/pkg/monitor/nvidia"
"github.com/Project-HAMi/HAMi/pkg/util"
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.

func TestDescribeCollectSync(t *testing.T) {
reg := prometheus.NewPedanticRegistry()

t.Setenv(util.NodeNameEnvName, "test-node")
client := fake.NewSimpleClientset()
informerFactory := informers.NewSharedInformerFactory(client, 0)
podLister := informerFactory.Core().V1().Pods().Lister()

c := &ClusterManager{
Zone: "test-zone",
LegacyMetrics: false,
PodLister: podLister,
containerLister: &nvidia.ContainerLister{},
}
cc := ClusterManagerCollector{ClusterManager: c}

if err := reg.Register(cc); err != nil {
t.Fatalf("Failed to register ClusterManagerCollector (non-legacy): %v", err)
}

if _, err := reg.Gather(); err != nil {
t.Errorf("Gather failed (non-legacy): %v", err)
}

regLegacy := prometheus.NewPedanticRegistry()
cLegacy := &ClusterManager{
Zone: "test-zone-legacy",
LegacyMetrics: true,
PodLister: podLister,
containerLister: &nvidia.ContainerLister{},
}
initLegacyDescriptors()
ccLegacy := ClusterManagerCollector{ClusterManager: cLegacy}

if err := regLegacy.Register(ccLegacy); err != nil {
t.Fatalf("Failed to register ClusterManagerCollector (legacy): %v", err)
}
if _, err := regLegacy.Gather(); err != nil {
t.Errorf("Gather failed (legacy): %v", err)
}
}
Loading