Skip to content

Commit bac2890

Browse files
committed
Merge branch '472-takipi-agent'
2 parents d9c9958 + 6b00ecd commit bac2890

9 files changed

Lines changed: 272 additions & 0 deletions

File tree

.idea/dictionaries/bhale.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ To learn how to configure various properties of the buildpack, follow the "Confi
9898
* [ProtectApp Security Provider](docs/framework-protect_app_security_provider.md) ([Configuration](docs/framework-protect_app_security_provider.md#configuration))
9999
* [Spring Auto Reconfiguration](docs/framework-spring_auto_reconfiguration.md) ([Configuration](docs/framework-spring_auto_reconfiguration.md#configuration))
100100
* [Spring Insight](docs/framework-spring_insight.md)
101+
* [Takipi Agent](docs/framework-takipi_agent.md) ([Configuration](docs/framework-takipi_agent.md#configuration))
101102
* [YourKit Profiler](docs/framework-your_kit_profiler.md) ([Configuration](docs/framework-your_kit_profiler.md#configuration))
102103
* Standard JREs
103104
* [Azul Zulu](docs/jre-zulu_jre.md) ([Configuration](docs/jre-zulu_jre.md#configuration))

config/components.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,6 @@ frameworks:
6363
- "JavaBuildpack::Framework::SpringAutoReconfiguration"
6464
- "JavaBuildpack::Framework::SpringInsight"
6565
- "JavaBuildpack::Framework::YourKitProfiler"
66+
- "JavaBuildpack::Framework::TakipiAgent"
6667
- "JavaBuildpack::Framework::SecurityProviders"
6768
- "JavaBuildpack::Framework::JavaOpts"

config/takipi_agent.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Cloud Foundry Java Buildpack
2+
# Copyright 2013-2017 the original author or authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Configuration for the Takipi framework
17+
---
18+
version: 4.+
19+
repository_root: http://get.takipi.com/cloudfoundry
20+
node_name_prefix: node
21+
application_name:

docs/framework-takipi_agent.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Takipi Agent Framework
2+
The Takipi Agent Framework causes an application to be automatically configured to work with [OverOps Service][].
3+
4+
<table>
5+
<tr>
6+
<td><strong>Detection Criterion</strong></td><td>Existence of a single bound Takipi service. The existence of an Takipi service defined by the <a href="http://docs.cloudfoundry.org/devguide/deploy-apps/environment-variable.html#VCAP-SERVICES"><code>VCAP_SERVICES</code></a> payload containing a service name, label or tag with <code>app-dynamics</code> or <code>takipi</code> as a substring.
7+
</td>
8+
</tr>
9+
<tr>
10+
<td><strong>Tags</strong></td><td><tt>takipi-agent=&lt;version&gt;</tt></td>
11+
</tr>
12+
</table>
13+
Tags are printed to standard output by the buildpack detect script
14+
15+
## User-Provided Service
16+
When binding Takipi using a user-provided service, it must have name or tag with `takipi` in it.
17+
The credential payload can contain the following entries.
18+
19+
| Name | Description
20+
| ---- | -----------
21+
| `secret_key` | (Optional) The agent installation key
22+
| `collector_host` | (Optional) The remote collector hostname or IP
23+
| `collector_port` | (Optional) the remote collector port
24+
25+
Setting `secret_key` will run a local collector alongside the agent. Setting `collector_host` will use a remote collector. More information can be found in [OverOps Remote Collector][]
26+
27+
## Configuration
28+
For general information on configuring the buildpack, including how to specify configuration values through environment variables, refer to [Configuration and Extension][].
29+
30+
The framework can be configured by modifying the [`config/takipi_agent.yml`][] file. The framework uses the [`Repository` utility support][repositories] and so it supports the [version syntax][] defined there.
31+
32+
| Name | Description
33+
| ---- | -----------
34+
| `node_name_prefix` | Node name prefix, will be concatenated with `-` and instance index
35+
| `application_name` | Override the Cloudfoundry default application name
36+
37+
## Logs
38+
39+
Currently, you can get the Takipi agent logs using `cf files` command:
40+
```
41+
cf files app_name app/.java-buildpack/takipi_agent/log/
42+
```
43+
44+
[`config/takipi_agent.yml`]: ../config/takipi_agent.yml
45+
[Configuration and Extension]: ../README.md#configuration-and-extension
46+
[repositories]: extending-repositories.md
47+
[version syntax]: extending-repositories.md#version-syntax-and-ordering
48+
[OverOps Remote Collector]: https://support.overops.com/hc/en-us/articles/227109628-Remote-Daemon-Process-
49+
[OverOps Service]: https://www.overops.com
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Cloud Foundry Java Buildpack
2+
#
3+
# Copyright 2013-2017 the original author or authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
require 'fileutils'
18+
require 'java_buildpack/component/versioned_dependency_component'
19+
require 'java_buildpack/framework'
20+
require 'java_buildpack/util/qualify_path'
21+
22+
module JavaBuildpack
23+
module Framework
24+
25+
# Encapsulates the functionality for enabling zero-touch OverOps (fka Takipi) support.
26+
class TakipiAgent < JavaBuildpack::Component::VersionedDependencyComponent
27+
include JavaBuildpack::Util
28+
29+
# (see JavaBuildpack::Component::BaseComponent#compile)
30+
def compile
31+
download_tar
32+
@droplet.copy_resources
33+
end
34+
35+
# (see JavaBuildpack::Component::BaseComponent#release)
36+
def release
37+
@droplet.java_opts
38+
.add_agentpath(agent)
39+
.add_system_property('takipi.name', application_name)
40+
41+
@droplet.environment_variables
42+
.add_environment_variable('LD_LIBRARY_PATH',
43+
"$LD_LIBRARY_PATH:#{qualify_path(lib, @droplet.root)}")
44+
.add_environment_variable('JVM_LIB_FILE', libjvm)
45+
.add_environment_variable('TAKIPI_HOME', @droplet.sandbox)
46+
.add_environment_variable('TAKIPI_MACHINE_NAME', node_name)
47+
48+
config_env_vars @application.services.find_service(FILTER)['credentials']
49+
end
50+
51+
protected
52+
53+
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
54+
def supports?
55+
@application.services.one_service? FILTER, [SECRET_KEY, COLLECTOR_HOST]
56+
end
57+
58+
private
59+
60+
COLLECTOR_HOST = 'collector_host'.freeze
61+
62+
FILTER = /takipi/
63+
64+
SECRET_KEY = 'secret_key'.freeze
65+
66+
private_constant :COLLECTOR_HOST, :FILTER, :SECRET_KEY
67+
68+
def agent
69+
@droplet.sandbox + 'lib/libTakipiAgent.so'
70+
end
71+
72+
def application_name
73+
@configuration['application_name'] || @application.details['application_name']
74+
end
75+
76+
def config_env_vars(credentials)
77+
env = @droplet.environment_variables
78+
79+
secret_key = credentials['secret_key']
80+
env.add_environment_variable 'TAKIPI_SECRET_KEY', secret_key if secret_key
81+
82+
collector_host = credentials['collector_host']
83+
env.add_environment_variable 'TAKIPI_MASTER_HOST', collector_host if collector_host
84+
85+
collector_port = credentials['collector_port']
86+
env.add_environment_variable 'TAKIPI_MASTER_PORT', collector_port if collector_port
87+
end
88+
89+
def lib
90+
@droplet.sandbox + 'lib'
91+
end
92+
93+
def libjvm
94+
@droplet.java_home.root + 'lib/amd64/server/libjvm.so'
95+
end
96+
97+
def node_name
98+
"#{@configuration['node_name_prefix']}-$CF_INSTANCE_INDEX"
99+
end
100+
101+
end
102+
103+
end
104+
end

rakelib/versions_task.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def initialize
8181
'redis_store' => 'Redis Session Store',
8282
'spring_auto_reconfiguration' => 'Spring Auto-reconfiguration',
8383
'spring_boot_cli' => 'Spring Boot CLI',
84+
'takipi_agent' => 'Takipi Agent',
8485
'tomcat' => 'Tomcat',
8586
'your_kit_profiler' => 'YourKit Profiler'
8687
}.freeze
1.1 KB
Binary file not shown.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Cloud Foundry Java Buildpack
2+
# Copyright 2013-2017 the original author or authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
require 'spec_helper'
17+
require 'component_helper'
18+
require 'java_buildpack/framework/takipi_agent'
19+
20+
describe JavaBuildpack::Framework::TakipiAgent do
21+
include_context 'component_helper'
22+
23+
let(:configuration) { { 'node_name_prefix' => nil } }
24+
25+
it 'does not detect without takipi-n/a service' do
26+
expect(component.detect).to be_nil
27+
end
28+
29+
context do
30+
31+
let(:credentials) { {} }
32+
33+
before do
34+
allow(services).to receive(:one_service?).with(/takipi/, %w[secret_key collector_host]).and_return(true)
35+
allow(services).to receive(:find_service).and_return('credentials' => credentials)
36+
end
37+
38+
it 'detects with takipi service' do
39+
expect(component.detect).to eq("takipi-agent=#{version}")
40+
end
41+
42+
it 'expands Takipi agent tarball',
43+
cache_fixture: 'stub-takipi-agent.tar.gz' do
44+
45+
component.compile
46+
47+
expect(sandbox + 'lib/libTakipiAgent.so').to exist
48+
end
49+
50+
context do
51+
let(:credentials) { { 'collector_host' => 'test-host' } }
52+
53+
it 'updates default environment variables' do
54+
component.release
55+
56+
expect(environment_variables)
57+
.to include('LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/.java-buildpack/takipi_agent/lib')
58+
expect(environment_variables).to include('JVM_LIB_FILE=$PWD/.test-java-home/lib/amd64/server/libjvm.so')
59+
expect(environment_variables).to include('TAKIPI_HOME=$PWD/.java-buildpack/takipi_agent')
60+
end
61+
62+
it 'updates user environment variables' do
63+
component.release
64+
65+
expect(environment_variables).to include('TAKIPI_MASTER_HOST=test-host')
66+
end
67+
68+
context 'secret key' do
69+
let(:credentials) { super().merge 'secret_key' => 'test-key' }
70+
71+
it 'secret key set' do
72+
component.release
73+
74+
expect(environment_variables).to include('TAKIPI_SECRET_KEY=test-key')
75+
end
76+
end
77+
78+
context 'configuration overrides' do
79+
80+
let(:configuration) { { 'node_name_prefix' => 'test-name', 'application_name' => 'test-name' } }
81+
82+
it 'update application name' do
83+
component.release
84+
expect(java_opts).to include('-agentpath:$PWD/.java-buildpack/takipi_agent/lib/libTakipiAgent.so')
85+
expect(java_opts).to include('-Dtakipi.name=test-name')
86+
end
87+
88+
end
89+
end
90+
91+
end
92+
93+
end

0 commit comments

Comments
 (0)