-
Notifications
You must be signed in to change notification settings - Fork 914
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce tests to check whether workqueue metrics exist
Signed-off-by: chaosi-zju <[email protected]>
- Loading branch information
1 parent
9f8da2c
commit 5462a31
Showing
6 changed files
with
347 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
Copyright 2023 The Karmada 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 e2e | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
appsv1 "k8s.io/api/apps/v1" | ||
"k8s.io/apimachinery/pkg/util/rand" | ||
|
||
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" | ||
"github.com/karmada-io/karmada/test/e2e/framework" | ||
testhelper "github.com/karmada-io/karmada/test/helper" | ||
) | ||
|
||
var _ = ginkgo.Describe("metrics testing", func() { | ||
var grabber *testhelper.Grabber | ||
|
||
var componentMetrics = map[string][]string{ | ||
testhelper.KarmadaControllerManagerDeploy: { | ||
"workqueue_queue_duration_seconds_sum", // workqueue metrics | ||
"cluster_ready_state", // custom ClusterCollectors metrics | ||
"work_sync_workload_duration_seconds_sum", // custom ResourceCollectors metrics | ||
}, | ||
testhelper.KarmadaSchedulerDeploy: { | ||
"workqueue_queue_duration_seconds_sum", // workqueue metrics | ||
//"schedule_attempts_total", // scheduler custom metrics | ||
}, | ||
testhelper.KarmadaDeschedulerDeploy: { | ||
"workqueue_queue_duration_seconds_sum", // workqueue metrics | ||
}, | ||
testhelper.KarmadaMetricsAdapterDeploy: { | ||
"workqueue_queue_duration_seconds_sum", // workqueue metrics | ||
}, | ||
testhelper.KarmadaSchedulerEstimatorDeploy: { | ||
"karmada_scheduler_estimator_estimating_request_total", // scheduler estimator custom metrics | ||
}, | ||
testhelper.KarmadaWebhookDeploy: { | ||
"controller_runtime_webhook_requests_total", // controller runtime hook server metrics | ||
}, | ||
} | ||
|
||
ginkgo.BeforeEach(func() { | ||
var err error | ||
grabber, err = testhelper.NewMetricsGrabber(context.TODO(), hostKubeClient) | ||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) | ||
}) | ||
|
||
ginkgo.Context("metrics presence testing", func() { | ||
ginkgo.It("metrics presence testing for each component", func() { | ||
ginkgo.By("1. do a simple scheduling to ensure above metrics exist", func() { | ||
name := deploymentNamePrefix + rand.String(RandomStrLength) | ||
deployment := testhelper.NewDeployment(testNamespace, name) | ||
policy := testhelper.NewPropagationPolicy(testNamespace, name, []policyv1alpha1.ResourceSelector{ | ||
{ | ||
APIVersion: deployment.APIVersion, | ||
Kind: deployment.Kind, | ||
Name: deployment.Name, | ||
}, | ||
}, policyv1alpha1.Placement{ | ||
ClusterAffinity: &policyv1alpha1.ClusterAffinity{ | ||
ClusterNames: framework.ClusterNames(), | ||
}, | ||
}) | ||
framework.CreateDeployment(kubeClient, deployment) | ||
framework.CreatePropagationPolicy(karmadaClient, policy) | ||
ginkgo.DeferCleanup(func() { | ||
framework.RemoveDeployment(kubeClient, deployment.Namespace, deployment.Name) | ||
framework.RemovePropagationPolicy(karmadaClient, policy.Namespace, policy.Name) | ||
}) | ||
framework.WaitDeploymentPresentOnClustersFitWith(framework.ClusterNames(), deployment.Namespace, deployment.Name, func(_ *appsv1.Deployment) bool { return true }) | ||
}) | ||
|
||
ginkgo.By("2. judge metrics presence", func() { | ||
for component, metricsList := range componentMetrics { | ||
// the output format of `metrics` is like: | ||
// { | ||
// "workqueue_queue_duration_seconds_sum": [{ | ||
// "metric": { | ||
// "__name__": "workqueue_queue_duration_seconds_sum", | ||
// "controller": "work-status-controller", | ||
// "name": "work-status-controller" | ||
// }, | ||
// "value": [0, "0.12403110800000001"] | ||
// }] | ||
// } | ||
metrics, err := grabber.GrabMetricsFromComponent(context.TODO(), component) | ||
gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) | ||
|
||
for _, metricName := range metricsList { | ||
testhelper.PrintMetricSample((*metrics)[metricName]) | ||
gomega.Expect((*metrics)[metricName]).ShouldNot(gomega.BeNil()) | ||
} | ||
} | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.