mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 18:31:15 +00:00
Merge pull request #87271 from tanjunchen/move-function-GetKubemarkMasterComponentResoureUsage
move function GetKubemarkMasterComponentResoureUsage and remove long-time TODO
This commit is contained in:
commit
02ac661794
@ -8,7 +8,6 @@ go_library(
|
|||||||
"expect.go",
|
"expect.go",
|
||||||
"flake_reporting_util.go",
|
"flake_reporting_util.go",
|
||||||
"framework.go",
|
"framework.go",
|
||||||
"get-kubemark-resource-usage.go",
|
|
||||||
"google_compute.go",
|
"google_compute.go",
|
||||||
"log.go",
|
"log.go",
|
||||||
"log_size_monitoring.go",
|
"log_size_monitoring.go",
|
||||||
|
@ -1,89 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2016 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 framework
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
// TODO: Remove the following imports (ref: https://github.com/kubernetes/kubernetes/issues/81245)
|
|
||||||
e2essh "k8s.io/kubernetes/test/e2e/framework/ssh"
|
|
||||||
)
|
|
||||||
|
|
||||||
// KubemarkResourceUsage is a struct for tracking the resource usage of kubemark.
|
|
||||||
type KubemarkResourceUsage struct {
|
|
||||||
Name string
|
|
||||||
MemoryWorkingSetInBytes uint64
|
|
||||||
CPUUsageInCores float64
|
|
||||||
}
|
|
||||||
|
|
||||||
func getMasterUsageByPrefix(prefix string) (string, error) {
|
|
||||||
sshResult, err := e2essh.SSH(fmt.Sprintf("ps ax -o %%cpu,rss,command | tail -n +2 | grep %v | sed 's/\\s+/ /g'", prefix), GetMasterHost()+":22", TestContext.Provider)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return sshResult.Stdout, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetKubemarkMasterComponentsResourceUsage returns the resource usage of kubemark which contains multiple combinations of cpu and memory usage for each pod name.
|
|
||||||
// TODO: figure out how to move this to kubemark directory (need to factor test SSH out of e2e framework)
|
|
||||||
func GetKubemarkMasterComponentsResourceUsage() map[string]*KubemarkResourceUsage {
|
|
||||||
result := make(map[string]*KubemarkResourceUsage)
|
|
||||||
// Get kubernetes component resource usage
|
|
||||||
sshResult, err := getMasterUsageByPrefix("kube")
|
|
||||||
if err != nil {
|
|
||||||
Logf("Error when trying to SSH to master machine. Skipping probe. %v", err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
scanner := bufio.NewScanner(strings.NewReader(sshResult))
|
|
||||||
for scanner.Scan() {
|
|
||||||
var cpu float64
|
|
||||||
var mem uint64
|
|
||||||
var name string
|
|
||||||
fmt.Sscanf(strings.TrimSpace(scanner.Text()), "%f %d /usr/local/bin/kube-%s", &cpu, &mem, &name)
|
|
||||||
if name != "" {
|
|
||||||
// Gatherer expects pod_name/container_name format
|
|
||||||
fullName := name + "/" + name
|
|
||||||
result[fullName] = &KubemarkResourceUsage{Name: fullName, MemoryWorkingSetInBytes: mem * 1024, CPUUsageInCores: cpu / 100}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Get etcd resource usage
|
|
||||||
sshResult, err = getMasterUsageByPrefix("bin/etcd")
|
|
||||||
if err != nil {
|
|
||||||
Logf("Error when trying to SSH to master machine. Skipping probe")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
scanner = bufio.NewScanner(strings.NewReader(sshResult))
|
|
||||||
for scanner.Scan() {
|
|
||||||
var cpu float64
|
|
||||||
var mem uint64
|
|
||||||
var etcdKind string
|
|
||||||
fmt.Sscanf(strings.TrimSpace(scanner.Text()), "%f %d /bin/sh -c /usr/local/bin/etcd", &cpu, &mem)
|
|
||||||
dataDirStart := strings.Index(scanner.Text(), "--data-dir")
|
|
||||||
if dataDirStart < 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
fmt.Sscanf(scanner.Text()[dataDirStart:], "--data-dir=/var/%s", &etcdKind)
|
|
||||||
if etcdKind != "" {
|
|
||||||
// Gatherer expects pod_name/container_name format
|
|
||||||
fullName := "etcd/" + etcdKind
|
|
||||||
result[fullName] = &KubemarkResourceUsage{Name: fullName, MemoryWorkingSetInBytes: mem * 1024, CPUUsageInCores: cpu / 100}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package framework
|
package framework
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -36,6 +37,9 @@ import (
|
|||||||
kubeletstatsv1alpha1 "k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1"
|
kubeletstatsv1alpha1 "k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1"
|
||||||
"k8s.io/kubernetes/pkg/master/ports"
|
"k8s.io/kubernetes/pkg/master/ports"
|
||||||
"k8s.io/kubernetes/test/e2e/system"
|
"k8s.io/kubernetes/test/e2e/system"
|
||||||
|
|
||||||
|
// TODO: Remove the following imports (ref: https://github.com/kubernetes/kubernetes/issues/81245)
|
||||||
|
e2essh "k8s.io/kubernetes/test/e2e/framework/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ResourceConstraint is a struct to hold constraints.
|
// ResourceConstraint is a struct to hold constraints.
|
||||||
@ -70,9 +74,6 @@ type ResourceUsagePerContainer map[string]*ContainerResourceUsage
|
|||||||
// we can't have int here, as JSON does not accept integer keys.
|
// we can't have int here, as JSON does not accept integer keys.
|
||||||
type ResourceUsageSummary map[string][]SingleContainerSummary
|
type ResourceUsageSummary map[string][]SingleContainerSummary
|
||||||
|
|
||||||
// NoCPUConstraint is the number of constraint for CPU.
|
|
||||||
const NoCPUConstraint = math.MaxFloat64
|
|
||||||
|
|
||||||
// PrintHumanReadable prints resource usage summary in human readable.
|
// PrintHumanReadable prints resource usage summary in human readable.
|
||||||
func (s *ResourceUsageSummary) PrintHumanReadable() string {
|
func (s *ResourceUsageSummary) PrintHumanReadable() string {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
@ -183,7 +184,7 @@ type resourceGatherWorker struct {
|
|||||||
func (w *resourceGatherWorker) singleProbe() {
|
func (w *resourceGatherWorker) singleProbe() {
|
||||||
data := make(ResourceUsagePerContainer)
|
data := make(ResourceUsagePerContainer)
|
||||||
if w.inKubemark {
|
if w.inKubemark {
|
||||||
kubemarkData := GetKubemarkMasterComponentsResourceUsage()
|
kubemarkData := getKubemarkMasterComponentsResourceUsage()
|
||||||
if data == nil {
|
if data == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -556,3 +557,65 @@ func (g *ContainerResourceGatherer) StopAndSummarize(percentiles []int, constrai
|
|||||||
}
|
}
|
||||||
return &summary, nil
|
return &summary, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// kubemarkResourceUsage is a struct for tracking the resource usage of kubemark.
|
||||||
|
type kubemarkResourceUsage struct {
|
||||||
|
Name string
|
||||||
|
MemoryWorkingSetInBytes uint64
|
||||||
|
CPUUsageInCores float64
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMasterUsageByPrefix(prefix string) (string, error) {
|
||||||
|
sshResult, err := e2essh.SSH(fmt.Sprintf("ps ax -o %%cpu,rss,command | tail -n +2 | grep %v | sed 's/\\s+/ /g'", prefix), GetMasterHost()+":22", TestContext.Provider)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return sshResult.Stdout, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// getKubemarkMasterComponentsResourceUsage returns the resource usage of kubemark which contains multiple combinations of cpu and memory usage for each pod name.
|
||||||
|
func getKubemarkMasterComponentsResourceUsage() map[string]*kubemarkResourceUsage {
|
||||||
|
result := make(map[string]*kubemarkResourceUsage)
|
||||||
|
// Get kubernetes component resource usage
|
||||||
|
sshResult, err := getMasterUsageByPrefix("kube")
|
||||||
|
if err != nil {
|
||||||
|
Logf("Error when trying to SSH to master machine. Skipping probe. %v", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
scanner := bufio.NewScanner(strings.NewReader(sshResult))
|
||||||
|
for scanner.Scan() {
|
||||||
|
var cpu float64
|
||||||
|
var mem uint64
|
||||||
|
var name string
|
||||||
|
fmt.Sscanf(strings.TrimSpace(scanner.Text()), "%f %d /usr/local/bin/kube-%s", &cpu, &mem, &name)
|
||||||
|
if name != "" {
|
||||||
|
// Gatherer expects pod_name/container_name format
|
||||||
|
fullName := name + "/" + name
|
||||||
|
result[fullName] = &kubemarkResourceUsage{Name: fullName, MemoryWorkingSetInBytes: mem * 1024, CPUUsageInCores: cpu / 100}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Get etcd resource usage
|
||||||
|
sshResult, err = getMasterUsageByPrefix("bin/etcd")
|
||||||
|
if err != nil {
|
||||||
|
Logf("Error when trying to SSH to master machine. Skipping probe")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
scanner = bufio.NewScanner(strings.NewReader(sshResult))
|
||||||
|
for scanner.Scan() {
|
||||||
|
var cpu float64
|
||||||
|
var mem uint64
|
||||||
|
var etcdKind string
|
||||||
|
fmt.Sscanf(strings.TrimSpace(scanner.Text()), "%f %d /bin/sh -c /usr/local/bin/etcd", &cpu, &mem)
|
||||||
|
dataDirStart := strings.Index(scanner.Text(), "--data-dir")
|
||||||
|
if dataDirStart < 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fmt.Sscanf(scanner.Text()[dataDirStart:], "--data-dir=/var/%s", &etcdKind)
|
||||||
|
if etcdKind != "" {
|
||||||
|
// Gatherer expects pod_name/container_name format
|
||||||
|
fullName := "etcd/" + etcdKind
|
||||||
|
result[fullName] = &kubemarkResourceUsage{Name: fullName, MemoryWorkingSetInBytes: mem * 1024, CPUUsageInCores: cpu / 100}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user