Skip to content

Commit 4f7f635

Browse files
committed
Add test for submitting gpu metrics.
1 parent aaa267c commit 4f7f635

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) 2023 Oracle and/or its affiliates.
4+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
5+
import unittest
6+
from unittest import mock
7+
import oci
8+
from ads.jobs.templates import oci_metrics
9+
10+
11+
class MetricsTest(unittest.TestCase):
12+
@mock.patch("oci.monitoring.MonitoringClient.post_metric_data")
13+
@mock.patch("subprocess.check_output")
14+
def test_submit_metrics(self, check_output, post_metric):
15+
check_output.return_value = (
16+
b"00000000:00:04.0, 42.27, 40, 20, 16384, 15287\n"
17+
b"00000000:00:05.0, 41.30, 42, 0, 16384, 479\n"
18+
)
19+
oci_metrics.submit_metrics(
20+
oci.monitoring.MonitoringClient(config=oci.config.from_file())
21+
)
22+
metric_data = post_metric.call_args.kwargs[
23+
"post_metric_data_details"
24+
].metric_data
25+
self.assertEqual(len(metric_data), 8)
26+
self.assertEqual(
27+
{data.name for data in metric_data},
28+
{
29+
"gpu.temperature",
30+
"gpu.power_draw",
31+
"gpu.gpu_utilization",
32+
"gpu.memory_usage",
33+
},
34+
)
35+
self.assertEqual(
36+
[data.datapoints[0].value for data in metric_data],
37+
[42.27, 40.0, 20.0, 93.3, 41.3, 42.0, 0.0, 2.92],
38+
)

0 commit comments

Comments
 (0)