Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion internal/common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ func ToStringSlice(val interface{}) ([]string, error) {
}

func CreateTestRunID() string {
return fmt.Sprintf("%d", rand.Intn(testRunMaxID-testRunMinID)+testRunMinID)
return CreateTestRunIDWithPrefix("")
}
Comment on lines 60 to +62
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is used also in other places (e.g. adding a random suffix to policies), those can be kept as they are now.

For instance:

Namespace: common.CreateTestRunID(),


func CreateTestRunIDWithPrefix(prefix string) string {
return fmt.Sprintf("%s%d", prefix, rand.Intn(testRunMaxID-testRunMinID)+testRunMinID)
}

func ProcessResourceApplyResults(results resource.ApplyResults) string {
Expand Down
7 changes: 6 additions & 1 deletion internal/testrunner/runners/system/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,12 @@ func (r *tester) createServiceInfo() (servicedeployer.ServiceInfo, error) {
svcInfo.Name = r.testFolder.Package
svcInfo.Logs.Folder.Local = r.locationManager.ServiceLogDir()
svcInfo.Logs.Folder.Agent = ServiceLogsAgentDir
svcInfo.Test.RunID = common.CreateTestRunID()

prefix := ""
if v, found := os.LookupEnv("ELASTIC_PACKAGE_PREFIX_SERVICE_TEST_RUN_ID"); found && v != "" {
prefix = v
}
svcInfo.Test.RunID = common.CreateTestRunIDWithPrefix(prefix)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of using the terraform service deployer, a part of updating the RunID used in as terraform variable, the alias used to render the policy templates in tests needs to be set to the same value as the terraform variable. This is needed for instance for aws.ec2_metrics that filters by the some resource name.


if r.runTearDown || r.runTestsOnly {
logger.Debug("Skip creating output directory")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource "local_file" "log" {
source = "./files/example.log"
filename = "/tmp/service_logs/file.log"
filename = "/tmp/service_logs/file-${var.TEST_RUN_ID}.log"
file_permission = "0777"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ variable "ENVIRONMENT" {
variable "REPO" {
default = "unknown-repo-name"
}

variable "TEST_RUN_ID" {
default = "detached"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ wait_for_data_timeout: 1m
data_stream:
vars:
paths:
- "{{ SERVICE_LOGS_DIR }}/file.log"
- "{{ SERVICE_LOGS_DIR }}/file-{{ TEST_RUN_ID }}.log"
- "{{ SERVICE_LOGS_DIR }}/file_vars.log"
assert:
hit_count: 2
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
variable "TEST_RUN_ID" {
default = "detached"
}

resource "local_file" "log" {
source = "./files/example.log"
filename = "/tmp/service_logs/${var.TEST_RUN_ID}.log"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ variable "ENVIRONMENT" {
variable "REPO" {
default = "unknown-repo-name"
}

variable "TEST_RUN_ID" {
default = "detached"
}