Skip to content

Commit d4a4d7a

Browse files
authored
add Elastic Stack and Elastic Package version to test results report (#3070)
Elastic stack version and elastic-package running version are now logged into the running test output when elastic-stack test is run.
1 parent 092615a commit d4a4d7a

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed

cmd/testrunner.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/elastic/elastic-package/internal/testrunner/runners/static"
3333
"github.com/elastic/elastic-package/internal/testrunner/runners/system"
3434
"github.com/elastic/elastic-package/internal/testrunner/script"
35+
"github.com/elastic/elastic-package/internal/version"
3536
)
3637

3738
const testLongDescription = `Use this command to run tests on a package. Currently, the following types of tests are available:
@@ -178,6 +179,13 @@ func testRunnerAssetCommandAction(cmd *cobra.Command, args []string) error {
178179
return fmt.Errorf("failed to read global config: %w", err)
179180
}
180181

182+
stackVersion, err := kibanaClient.Version()
183+
if err != nil {
184+
return fmt.Errorf("fetching stack version failed: %w", err)
185+
}
186+
187+
logger.Info(version.Version())
188+
logger.Infof("elastic-stack: %s\n", stackVersion.Version())
181189
runner := asset.NewAssetTestRunner(asset.AssetTestRunnerOptions{
182190
PackageRoot: packageRoot,
183191
KibanaClient: kibanaClient,
@@ -266,6 +274,7 @@ func testRunnerStaticCommandAction(cmd *cobra.Command, args []string) error {
266274
return fmt.Errorf("failed to read global config: %w", err)
267275
}
268276

277+
logger.Info(version.Version())
269278
runner := static.NewStaticTestRunner(static.StaticTestRunnerOptions{
270279
PackageRoot: packageRoot,
271280
DataStreams: dataStreams,
@@ -384,6 +393,13 @@ func testRunnerPipelineCommandAction(cmd *cobra.Command, args []string) error {
384393
return fmt.Errorf("failed to read global config: %w", err)
385394
}
386395

396+
esClientInfo, err := esClient.Info(ctx)
397+
if err != nil {
398+
return fmt.Errorf("fetching stack version failed: %w", err)
399+
}
400+
401+
logger.Info(version.Version())
402+
logger.Infof("elastic-stack: %s\n", esClientInfo.Version.Number)
387403
runner := pipeline.NewPipelineTestRunner(pipeline.PipelineTestRunnerOptions{
388404
Profile: profile,
389405
PackageRoot: packageRoot,
@@ -576,6 +592,13 @@ func testRunnerSystemCommandAction(cmd *cobra.Command, args []string) error {
576592
return fmt.Errorf("failed to read global config: %w", err)
577593
}
578594

595+
info, err := esClient.Info(ctx)
596+
if err != nil {
597+
return fmt.Errorf("fetching stack version failed: %w", err)
598+
}
599+
600+
logger.Info(version.Version())
601+
logger.Infof("elastic-stack: %s", info.Version.Number)
579602
runner := system.NewSystemTestRunner(system.SystemTestRunnerOptions{
580603
Profile: profile,
581604
PackageRoot: packageRoot,
@@ -742,6 +765,13 @@ func testRunnerPolicyCommandAction(cmd *cobra.Command, args []string) error {
742765
return fmt.Errorf("failed to read global config: %w", err)
743766
}
744767

768+
stackVersion, err := kibanaClient.Version()
769+
if err != nil {
770+
return fmt.Errorf("fetching stack version failed: %w", err)
771+
}
772+
773+
logger.Info(version.Version())
774+
logger.Infof("elastic-stack: %s", stackVersion.Version())
745775
runner := policy.NewPolicyTestRunner(policy.PolicyTestRunnerOptions{
746776
PackageRoot: packageRoot,
747777
KibanaClient: kibanaClient,

cmd/version.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package cmd
66

77
import (
88
"fmt"
9-
"strings"
109

1110
"github.com/spf13/cobra"
1211

@@ -29,13 +28,6 @@ func setupVersionCommand() *cobraext.Command {
2928
}
3029

3130
func versionCommandAction(cmd *cobra.Command, args []string) error {
32-
var sb strings.Builder
33-
sb.WriteString("elastic-package ")
34-
if version.Tag != "" {
35-
sb.WriteString(version.Tag)
36-
sb.WriteString(" ")
37-
}
38-
sb.WriteString(fmt.Sprintf("version-hash %s (build time: %s)", version.CommitHash, version.BuildTimeFormatted()))
39-
fmt.Println(sb.String())
31+
fmt.Println(version.Version())
4032
return nil
4133
}

internal/version/version.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
package version
66

77
import (
8+
"fmt"
89
"runtime/debug"
910
"strconv"
11+
"strings"
1012
"time"
1113
)
1214

@@ -32,8 +34,8 @@ func init() {
3234
}
3335
}
3436

35-
// BuildTimeFormatted method returns the build time preserving the RFC3339 format.
36-
func BuildTimeFormatted() string {
37+
// buildTimeFormatted method returns the build time preserving the RFC3339 format.
38+
func buildTimeFormatted() string {
3739
if BuildTime == "unknown" {
3840
return BuildTime
3941
}
@@ -44,3 +46,14 @@ func BuildTimeFormatted() string {
4446
}
4547
return time.Unix(seconds, 0).Format(time.RFC3339)
4648
}
49+
50+
func Version() string {
51+
var sb strings.Builder
52+
sb.WriteString("elastic-package ")
53+
if Tag != "" {
54+
sb.WriteString(Tag)
55+
sb.WriteString(" ")
56+
}
57+
sb.WriteString(fmt.Sprintf("version-hash %s (build time: %s)", CommitHash, buildTimeFormatted()))
58+
return sb.String()
59+
}

0 commit comments

Comments
 (0)