mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-06 01:38:10 +00:00
Adjustments after metrics-server update
This commit is contained in:
parent
b480e45a67
commit
47a5ed8047
2 changed files with 13 additions and 16 deletions
|
|
@ -120,9 +120,9 @@ type nsQueryResults struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetContainerMetrics implements the api.MetricsProvider interface. It may return nil, nil, nil.
|
// GetContainerMetrics implements the api.MetricsProvider interface. It may return nil, nil, nil.
|
||||||
func (p *resourceProvider) GetContainerMetrics(pods ...apitypes.NamespacedName) ([]api.TimeInfo, [][]metrics.ContainerMetrics, error) {
|
func (p *resourceProvider) GetContainerMetrics(pods ...apitypes.NamespacedName) ([]api.TimeInfo, [][]metrics.ContainerMetrics) {
|
||||||
if len(pods) == 0 {
|
if len(pods) == 0 {
|
||||||
return nil, nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(directxman12): figure out how well this scales if we go to list 1000+ pods
|
// TODO(directxman12): figure out how well this scales if we go to list 1000+ pods
|
||||||
|
|
@ -168,7 +168,7 @@ func (p *resourceProvider) GetContainerMetrics(pods ...apitypes.NamespacedName)
|
||||||
p.assignForPod(pod, resultsByNs, &resMetrics[i], &resTimes[i])
|
p.assignForPod(pod, resultsByNs, &resMetrics[i], &resTimes[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
return resTimes, resMetrics, nil
|
return resTimes, resMetrics
|
||||||
}
|
}
|
||||||
|
|
||||||
// assignForPod takes the resource metrics for all containers in the given pod
|
// assignForPod takes the resource metrics for all containers in the given pod
|
||||||
|
|
@ -240,10 +240,10 @@ func (p *resourceProvider) assignForPod(pod apitypes.NamespacedName, resultsByNs
|
||||||
*resMetrics = containerMetricsList
|
*resMetrics = containerMetricsList
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNodeMetrics implements the api.MetricsProvider interface. It may return nil, nil, nil.
|
// GetNodeMetrics implements the api.MetricsProvider interface. It may return nil, nil.
|
||||||
func (p *resourceProvider) GetNodeMetrics(nodes ...string) ([]api.TimeInfo, []corev1.ResourceList, error) {
|
func (p *resourceProvider) GetNodeMetrics(nodes ...string) ([]api.TimeInfo, []corev1.ResourceList) {
|
||||||
if len(nodes) == 0 {
|
if len(nodes) == 0 {
|
||||||
return nil, nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
now := pmodel.Now()
|
now := pmodel.Now()
|
||||||
|
|
@ -251,7 +251,8 @@ func (p *resourceProvider) GetNodeMetrics(nodes ...string) ([]api.TimeInfo, []co
|
||||||
// run the actual query
|
// run the actual query
|
||||||
qRes := p.queryBoth(now, nodeResource, "", nodes...)
|
qRes := p.queryBoth(now, nodeResource, "", nodes...)
|
||||||
if qRes.err != nil {
|
if qRes.err != nil {
|
||||||
return nil, nil, qRes.err
|
klog.Errorf("failed querying node metrics: %v", qRes.err)
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
resTimes := make([]api.TimeInfo, len(nodes))
|
resTimes := make([]api.TimeInfo, len(nodes))
|
||||||
|
|
@ -295,7 +296,7 @@ func (p *resourceProvider) GetNodeMetrics(nodes ...string) ([]api.TimeInfo, []co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return resTimes, resMetrics, nil
|
return resTimes, resMetrics
|
||||||
}
|
}
|
||||||
|
|
||||||
// queryBoth queries for both CPU and memory metrics on the given
|
// queryBoth queries for both CPU and memory metrics on the given
|
||||||
|
|
|
||||||
|
|
@ -146,8 +146,7 @@ var _ = Describe("Resource Metrics Provider", func() {
|
||||||
}
|
}
|
||||||
|
|
||||||
By("querying for metrics for some pods")
|
By("querying for metrics for some pods")
|
||||||
times, metricVals, err := prov.GetContainerMetrics(pods...)
|
times, metricVals := prov.GetContainerMetrics(pods...)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
|
|
||||||
By("verifying that the reported times for each are the earliest times for each pod")
|
By("verifying that the reported times for each are the earliest times for each pod")
|
||||||
Expect(times).To(Equal([]api.TimeInfo{
|
Expect(times).To(Equal([]api.TimeInfo{
|
||||||
|
|
@ -185,11 +184,10 @@ var _ = Describe("Resource Metrics Provider", func() {
|
||||||
}
|
}
|
||||||
|
|
||||||
By("querying for metrics for some pods, one of which is missing")
|
By("querying for metrics for some pods, one of which is missing")
|
||||||
times, metricVals, err := prov.GetContainerMetrics(
|
times, metricVals := prov.GetContainerMetrics(
|
||||||
types.NamespacedName{Namespace: "some-ns", Name: "pod1"},
|
types.NamespacedName{Namespace: "some-ns", Name: "pod1"},
|
||||||
types.NamespacedName{Namespace: "some-ns", Name: "pod-nonexistant"},
|
types.NamespacedName{Namespace: "some-ns", Name: "pod-nonexistant"},
|
||||||
)
|
)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
|
|
||||||
By("verifying that the missing pod had nil metrics")
|
By("verifying that the missing pod had nil metrics")
|
||||||
Expect(metricVals).To(HaveLen(2))
|
Expect(metricVals).To(HaveLen(2))
|
||||||
|
|
@ -216,8 +214,7 @@ var _ = Describe("Resource Metrics Provider", func() {
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
By("querying for metrics for some nodes")
|
By("querying for metrics for some nodes")
|
||||||
times, metricVals, err := prov.GetNodeMetrics("node1", "node2")
|
times, metricVals := prov.GetNodeMetrics("node1", "node2")
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
|
|
||||||
By("verifying that the reported times for each are the earliest times for each pod")
|
By("verifying that the reported times for each are the earliest times for each pod")
|
||||||
Expect(times).To(Equal([]api.TimeInfo{
|
Expect(times).To(Equal([]api.TimeInfo{
|
||||||
|
|
@ -244,8 +241,7 @@ var _ = Describe("Resource Metrics Provider", func() {
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
By("querying for metrics for some nodes, one of which is missing")
|
By("querying for metrics for some nodes, one of which is missing")
|
||||||
times, metricVals, err := prov.GetNodeMetrics("node1", "node2", "node3")
|
times, metricVals := prov.GetNodeMetrics("node1", "node2", "node3")
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
|
|
||||||
By("verifying that the missing pod had nil metrics")
|
By("verifying that the missing pod had nil metrics")
|
||||||
Expect(metricVals).To(HaveLen(3))
|
Expect(metricVals).To(HaveLen(3))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue