Skip to content

Commit 7841c8c

Browse files
[9.2] (backport #11237) Add OTEL_COMPONENT=true to packaging to allow building a seperate OTEL EDOT binary (#11417)
* Add `OTEL_COMPONENT=true` to packaging to allow building a seperate OTEL EDOT binary (#11237) * Add ability to build seperate edot binary. Add build flag to change build. * Get this working. * Fix crossBuild log. * Fix imports. * fixes from code review. * Revert the change for packageAgent. * Update binary name. * Fix docker container. Add CI steps for build. * Change to serial deps. * Try not using go list. * Revert "Change to serial deps." This reverts commit 329de79. * Fix BK to build windows OTEL_COMPONENT. (cherry picked from commit 9f1c464) * Change to SerialDeps. --------- Co-authored-by: Blake Rouse <[email protected]>
1 parent 81dcd10 commit 7841c8c

File tree

15 files changed

+289
-23
lines changed

15 files changed

+289
-23
lines changed

.buildkite/integration.pipeline.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ steps:
3939
machineType: "n2-standard-8"
4040
image: "${IMAGE_UBUNTU_2204_X86_64}"
4141

42+
# Temporary build step to verify building the elastic-agent works.
43+
# This will be removed once OTEL_COMPONENT is removed, because it
44+
# became the default.
45+
- label: ":package: amd64: OTEL_COMPONENT zip,tar.gz,rpm,deb "
46+
key: packaging-amd64-otel-component
47+
env:
48+
PLATFORMS: "windows/amd64,linux/amd64"
49+
PACKAGES: "zip,tar.gz,rpm,deb"
50+
OTEL_COMPONENT: "true"
51+
command: ".buildkite/scripts/steps/integration-package.sh"
52+
artifact_paths:
53+
- build/distributions/**
54+
retry:
55+
automatic:
56+
limit: 1
57+
agents:
58+
provider: "gcp"
59+
machineType: "n2-standard-8"
60+
image: "${IMAGE_UBUNTU_2204_X86_64}"
61+
4262
- label: ":package: amd64: FIPS tar.gz"
4363
key: "packaging-amd64-fips"
4464
env:
@@ -73,6 +93,26 @@ steps:
7393
instanceType: "c6g.2xlarge"
7494
image: "${IMAGE_UBUNTU_2204_ARM_64}"
7595

96+
# Temporary build step to verify building the elastic-agent works.
97+
# This will be removed once OTEL_COMPONENT is removed, because it
98+
# became the default.
99+
- label: ":package: arm64: OTEL_COMPONENT zip,tar.gz"
100+
key: packaging-arm64-otel-component
101+
env:
102+
PLATFORMS: "windows/arm64,linux/arm64"
103+
PACKAGES: "tar.gz,zip"
104+
OTEL_COMPONENT: "true"
105+
command: ".buildkite/scripts/steps/integration-package.sh"
106+
artifact_paths:
107+
- build/distributions/**
108+
retry:
109+
automatic:
110+
limit: 1
111+
agents:
112+
provider: "aws"
113+
instanceType: "c6g.2xlarge"
114+
image: "${IMAGE_UBUNTU_2204_ARM_64}"
115+
76116
- label: ":package: arm64: FIPS tar.gz"
77117
key: "packaging-arm64-fips"
78118
env:
@@ -158,6 +198,40 @@ steps:
158198
diskSizeGb: 200
159199
image: "${IMAGE_UBUNTU_2204_ARM_64}"
160200

201+
- label: ":package: amd64: OTEL_COMPONENT Containers"
202+
key: packaging-containers-amd64-otel-component
203+
env:
204+
PACKAGES: "docker"
205+
PLATFORMS: "linux/amd64"
206+
OTEL_COMPONENT: "true"
207+
command: |
208+
.buildkite/scripts/steps/integration-package.sh
209+
artifact_paths:
210+
- build/distributions/**
211+
agents:
212+
provider: "gcp"
213+
machineType: "n2-standard-8"
214+
diskSizeGb: 200
215+
image: "${IMAGE_UBUNTU_2204_X86_64}"
216+
plugins:
217+
- *vault_docker_login
218+
219+
- label: ":package: arm64: OTEL_COMPONENT Containers"
220+
key: packaging-containers-arm64-otel-component
221+
env:
222+
PACKAGES: "docker"
223+
PLATFORMS: "linux/arm64"
224+
OTEL_COMPONENT: "true"
225+
command: |
226+
.buildkite/scripts/steps/integration-package.sh
227+
artifact_paths:
228+
- build/distributions/**
229+
agents:
230+
provider: "aws"
231+
instanceType: "c6g.2xlarge"
232+
diskSizeGb: 200
233+
image: "${IMAGE_UBUNTU_2204_ARM_64}"
234+
161235
- label: "Triggering Integration tests"
162236
command: "buildkite-agent pipeline upload .buildkite/bk.integration.pipeline.yml"
163237

dev-tools/mage/build.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ func DefaultBuildArgs() BuildArgs {
108108
}
109109
}
110110

111+
if OTELComponentBuild {
112+
args.ExtraFlags = append(args.ExtraFlags, "-tags=otelexternal")
113+
}
114+
111115
if DevBuild {
112116
// Disable optimizations (-N) and inlining (-l) for debugging.
113117
args.ExtraFlags = append(args.ExtraFlags, `-gcflags=all=-N -l`)

dev-tools/mage/crossbuild.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ type CrossBuildOption func(params *crossBuildParams)
7474
// ImageSelectorFunc returns the name of the builder image.
7575
type ImageSelectorFunc func(platform string) (string, error)
7676

77+
// WithName adjust the name of the cross build action.
78+
func WithName(name string) CrossBuildOption {
79+
return func(params *crossBuildParams) {
80+
params.Name = name
81+
}
82+
}
83+
7784
// ForPlatforms filters the platforms based on the given expression.
7885
func ForPlatforms(expr string) func(params *crossBuildParams) {
7986
return func(params *crossBuildParams) {
@@ -123,6 +130,7 @@ func AddPlatforms(expressions ...string) func(params *crossBuildParams) {
123130
}
124131

125132
type crossBuildParams struct {
133+
Name string
126134
Platforms BuildPlatformList
127135
Target string
128136
Serial bool
@@ -132,11 +140,12 @@ type crossBuildParams struct {
132140

133141
// CrossBuild executes a given build target once for each target platform.
134142
func CrossBuild(options ...CrossBuildOption) error {
135-
fmt.Println("--- CrossBuild Elastic-Agent")
136143
params := crossBuildParams{Platforms: Platforms, Target: defaultCrossBuildTarget, ImageSelector: CrossBuildImage}
144+
params.Name = "Elastic-Agent"
137145
for _, opt := range options {
138146
opt(&params)
139147
}
148+
fmt.Printf("--- CrossBuild %s\n", params.Name)
140149

141150
if len(params.Platforms) == 0 {
142151
log.Printf("Skipping cross-build of target=%v because platforms list is empty.", params.Target)
@@ -178,7 +187,7 @@ func CrossBuild(options ...CrossBuildOption) error {
178187
// Build the magefile for Linux, so we can run it inside the container.
179188
mg.Deps(buildMage)
180189

181-
log.Println("crossBuild: Platform list =", params.Platforms)
190+
log.Printf("crossBuild(%s): Platform list = %s\n", params.Name, params.Platforms)
182191
var deps []interface{}
183192
for _, buildPlatform := range params.Platforms {
184193
if !buildPlatform.Flags.CanCrossBuild() {
@@ -364,6 +373,7 @@ func (b GolangCrossBuilder) Build() error {
364373
"--env", fmt.Sprintf("DEV=%v", DevBuild),
365374
"--env", fmt.Sprintf("EXTERNAL=%v", ExternalBuild),
366375
"--env", fmt.Sprintf("FIPS=%v", FIPSBuild),
376+
"--env", fmt.Sprintf("OTEL_COMPONENT=%v", OTELComponentBuild),
367377
"-v", repoInfo.RootDir+":"+mountPoint,
368378
"-w", workDir,
369379
image,

dev-tools/mage/gotest.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ func testTagsFromEnv() []string {
8888
if FIPSBuild {
8989
tags = append(tags, "requirefips", "ms_tls13kdf")
9090
}
91+
if OTELComponentBuild {
92+
tags = append(tags, "otelexternal")
93+
}
9194
return tags
9295
}
9396

dev-tools/mage/settings.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ var (
8989

9090
BeatProjectType ProjectType
9191

92-
Snapshot bool
93-
DevBuild bool
94-
ExternalBuild bool
95-
FIPSBuild bool
92+
Snapshot bool
93+
DevBuild bool
94+
ExternalBuild bool
95+
FIPSBuild bool
96+
OTELComponentBuild bool
9697

9798
versionQualified bool
9899
versionQualifier string
@@ -164,6 +165,11 @@ func initGlobals() {
164165
panic(fmt.Errorf("failed to parse FIPS env value: %w", err))
165166
}
166167

168+
OTELComponentBuild, err = strconv.ParseBool(EnvOr("OTEL_COMPONENT", "false"))
169+
if err != nil {
170+
panic(fmt.Errorf("failed to parse OTEL_COMPONENT env value: %w", err))
171+
}
172+
167173
versionQualifier, versionQualified = os.LookupEnv("VERSION_QUALIFIER")
168174

169175
// order matters: this will override some of the values. Those values can be used
@@ -230,6 +236,7 @@ func varMap(args ...map[string]interface{}) map[string]interface{} {
230236
"DEV": DevBuild,
231237
"EXTERNAL": ExternalBuild,
232238
"FIPS": FIPSBuild,
239+
"OTEL_COMPONENT": OTELComponentBuild,
233240
"Qualifier": versionQualifier,
234241
"CI": CI,
235242
}

dev-tools/packaging/packages.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ shared:
369369
'data/{{.BeatName}}-{{ commit_short }}/{{.BeatName}}{{.BinaryExt}}':
370370
source: build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}}
371371
mode: 0755
372+
'data/{{.BeatName}}-{{ commit_short }}/elastic-otel-collector{{.BinaryExt}}':
373+
source: build/golang-crossbuild/elastic-otel-collector-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}}
374+
mode: 0755
375+
skip_on_missing: true
372376
'data/{{.BeatName}}-{{ commit_short }}/package.version':
373377
content: >
374378
{{ agent_package_version }}
@@ -390,6 +394,10 @@ shared:
390394
'data/{{.BeatName}}-{{ commit_short }}/elastic-agent.app/Contents/MacOS/{{.BeatName}}{{.BinaryExt}}':
391395
source: build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}}
392396
mode: 0755
397+
'data/{{.BeatName}}-{{ commit_short }}/elastic-otel-collector{{.BinaryExt}}':
398+
source: build/golang-crossbuild/elastic-otel-collector-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}}
399+
mode: 0755
400+
skip_on_missing: true
393401
'data/{{.BeatName}}-{{ commit_short }}/package.version':
394402
content: >
395403
{{ agent_package_version }}

dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ RUN true && \
4444
(chmod 0755 {{ $beatHome }}/data/elastic-agent-*/components/pf-elastic-collector || true) && \
4545
(chmod 0755 {{ $beatHome }}/data/elastic-agent-*/components/pf-elastic-symbolizer || true) && \
4646
(chmod 0755 {{ $beatHome }}/data/elastic-agent-*/components/pf-host-agent || true) && \
47+
(chmod 0755 {{ $beatHome }}/data/elastic-agent-*/elastic-otel-collector || true) && \
4748
(chmod 0755 {{ $beatHome }}/data/elastic-agent-*/otelcol || true) && \
4849
(chmod 0755 {{ $beatHome }}/otelcol || true) && \
4950
find {{ $beatHome }}/data/elastic-agent-{{ commit_short }}/components -name "*.yml*" -type f -exec chmod 0644 {} \; && \

internal/edot/cmd/otel.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ func NewOtelCommandWithArgs(args []string, streams *cli.IOStreams) *cobra.Comman
7070
SilenceErrors: true,
7171
}
7272

73+
origHelp := cmd.HelpFunc()
7374
cmd.SetHelpFunc(func(c *cobra.Command, s []string) {
7475
hideInheritedFlags(c)
75-
c.Root().HelpFunc()(c, s)
76+
origHelp(c, s)
7677
})
7778

7879
SetupOtelFlags(cmd.Flags())

internal/edot/cmd/validate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ func newValidateCommandWithArgs(_ []string, _ *cli.IOStreams) *cobra.Command {
3030
}
3131

3232
SetupOtelFlags(cmd.Flags())
33+
origHelpFunc := cmd.HelpFunc()
3334
cmd.SetHelpFunc(func(c *cobra.Command, s []string) {
3435
hideInheritedFlags(c)
35-
c.Root().HelpFunc()(c, s)
36+
origHelpFunc(c, s)
3637
})
3738

3839
return cmd

internal/edot/main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
// or more contributor license agreements. Licensed under the Elastic License 2.0;
3+
// you may not use this file except in compliance with the Elastic License 2.0.
4+
5+
package main
6+
7+
import (
8+
"fmt"
9+
"os"
10+
11+
edotCmd "github.com/elastic/elastic-agent/internal/edot/cmd"
12+
"github.com/elastic/elastic-agent/internal/pkg/cli"
13+
)
14+
15+
func main() {
16+
cmd := edotCmd.NewOtelCommandWithArgs(os.Args, cli.NewIOStreams())
17+
err := cmd.Execute()
18+
if err != nil {
19+
fmt.Fprintf(os.Stderr, "%v\n", err)
20+
os.Exit(1)
21+
}
22+
}

0 commit comments

Comments
 (0)