Skip to content

Commit

Permalink
Add missing Test Run ID for service up command (#1871)
Browse files Browse the repository at this point in the history
Add missing test run ID when creating the service using the
"elastic-package service up" command
  • Loading branch information
mrodm authored Jun 3, 2024
1 parent 4866988 commit 418d9a2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
10 changes: 10 additions & 0 deletions internal/common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ package common

import (
"fmt"
"math/rand"
"slices"
"strings"
)

const (
testRunMaxID = 99999
testRunMinID = 10000
)

// TrimStringSlice removes whitespace from the beginning and end of the contents of a []string.
func TrimStringSlice(slice []string) {
for iterator, item := range slice {
Expand Down Expand Up @@ -48,3 +54,7 @@ func ToStringSlice(val interface{}) ([]string, error) {
}
return s, nil
}

func CreateTestRunID() string {
return fmt.Sprintf("%d", rand.Intn(testRunMaxID-testRunMinID)+testRunMinID)
}
2 changes: 2 additions & 0 deletions internal/service/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os/signal"
"syscall"

"github.com/elastic/elastic-package/internal/common"
"github.com/elastic/elastic-package/internal/logger"
"github.com/elastic/elastic-package/internal/profile"

Expand Down Expand Up @@ -64,6 +65,7 @@ func BootUp(ctx context.Context, options Options) error {
svcInfo.Name = options.ServiceName
svcInfo.Logs.Folder.Agent = system.ServiceLogsAgentDir
svcInfo.Logs.Folder.Local = locationManager.ServiceLogDir()
svcInfo.Test.RunID = common.CreateTestRunID()
deployed, err := serviceDeployer.SetUp(ctx, svcInfo)
if err != nil {
return fmt.Errorf("can't set up the service deployer: %w", err)
Expand Down
3 changes: 0 additions & 3 deletions internal/servicedeployer/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ type FactoryOptions struct {

PolicyName string

PackageName string
DataStream string

Variant string

RunTearDown bool
Expand Down
14 changes: 2 additions & 12 deletions internal/testrunner/runners/system/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/json"
"errors"
"fmt"
"math/rand"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -41,9 +40,6 @@ import (
)

const (
testRunMaxID = 99999
testRunMinID = 10000

checkFieldsBody = `{
"fields": ["*"],
"runtime_mappings": {
Expand Down Expand Up @@ -339,8 +335,6 @@ func (r *runner) createServiceOptions(variantName string) servicedeployer.Factor
Variant: variantName,
Type: servicedeployer.TypeTest,
StackVersion: r.stackVersion.Version(),
PackageName: r.options.TestFolder.Package,
DataStream: r.options.TestFolder.DataStream,
RunTearDown: r.options.RunTearDown,
RunTestsOnly: r.options.RunTestsOnly,
RunSetup: r.options.RunSetup,
Expand Down Expand Up @@ -387,7 +381,7 @@ func (r *runner) createServiceInfo() (servicedeployer.ServiceInfo, error) {
svcInfo.Name = r.options.TestFolder.Package
svcInfo.Logs.Folder.Local = r.locationManager.ServiceLogDir()
svcInfo.Logs.Folder.Agent = ServiceLogsAgentDir
svcInfo.Test.RunID = createTestRunID()
svcInfo.Test.RunID = common.CreateTestRunID()

if r.options.RunTearDown || r.options.RunTestsOnly {
logger.Debug("Skip creating output directory")
Expand Down Expand Up @@ -648,10 +642,6 @@ func (r *runner) runTestPerVariant(ctx context.Context, result *testrunner.Resul
return partial, nil
}

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

func (r *runner) isSyntheticsEnabled(ctx context.Context, dataStream, componentTemplatePackage string) (bool, error) {
resp, err := r.options.API.Cluster.GetComponentTemplate(
r.options.API.Cluster.GetComponentTemplate.WithContext(ctx),
Expand Down Expand Up @@ -1258,7 +1248,7 @@ func (r *runner) setupAgent(ctx context.Context, config *testConfig, state Servi
if !r.options.RunIndependentElasticAgent {
return nil, agentdeployer.AgentInfo{}, nil
}
agentRunID := createTestRunID()
agentRunID := common.CreateTestRunID()
if r.options.RunTearDown || r.options.RunTestsOnly {
agentRunID = state.AgentRunID
}
Expand Down

0 comments on commit 418d9a2

Please sign in to comment.