Skip to content

Commit 30989b6

Browse files
committed
Remove references to prometheus is test/e2e
1 parent 42fe74c commit 30989b6

File tree

4 files changed

+41
-48
lines changed

4 files changed

+41
-48
lines changed

staging/src/k8s.io/component-base/metrics/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ package_group(
9494
"//staging/src/k8s.io/apiserver/pkg/admission/metrics",
9595
"//staging/src/k8s.io/apiserver/pkg/util/flowcontrol/metrics",
9696
"//staging/src/k8s.io/component-base/metrics/...",
97-
"//test/e2e",
98-
"//test/e2e/storage",
9997
"//test/e2e_node",
10098
"//vendor/...",
10199
],

staging/src/k8s.io/component-base/metrics/testutil/metrics.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,34 @@ func ComputeHistogramDelta(before, after model.Samples, label model.LabelName) {
147147
func makeKey(a, b model.LabelValue) string {
148148
return string(a) + "___" + string(b)
149149
}
150+
151+
// GetMetricValuesForLabel returns value of metric for a given dimension
152+
func GetMetricValuesForLabel(ms Metrics, metricName, label string) map[string]int64 {
153+
samples, found := ms[metricName]
154+
result := make(map[string]int64, len(samples))
155+
if !found {
156+
return result
157+
}
158+
for _, sample := range samples {
159+
count := int64(sample.Value)
160+
dimensionName := string(sample.Metric[model.LabelName(label)])
161+
result[dimensionName] = count
162+
}
163+
return result
164+
}
165+
166+
// ValidateMetrics verifies if every sample of metric has all expected labels
167+
func ValidateMetrics(metrics Metrics, metricName string, expectedLabels ...string) error {
168+
samples, ok := metrics[metricName]
169+
if !ok {
170+
return fmt.Errorf("metric %q was not found in metrics", metricName)
171+
}
172+
for _, sample := range samples {
173+
for _, l := range expectedLabels {
174+
if _, ok := sample.Metric[model.LabelName(l)]; !ok {
175+
return fmt.Errorf("metric %q is missing label %q, sample: %q", metricName, l, sample.String())
176+
}
177+
}
178+
}
179+
return nil
180+
}

test/e2e/storage/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ go_library(
8686
"//vendor/github.com/aws/aws-sdk-go/service/ec2:go_default_library",
8787
"//vendor/github.com/onsi/ginkgo:go_default_library",
8888
"//vendor/github.com/onsi/gomega:go_default_library",
89-
"//vendor/github.com/prometheus/common/model:go_default_library",
9089
"//vendor/google.golang.org/api/googleapi:go_default_library",
9190
],
9291
)

test/e2e/storage/volume_metrics.go

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"github.com/onsi/ginkgo"
2424
"github.com/onsi/gomega"
25-
"github.com/prometheus/common/model"
2625

2726
v1 "k8s.io/api/core/v1"
2827
storagev1 "k8s.io/api/storage/v1"
@@ -281,8 +280,8 @@ var _ = utils.SIGDescribe("[Serial] Volume metrics", func() {
281280

282281
metricKey := "volume_operation_total_seconds_count"
283282
dimensions := []string{"operation_name", "plugin_name"}
284-
valid := hasValidMetrics(testutil.Metrics(controllerMetrics), metricKey, dimensions...)
285-
framework.ExpectEqual(valid, true, "Invalid metric in P/V Controller metrics: %q", metricKey)
283+
err = testutil.ValidateMetrics(testutil.Metrics(controllerMetrics), metricKey, dimensions...)
284+
framework.ExpectNoError(err, "Invalid metric in P/V Controller metrics: %q", metricKey)
286285

287286
framework.Logf("Deleting pod %q/%q", pod.Namespace, pod.Name)
288287
framework.ExpectNoError(e2epod.DeletePodWithWait(c, pod))
@@ -311,8 +310,8 @@ var _ = utils.SIGDescribe("[Serial] Volume metrics", func() {
311310
// Metrics should have dimensions plugin_name and state available
312311
totalVolumesKey := "volume_manager_total_volumes"
313312
dimensions := []string{"state", "plugin_name"}
314-
valid := hasValidMetrics(testutil.Metrics(kubeMetrics), totalVolumesKey, dimensions...)
315-
framework.ExpectEqual(valid, true, "Invalid metric in Volume Manager metrics: %q", totalVolumesKey)
313+
err = testutil.ValidateMetrics(testutil.Metrics(kubeMetrics), totalVolumesKey, dimensions...)
314+
framework.ExpectNoError(err, "Invalid metric in Volume Manager metrics: %q", totalVolumesKey)
316315

317316
framework.Logf("Deleting pod %q/%q", pod.Namespace, pod.Name)
318317
framework.ExpectNoError(e2epod.DeletePodWithWait(c, pod))
@@ -439,7 +438,7 @@ var _ = utils.SIGDescribe("[Serial] Volume metrics", func() {
439438
// Concretely, we expect the difference of the updated values and original values for each
440439
// test suit are equal to expectValues.
441440
actualValues := calculateRelativeValues(originMetricValues[i],
442-
getPVControllerMetrics(controllerMetrics, metric.name, metric.dimension))
441+
testutil.GetMetricValuesForLabel(testutil.Metrics(controllerMetrics), metric.name, metric.dimension))
443442
framework.ExpectEqual(actualValues, expectValues, "Wrong pv controller metric %s(%s): wanted %v, got %v",
444443
metric.name, metric.dimension, expectValues, actualValues)
445444
}
@@ -458,7 +457,7 @@ var _ = utils.SIGDescribe("[Serial] Volume metrics", func() {
458457
framework.ExpectNoError(err, "Error getting c-m metricValues: %v", err)
459458
for _, metric := range metrics {
460459
originMetricValues = append(originMetricValues,
461-
getPVControllerMetrics(controllerMetrics, metric.name, metric.dimension))
460+
testutil.GetMetricValuesForLabel(testutil.Metrics(controllerMetrics), metric.name, metric.dimension))
462461
}
463462
})
464463

@@ -694,28 +693,13 @@ func waitForPVControllerSync(metricsGrabber *metrics.Grabber, metricName, dimens
694693
framework.Logf("Error fetching controller-manager metrics")
695694
return false, err
696695
}
697-
return len(getPVControllerMetrics(updatedMetrics, metricName, dimension)) > 0, nil
696+
return len(testutil.GetMetricValuesForLabel(testutil.Metrics(updatedMetrics), metricName, dimension)) > 0, nil
698697
}
699698
waitErr := wait.ExponentialBackoff(backoff, verifyMetricFunc)
700699
framework.ExpectNoError(waitErr,
701700
"Timeout error fetching pv controller metrics : %v", waitErr)
702701
}
703702

704-
func getPVControllerMetrics(ms metrics.ControllerManagerMetrics, metricName, dimension string) map[string]int64 {
705-
result := make(map[string]int64)
706-
for method, samples := range ms {
707-
if method != metricName {
708-
continue
709-
}
710-
for _, sample := range samples {
711-
count := int64(sample.Value)
712-
dimensionName := string(sample.Metric[model.LabelName(dimension)])
713-
result[dimensionName] = count
714-
}
715-
}
716-
return result
717-
}
718-
719703
func calculateRelativeValues(originValues, updatedValues map[string]int64) map[string]int64 {
720704
relativeValues := make(map[string]int64)
721705
for key, value := range updatedValues {
@@ -732,26 +716,6 @@ func calculateRelativeValues(originValues, updatedValues map[string]int64) map[s
732716
return relativeValues
733717
}
734718

735-
func hasValidMetrics(metrics testutil.Metrics, metricKey string, dimensions ...string) bool {
736-
var errCount int
737-
framework.Logf("Looking for sample in metric %q", metricKey)
738-
samples, ok := metrics[metricKey]
739-
if !ok {
740-
framework.Logf("Key %q was not found in metrics", metricKey)
741-
return false
742-
}
743-
for _, sample := range samples {
744-
framework.Logf("Found sample %q", sample.String())
745-
for _, d := range dimensions {
746-
if _, ok := sample.Metric[model.LabelName(d)]; !ok {
747-
framework.Logf("Error getting dimension %q for metric %q, sample %q", d, metricKey, sample.String())
748-
errCount++
749-
}
750-
}
751-
}
752-
return errCount == 0
753-
}
754-
755719
func getStatesMetrics(metricKey string, givenMetrics testutil.Metrics) map[string]map[string]int64 {
756720
states := make(map[string]map[string]int64)
757721
for _, sample := range givenMetrics[metricKey] {
@@ -775,8 +739,9 @@ func waitForADControllerStatesMetrics(metricsGrabber *metrics.Grabber, metricNam
775739
framework.Skipf("Could not get controller-manager metrics - skipping")
776740
return false, err
777741
}
778-
if !hasValidMetrics(testutil.Metrics(updatedMetrics), metricName, dimensions...) {
779-
return false, fmt.Errorf("could not get valid metrics for %q", metricName)
742+
err = testutil.ValidateMetrics(testutil.Metrics(updatedMetrics), metricName, dimensions...)
743+
if err != nil {
744+
return false, fmt.Errorf("could not get valid metrics: %v ", err)
780745
}
781746
states := getStatesMetrics(metricName, testutil.Metrics(updatedMetrics))
782747
for _, name := range stateNames {

0 commit comments

Comments
 (0)