Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java attacher runs only in non-cloud environments #6617

Merged
merged 7 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ docker-compose.yml.bck
Dockerfile.bck
version.asciidoc.bck
.imported-java-agent-pubkey
/agent
22 changes: 21 additions & 1 deletion beater/beater.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
"github.com/elastic/beats/v7/libbeat/publisher/pipetool"

"github.com/elastic/apm-server/beater/config"
javaattacher "github.com/elastic/apm-server/beater/java_attacher"
"github.com/elastic/apm-server/elasticsearch"
"github.com/elastic/apm-server/kibana"
logs "github.com/elastic/apm-server/log"
Expand Down Expand Up @@ -416,7 +417,8 @@ func (s *serverRunner) run(listener net.Listener) error {
cfg := ucfg.Config(*s.rawConfig)
parentCfg := cfg.Parent()
// Check for an environment variable set when running in a cloud environment
if eac := os.Getenv("ELASTIC_AGENT_CLOUD"); eac != "" && s.config.Kibana.Enabled {
eac := os.Getenv("ELASTIC_AGENT_CLOUD")
felixbarny marked this conversation as resolved.
Show resolved Hide resolved
if eac != "" && s.config.Kibana.Enabled {
// Don't block server startup sending the config.
go func() {
if err := kibana.SendConfig(s.runServerContext, kibanaClient, parentCfg); err != nil {
Expand All @@ -425,6 +427,24 @@ func (s *serverRunner) run(listener net.Listener) error {
}()
}

if s.config.JavaAttacherConfig.Enabled {
if eac == "" {
// We aren't running in a cloud environment
go func() {
attacher, err := javaattacher.New(s.config.JavaAttacherConfig)
if err != nil {
s.logger.Errorf("failed to start java attacher: %v", err)
return
}
if err := attacher.Run(s.runServerContext); err != nil {
s.logger.Errorf("failed to run java attacher: %v", err)
}
}()
} else {
s.logger.Error("java attacher not supported in cloud environments")
}
}
stuartnelson3 marked this conversation as resolved.
Show resolved Hide resolved

g, ctx := errgroup.WithContext(s.runServerContext)

// Ensure the libbeat output and go-elasticsearch clients do not index
Expand Down
3 changes: 1 addition & 2 deletions beater/java_attacher/java_attacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ func New(cfg config.JavaAttacherConfig) (JavaAttacher, error) {
}

// javaAttacher is bundled by the server
// TODO: Figure out the real path
var javaAttacher = filepath.FromSlash("/bin/apm-agent-attach-cli-1.24.0-slim.jar")
var javaAttacher = filepath.FromSlash("./java-attacher.jar")

func (j JavaAttacher) Run(ctx context.Context) error {
cmd := j.build(ctx)
Expand Down
2 changes: 1 addition & 1 deletion beater/java_attacher/java_attacher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestBuild(t *testing.T) {

cmd := attacher.build(context.Background())

want := filepath.FromSlash("/usr/bin/java -jar /bin/apm-agent-attach-cli-1.24.0-slim.jar") +
want := filepath.FromSlash("/usr/bin/java -jar ./java-attacher.jar") +
" --continuous --log-level debug --download-agent-version 1.25.0 --exclude-user root --include-main MyApplication " +
"--include-main my-application.jar --include-vmarg elastic.apm.agent.attach=true " +
"--config server_url=http://localhost:8200 --config service_name=my-cool-service"
Expand Down
1 change: 1 addition & 0 deletions changelogs/head.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ https://github.com/elastic/apm-server/compare/7.15\...master[View commits]
- Changed RUM traces to use a dedicated data stream (`traces-apm.rum`). RUM traces are kept for 90 days {pull}6480[6480]
- `apm-server` artifacts now have the apm java-attacher.jar packaged alongside them {pull}6593[6593]
- When `auth.anonymous.enabled` isn't specified and RUM is enabled (`rum.enabled:true`), `auth.anonymous.enabled` will be set to `true` {pull}6607[6607]
- Run the java attacher jar when configured and not in a cloud environment {pull}6617[6617]

[float]
==== Deprecated
Expand Down