Skip to content

Commit

Permalink
ci(dra): support qualifier for the main branch (#15217)
Browse files Browse the repository at this point in the history
(cherry picked from commit a6cf66b)
  • Loading branch information
v1v authored and mergify[bot] committed Jan 17, 2025
1 parent 5d664d2 commit 101b195
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 14 deletions.
8 changes: 8 additions & 0 deletions .buildkite/scripts/dra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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:
Expand All @@ -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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down
8 changes: 7 additions & 1 deletion go.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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/')
2 changes: 1 addition & 1 deletion internal/beatcmd/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions internal/beatcmd/beat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion internal/beatcmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/beater/api/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)...)
Expand Down
2 changes: 1 addition & 1 deletion internal/beater/api/mux_root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down
6 changes: 3 additions & 3 deletions internal/beater/beater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion internal/beater/processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/elasticsearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion internal/kibana/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
Expand Down
10 changes: 10 additions & 0 deletions internal/version/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package version

import (
"fmt"
"runtime/debug"
"time"
)
Expand All @@ -26,6 +27,7 @@ var (
vcsRevision string
vcsTime time.Time
vcsModified bool
qualifier string
)

func init() {
Expand Down Expand Up @@ -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)
}

0 comments on commit 101b195

Please sign in to comment.