From 91e285f87d68ab98041108d7d25c8fe8180ec13b Mon Sep 17 00:00:00 2001 From: Vishnu Challa Date: Fri, 25 Oct 2024 21:10:28 -0400 Subject: [PATCH] Fixing indexing bugs for workers-scale Signed-off-by: Vishnu Challa --- .github/workflows/linters.yml | 5 +++++ pkg/workerscale/metrics.go | 6 ++++++ pkg/workerscale/rosa.go | 7 +++++++ pkg/workerscale/types.go | 3 ++- workers-scale.go | 3 +++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 58d940d5..d8d3af2d 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -13,6 +13,11 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} persist-credentials: false + - name: Set up Go 1.21.1 + uses: actions/setup-go@v5 + with: + go-version: 1.21.1 + - name: Set up Go environment run: go env -w GOPROXY=direct diff --git a/pkg/workerscale/metrics.go b/pkg/workerscale/metrics.go index 95764715..0f9bca49 100644 --- a/pkg/workerscale/metrics.go +++ b/pkg/workerscale/metrics.go @@ -90,7 +90,13 @@ func calculateMetrics(machineSetsToEdit *sync.Map, scaledMachineDetails map[stri nmValue, _ := nodeMetrics.Load(info.nodeUID) nodeMetricValue := nmValue.(measurements.NodeMetric) uuid = nodeMetricValue.UUID + // Prevents OS indexing error due to conflicts + if osID, exists := nodeMetricValue.Labels["node.openshift.io/os_id"]; exists { + nodeMetricValue.Labels["node_openshift_io_os_id"] = osID + delete(nodeMetricValue.Labels, "node.openshift.io/os_id") + } normLatencies = append(normLatencies, NodeReadyMetric{ + Timestamp: time.Now().UTC(), ScaleEventTimestamp: scaleEventTimestamp, MachineCreationTimestamp: machineCreationTimeStamp, MachineCreationLatency: int(machineCreationTimeStamp.Sub(scaleEventTimestamp).Milliseconds()), diff --git a/pkg/workerscale/rosa.go b/pkg/workerscale/rosa.go index 11d39bd3..2746a791 100644 --- a/pkg/workerscale/rosa.go +++ b/pkg/workerscale/rosa.go @@ -18,6 +18,7 @@ import ( "context" "encoding/json" "fmt" + "os" "os/exec" "sync" "time" @@ -125,6 +126,8 @@ func editMachinepool(clusterID string, minReplicas int, maxReplicas int, autoSca cmdArgs = append(cmdArgs, fmt.Sprintf("--replicas=%d", maxReplicas)) } cmd := exec.Command("rosa", cmdArgs...) + // Pass the current environment to the command + cmd.Env = os.Environ() editOutput, err := cmd.CombinedOutput() if err != nil { log.Fatalf("Failed to edit machinepool: %v. Output: %s", err, string(editOutput)) @@ -144,6 +147,8 @@ func verifyRosaInstall() { log.Info("ROSA CLI is installed.") cmd := exec.Command("rosa", "whoami") + // Pass the current environment to the command + cmd.Env = os.Environ() output, err := cmd.CombinedOutput() if err != nil { log.Fatal("You are not logged in. Please login using 'rosa login' and retry.") @@ -173,6 +178,8 @@ func getClusterID(dynamicClient dynamic.Interface, mcPrescence bool) string { // Special case for hcp where cluster version object has external ID if mcPrescence { cmd := exec.Command("rosa", "describe", "cluster", "-c", clusterID, "-o", "json") + // Pass the current environment to the command + cmd.Env = os.Environ() output, err := cmd.CombinedOutput() if err != nil { log.Fatalf("Failed to describe cluster: %v", err) diff --git a/pkg/workerscale/types.go b/pkg/workerscale/types.go index 4d12bdbb..4fae18af 100644 --- a/pkg/workerscale/types.go +++ b/pkg/workerscale/types.go @@ -76,7 +76,8 @@ type ProviderStatus struct { // NodeReadyMetric to capture details on node bootup type NodeReadyMetric struct { - ScaleEventTimestamp time.Time `json:"-"` + Timestamp time.Time `json"timestamp"` + ScaleEventTimestamp time.Time `json:"scaleEventTimestamp"` MachineCreationTimestamp time.Time `json:"-"` MachineCreationLatency int `json:"machineCreationLatency"` MachineReadyTimestamp time.Time `json:"-"` diff --git a/workers-scale.go b/workers-scale.go index ca233369..fdf5e578 100644 --- a/workers-scale.go +++ b/workers-scale.go @@ -53,6 +53,7 @@ func NewWorkersScale(metricsEndpoint *string, ocpMetaAgent *ocpmetadata.Metadata Long: "If no other indexer is specified, local indexer is used by default", SilenceUsage: true, PostRun: func(cmd *cobra.Command, args []string) { + log.Info("👋 Exiting kube-burner ", uuid) os.Exit(rc) }, Run: func(cmd *cobra.Command, args []string) { @@ -96,6 +97,8 @@ func NewWorkersScale(metricsEndpoint *string, ocpMetaAgent *ocpmetadata.Metadata } clusterMetadata, err = ocpMetaAgent.GetClusterMetadata() + clusterMetadata.WorkerNodesCount += additionalWorkerNodes + clusterMetadata.TotalNodes += additionalWorkerNodes if err != nil { log.Fatal("Error obtaining clusterMetadata: ", err.Error()) }