mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-29 13:24:42 +00:00
e2e framework: move metrics gathering into sub package
This reduces the size of the test/e2e/framework itself. Because it does not gather metrics data anymore by default, E2E test suites must set their callbacks function or set the original one by importing "k8s.io/kubernetes/test/e2e/framework/todo/metrics/init".
This commit is contained in:
parent
b8d28cb6c3
commit
802451b6ca
@ -65,6 +65,7 @@ import (
|
|||||||
|
|
||||||
// reconfigure framework
|
// reconfigure framework
|
||||||
_ "k8s.io/kubernetes/test/e2e/framework/debug/init"
|
_ "k8s.io/kubernetes/test/e2e/framework/debug/init"
|
||||||
|
_ "k8s.io/kubernetes/test/e2e/framework/todo/metrics/init"
|
||||||
_ "k8s.io/kubernetes/test/e2e/framework/todo/node/init"
|
_ "k8s.io/kubernetes/test/e2e/framework/todo/node/init"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,9 +50,6 @@ import (
|
|||||||
admissionapi "k8s.io/pod-security-admission/api"
|
admissionapi "k8s.io/pod-security-admission/api"
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/v2"
|
"github.com/onsi/ginkgo/v2"
|
||||||
|
|
||||||
// TODO: Remove the following imports (ref: https://github.com/kubernetes/kubernetes/issues/81245)
|
|
||||||
e2emetrics "k8s.io/kubernetes/test/e2e/framework/metrics"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -123,9 +120,6 @@ type Framework struct {
|
|||||||
// or stdout if ReportDir is not set once test ends.
|
// or stdout if ReportDir is not set once test ends.
|
||||||
TestSummaries []TestDataSummary
|
TestSummaries []TestDataSummary
|
||||||
|
|
||||||
// Place to keep ClusterAutoscaler metrics from before test in order to compute delta.
|
|
||||||
clusterAutoscalerMetricsBeforeTest e2emetrics.Collection
|
|
||||||
|
|
||||||
// Timeouts contains the custom timeouts used during the test execution.
|
// Timeouts contains the custom timeouts used during the test execution.
|
||||||
Timeouts *TimeoutContext
|
Timeouts *TimeoutContext
|
||||||
|
|
||||||
@ -304,22 +298,6 @@ func (f *Framework) BeforeEach() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
gatherMetricsAfterTest := TestContext.GatherMetricsAfterTest == "true" || TestContext.GatherMetricsAfterTest == "master"
|
|
||||||
if gatherMetricsAfterTest && TestContext.IncludeClusterAutoscalerMetrics {
|
|
||||||
grabber, err := e2emetrics.NewMetricsGrabber(f.ClientSet, f.KubemarkExternalClusterClientSet, f.ClientConfig(), !ProviderIs("kubemark"), false, false, false, TestContext.IncludeClusterAutoscalerMetrics, false)
|
|
||||||
if err != nil {
|
|
||||||
Logf("Failed to create MetricsGrabber (skipping ClusterAutoscaler metrics gathering before test): %v", err)
|
|
||||||
} else {
|
|
||||||
f.clusterAutoscalerMetricsBeforeTest, err = grabber.Grab()
|
|
||||||
if err != nil {
|
|
||||||
Logf("MetricsGrabber failed to grab CA metrics before test (skipping metrics gathering): %v", err)
|
|
||||||
} else {
|
|
||||||
Logf("Gathered ClusterAutoscaler metrics before test")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
f.flakeReport = NewFlakeReport()
|
f.flakeReport = NewFlakeReport()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -445,23 +423,6 @@ func (f *Framework) AfterEach() {
|
|||||||
f.TestSummaries = append(f.TestSummaries, f.logsSizeVerifier.GetSummary())
|
f.TestSummaries = append(f.TestSummaries, f.logsSizeVerifier.GetSummary())
|
||||||
}
|
}
|
||||||
|
|
||||||
if TestContext.GatherMetricsAfterTest != "false" {
|
|
||||||
ginkgo.By("Gathering metrics")
|
|
||||||
// Grab apiserver, scheduler, controller-manager metrics and (optionally) nodes' kubelet metrics.
|
|
||||||
grabMetricsFromKubelets := TestContext.GatherMetricsAfterTest != "master" && !ProviderIs("kubemark")
|
|
||||||
grabber, err := e2emetrics.NewMetricsGrabber(f.ClientSet, f.KubemarkExternalClusterClientSet, f.ClientConfig(), grabMetricsFromKubelets, true, true, true, TestContext.IncludeClusterAutoscalerMetrics, false)
|
|
||||||
if err != nil {
|
|
||||||
Logf("Failed to create MetricsGrabber (skipping metrics gathering): %v", err)
|
|
||||||
} else {
|
|
||||||
received, err := grabber.Grab()
|
|
||||||
if err != nil {
|
|
||||||
Logf("MetricsGrabber failed to grab some of the metrics: %v", err)
|
|
||||||
}
|
|
||||||
(*e2emetrics.ComponentCollection)(&received).ComputeClusterAutoscalerMetricsDelta(f.clusterAutoscalerMetricsBeforeTest)
|
|
||||||
f.TestSummaries = append(f.TestSummaries, (*e2emetrics.ComponentCollection)(&received))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TestContext.CloudConfig.Provider.FrameworkAfterEach(f)
|
TestContext.CloudConfig.Provider.FrameworkAfterEach(f)
|
||||||
|
|
||||||
// Report any flakes that were observed in the e2e test and reset.
|
// Report any flakes that were observed in the e2e test and reset.
|
||||||
|
74
test/e2e/framework/todo/metrics/grab.go
Normal file
74
test/e2e/framework/todo/metrics/grab.go
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2015 The Kubernetes 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 metrics
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/onsi/ginkgo/v2"
|
||||||
|
|
||||||
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
|
e2emetrics "k8s.io/kubernetes/test/e2e/framework/metrics"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GrabBeforeEach(f *framework.Framework) (result *e2emetrics.Collection) {
|
||||||
|
gatherMetricsAfterTest := framework.TestContext.GatherMetricsAfterTest == "true" || framework.TestContext.GatherMetricsAfterTest == "master"
|
||||||
|
if !gatherMetricsAfterTest || !framework.TestContext.IncludeClusterAutoscalerMetrics {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ginkgo.By("Gathering metrics before test", func() {
|
||||||
|
grabber, err := e2emetrics.NewMetricsGrabber(f.ClientSet, f.KubemarkExternalClusterClientSet, f.ClientConfig(), !framework.ProviderIs("kubemark"), false, false, false, framework.TestContext.IncludeClusterAutoscalerMetrics, false)
|
||||||
|
if err != nil {
|
||||||
|
framework.Logf("Failed to create MetricsGrabber (skipping ClusterAutoscaler metrics gathering before test): %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
metrics, err := grabber.Grab()
|
||||||
|
if err != nil {
|
||||||
|
framework.Logf("MetricsGrabber failed to grab CA metrics before test (skipping metrics gathering): %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
framework.Logf("Gathered ClusterAutoscaler metrics before test")
|
||||||
|
result = &metrics
|
||||||
|
})
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func GrabAfterEach(f *framework.Framework, before *e2emetrics.Collection) {
|
||||||
|
if framework.TestContext.GatherMetricsAfterTest == "false" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ginkgo.By("Gathering metrics after test", func() {
|
||||||
|
// Grab apiserver, scheduler, controller-manager metrics and (optionally) nodes' kubelet metrics.
|
||||||
|
grabMetricsFromKubelets := framework.TestContext.GatherMetricsAfterTest != "master" && !framework.ProviderIs("kubemark")
|
||||||
|
grabber, err := e2emetrics.NewMetricsGrabber(f.ClientSet, f.KubemarkExternalClusterClientSet, f.ClientConfig(), grabMetricsFromKubelets, true, true, true, framework.TestContext.IncludeClusterAutoscalerMetrics, false)
|
||||||
|
if err != nil {
|
||||||
|
framework.Logf("Failed to create MetricsGrabber (skipping metrics gathering): %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
received, err := grabber.Grab()
|
||||||
|
if err != nil {
|
||||||
|
framework.Logf("MetricsGrabber failed to grab some of the metrics: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if before == nil {
|
||||||
|
before = &e2emetrics.Collection{}
|
||||||
|
}
|
||||||
|
(*e2emetrics.ComponentCollection)(&received).ComputeClusterAutoscalerMetricsDelta(*before)
|
||||||
|
f.TestSummaries = append(f.TestSummaries, (*e2emetrics.ComponentCollection)(&received))
|
||||||
|
})
|
||||||
|
}
|
39
test/e2e/framework/todo/metrics/init/init.go
Normal file
39
test/e2e/framework/todo/metrics/init/init.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2015 The Kubernetes 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 init installs GrabBeforeEach and GrabAfterEach as callbacks
|
||||||
|
// for gathering data before and after a test.
|
||||||
|
package init
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/onsi/ginkgo/v2"
|
||||||
|
|
||||||
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
|
e2etodometrics "k8s.io/kubernetes/test/e2e/framework/todo/metrics"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
framework.NewFrameworkExtensions = append(framework.NewFrameworkExtensions,
|
||||||
|
func(f *framework.Framework) {
|
||||||
|
ginkgo.BeforeEach(func() {
|
||||||
|
metrics := e2etodometrics.GrabBeforeEach(f)
|
||||||
|
ginkgo.DeferCleanup(func() {
|
||||||
|
e2etodometrics.GrabAfterEach(f, metrics)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
@ -30,6 +30,7 @@ import (
|
|||||||
|
|
||||||
// reconfigure framework
|
// reconfigure framework
|
||||||
_ "k8s.io/kubernetes/test/e2e/framework/debug/init"
|
_ "k8s.io/kubernetes/test/e2e/framework/debug/init"
|
||||||
|
_ "k8s.io/kubernetes/test/e2e/framework/todo/metrics/init"
|
||||||
_ "k8s.io/kubernetes/test/e2e/framework/todo/node/init"
|
_ "k8s.io/kubernetes/test/e2e/framework/todo/node/init"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ import (
|
|||||||
|
|
||||||
// reconfigure framework
|
// reconfigure framework
|
||||||
_ "k8s.io/kubernetes/test/e2e/framework/debug/init"
|
_ "k8s.io/kubernetes/test/e2e/framework/debug/init"
|
||||||
|
_ "k8s.io/kubernetes/test/e2e/framework/todo/metrics/init"
|
||||||
_ "k8s.io/kubernetes/test/e2e/framework/todo/node/init"
|
_ "k8s.io/kubernetes/test/e2e/framework/todo/node/init"
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/v2"
|
"github.com/onsi/ginkgo/v2"
|
||||||
|
Loading…
Reference in New Issue
Block a user