diff --git a/.buildkite/scripts/dra.sh b/.buildkite/scripts/dra.sh index 73559e6ddcd..bf7d40be1a7 100644 --- a/.buildkite/scripts/dra.sh +++ b/.buildkite/scripts/dra.sh @@ -72,6 +72,7 @@ fi dra() { local workflow=$1 local command=$2 + local qualifier=${ELASTIC_QUALIFIER:-""} echo "--- Run release manager $workflow (DRA command: $command)" docker run --rm \ --name release-manager \ @@ -86,6 +87,7 @@ dra() { --commit $BUILDKITE_COMMIT \ --workflow $workflow \ --artifact-set main \ + --qualifier "$qualifier" \ --version $VERSION | tee rm-output.txt # Create Buildkite annotation similarly done in Beats: @@ -106,3 +108,9 @@ if [[ "${DRA_BRANCH}" != "main" && "${DRA_BRANCH}" != "8.x" ]]; then echo "DRA_BRANCH is neither 'main' nor '8.x'" dra "staging" "$dra_command" fi + +## Exception for main branch as requested by the Release Team. +if [[ "${DRA_BRANCH}" == "main" ]]; then + echo "Exception form main branch with the qualifier alpha1" + dra "staging" "$dra_command" +fi diff --git a/Makefile b/Makefile index 205c43f94cb..beaacb92470 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,9 @@ PYTHON_BIN:=$(PYTHON_VENV_DIR)/bin PYTHON=$(PYTHON_BIN)/python CURRENT_DIR=$(shell dirname $(shell readlink -f $(firstword $(MAKEFILE_LIST)))) +# Support DRA qualifier with the following environment variable. +ELASTIC_QUALIFIER?= + # Create a local config.mk file to override configuration. -include config.mk @@ -38,6 +41,7 @@ APM_SERVER_BINARIES:= \ # Strip binary and inject the Git commit hash and timestamp. LDFLAGS := \ -s \ + -X github.com/elastic/apm-server/internal/version.qualifier=$(ELASTIC_QUALIFIER) \ -X github.com/elastic/beats/v7/libbeat/version.commit=$(GITCOMMIT) \ -X github.com/elastic/beats/v7/libbeat/version.buildTime=$(GITCOMMITTIMESTAMP) diff --git a/go.mk b/go.mk index a4c8491f739..90cbc9485d4 100644 --- a/go.mk +++ b/go.mk @@ -8,5 +8,11 @@ GITROOT ?= $(shell git rev-parse --show-toplevel) GOLANG_VERSION=$(shell cat $(GITROOT)/.go-version) GOARCH:=$(shell go env GOARCH) -APM_SERVER_VERSION=$(shell grep "const Version" $(GITROOT)/internal/version/version.go | cut -d'=' -f2 | tr -d '" ') +APM_SERVER_ONLY_VERSION=$(shell grep "const Version" $(GITROOT)/internal/version/version.go | cut -d'=' -f2 | tr -d '" ') +# DRA uses a qualifier to annotate the type of release (alpha, rc, etc) +ifdef ELASTIC_QUALIFIER + APM_SERVER_VERSION=$(APM_SERVER_ONLY_VERSION)-$(ELASTIC_QUALIFIER) +else + APM_SERVER_VERSION=$(APM_SERVER_ONLY_VERSION) +endif APM_SERVER_VERSION_MAJORMINOR=$(shell echo $(APM_SERVER_VERSION) | sed 's/\(.*\..*\)\..*/\1/') diff --git a/internal/beatcmd/beat.go b/internal/beatcmd/beat.go index ba01835bdb8..b63d99d8f65 100644 --- a/internal/beatcmd/beat.go +++ b/internal/beatcmd/beat.go @@ -116,7 +116,7 @@ func NewBeat(args BeatParams) (*Beat, error) { Beat: "apm-server", ElasticLicensed: args.ElasticLicensed, IndexPrefix: "apm-server", - Version: version.Version, + Version: version.VersionWithQualifier(), Name: beatName, Hostname: hostname, StartTime: time.Now(), diff --git a/internal/beatcmd/beat_test.go b/internal/beatcmd/beat_test.go index fca8509aa1f..ddd34fdf031 100644 --- a/internal/beatcmd/beat_test.go +++ b/internal/beatcmd/beat_test.go @@ -93,7 +93,7 @@ func TestRunnerParams(t *testing.T) { assert.NoError(t, stop()) assert.Equal(t, "apm-server", args.Info.Beat) - assert.Equal(t, version.Version, args.Info.Version) + assert.Equal(t, version.VersionWithQualifier(), args.Info.Version) assert.True(t, args.Info.ElasticLicensed) assert.Equal(t, "my-custom-name", b.Beat.Info.Name) assert.NotZero(t, args.Info.ID) @@ -225,7 +225,7 @@ func TestRunManager_Reloader(t *testing.T) { agentInfo := &proto.AgentInfo{ Id: "elastic-agent-id", - Version: version.Version, + Version: version.VersionWithQualifier(), Snapshot: true, } srv := integration.NewMockServer([]*proto.CheckinExpected{ @@ -358,7 +358,7 @@ func TestRunManager_Reloader_newRunnerError(t *testing.T) { } agentInfo := &proto.AgentInfo{ Id: "elastic-agent-id", - Version: version.Version, + Version: version.VersionWithQualifier(), Snapshot: true, } srv := integration.NewMockServer([]*proto.CheckinExpected{ diff --git a/internal/beatcmd/version.go b/internal/beatcmd/version.go index 29746ff2840..f3405ded4ac 100644 --- a/internal/beatcmd/version.go +++ b/internal/beatcmd/version.go @@ -41,7 +41,7 @@ var versionCommand = &cobra.Command{ fmt.Fprintf(cmd.OutOrStdout(), "apm-server version %s (%s/%s) [%s]\n", - version.Version, runtime.GOOS, runtime.GOARCH, + version.VersionWithQualifier(), runtime.GOOS, runtime.GOARCH, buf.String(), ) return nil diff --git a/internal/beater/api/mux.go b/internal/beater/api/mux.go index 56309566095..639b7ead0a9 100644 --- a/internal/beater/api/mux.go +++ b/internal/beater/api/mux.go @@ -222,7 +222,7 @@ func (r *routeBuilder) rumIntakeHandler() func() (request.Handler, error) { func (r *routeBuilder) rootHandler(publishReady func() bool) func() (request.Handler, error) { return func() (request.Handler, error) { h := root.Handler(root.HandlerConfig{ - Version: version.Version, + Version: version.VersionWithQualifier(), PublishReady: publishReady, }) return middleware.Wrap(h, rootMiddleware(r.cfg, r.authenticator)...) diff --git a/internal/beater/api/mux_root_test.go b/internal/beater/api/mux_root_test.go index b2b2fc1f013..b31f58b0c07 100644 --- a/internal/beater/api/mux_root_test.go +++ b/internal/beater/api/mux_root_test.go @@ -55,7 +55,7 @@ func TestRootHandler_AuthorizationMiddleware(t *testing.T) { } err = json.Unmarshal(rec.Body.Bytes(), &result) require.NoError(t, err) - assert.Equal(t, version.Version, result.Version) + assert.Equal(t, version.VersionWithQualifier(), result.Version) }) } diff --git a/internal/beater/beater.go b/internal/beater/beater.go index c6c2184347b..fe779bee8fe 100644 --- a/internal/beater/beater.go +++ b/internal/beater/beater.go @@ -535,7 +535,7 @@ func newInstrumentation(rawConfig *agentconfig.C) (instrumentation.Instrumentati cfg, err := rawConfig.Child("instrumentation", -1) if err != nil || !cfg.Enabled() { // Fallback to instrumentation.New if the configs are not present or disabled. - return instrumentation.New(rawConfig, "apm-server", version.Version) + return instrumentation.New(rawConfig, "apm-server", version.VersionWithQualifier()) } if err := cfg.Unpack(&apmCfg); err != nil { return nil, err @@ -578,7 +578,7 @@ func newInstrumentation(rawConfig *agentconfig.C) (instrumentation.Instrumentati os.Setenv(envSamplingRate, strconv.FormatFloat(float64(r), 'f', -1, 32)) defer os.Unsetenv(envSamplingRate) } - return instrumentation.New(rawConfig, "apm-server", version.Version) + return instrumentation.New(rawConfig, "apm-server", version.VersionWithQualifier()) } func maxConcurrentDecoders(memLimitGB float64) uint { @@ -870,7 +870,7 @@ func (s *Runner) newLibbeatFinalBatchProcessor( beatInfo := beat.Info{ Beat: "apm-server", IndexPrefix: "apm-server", - Version: version.Version, + Version: version.VersionWithQualifier(), Hostname: hostname, Name: hostname, } diff --git a/internal/beater/processors.go b/internal/beater/processors.go index dd57b430ed0..1438de0f363 100644 --- a/internal/beater/processors.go +++ b/internal/beater/processors.go @@ -79,7 +79,7 @@ func newObserverBatchProcessor() modelpb.ProcessBatchFunc { observer := (*b)[i].Observer observer.Hostname = hostname observer.Type = "apm-server" - observer.Version = version.Version + observer.Version = version.VersionWithQualifier() } return nil } diff --git a/internal/elasticsearch/client.go b/internal/elasticsearch/client.go index aa7757ca3ae..bb9be3376b5 100644 --- a/internal/elasticsearch/client.go +++ b/internal/elasticsearch/client.go @@ -36,7 +36,7 @@ var retryableStatuses = []int{ http.StatusTooManyRequests, } -var userAgent = fmt.Sprintf("Elastic-APM-Server/%s go-elasticsearch/%s", version.Version, esv8.Version) +var userAgent = fmt.Sprintf("Elastic-APM-Server/%s go-elasticsearch/%s", version.VersionWithQualifier(), esv8.Version) type Client = esv8.Client diff --git a/internal/kibana/client.go b/internal/kibana/client.go index cf10c4a0d25..b4d8a4d7158 100644 --- a/internal/kibana/client.go +++ b/internal/kibana/client.go @@ -43,7 +43,7 @@ func NewClient(cfg ClientConfig) (*Client, error) { cfg.IgnoreVersion = true client, err := kibana.NewClientWithConfig( &cfg, "apm-server", - version.Version, + version.VersionWithQualifier(), version.CommitHash(), version.CommitTime().String(), ) diff --git a/internal/version/settings.go b/internal/version/settings.go index 1485abfa346..af6f4fae404 100644 --- a/internal/version/settings.go +++ b/internal/version/settings.go @@ -18,6 +18,7 @@ package version import ( + "fmt" "runtime/debug" "time" ) @@ -26,6 +27,7 @@ var ( vcsRevision string vcsTime time.Time vcsModified bool + qualifier string ) func init() { @@ -58,3 +60,11 @@ func CommitTime() time.Time { func VCSModified() bool { return vcsModified } + +// VersionWithQualifier returns the version and the qualifier. +func VersionWithQualifier() string { + if qualifier == "" { + return Version + } + return fmt.Sprintf("%s-%s", Version, qualifier) +}