Skip to content

Commit

Permalink
feat(KONFLUX-4319): Capture Application & Component JSONs after load …
Browse files Browse the repository at this point in the history
…test (#1459)

* added changes to capture application & component yamls after load test

* fix review suggestions
  • Loading branch information
rh-rahulshetty authored Nov 20, 2024
1 parent fa2e7ac commit 766cb58
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
8 changes: 0 additions & 8 deletions tests/load-tests/ci-scripts/collect-results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 0 additions & 7 deletions tests/load-tests/ci-scripts/stage/collect-results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
46 changes: 46 additions & 0 deletions tests/load-tests/pkg/journey/handle_collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package journey

import "fmt"
import "os"
import "errors"
import "path/filepath"
import "encoding/json"

Expand Down Expand Up @@ -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)
Expand All @@ -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
}

0 comments on commit 766cb58

Please sign in to comment.