Skip to content

Commit b0408ed

Browse files
xcoulonrsoaresd
andauthored
refactor: include scheme in base URL for metrics (#1243)
don't assume it's always `https`, so we can be more flexible when testing against an `http` endpoint also, update vuln exclusions --------- Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Co-authored-by: Rafaela Maria Soares da Silva <rsoaresd@redhat.com>
1 parent 6e1f4ec commit b0408ed

4 files changed

Lines changed: 36 additions & 27 deletions

File tree

.govulncheck.yaml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,52 @@ ignored-vulnerabilities:
44
# Fixed in: crypto/x509@go1.24.8
55
- id: GO-2025-4013
66
info: https://pkg.go.dev/vuln/GO-2025-4013
7-
silence-until: 2025-12-03
7+
silence-until: 2026-02-05
88
# Lack of limit when parsing cookies can cause memory exhaustion in net/http
99
# Found in: net/http@go1.23.12
1010
# Fixed in: net/http@go1.24.8
1111
- id: GO-2025-4012
1212
info: https://pkg.go.dev/vuln/GO-2025-4012
13-
silence-until: 2025-12-03
13+
silence-until: 2026-02-05
1414
# Parsing DER payload can cause memory exhaustion in encoding/asn1
1515
# Found in: encoding/asn1@go1.23.12
1616
# Fixed in: encoding/asn1@go1.24.8
1717
- id: GO-2025-4011
1818
info: https://pkg.go.dev/vuln/GO-2025-4011
19-
silence-until: 2025-12-03
19+
silence-until: 2026-02-05
2020
# Insufficient validation of bracketed IPv6 hostnames in net/url
2121
# Found in: net/url@go1.23.12
2222
# Fixed in: net/url@go1.24.8
2323
- id: GO-2025-4010
2424
info: https://pkg.go.dev/vuln/GO-2025-4010
25-
silence-until: 2025-12-03
25+
silence-until: 2026-02-05
2626
# Quadratic complexity when parsing some invalid inputs in encoding/pem
2727
# Found in: encoding/pem@go1.23.12
2828
# Fixed in: encoding/pem@go1.24.8
2929
- id: GO-2025-4009
3030
info: https://pkg.go.dev/vuln/GO-2025-4009
31-
silence-until: 2025-12-03
31+
silence-until: 2026-02-05
3232
# ALPN negotiation error contains attacker controlled information in crypto/tls
3333
# Found in: crypto/tls@go1.23.12
3434
# Fixed in: crypto/tls@go1.24.8
3535
- id: GO-2025-4008
3636
info: https://pkg.go.dev/vuln/GO-2025-4008
37-
silence-until: 2025-12-03
37+
silence-until: 2026-02-05
3838
# Quadratic complexity when checking name constraints in crypto/x509
3939
# Found in: crypto/x509@go1.23.12
4040
# Fixed in: crypto/x509@go1.24.9
4141
- id: GO-2025-4007
4242
info: https://pkg.go.dev/vuln/GO-2025-4007
43-
silence-until: 2025-12-03
43+
silence-until: 2026-02-05
44+
# Excessive resource consumption when printing error string for host certificate validation in crypto/x509
45+
# Found in: crypto/x509@go1.23.12
46+
# Fixed in: crypto/x509@go1.24.11
47+
- id: GO-2025-4155
48+
info: https://pkg.go.dev/vuln/GO-2025-4155
49+
silence-until: 2026-02-04
50+
# Improper application of excluded DNS name constraints when verifying wildcard names in crypto/x509
51+
# Found in: crypto/x509@go1.23.12
52+
# Fixed in: crypto/x509@go1.24.11
53+
- id: GO-2025-4175
54+
info: https://pkg.go.dev/vuln/GO-2025-4175
55+
silence-until: 2026-02-04

testsupport/init.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,12 @@ func WaitForDeployments(t *testing.T) wait.Awaitilities {
207207
// setup host metrics route for metrics verification in tests
208208
hostMetricsRoute, err := initHostAwait.SetupRouteForService(t, "host-operator-metrics-service", "/metrics")
209209
require.NoError(t, err)
210-
initHostAwait.MetricsURL = hostMetricsRoute.Status.Ingress[0].Host
210+
initHostAwait.MetricsURL = "https://" + hostMetricsRoute.Status.Ingress[0].Host
211211

212212
// setup member metrics route for metrics verification in tests
213213
memberMetricsRoute, err := initMemberAwait.SetupRouteForService(t, "member-operator-metrics-service", "/metrics")
214214
require.NoError(t, err, "failed while setting up or waiting for the route to the 'member-operator-metrics' service to be available")
215-
initMemberAwait.MetricsURL = memberMetricsRoute.Status.Ingress[0].Host
215+
initMemberAwait.MetricsURL = "https://" + memberMetricsRoute.Status.Ingress[0].Host
216216

217217
// Wait for the webhooks in Member 1 only because we do not deploy webhooks for Member 2
218218
// (we can't deploy the same webhook multiple times on the same cluster)

testsupport/metrics/metrics.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,27 @@ import (
1313
"k8s.io/client-go/rest"
1414
)
1515

16-
func GetMetricValue(restConfig *rest.Config, url string, family string, expectedLabels []string) (float64, error) {
17-
value, err := getMetricValue(restConfig, url, family, expectedLabels, getValue)
16+
func GetMetricValue(restConfig *rest.Config, baseURL string, family string, expectedLabels []string) (float64, error) {
17+
value, err := getMetricValue(restConfig, baseURL, family, expectedLabels, getValue)
1818
if value == nil {
1919
return -1, err
2020
}
2121
return *value, err
2222
}
2323

24-
func GetHistogramBuckets(restConfig *rest.Config, url string, family string, expectedLabels []string) ([]*dto.Bucket, error) {
25-
value, err := getMetricValue(restConfig, url, family, expectedLabels, getBuckets)
24+
func GetHistogramBuckets(restConfig *rest.Config, baseURL string, family string, expectedLabels []string) ([]*dto.Bucket, error) {
25+
value, err := getMetricValue(restConfig, baseURL, family, expectedLabels, getBuckets)
2626
if value == nil {
2727
return nil, err
2828
}
2929
return *value, err
3030
}
3131

32-
func getMetricValue[T any](restConfig *rest.Config, url string, family string, expectedLabels []string, getValue func(dto.MetricType, *dto.Metric) (*T, error)) (*T, error) {
32+
func getMetricValue[T any](restConfig *rest.Config, baseURL string, family string, expectedLabels []string, getValue func(dto.MetricType, *dto.Metric) (*T, error)) (*T, error) {
3333
if len(expectedLabels)%2 != 0 {
3434
return nil, fmt.Errorf("received odd number of label arguments, labels must be key-value pairs")
3535
}
36-
uri := fmt.Sprintf("https://%s/metrics", url)
36+
uri := baseURL + "/metrics"
3737
var metrics []byte
3838

3939
client := http.Client{
@@ -128,8 +128,8 @@ func getBuckets(t dto.MetricType, m *dto.Metric) (*[]*dto.Bucket, error) {
128128
}
129129

130130
// GetMetricLabels return all labels (indexed by key) for all metrics of the given `family`
131-
func GetMetricLabels(restConfig *rest.Config, url string, family string) ([]map[string]string, error) {
132-
uri := fmt.Sprintf("https://%s/metrics", url)
131+
func GetMetricLabels(restConfig *rest.Config, baseURL string, family string) ([]map[string]string, error) {
132+
uri := baseURL + "/metrics"
133133
var metrics []byte
134134

135135
client := http.Client{

testsupport/metrics/metrics_test.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"net/http"
66
"net/http/httptest"
7-
"strings"
87
"testing"
98

109
"github.com/stretchr/testify/assert"
@@ -62,36 +61,34 @@ func TestGetMetricValue(t *testing.T) {
6261
BearerToken: "1a2b3bc",
6362
}
6463

65-
url := strings.TrimPrefix(ts.URL, "https://")
66-
6764
t.Run("valid metrics", func(t *testing.T) {
6865
t.Run("counter with no labels", func(t *testing.T) {
6966
// when
70-
result, err := GetMetricValue(config, url, "sandbox_user_signups_total", []string{})
67+
result, err := GetMetricValue(config, ts.URL, "sandbox_user_signups_total", []string{})
7168
// then
7269
require.NoError(t, err)
7370
assert.InDelta(t, float64(7), result, 0.1)
7471
})
7572

7673
t.Run("counter with single label", func(t *testing.T) {
7774
// when
78-
result, err := GetMetricValue(config, url, "workqueue_depth", []string{"name", "masteruserrecord-controller"})
75+
result, err := GetMetricValue(config, ts.URL, "workqueue_depth", []string{"name", "masteruserrecord-controller"})
7976
// then
8077
require.NoError(t, err)
8178
assert.InDelta(t, float64(0), result, 0.1)
8279
})
8380

8481
t.Run("counter with two labels", func(t *testing.T) {
8582
// when
86-
result, err := GetMetricValue(config, url, "controller_runtime_reconcile_total", []string{"controller", "usersignup-controller", "result", "success"})
83+
result, err := GetMetricValue(config, ts.URL, "controller_runtime_reconcile_total", []string{"controller", "usersignup-controller", "result", "success"})
8784
// then
8885
require.NoError(t, err)
8986
assert.InDelta(t, float64(10), result, 0.1)
9087
})
9188

9289
t.Run("gauge with no labels", func(t *testing.T) {
9390
// when
94-
result, err := GetMetricValue(config, url, "sandbox_master_user_record_current", []string{})
91+
result, err := GetMetricValue(config, ts.URL, "sandbox_master_user_record_current", []string{})
9592
// then
9693
require.NoError(t, err)
9794
assert.InDelta(t, float64(7), result, 0.01)
@@ -101,7 +98,7 @@ func TestGetMetricValue(t *testing.T) {
10198
t.Run("failures", func(t *testing.T) {
10299
t.Run("metric does not exist", func(t *testing.T) {
103100
// when
104-
result, err := GetMetricValue(config, url, "non_existent_counter", []string{})
101+
result, err := GetMetricValue(config, ts.URL, "non_existent_counter", []string{})
105102
// then
106103
require.Error(t, err)
107104
require.EqualError(t, err, "metric 'non_existent_counter{[]}' not found")
@@ -110,7 +107,7 @@ func TestGetMetricValue(t *testing.T) {
110107

111108
t.Run("metric family exists but labels do not match", func(t *testing.T) {
112109
// when
113-
result, err := GetMetricValue(config, url, "workqueue_depth", []string{"name", "non-existent-controller"})
110+
result, err := GetMetricValue(config, ts.URL, "workqueue_depth", []string{"name", "non-existent-controller"})
114111
// then
115112
require.Error(t, err)
116113
require.EqualError(t, err, "metric 'workqueue_depth{[name non-existent-controller]}' not found")
@@ -119,7 +116,7 @@ func TestGetMetricValue(t *testing.T) {
119116

120117
t.Run("odd number of label parameters", func(t *testing.T) {
121118
// when
122-
result, err := GetMetricValue(config, url, "workqueue_depth", []string{"name"})
119+
result, err := GetMetricValue(config, ts.URL, "workqueue_depth", []string{"name"})
123120
// then
124121
require.Error(t, err)
125122
require.EqualError(t, err, "received odd number of label arguments, labels must be key-value pairs")

0 commit comments

Comments
 (0)