Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 docs/framework-dynatrace_one_agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The credential payload of the service may contain the following entries:
| `environmentid` | Your Dynatrace environment ID is the unique identifier of your Dynatrace environment. You can find it in the deploy Dynatrace section within your environment.
| `networkzone` | (Optional) Network zones are Dynatrace entities that represent your network structure. They help you to route the traffic efficiently, avoiding unnecessary traffic across data centers and network regions. Enter the network zone you wish to pass to the server during the OneAgent Download.
| `skiperrors` | (Optional) The errors during agent download are skipped and the injection is disabled. Use this option at your own risk. Possible values are 'true' and 'false'. This option is disabled by default!
| `enablefips`| (Optional) Enables the use of [FIPS 140 cryptographic algorithms](https://docs.dynatrace.com/docs/shortlink/oneagentctl#fips-140). Possible values are 'true' and 'false'. This option is disabled by default!

## Configuration
For general information on configuring the buildpack, including how to specify configuration values through environment variables, refer to [Configuration and Extension][].
Expand Down
27 changes: 20 additions & 7 deletions lib/java_buildpack/framework/dynatrace_one_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ def release

manifest = agent_manifest

@droplet.java_opts.add_agentpath(agent_path(manifest))
@droplet.java_opts.add_preformatted_options('-Xshare:off')
environment_variables = @droplet.environment_variables
environment_variables.add_environment_variable(LD_PRELOAD, agent_path(manifest))

if enable_fips?
File.delete(@droplet.sandbox + 'agent/dt_fips_disabled.flag')
end

dynatrace_environment_variables(manifest)
end
Expand All @@ -87,6 +91,8 @@ def supports?

APITOKEN = 'apitoken'

ENABLE_FIPS = 'enablefips'

DT_APPLICATION_ID = 'DT_APPLICATIONID'

DT_CONNECTION_POINT = 'DT_CONNECTION_POINT'
Expand All @@ -99,6 +105,8 @@ def supports?

DT_NETWORK_ZONE = 'DT_NETWORK_ZONE'

LD_PRELOAD = 'LD_PRELOAD'

ENVIRONMENTID = 'environmentid'

FILTER = /dynatrace/.freeze
Expand All @@ -107,8 +115,9 @@ def supports?

SKIP_ERRORS = 'skiperrors'

private_constant :APIURL, :APITOKEN, :DT_APPLICATION_ID, :DT_CONNECTION_POINT, :DT_NETWORK_ZONE, :DT_LOGSTREAM,
:DT_TENANT, :DT_TENANTTOKEN, :ENVIRONMENTID, :FILTER, :NETWORKZONE, :SKIP_ERRORS
private_constant :APIURL, :APITOKEN, :ENABLE_FIPS, :DT_APPLICATION_ID, :DT_CONNECTION_POINT, :DT_NETWORK_ZONE,
:DT_LOGSTREAM, :DT_TENANT, :DT_TENANTTOKEN, :LD_PRELOAD, :ENVIRONMENTID, :FILTER, :NETWORKZONE,
:SKIP_ERRORS

def agent_download_url
download_uri = "#{api_base_url(credentials)}/v1/deployment/installer/agent/unix/paas/latest?include=java" \
Expand All @@ -126,8 +135,8 @@ def agent_manifest

def agent_path(manifest)
technologies = manifest['technologies']
java_binaries = technologies['java']['linux-x86-64']
loader = java_binaries.find { |bin| bin['binarytype'] == 'loader' }
java_binaries = technologies['process']['linux-x86-64']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change from java to process ?

Copy link
Contributor Author

@joushx joushx Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of java is for historical reasons. process is now the default and also used in other buildpacks (e.g. https://github.com/Dynatrace/libbuildpack-dynatrace/blob/master/hook.go#L403)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok!

loader = java_binaries.find { |bin| bin['binarytype'] == 'primary' }
@droplet.sandbox + loader['path']
end

Expand Down Expand Up @@ -191,7 +200,11 @@ def logstream?
end

def skip_errors?
credentials[SKIP_ERRORS].to_b
credentials[SKIP_ERRORS] == "true"
Copy link
Contributor

@anthonydahanne anthonydahanne Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ignoring credentials[SKIP_ERRORS] ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry my mistake ; should be the same - why the change though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We found that the method was not working in the way we expected it (see https://try.ruby-lang.org/playground/#code=class+String%0A++def+to_b%0A++++casecmp+'true'%0A++end%0Aend%0A%0Aif+%22false%22.to_b%0A++puts+%22yes%22%0Aend&engine=cruby-3.2.0).

Also, from my understanding it would match against "t" or other parts of "true". Which contradicts the information in our documentation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, makes sense!

end

def enable_fips?
credentials[ENABLE_FIPS] == "true"
Copy link
Contributor

@anthonydahanne anthonydahanne Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, why is it unconditional?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry my mistake - all is fine!

end

def tenanttoken(manifest)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"technologies" : {
"java" : {
"process" : {
"linux-x86-64" : [
{
"path": "agent/lib64/liboneagentloader.so",
"binarytype" : "loader"
"path": "agent/lib64/liboneagentproc.so",
"binarytype" : "primary"
}
]
}
Expand Down
Binary file modified spec/fixtures/stub-dynatrace-one-agent.zip
Binary file not shown.
11 changes: 5 additions & 6 deletions spec/java_buildpack/framework/dynatrace_one_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,17 @@

component.compile

expect(sandbox + 'agent/lib64/liboneagentloader.so').to exist
expect(sandbox + 'agent/lib64/liboneagentproc.so').to exist
expect(sandbox + 'manifest.json').to exist
end

it 'updates JAVA_OPTS with agent loader and share set to off',
it 'sets LD_PRELOAD with liboneagentproc',
app_fixture: 'framework_dynatrace_one_agent' do

component.release

expect(java_opts).to include('-agentpath:$PWD/.java-buildpack/dynatrace_one_agent/agent/lib64/' \
'liboneagentloader.so')
expect(java_opts).to include('-Xshare:off')
expect(environment_variables).to include('LD_PRELOAD=$PWD/.java-buildpack/dynatrace_one_agent/agent/lib64/' \
'liboneagentproc.so')
end

it 'updates environment variables',
Expand Down Expand Up @@ -112,7 +111,7 @@

component.compile

expect(sandbox + 'agent/lib64/liboneagentloader.so').to exist
expect(sandbox + 'agent/lib64/liboneagentproc.so').to exist
expect(sandbox + 'manifest.json').to exist
end
end
Expand Down