diff --git a/test/e2e/framework/BUILD b/test/e2e/framework/BUILD index d73f3af6899..cc220343ed6 100644 --- a/test/e2e/framework/BUILD +++ b/test/e2e/framework/BUILD @@ -8,7 +8,6 @@ go_library( "expect.go", "flake_reporting_util.go", "framework.go", - "get-kubemark-resource-usage.go", "google_compute.go", "log.go", "log_size_monitoring.go", diff --git a/test/e2e/framework/get-kubemark-resource-usage.go b/test/e2e/framework/get-kubemark-resource-usage.go deleted file mode 100644 index f9b60a32db6..00000000000 --- a/test/e2e/framework/get-kubemark-resource-usage.go +++ /dev/null @@ -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 -} diff --git a/test/e2e/framework/resource_usage_gatherer.go b/test/e2e/framework/resource_usage_gatherer.go index 9ce357b081b..f354df35298 100644 --- a/test/e2e/framework/resource_usage_gatherer.go +++ b/test/e2e/framework/resource_usage_gatherer.go @@ -17,6 +17,7 @@ limitations under the License. package framework import ( + "bufio" "bytes" "context" "encoding/json" @@ -36,6 +37,9 @@ import ( kubeletstatsv1alpha1 "k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1" "k8s.io/kubernetes/pkg/master/ports" "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. @@ -70,9 +74,6 @@ type ResourceUsagePerContainer map[string]*ContainerResourceUsage // we can't have int here, as JSON does not accept integer keys. 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. func (s *ResourceUsageSummary) PrintHumanReadable() string { buf := &bytes.Buffer{} @@ -183,7 +184,7 @@ type resourceGatherWorker struct { func (w *resourceGatherWorker) singleProbe() { data := make(ResourceUsagePerContainer) if w.inKubemark { - kubemarkData := GetKubemarkMasterComponentsResourceUsage() + kubemarkData := getKubemarkMasterComponentsResourceUsage() if data == nil { return } @@ -556,3 +557,65 @@ func (g *ContainerResourceGatherer) StopAndSummarize(percentiles []int, constrai } 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 +}