Skip to content

Commit

Permalink
Polishing after #893 (#894)
Browse files Browse the repository at this point in the history
-  Remove DynatraceAppmonAgent from the component list. This was missed when AppMon Agent was removed.
- Fixes syntax error with missing `end` block
- Fixes Rubocop violation for single line if blocks, use `cmd if expr` syntax intead
- Adds referenced but missing method to pull the networkzone property from credentials
- Adds docs for the networkzone property
- Adds a unit test to validate that networkzone is passed in the URL when present in the binding
  • Loading branch information
Daniel Mikusa committed Jul 14, 2021
1 parent 5483a87 commit fd50c13
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
1 change: 0 additions & 1 deletion config/components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ frameworks:
- "JavaBuildpack::Framework::ContrastSecurityAgent"
- "JavaBuildpack::Framework::DatadogJavaagent"
- "JavaBuildpack::Framework::Debug"
- "JavaBuildpack::Framework::DynatraceAppmonAgent"
- "JavaBuildpack::Framework::DynatraceOneAgent"
- "JavaBuildpack::Framework::ElasticApmAgent"
- "JavaBuildpack::Framework::GoogleStackdriverDebugger"
Expand Down
1 change: 1 addition & 0 deletions docs/framework-dynatrace_one_agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The credential payload of the service may contain the following entries:
| `apitoken` | The token for integrating your Dynatrace environment with Cloud Foundry. You can find it in the deploy Dynatrace section within your environment.
| `apiurl` | (Optional) The base URL of the Dynatrace API. If you are using Dynatrace Managed you will need to set this property to `https://<your-managed-server-url>/e/<environmentId>/api`. If you are using Dynatrace SaaS you don't need to set this property.
| `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!

## Configuration
Expand Down
14 changes: 7 additions & 7 deletions lib/java_buildpack/framework/dynatrace_one_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,10 @@ def supports?

def agent_download_url
download_uri = "#{api_base_url(credentials)}/v1/deployment/installer/agent/unix/paas/latest?include=java" \
"&bitness=64" \
'&bitness=64' \
"&Api-Token=#{credentials[APITOKEN]}"
#
# setting networkzone parameter if it's configured
if networkzone?
download_uri += "&networkzone=#{networkzone_value}"

download_uri += "&networkzone=#{networkzone}" if networkzone?

['latest', download_uri]
end
Expand Down Expand Up @@ -180,6 +178,10 @@ def expand(file)
end
end

def networkzone
credentials[NETWORKZONE]
end

def networkzone?
credentials.key?(NETWORKZONE)
end
Expand All @@ -201,8 +203,6 @@ def unpack_agent(root)
FileUtils.mv(root + 'agent', @droplet.sandbox)
FileUtils.mv(root + 'manifest.json', @droplet.sandbox)
end

end

end
end
25 changes: 25 additions & 0 deletions spec/java_buildpack/framework/dynatrace_one_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,31 @@

end

context do

before do
allow(services).to receive(:one_service?).with(/dynatrace/, 'apitoken', 'environmentid').and_return(true)
allow(services).to receive(:find_service).and_return('credentials' => { 'environmentid' => 'test-environmentid',
'apiurl' => 'test-apiurl',
'apitoken' => 'test-apitoken',
'networkzone' => 'test-network-zone' })

allow(application_cache).to receive(:get)
.with('test-apiurl/v1/deployment/installer/agent/unix/paas/latest?include=java&bitness=64&' \
'Api-Token=test-apitoken&networkzone=test-network-zone')
.and_yield(Pathname.new('spec/fixtures/stub-dynatrace-one-agent.zip').open, false)
end

it 'downloads Dynatrace agent zip with networkzone',
cache_fixture: 'stub-dynatrace-one-agent.zip' do

component.compile

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

context do

before do
Expand Down

0 comments on commit fd50c13

Please sign in to comment.