forked from msazurestackworkloads/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics_grabber.go
102 lines (88 loc) · 3.21 KB
/
metrics_grabber.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
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 monitoring
import (
"strings"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/e2e/framework/metrics"
instrumentation "k8s.io/kubernetes/test/e2e/instrumentation/common"
gin "github.com/onsi/ginkgo"
gom "github.com/onsi/gomega"
)
var _ = instrumentation.SIGDescribe("MetricsGrabber", func() {
f := framework.NewDefaultFramework("metrics-grabber")
var c, ec clientset.Interface
var grabber *metrics.MetricsGrabber
gin.BeforeEach(func() {
var err error
c = f.ClientSet
ec = f.KubemarkExternalClusterClientSet
framework.ExpectNoError(err)
grabber, err = metrics.NewMetricsGrabber(c, ec, true, true, true, true, true)
framework.ExpectNoError(err)
})
gin.It("should grab all metrics from API server.", func() {
gin.By("Connecting to /metrics endpoint")
response, err := grabber.GrabFromApiServer()
framework.ExpectNoError(err)
gom.Expect(response).NotTo(gom.BeEmpty())
})
gin.It("should grab all metrics from a Kubelet.", func() {
gin.By("Proxying to Node through the API server")
nodes := framework.GetReadySchedulableNodesOrDie(f.ClientSet)
gom.Expect(nodes.Items).NotTo(gom.BeEmpty())
response, err := grabber.GrabFromKubelet(nodes.Items[0].Name)
framework.ExpectNoError(err)
gom.Expect(response).NotTo(gom.BeEmpty())
})
gin.It("should grab all metrics from a Scheduler.", func() {
gin.By("Proxying to Pod through the API server")
// Check if master Node is registered
nodes, err := c.CoreV1().Nodes().List(metav1.ListOptions{})
framework.ExpectNoError(err)
var masterRegistered = false
for _, node := range nodes.Items {
if strings.HasSuffix(node.Name, "master") {
masterRegistered = true
}
}
if !masterRegistered {
framework.Logf("Master is node api.Registry. Skipping testing Scheduler metrics.")
return
}
response, err := grabber.GrabFromScheduler()
framework.ExpectNoError(err)
gom.Expect(response).NotTo(gom.BeEmpty())
})
gin.It("should grab all metrics from a ControllerManager.", func() {
gin.By("Proxying to Pod through the API server")
// Check if master Node is registered
nodes, err := c.CoreV1().Nodes().List(metav1.ListOptions{})
framework.ExpectNoError(err)
var masterRegistered = false
for _, node := range nodes.Items {
if strings.HasSuffix(node.Name, "master") {
masterRegistered = true
}
}
if !masterRegistered {
framework.Logf("Master is node api.Registry. Skipping testing ControllerManager metrics.")
return
}
response, err := grabber.GrabFromControllerManager()
framework.ExpectNoError(err)
gom.Expect(response).NotTo(gom.BeEmpty())
})
})