Skip to content

Commit

Permalink
Merge pull request kubernetes#5100 from jbartosik/metric_server_respo…
Browse files Browse the repository at this point in the history
…nses

Export metric about result of queried VPA makes to metrics server
  • Loading branch information
k8s-ci-robot authored Aug 17, 2022
2 parents c26bbbb + 89e523c commit 53794f7
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,36 @@ package metrics

import (
"context"
"strconv"
"time"

"github.com/prometheus/client_golang/prometheus"
k8sapiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/recommender/model"
"k8s.io/klog/v2"
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/metrics"
klog "k8s.io/klog/v2"
"k8s.io/metrics/pkg/apis/metrics/v1beta1"
resourceclient "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1"
)

const (
metricsNamespace = metrics.TopMetricsNamespace + "metrics-server-client"
)

var metricServerResponses = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: metricsNamespace,
Name: "metric_server_responses",
Help: "Count of responses to queries to metrics server",
}, []string{"is_error"},
)

// Register initializes all VPA metrics for metrics server client
func Register() {
prometheus.MustRegister(metricServerResponses)
}

// ContainerMetricsSnapshot contains information about usage of certain container within defined time window.
type ContainerMetricsSnapshot struct {
// ID identifies a specific container those metrics are coming from.
Expand Down Expand Up @@ -68,14 +88,15 @@ func (c *metricsClient) GetContainersMetrics() ([]*ContainerMetricsSnapshot, err
podMetricsInterface := c.metricsGetter.PodMetricses(c.namespace)
podMetricsList, err := podMetricsInterface.List(context.TODO(), metav1.ListOptions{})
if err != nil {
metricServerResponses.WithLabelValues(strconv.FormatBool(true)).Inc()
return nil, err
}
klog.V(3).Infof("%v podMetrics retrieved for all namespaces", len(podMetricsList.Items))
for _, podMetrics := range podMetricsList.Items {
metricsSnapshotsForPod := createContainerMetricsSnapshots(podMetrics)
metricsSnapshots = append(metricsSnapshots, metricsSnapshotsForPod...)
}

metricServerResponses.WithLabelValues(strconv.FormatBool(false)).Inc()
return metricsSnapshots, nil
}

Expand Down

0 comments on commit 53794f7

Please sign in to comment.