-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement using /metrics/resource Kubelet endpoint
Signed-off-by: JunYang <[email protected]>
- Loading branch information
1 parent
d766094
commit c6398d6
Showing
24 changed files
with
946 additions
and
1,782 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 |
---|---|---|
|
@@ -55,7 +55,7 @@ rules: | |
resources: | ||
- pods | ||
- nodes | ||
- nodes/stats | ||
- nodes/metrics | ||
- namespaces | ||
- configmaps | ||
verbs: | ||
|
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,105 @@ | ||
// Copyright 2021 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 resource | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/prometheus/common/model" | ||
) | ||
|
||
func TestClient(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Decode Suite") | ||
} | ||
|
||
var _ = Describe("Decode", func() { | ||
var ( | ||
metricsOrigData string | ||
) | ||
It("should use the decode node result from the CPU", func() { | ||
metricsOrigData = `# HELP node_cpu_usage_seconds_total [ALPHA] Cumulative cpu time consumed by the node in core-seconds | ||
# TYPE node_cpu_usage_seconds_total counter | ||
node_cpu_usage_seconds_total 497090.546884895 1621165414370 | ||
` | ||
|
||
By("decoding") | ||
samples, err := decodeProm004(metricsOrigData) | ||
|
||
By("verifying that the scrape CumulativeCpuUsed and Timestamp are as expected") | ||
Expect(err).Should(BeNil()) | ||
Expect(len(samples)).To(Equal(1)) | ||
Expect(string(samples[0].Metric[model.MetricNameLabel])).To(Equal("node_cpu_usage_seconds_total")) | ||
Expect(float64(samples[0].Value)).To(Equal(497090.546884895)) | ||
Expect(int(samples[0].Timestamp)).To(Equal(1621165414370)) | ||
}) | ||
|
||
It("should use the decode node result from the Memory", func() { | ||
metricsOrigData = `# HELP node_memory_working_set_bytes [ALPHA] Current working set of the node in bytes | ||
# TYPE node_memory_working_set_bytes gauge | ||
node_memory_working_set_bytes 8.391589888e+09 1621165414370 | ||
` | ||
By("decoding") | ||
samples, err := decodeProm004(metricsOrigData) | ||
|
||
By("verifying that the scrape MemoryUsage and Timestamp are as expected") | ||
Expect(err).Should(BeNil()) | ||
Expect(len(samples)).To(Equal(1)) | ||
Expect(string(samples[0].Metric[model.MetricNameLabel])).To(Equal("node_memory_working_set_bytes")) | ||
Expect(float64(samples[0].Value)).To(Equal(8.391589888e+09)) | ||
Expect(int(samples[0].Timestamp)).To(Equal(1621165414370)) | ||
}) | ||
|
||
It("should use the decode pod result from the CumulativeCpuUsed", func() { | ||
metricsOrigData = `# HELP container_cpu_usage_seconds_total [ALPHA] Cumulative cpu time consumed by the container in core-seconds | ||
# TYPE container_cpu_usage_seconds_total counter | ||
container_cpu_usage_seconds_total{container="container1",namespace="default",pod="pod1"} 15625.474020075 1621165406043 | ||
` | ||
|
||
By("decoding") | ||
samples, err := decodeProm004(metricsOrigData) | ||
|
||
By("verifying that the scrape CumulativeCpuUsed and Timestamp are as expected") | ||
Expect(err).Should(BeNil()) | ||
Expect(len(samples)).To(Equal(1)) | ||
Expect(string(samples[0].Metric[model.MetricNameLabel])).To(Equal("container_cpu_usage_seconds_total")) | ||
Expect(string(samples[0].Metric["namespace"])).To(Equal("default")) | ||
Expect(string(samples[0].Metric["pod"])).To(Equal("pod1")) | ||
Expect(string(samples[0].Metric["container"])).To(Equal("container1")) | ||
Expect(float64(samples[0].Value)).To(Equal(15625.474020075)) | ||
Expect(int(samples[0].Timestamp)).To(Equal(1621165406043)) | ||
}) | ||
|
||
It("should use the decode pod result from the Memory", func() { | ||
metricsOrigData = `# HELP container_memory_working_set_bytes [ALPHA] Current working set of the container in bytes | ||
# TYPE container_memory_working_set_bytes gauge | ||
container_memory_working_set_bytes{container="container1",namespace="default",pod="pod1"} 1.6244736e+07 1621165406043 | ||
` | ||
By("decoding") | ||
samples, err := decodeProm004(metricsOrigData) | ||
|
||
By("verifying that the scrape MemoryUsage and Timestamp are as expected") | ||
Expect(err).Should(BeNil()) | ||
Expect(len(samples)).To(Equal(1)) | ||
Expect(string(samples[0].Metric[model.MetricNameLabel])).To(Equal("container_memory_working_set_bytes")) | ||
Expect(string(samples[0].Metric["namespace"])).To(Equal("default")) | ||
Expect(string(samples[0].Metric["pod"])).To(Equal("pod1")) | ||
Expect(string(samples[0].Metric["container"])).To(Equal("container1")) | ||
Expect(float64(samples[0].Value)).To(Equal(1.6244736e+07)) | ||
Expect(int(samples[0].Timestamp)).To(Equal(1621165406043)) | ||
}) | ||
}) |
Oops, something went wrong.