From 766cb58dab7674a475b965a5329a728e4f9394d5 Mon Sep 17 00:00:00 2001 From: Rahul Shetty <160733420+rh-rahulshetty@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:48:04 +0530 Subject: [PATCH] feat(KONFLUX-4319): Capture Application & Component JSONs after load test (#1459) * added changes to capture application & component yamls after load test * fix review suggestions --- .../load-tests/ci-scripts/collect-results.sh | 8 ---- .../ci-scripts/stage/collect-results.sh | 7 --- .../pkg/journey/handle_collections.go | 46 +++++++++++++++++++ 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/tests/load-tests/ci-scripts/collect-results.sh b/tests/load-tests/ci-scripts/collect-results.sh index e3f771a82..eae37e4bd 100755 --- a/tests/load-tests/ci-scripts/collect-results.sh +++ b/tests/load-tests/ci-scripts/collect-results.sh @@ -76,14 +76,6 @@ application_stub=$ARTIFACT_DIR/collected-data/collected-applications.appstudio.r component_stub=$ARTIFACT_DIR/collected-data/collected-components.appstudio.redhat.com node_stub=$ARTIFACT_DIR/collected-data/collected-nodes -## Application info -echo "Collecting Application timestamps..." -collect_application "-A" "$application_stub" - -## Component info -echo "Collecting Component timestamps..." -collect_component "-A" "$component_stub" - ## Nodes info #echo "Collecting node specs" #collect_nodes "$node_stub" diff --git a/tests/load-tests/ci-scripts/stage/collect-results.sh b/tests/load-tests/ci-scripts/stage/collect-results.sh index 828f4a5cb..8688d476e 100755 --- a/tests/load-tests/ci-scripts/stage/collect-results.sh +++ b/tests/load-tests/ci-scripts/stage/collect-results.sh @@ -105,13 +105,6 @@ else fi tenant="${username}-tenant" - # Application info - echo "Collecting Application timestamps..." - collect_application "-n ${tenant}" "$application_stub-$tenant" || echo "ERROR: Failed collecting applications" - - # Component info - echo "Collecting Component timestamps..." - collect_component "-n ${tenant}" "$component_stub-$tenant" || echo "ERROR: Failed collecting components" done fi diff --git a/tests/load-tests/pkg/journey/handle_collections.go b/tests/load-tests/pkg/journey/handle_collections.go index 1cad830dd..f0b2b616f 100644 --- a/tests/load-tests/pkg/journey/handle_collections.go +++ b/tests/load-tests/pkg/journey/handle_collections.go @@ -2,6 +2,7 @@ package journey import "fmt" import "os" +import "errors" import "path/filepath" import "encoding/json" @@ -131,6 +132,46 @@ func collectPipelineRunJSONs(f *framework.Framework, dirPath, namespace, applica return nil } +func collectApplicationComponentJSONs(f *framework.Framework, dirPath, namespace, application, component string) error { + appJsonFileName := "collected-application-" + application + ".json" + // Only save Application JSON if it has not already been collected (as HandlePerComponentCollection method is called for each component) + if _, err := os.Stat(filepath.Join(dirPath, appJsonFileName)); errors.Is(err, os.ErrNotExist) { + // Get Application JSON + app, err := f.AsKubeDeveloper.HasController.GetApplication(application, namespace) + if err != nil { + return fmt.Errorf("Failed to get Application %s: %v", application, err) + } + + appJSON, err := json.Marshal(app) + if err != nil { + return fmt.Errorf("Failed to dump Application JSON: %v", err) + } + + err = writeToFile(dirPath, appJsonFileName, appJSON) + if err != nil { + return fmt.Errorf("Failed to write Application: %v", err) + } + } + + // Collect Component JSON + comp, err := f.AsKubeDeveloper.HasController.GetComponent(component, namespace) + if err != nil { + return fmt.Errorf("Failed to get Component %s: %v", component, err) + } + + compJSON, err := json.Marshal(comp) + if err != nil { + return fmt.Errorf("Failed to dump Component JSON: %v", err) + } + + err = writeToFile(dirPath, "collected-component-" + component + ".json", compJSON) + if err != nil { + return fmt.Errorf("Failed to write Component: %v", err) + } + + return nil +} + func HandlePerComponentCollection(ctx *PerComponentContext) error { if ctx.ComponentName == "" { logging.Logger.Debug("Component name not populated, so skipping per-component collections in %s", ctx.ParentContext.ParentContext.Namespace) @@ -156,5 +197,10 @@ func HandlePerComponentCollection(ctx *PerComponentContext) error { return logging.Logger.Fail(102, "Failed to collect pipeline run JSONs: %v", err) } + err = collectApplicationComponentJSONs(ctx.Framework, dirPath, ctx.ParentContext.ParentContext.Namespace, ctx.ParentContext.ApplicationName, ctx.ComponentName) + if err != nil { + return logging.Logger.Fail(102, "Failed to collect Application and Component JSONs: %v", err) + } + return nil }