mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Better URL for scraping metrics from kubelet
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
		@@ -164,7 +164,7 @@ var _ = SIGDescribe("CPU Manager Metrics [Serial][Feature:CPUManager]", func() {
 | 
			
		||||
 | 
			
		||||
func getKubeletMetrics(ctx context.Context) (e2emetrics.KubeletMetrics, error) {
 | 
			
		||||
	ginkgo.By("getting Kubelet metrics from the metrics API")
 | 
			
		||||
	return e2emetrics.GrabKubeletMetricsWithoutProxy(ctx, framework.TestContext.NodeName+":10255", "/metrics")
 | 
			
		||||
	return e2emetrics.GrabKubeletMetricsWithoutProxy(ctx, nodeNameOrIP()+":10255", "/metrics")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func makeGuaranteedCPUExclusiveSleeperPod(name string, cpus int) *v1.Pod {
 | 
			
		||||
 
 | 
			
		||||
@@ -965,7 +965,7 @@ func waitForTopologyUnawareResources(ctx context.Context, f *framework.Framework
 | 
			
		||||
func getPodResourcesMetrics(ctx context.Context) (e2emetrics.KubeletMetrics, error) {
 | 
			
		||||
	// we are running out of good names, so we need to be unnecessarily specific to avoid clashes
 | 
			
		||||
	ginkgo.By("getting Pod Resources metrics from the metrics API")
 | 
			
		||||
	return e2emetrics.GrabKubeletMetricsWithoutProxy(ctx, framework.TestContext.NodeName+":10255", "/metrics")
 | 
			
		||||
	return e2emetrics.GrabKubeletMetricsWithoutProxy(ctx, nodeNameOrIP()+":10255", "/metrics")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func timelessSampleAtLeast(lower interface{}) types.GomegaMatcher {
 | 
			
		||||
 
 | 
			
		||||
@@ -131,7 +131,7 @@ var _ = SIGDescribe("ResourceMetricsAPI [NodeFeature:ResourceMetrics]", func() {
 | 
			
		||||
 | 
			
		||||
func getResourceMetrics(ctx context.Context) (e2emetrics.KubeletMetrics, error) {
 | 
			
		||||
	ginkgo.By("getting stable resource metrics API")
 | 
			
		||||
	return e2emetrics.GrabKubeletMetricsWithoutProxy(ctx, framework.TestContext.NodeName+":10255", "/metrics/resource")
 | 
			
		||||
	return e2emetrics.GrabKubeletMetricsWithoutProxy(ctx, nodeNameOrIP()+":10255", "/metrics/resource")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func nodeID(element interface{}) string {
 | 
			
		||||
 
 | 
			
		||||
@@ -40,6 +40,7 @@ import (
 | 
			
		||||
	v1 "k8s.io/api/core/v1"
 | 
			
		||||
	apiequality "k8s.io/apimachinery/pkg/api/equality"
 | 
			
		||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
			
		||||
	utilnet "k8s.io/apimachinery/pkg/util/net"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/util/runtime"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/util/sets"
 | 
			
		||||
	utilfeature "k8s.io/apiserver/pkg/util/feature"
 | 
			
		||||
@@ -289,7 +290,7 @@ func logKubeletLatencyMetrics(ctx context.Context, metricNames ...string) {
 | 
			
		||||
	for _, key := range metricNames {
 | 
			
		||||
		metricSet.Insert(kubeletmetrics.KubeletSubsystem + "_" + key)
 | 
			
		||||
	}
 | 
			
		||||
	metric, err := e2emetrics.GrabKubeletMetricsWithoutProxy(ctx, fmt.Sprintf("%s:%d", framework.TestContext.NodeName, ports.KubeletReadOnlyPort), "/metrics")
 | 
			
		||||
	metric, err := e2emetrics.GrabKubeletMetricsWithoutProxy(ctx, fmt.Sprintf("%s:%d", nodeNameOrIP(), ports.KubeletReadOnlyPort), "/metrics")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		framework.Logf("Error getting kubelet metrics: %v", err)
 | 
			
		||||
	} else {
 | 
			
		||||
@@ -623,3 +624,22 @@ func WaitForPodInitContainerToFail(ctx context.Context, c clientset.Interface, n
 | 
			
		||||
		return false, nil
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func nodeNameOrIP() string {
 | 
			
		||||
	// Check if the node name in test context can be resolved
 | 
			
		||||
	if ips, err := net.LookupIP(framework.TestContext.NodeName); err != nil {
 | 
			
		||||
		if dnsErr, ok := err.(*net.DNSError); ok && dnsErr.IsNotFound {
 | 
			
		||||
			// if it can't be resolved, pick a host interface
 | 
			
		||||
			if ip, err := utilnet.ChooseHostInterface(); err == nil {
 | 
			
		||||
				return ip.String()
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		if len(ips) > 0 {
 | 
			
		||||
			// yay, node name resolved correctly, pick the first
 | 
			
		||||
			return ips[0].String()
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	// fallback to node name in test context
 | 
			
		||||
	return framework.TestContext.NodeName
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user