diff --git a/go.mod b/go.mod index 47ce229..acdf1e2 100644 --- a/go.mod +++ b/go.mod @@ -3,16 +3,16 @@ module github.com/rsevilla87/ingress-perf go 1.19 require ( - github.com/cloud-bulldozer/go-commons v1.0.0 + github.com/cloud-bulldozer/go-commons v1.0.1 github.com/openshift/api v0.0.0-20230414095907-0540dde8186d github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c github.com/satori/go.uuid v1.2.0 github.com/sirupsen/logrus v1.9.0 github.com/spf13/cobra v1.7.0 gopkg.in/yaml.v3 v3.0.1 - k8s.io/api v0.27.0 - k8s.io/apimachinery v0.27.0 - k8s.io/client-go v0.27.0 + k8s.io/api v0.27.1 + k8s.io/apimachinery v0.27.1 + k8s.io/client-go v0.27.1 k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 ) diff --git a/go.sum b/go.sum index f6f404e..151edbc 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,8 @@ github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWR github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cloud-bulldozer/go-commons v1.0.0 h1:YOWLH/aN/PN5MDaVrhktzeTM1SsU8XHIHfdKjwLLM8c= -github.com/cloud-bulldozer/go-commons v1.0.0/go.mod h1:HLdZZlRpv8bWVkq1g9AyLE7bpsbAbau5Uqfw/fM9bLE= +github.com/cloud-bulldozer/go-commons v1.0.1 h1:WLmRyQZrBokGyULExmSM/IMJu63LJdc4Q+ofFSD1IjM= +github.com/cloud-bulldozer/go-commons v1.0.1/go.mod h1:yJ1b4WosXfRKVXoomu/gc5cRMSi3HQEzFFwVBPZszSg= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= @@ -496,12 +496,12 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -k8s.io/api v0.27.0 h1:2owttiA8Oa+J3idFeq8TSnNpm4y6AOGPI3PDbIpp2cE= -k8s.io/api v0.27.0/go.mod h1:Wl+QRvQlh+T8SK5f4F6YBhhyH6hrFO08nl74xZb1MUE= -k8s.io/apimachinery v0.27.0 h1:vEyy/PVMbPMCPutrssCVHCf0JNZ0Px+YqPi82K2ALlk= -k8s.io/apimachinery v0.27.0/go.mod h1:5ikh59fK3AJ287GUvpUsryoMFtH9zj/ARfWCo3AyXTM= -k8s.io/client-go v0.27.0 h1:DyZS1fJkv73tEy7rWv4VF6NwGeJ7SKvNaLRXZBYLA+4= -k8s.io/client-go v0.27.0/go.mod h1:XVEmpNnM+4JYO3EENoFV/ZDv3KxKVJUnzGo70avk+C4= +k8s.io/api v0.27.1 h1:Z6zUGQ1Vd10tJ+gHcNNNgkV5emCyW+v2XTmn+CLjSd0= +k8s.io/api v0.27.1/go.mod h1:z5g/BpAiD+f6AArpqNjkY+cji8ueZDU/WV1jcj5Jk4E= +k8s.io/apimachinery v0.27.1 h1:EGuZiLI95UQQcClhanryclaQE6xjg1Bts6/L3cD7zyc= +k8s.io/apimachinery v0.27.1/go.mod h1:5ikh59fK3AJ287GUvpUsryoMFtH9zj/ARfWCo3AyXTM= +k8s.io/client-go v0.27.1 h1:oXsfhW/qncM1wDmWBIuDzRHNS2tLhK3BZv512Nc59W8= +k8s.io/client-go v0.27.1/go.mod h1:f8LHMUkVb3b9N8bWturc+EDtVVVwZ7ueTVquFAJb2vA= k8s.io/klog/v2 v2.90.1 h1:m4bYOKall2MmOiRaR1J+We67Do7vm9KiQVlT96lnHUw= k8s.io/klog/v2 v2.90.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a h1:gmovKNur38vgoWfGtP5QOGNOA7ki4n6qNYoFAgMlNvg= diff --git a/pkg/runner/exec.go b/pkg/runner/exec.go index bbe2637..c6484bb 100644 --- a/pkg/runner/exec.go +++ b/pkg/runner/exec.go @@ -7,6 +7,7 @@ import ( "sync" "time" + ocpmetadata "github.com/cloud-bulldozer/go-commons/ocp-metadata" "github.com/rsevilla87/ingress-perf/pkg/config" "github.com/rsevilla87/ingress-perf/pkg/runner/tools" log "github.com/sirupsen/logrus" @@ -19,7 +20,7 @@ import ( var lock = &sync.Mutex{} -func runBenchmark(cfg config.Config) ([]interface{}, error) { +func runBenchmark(cfg config.Config, clusterMetadata ocpmetadata.ClusterMetadata) ([]interface{}, error) { var benchmarkResult []interface{} var clientPods []corev1.Pod var wg sync.WaitGroup @@ -44,7 +45,7 @@ func runBenchmark(cfg config.Config) ([]interface{}, error) { if err != nil { return benchmarkResult, err } - // Filter out pods in terminating status from the list + // Filter out pods in terminating state from the list for _, p := range allClientPods.Items { if p.DeletionTimestamp == nil { clientPods = append(clientPods, p) @@ -55,10 +56,11 @@ func runBenchmark(cfg config.Config) ([]interface{}, error) { } for i := 1; i <= cfg.Samples; i++ { result := tools.Result{ - UUID: cfg.UUID, - Sample: i, - Config: cfg, - Timestamp: time.Now().UTC(), + UUID: cfg.UUID, + Sample: i, + Config: cfg, + Timestamp: time.Now().UTC(), + ClusterMetadata: clusterMetadata, } log.Infof("Running sample %d/%d: %v", i, cfg.Samples, cfg.Duration) // TODO ingress controller warmup is needed @@ -93,6 +95,7 @@ func exec(ctx context.Context, wg *sync.WaitGroup, tool tools.Tool, pod corev1.P exec, err := remotecommand.NewSPDYExecutor(restConfig, "POST", req.URL()) if err != nil { log.Error(err.Error()) + return } err = exec.StreamWithContext(ctx, remotecommand.StreamOptions{ Stdout: &stdout, @@ -103,10 +106,19 @@ func exec(ctx context.Context, wg *sync.WaitGroup, tool tools.Tool, pod corev1.P return } podResult, err := tool.ParseResult(stdout.String(), stderr.String()) + if err != nil { + log.Errorf("Result parsing failed, skipping: %v", err.Error()) + return + } podResult.Name = pod.Name podResult.Node = pod.Spec.NodeName + node, err := clientSet.CoreV1().Nodes().Get(context.TODO(), podResult.Node, metav1.GetOptions{}) if err != nil { - log.Fatal(err) + log.Errorf("Couldn't fetch node: %v", err.Error()) + return + } + if d, ok := node.Labels["node.kubernetes.io/instance-type"]; ok { + podResult.InstanceType = d } lock.Lock() result.Pods = append(result.Pods, podResult) diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index c1f6bc6..4341e86 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -7,6 +7,7 @@ import ( "time" "github.com/cloud-bulldozer/go-commons/indexers" + ocpmetadata "github.com/cloud-bulldozer/go-commons/ocp-metadata" "github.com/rsevilla87/ingress-perf/pkg/config" log "github.com/sirupsen/logrus" appsv1 "k8s.io/api/apps/v1" @@ -45,6 +46,14 @@ func Start(uuid string, indexer *indexers.Indexer) error { clientSet = kubernetes.NewForConfigOrDie(restConfig) orClientSet = openshiftrouteclientset.NewForConfigOrDie(restConfig) dynamicClient = dynamic.NewForConfigOrDie(restConfig) + ocpMetadata, err := ocpmetadata.NewMetadata(restConfig) + if err != nil { + return err + } + clusterMetadata, err := ocpMetadata.GetClusterMetadata() + if err != nil { + return err + } if err := deployAssets(); err != nil { return err } @@ -59,7 +68,7 @@ func Start(uuid string, indexer *indexers.Indexer) error { return err } } - if result, err = runBenchmark(cfg); err != nil { + if result, err = runBenchmark(cfg, clusterMetadata); err != nil { return err } if indexer != nil { diff --git a/pkg/runner/tools/types.go b/pkg/runner/tools/types.go index b5fd7a8..9cb7ef3 100644 --- a/pkg/runner/tools/types.go +++ b/pkg/runner/tools/types.go @@ -3,6 +3,7 @@ package tools import ( "time" + ocpmetadata "github.com/cloud-bulldozer/go-commons/ocp-metadata" "github.com/rsevilla87/ingress-perf/pkg/config" ) @@ -14,6 +15,7 @@ type Tool interface { type PodResult struct { Name string `json:"pod"` Node string `json:"node"` + InstanceType string `json:"instanceType"` AvgRps float64 `json:"rps"` StdevRps float64 `json:"rps_stdev"` StdevLatency float64 `json:"stdev_lat"` @@ -44,4 +46,5 @@ type Result struct { Errors int64 `json:"http_errors"` Requests int64 `json:"requests"` Timeouts int64 `json:"timeouts"` + ocpmetadata.ClusterMetadata }