@@ -19,21 +19,18 @@ import (
1919 "github.com/prometheus/common/model"
2020
2121 corev1 "k8s.io/api/core/v1"
22+ k8serrors "k8s.io/apimachinery/pkg/api/errors"
2223 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
2425 . "github.com/onsi/ginkgo/v2"
2526 . "github.com/onsi/gomega"
2627)
2728
28- var _ = Describe ("[sriov] Metrics Exporter" , Ordered , func () {
29+ var _ = Describe ("[sriov] Metrics Exporter" , Ordered , ContinueOnFailure , func () {
2930 var node string
3031 var nic * sriovv1.InterfaceExt
3132
3233 BeforeAll (func () {
33- if cluster .VirtualCluster () {
34- Skip ("IGB driver does not support VF statistics" )
35- }
36-
3734 err := namespaces .Create (namespaces .Test , clients )
3835 Expect (err ).ToNot (HaveOccurred ())
3936
@@ -73,6 +70,9 @@ var _ = Describe("[sriov] Metrics Exporter", Ordered, func() {
7370 })
7471
7572 It ("collects metrics regarding receiving traffic via VF" , func () {
73+ if cluster .VirtualCluster () {
74+ Skip ("IGB driver does not support VF statistics" )
75+ }
7676
7777 pod := createTestPod (node , []string {"test-me-network" })
7878 DeferCleanup (namespaces .CleanPods , namespaces .Test , clients )
@@ -98,27 +98,76 @@ var _ = Describe("[sriov] Metrics Exporter", Ordered, func() {
9898 Expect (finalRxPackets ).Should (BeNumerically (">" , initialRxPackets ))
9999 })
100100
101- It ("PrometheusRule should provide namespaced metrics" , func () {
102- pod := createTestPod (node , []string {"test-me-network" })
103- DeferCleanup (namespaces .CleanPods , namespaces .Test , clients )
101+ Context ("When Prometheus operator is available" , func () {
102+ BeforeEach (func () {
103+ _ , err := clients .ServiceMonitors (operatorNamespace ).List (context .Background (), metav1.ListOptions {})
104+ if k8serrors .IsNotFound (err ) {
105+ Skip ("Prometheus operator not available in the cluster" )
106+ }
107+ })
104108
105- namespacedMetricNames := []string {
106- "network:sriov_vf_rx_bytes" ,
107- "network:sriov_vf_tx_bytes" ,
108- "network:sriov_vf_rx_packets" ,
109- "network:sriov_vf_tx_packets" ,
110- "network:sriov_vf_rx_dropped" ,
111- "network:sriov_vf_tx_dropped" ,
112- "network:sriov_vf_rx_broadcast" ,
113- "network:sriov_vf_rx_multicast" ,
114- }
109+ It ("PrometheusRule should provide namespaced metrics" , func () {
110+ pod := createTestPod (node , []string {"test-me-network" })
111+ DeferCleanup (namespaces .CleanPods , namespaces .Test , clients )
112+
113+ namespacedMetricNames := []string {
114+ "network:sriov_vf_rx_bytes" ,
115+ "network:sriov_vf_tx_bytes" ,
116+ "network:sriov_vf_rx_packets" ,
117+ "network:sriov_vf_tx_packets" ,
118+ "network:sriov_vf_rx_dropped" ,
119+ "network:sriov_vf_tx_dropped" ,
120+ "network:sriov_vf_rx_broadcast" ,
121+ "network:sriov_vf_rx_multicast" ,
122+ }
115123
116- Eventually (func (g Gomega ) {
117- for _ , metricName := range namespacedMetricNames {
118- values := runPromQLQuery (fmt .Sprintf (`%s{namespace="%s",pod="%s"}` , metricName , pod .Namespace , pod .Name ))
119- g .Expect (values ).ToNot (BeEmpty (), "no value for metric %s" , metricName )
124+ Eventually (func (g Gomega ) {
125+ for _ , metricName := range namespacedMetricNames {
126+ values := runPromQLQuery (fmt .Sprintf (`%s{namespace="%s",pod="%s"}` , metricName , pod .Namespace , pod .Name ))
127+ g .Expect (values ).ToNot (BeEmpty (), "no value for metric %s" , metricName )
128+ }
129+ }, "90s" , "1s" ).Should (Succeed ())
130+ })
131+
132+ It ("Metrics should have the correct labels" , func () {
133+ pod := createTestPod (node , []string {"test-me-network" })
134+ DeferCleanup (namespaces .CleanPods , namespaces .Test , clients )
135+
136+ metricsName := []string {
137+ "sriov_vf_rx_bytes" ,
138+ "sriov_vf_tx_bytes" ,
139+ "sriov_vf_rx_packets" ,
140+ "sriov_vf_tx_packets" ,
141+ "sriov_vf_rx_dropped" ,
142+ "sriov_vf_tx_dropped" ,
143+ "sriov_vf_rx_broadcast" ,
144+ "sriov_vf_rx_multicast" ,
120145 }
121- }, "40s" , "1s" ).Should (Succeed ())
146+
147+ Eventually (func (g Gomega ) {
148+ for _ , metricName := range metricsName {
149+ samples := runPromQLQuery (metricName )
150+ g .Expect (samples ).ToNot (BeEmpty (), "no value for metric %s" , metricName )
151+ g .Expect (samples [0 ].Metric ).To (And (
152+ HaveKey (model .LabelName ("pciAddr" )),
153+ HaveKey (model .LabelName ("node" )),
154+ HaveKey (model .LabelName ("pf" )),
155+ HaveKey (model .LabelName ("vf" )),
156+ ))
157+ }
158+ }, "90s" , "1s" ).Should (Succeed ())
159+
160+ // sriov_kubepoddevice has a different sets of label than statistics metrics
161+ samples := runPromQLQuery (fmt .Sprintf (`sriov_kubepoddevice{namespace="%s",pod="%s"}` , pod .Namespace , pod .Name ))
162+ Expect (samples ).ToNot (BeEmpty (), "no value for metric sriov_kubepoddevice" )
163+ Expect (samples [0 ].Metric ).To (And (
164+ HaveKey (model .LabelName ("pciAddr" )),
165+ HaveKeyWithValue (model .LabelName ("node" ), model .LabelValue (pod .Spec .NodeName )),
166+ HaveKeyWithValue (model .LabelName ("dev_type" ), model .LabelValue ("openshift.io/metricsResource" )),
167+ HaveKeyWithValue (model .LabelName ("namespace" ), model .LabelValue (pod .Namespace )),
168+ HaveKeyWithValue (model .LabelName ("pod" ), model .LabelValue (pod .Name )),
169+ ))
170+ })
122171 })
123172})
124173
0 commit comments