Skip to content

Commit 1393184

Browse files
author
Christopher Frost
committed
Refactor the Dynatrace support
This commit moves the Dynatrace to be inline with the other supported frameworks. Also includes updates to the documentation. The support has been tested against a live Dynatrace server. [#95410056]
1 parent c862ac8 commit 1393184

3 files changed

Lines changed: 51 additions & 62 deletions

File tree

docs/framework-dyna_trace_agent.md

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# DynaTrace Agent Framework
22
The DynaTrace Agent Framework causes an application to be automatically configured to work with a bound [DynaTrace Service][] instance (Free trials available).
33

4-
The Cloud Foundry pushed application name is used as the `agent group` in DynaTrace, and must be pre-configured on the DynaTrace server.
5-
A system profile may be provided as an optional argument (defaults to `Monitoring`).
4+
The applications Cloud Foundry name is used as the `agent group` in DynaTrace, and must be pre-configured on the DynaTrace server.
65

7-
**Current Issues:**
8-
* The DynaTrace agent slows down app execution significantly at first, but gets faster over time. You may want to update your CF deployment manifest to set `maximum_health_check_timeout` to 180 or more and/or execute `cf push -t 180` or more when pushing a DynaTrace-monitored application.
6+
**NOTE**
97

10-
* As you `cf push` multiple times, many dead penguins will litter the DynaTrace agent dashboard, as CF launches/disposes application containers. These can be hidden but will collect in the dynatrace database.
8+
* The DynaTrace agent slows down app execution significantly at first, but gets faster over time. Setting the application manifest to contain `maximum_health_check_timeout` of 180 or more and/or using `cf push -t 180` or more when pushing a DynaTrace-monitored application may help.
9+
* Multiple `cf push`s will cause dead penguins to build up in the DynaTrace agent dashboard, as CF launches/disposes application containers. These can be hidden but will collect in the dynatrace database.
1110

1211
<table>
1312
<tr>
@@ -31,10 +30,12 @@ The credential payload of the service may contain the following entries:
3130

3231
| Name | Description
3332
| ---- | -----------
34-
| `server` | The DynaTrace collector hostname to connect to. Use `host:port` format for a specific port number.
35-
| `profile` | (optional) The DynaTrace server profile this is associated with. Uses `Monitoring` by default.
33+
| `server` | The DynaTrace collector hostname to connect to. Use `host:port` format for a specific port number.
34+
| `profile` | (Optional) The DynaTrace server profile this is associated with. Uses `Monitoring` by default.
3635

37-
**NOTE** Be sure to open an Application Security Group to your DynaTrace collector prior to starting your application:
36+
**NOTE**
37+
38+
Be sure to open an Application Security Group to your DynaTrace collector prior to starting the application:
3839
```
3940
$ cat security.json
4041
[
@@ -59,39 +60,18 @@ TIP: Changes will not apply to existing running applications until they are rest
5960
## Configuration
6061
For general information on configuring the buildpack, refer to [Configuration and Extension][].
6162

62-
The framework can be configured by modifying the [`dyna_trace_agent.yml`][] file in the buildpack fork. The framework uses the [`Repository` utility support][repositories] and so it supports the [version syntax][] defined there.
63+
The framework can be configured by modifying the [`config/dyna_trace_agent.yml`][] file in the buildpack fork. The framework uses the [`Repository` utility support][repositories] and so it supports the [version syntax][] defined there.
6364

6465
| Name | Description
6566
| ---- | -----------
6667
| `repository_root` | The URL of the DynaTrace repository index ([details][repositories]).
6768
| `version` | The version of DynaTrace to use. This buildpack framework has been tested on 6.1.0.
6869

69-
70-
**NOTE:** This framework does not connect to a pre-populated repository. Instead you will need to create your own repository by:
71-
72-
1. Downloading the DynaTrace agent unix binary (in JAR format) to an HTTP-accesible location
73-
1. Uploading an `index.yml` file with a mapping from the version of the agent to its location to the same HTTP-accessible location
74-
1. Configuring the [`dyna_trace_agent.yml`][] file to point to the root of the repository holding both the index and agent binary
75-
76-
Sample **`repository_root`** for [`dyna_trace_agent.yml`][] (under java-buildpack/config) assuming a bosh-lite setup and a local webserver (e.g. `brew install tomcat7`) on port 8080
77-
78-
```
79-
repository_root: "http://files.192.168.50.1.xip.io:8080/fileserver/dynatrace"
80-
```
81-
82-
The buildpack would look for an **`index.yml`** file at the specified **repository_root** for obtaining the DynaTrace agent.
83-
84-
The index.yml at the repository_root location should have a entry matching the DynaTrace version and the corresponding DynaTrace agent download JAR
85-
86-
```
87-
---
88-
6.1.0.7880: http://files.192.168.50.1.xip.io:8080/fileserver/dynatrace/dynatrace-agent-6.1.0.7880-unix.jar
89-
```
90-
91-
Ensure the DynaTrace binary is available at the location indicated by the index.yml referred by the DynaTrace repository_root.
70+
### Additional Resources
71+
The framework can also be configured by overlaying a set of resources on the default distribution. To do this, add files to the `resources/ca_wily_agent` directory in the buildpack fork. For example, to override the default profile add your custom profile to `resources/introscope_agent/`.
9272

9373
[Configuration and Extension]: ../README.md#configuration-and-extension
94-
[`dyna_trace_agent.yml`]: ../config/dyna_trace_agent.yml
74+
[`config/dyna_trace_agent.yml`]: ../config/dyna_trace_agent.yml
9575
[DynaTrace Service]: https://dynatrace.com
9676
[repositories]: extending-repositories.md
9777
[version syntax]: extending-repositories.md#version-syntax-and-ordering

lib/java_buildpack/framework/dyna_trace_agent.rb

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,14 @@ class DynaTraceAgent < JavaBuildpack::Component::VersionedDependencyComponent
2828

2929
# (see JavaBuildpack::Component::BaseComponent#compile)
3030
def compile
31-
download_zip false
31+
download(@version, @uri) { |file| expand file }
3232
@droplet.copy_resources
33-
FileUtils.mkdir(home_dir)
34-
FileUtils.mv(@droplet.sandbox + 'agent/linux-x86-64/agent', home_dir)
35-
delete_extra_files
3633
end
3734

3835
# (see JavaBuildpack::Component::BaseComponent#release)
3936
def release
40-
@droplet.java_opts
41-
.add_agentpath_with_props(agent_dir + 'libdtagent.so',
42-
name: application_name + '_' + profile_name,
43-
server: server)
37+
@droplet.java_opts.add_agentpath_with_props(agent_path, name: agent_name, server: server)
38+
# -agentpath:<path to libdtagent.so>=name=Tomcat_Monitoring,server=ubuntu:9998
4439
end
4540

4641
protected
@@ -56,33 +51,48 @@ def supports?
5651

5752
private_constant :FILTER
5853

59-
def application_name
60-
@application.details['application_name']
54+
def agent_dir
55+
@droplet.sandbox + 'agent'
6156
end
6257

63-
def profile_name
64-
@application.services.find_service(FILTER)['credentials']['profile'] || 'Monitoring'
58+
def agent_path
59+
agent_dir + lib_name + 'libdtagent.so'
6560
end
6661

67-
def agent_dir
68-
@droplet.sandbox + 'home/agent/lib64'
62+
def agent_name
63+
"#{@application.details['application_name']}_#{profile_name}"
64+
end
65+
66+
def architecture
67+
`uname -m`.strip
6968
end
7069

71-
def delete_extra_files
72-
FileUtils.rm_rf(@droplet.sandbox + 'agent')
73-
FileUtils.rm_rf(@droplet.sandbox + 'init.d')
74-
FileUtils.rm_rf(@droplet.sandbox + 'com')
75-
FileUtils.rm_rf(@droplet.sandbox + 'org')
76-
FileUtils.rm_rf(@droplet.sandbox + 'META_INF')
77-
FileUtils.rm_f(@droplet.sandbox + 'YouShouldNotHaveUnzippedMe.txt')
70+
def expand(file)
71+
with_timing "Expanding Dynatrace to #{@droplet.sandbox.relative_path_from(@droplet.root)}" do
72+
Dir.mktmpdir do |root|
73+
root_path = Pathname.new(root)
74+
shell "unzip -qq #{file.path} -d #{root_path} 2>&1"
75+
unpack_agent root_path
76+
end
77+
end
7878
end
7979

80-
def logs_dir
81-
@droplet.sandbox + 'home/log'
80+
def lib_name
81+
architecture == 'x86_64' || architecture == 'i686' ? 'lib64' : 'lib'
8282
end
8383

84-
def home_dir
85-
@droplet.sandbox + 'home'
84+
def agent_unpack_path
85+
architecture == 'x86_64' || architecture == 'i686' ? 'linux-x86-64/agent' : 'linux-x86-32/agent'
86+
end
87+
88+
def unpack_agent(root)
89+
FileUtils.mkdir_p(agent_dir)
90+
FileUtils.mv(root + 'agent' + agent_unpack_path + 'conf', agent_dir)
91+
FileUtils.mv(root + 'agent' + agent_unpack_path + lib_name, agent_dir)
92+
end
93+
94+
def profile_name
95+
@application.services.find_service(FILTER)['credentials']['profile'] || 'Monitoring'
8696
end
8797

8898
def server

spec/java_buildpack/framework/dyna_trace_agent_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,13 @@
4040
cache_fixture: 'stub-dyna-trace-agent.jar' do
4141

4242
component.compile
43-
expect(sandbox + 'home/agent/lib64/libdtagent.so').to exist
44-
expect(sandbox + 'YouShouldNotHaveUnzippedMe.txt').not_to exist
43+
expect(sandbox + 'agent/lib64/libdtagent.so').to exist
4544
end
4645

4746
it 'updates JAVA_OPTS' do
4847
component.release
4948
expect(java_opts).to include(
50-
'-agentpath:$PWD/.java-buildpack/dyna_trace_agent/home/agent/lib64/'\
49+
'-agentpath:$PWD/.java-buildpack/dyna_trace_agent/agent/lib64/'\
5150
'libdtagent.so=name=test-application-name_Monitoring,server=test-host-name')
5251
end
5352
end
@@ -62,7 +61,7 @@
6261
it 'updates JAVA_OPTS with custom profile' do
6362
component.release
6463
expect(java_opts).to include(
65-
'-agentpath:$PWD/.java-buildpack/dyna_trace_agent/home/agent/lib64/'\
64+
'-agentpath:$PWD/.java-buildpack/dyna_trace_agent/agent/lib64/'\
6665
'libdtagent.so=name=test-application-name_test-profile,server=test-host-name')
6766
end
6867

0 commit comments

Comments
 (0)