Skip to content

Conversation

@mrodm
Copy link
Contributor

@mrodm mrodm commented Jul 17, 2025

This PR allows to customize the Service TestRunID used in system tests to include a prefix string. This prefix is defined via environment variable:

export ELASTIC_PACKAGE_PREFIX_SERVICE_TEST_RUN_ID=1a2b

How to test this PR locally

elastic-package stack up -v -d cd test/packages/parallel/terraform_local export ELASTIC_PACKAGE_PREFIX_SERVICE_TEST_RUN_ID=1a2b elastic-package test system -v 

While the system tests are running you can check the files created by terraform at:

ls -l ~/.elastic-package/profiles/default/service_logs/agent-terraform_local-local-*/file*

it should countain a prefix of 9 digits (e.g. file-1a2b21464.log).

or via the Discover view in Kibana filtering by data_stream.dataset : "terraform_local.local", and it should contain a log field similar to:

 "log": { "file": { "path": "/tmp/service_logs/file-1a2b21464.log" }, "offset": 0 }, 

Author's Checklist

  • Test with a package creating resources in Terraform
  • Test with packages defined in the integrations repository
@mrodm mrodm self-assigned this Jul 17, 2025
@mrodm mrodm changed the title Allow setting an optional prefix for the service TestRunID [system tests] Allow setting an optional prefix for the service TestRunID Jul 18, 2025
@mrodm mrodm marked this pull request as ready for review July 18, 2025 14:06
@mrodm mrodm requested a review from a team July 18, 2025 14:06
Comment on lines 486 to 491

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.

Comment on lines 60 to +62
func CreateTestRunID() string {
return fmt.Sprintf("%d", rand.Intn(testRunMaxID-testRunMinID)+testRunMinID)
return CreateTestRunIDWithPrefix("")
}
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(),

@mrodm mrodm enabled auto-merge (squash) July 18, 2025 14:53
@mrodm mrodm merged commit 6593320 into elastic:main Jul 18, 2025
3 checks passed
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

cc @mrodm

@mrodm mrodm deleted the allow_add_prefix_service_testrunID branch July 18, 2025 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants