From 00d857bdb217323779bebf02d691331e9a900b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Sevilla?= Date: Fri, 22 Sep 2023 09:42:08 +0200 Subject: [PATCH] Haproxy version (#37) ## Type of change - [ ] Refactor - [x] New feature - [ ] Bug fix - [ ] Optimization - [ ] Documentation Update ## Description Capturing HAProxy RPM version using `rpm -qa | grep haproxy` and including it in the metadata: ## Related Tickets & Documents - Related Issue # - Closes #36 ## Checklist before requesting a review - [x] I have performed a self-review of my code. - [ ] If it is a core feature, I have added thorough tests. ## Testing Quick example shows: ```json [ { "uuid": "9ddf05c5-f6ec-410d-bf7c-aa07f5957707", "sample": 1, "config": { "termination": "http", "connections": 20, "samples": 1, "duration": 10000000000, "path": "/1024.html", "concurrency": 1, "procs": 1, "tool": "wrk", "serverReplicas": 90, "tuningPatch": "", "Delay": 0, "RequestTimeout": 2000000000 }, "pods": [ { "pod": "ingress-perf-client-c8d5548c9-s5rgw", "node": "ip-10-0-217-162.us-west-2.compute.internal", "instanceType": "m5.2xlarge", "rps": 8234.8, "rps_stdev": 558.69, "stdev_lat": 1693.48, "avg_lat_us": 2607.02, "max_lat_us": 33100, "p90_lat_us": 3930, "p95_lat_us": 5845, "p99_lat_us": 10033, "http_errors": 0, "read_errors": 0, "write_errors": 0, "requests": 83167, "timeouts": 0 } ], "timestamp": "2023-09-21T10:22:54.989431717Z", "total_avg_rps": 8234.8, "rps_stdev": 558.69, "stdev_lat": 1693.48, "avg_lat_us": 2607.02, "max_lat_us": 33100, "p90_lat_us": 3930, "p95_lat_us": 5845, "p99_lat_us": 10033, "http_errors": 0, "read_errors": 0, "write_errors": 0, "requests": 83167, "timeouts": 0, "version": "haproxy-version@4370fc887e1117a3256687ffdeb0224a285461c7", "platform": "AWS", "clusterType": "self-managed", "ocpVersion": "4.12.18", "ocpMajorVersion": "4.12", "k8sVersion": "v1.25.8+37a9a08", "masterNodesType": "m5.2xlarge", "workerNodesType": "m5.large", "masterNodesCount": 3, "infraNodesType": "", "workerNodesCount": 5, "infraNodesCount": 0, "otherNodesCount": 0, "totalNodes": 5, "sdnType": "OpenShiftSDN", "clusterName": "cloud-bulldozer-ci-6hwqr", "region": "us-west-2", "haproxyVersion": "haproxy22-2.2.24-3.rhaos4.12.el8.x86_64" } ] ``` Signed-off-by: Raul Sevilla --- pkg/runner/exec.go | 3 +-- pkg/runner/metadata.go | 52 +++++++++++++++++++++++++++++++++++++++ pkg/runner/runner.go | 7 +++++- pkg/runner/tools/types.go | 8 +++++- 4 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 pkg/runner/metadata.go diff --git a/pkg/runner/exec.go b/pkg/runner/exec.go index b6f7749..fb4bd4c 100644 --- a/pkg/runner/exec.go +++ b/pkg/runner/exec.go @@ -21,7 +21,6 @@ import ( "sync" "time" - ocpmetadata "github.com/cloud-bulldozer/go-commons/ocp-metadata" "github.com/cloud-bulldozer/go-commons/version" "github.com/cloud-bulldozer/ingress-perf/pkg/config" "github.com/cloud-bulldozer/ingress-perf/pkg/runner/tools" @@ -36,7 +35,7 @@ import ( var lock = &sync.Mutex{} -func runBenchmark(cfg config.Config, clusterMetadata ocpmetadata.ClusterMetadata) ([]tools.Result, error) { +func runBenchmark(cfg config.Config, clusterMetadata tools.ClusterMetadata) ([]tools.Result, error) { var aggAvgRps, aggAvgLatency, aggP99Latency float64 var timeouts, httpErrors int64 var benchmarkResult []tools.Result diff --git a/pkg/runner/metadata.go b/pkg/runner/metadata.go new file mode 100644 index 0000000..04cafad --- /dev/null +++ b/pkg/runner/metadata.go @@ -0,0 +1,52 @@ +package runner + +import ( + "bytes" + "context" + "strings" + + log "github.com/sirupsen/logrus" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/tools/remotecommand" +) + +func getHAProxyVersion() (string, error) { + var stdout, stderr bytes.Buffer + podList, err := clientSet.CoreV1().Pods("openshift-ingress").List(context.TODO(), + metav1.ListOptions{ + LabelSelector: "ingresscontroller.operator.openshift.io/deployment-ingresscontroller=default", + FieldSelector: "status.phase=Running"}, + ) + if err != nil { + return "", err + } + routerPod := podList.Items[0] + req := clientSet.CoreV1().RESTClient().Post(). + Resource("pods"). + Name(routerPod.Name). + Namespace(routerPod.Namespace). + SubResource("exec") + req.VersionedParams(&corev1.PodExecOptions{ + Container: "router", + Stdin: false, + Stdout: true, + Stderr: true, + Command: []string{"bash", "-c", "rpm -qa | grep haproxy"}, + TTY: false, + }, scheme.ParameterCodec) + exec, err := remotecommand.NewSPDYExecutor(restConfig, "POST", req.URL()) + if err != nil { + log.Error(err.Error()) + return "", err + } + err = exec.StreamWithContext(context.TODO(), remotecommand.StreamOptions{ + Stdout: &stdout, + Stderr: &stderr, + }) + if err != nil { + return "", err + } + return strings.TrimRight(stdout.String(), "\n"), err +} diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index a6f1bbf..62cc699 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -53,6 +53,7 @@ func Start(uuid, baseUUID, baseIndex string, tolerancy int, indexer *indexers.In var kubeconfig string var benchmarkResult []tools.Result var comparator comparison.Comparator + var clusterMetadata tools.ClusterMetadata passed := true if os.Getenv("KUBECONFIG") != "" { kubeconfig = os.Getenv("KUBECONFIG") @@ -72,7 +73,11 @@ func Start(uuid, baseUUID, baseIndex string, tolerancy int, indexer *indexers.In if err != nil { return err } - clusterMetadata, err := ocpMetadata.GetClusterMetadata() + clusterMetadata.ClusterMetadata, err = ocpMetadata.GetClusterMetadata() + if err != nil { + return err + } + clusterMetadata.HAProxyVersion, err = getHAProxyVersion() if err != nil { return err } diff --git a/pkg/runner/tools/types.go b/pkg/runner/tools/types.go index dad6ee7..a2112f0 100644 --- a/pkg/runner/tools/types.go +++ b/pkg/runner/tools/types.go @@ -21,6 +21,12 @@ import ( "github.com/cloud-bulldozer/ingress-perf/pkg/config" ) +// We need to embed ClusterMetadata in order to add extra fields to it +type ClusterMetadata struct { + ocpmetadata.ClusterMetadata + HAProxyVersion string `json:"haproxyVersion,omitempty"` +} + type Tool interface { ParseResult(string, string) (PodResult, error) Cmd() []string @@ -65,5 +71,5 @@ type Result struct { Requests int64 `json:"requests"` Timeouts int64 `json:"timeouts"` Version string `json:"version"` - ocpmetadata.ClusterMetadata + ClusterMetadata }