Skip to content

Commit 02ab527

Browse files
chooknebhale
authored andcommitted
Takipi Agent Framework
This change adds the Takipi agent framework to the buildpack. This framework supports both the local and remote collector approaches for using the Takipi agent. [#472]
1 parent d9c9958 commit 02ab527

File tree

7 files changed

+281
-0
lines changed

7 files changed

+281
-0
lines changed

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+
java_opts = @droplet.java_opts
38+
java_opts.add_agentpath(@droplet.sandbox + 'lib/libTakipiAgent.so')
39+
application_name java_opts
40+
default_env_vars
41+
credentials = @application.services.find_service(FILTER)['credentials']
42+
config_env_vars credentials
43+
end
44+
45+
protected
46+
47+
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
48+
def supports?
49+
@application.services.one_service? FILTER, [SECRET_KEY, COLLECTOR_HOST]
50+
end
51+
52+
private
53+
54+
FILTER = /takipi/
55+
56+
SECRET_KEY = 'secret_key'.freeze
57+
58+
COLLECTOR_HOST = 'collector_host'.freeze
59+
60+
private_constant :FILTER
61+
62+
def jvm_lib_file
63+
@droplet.java_home.root + 'lib/amd64/server/libjvm.so'
64+
end
65+
66+
def default_env_vars
67+
env = @droplet.environment_variables
68+
sandbox = @droplet.sandbox
69+
70+
env.add_environment_variable(
71+
'LD_LIBRARY_PATH',
72+
"$LD_LIBRARY_PATH:#{qualify_path(sandbox + 'lib', @droplet.root)}"
73+
)
74+
env.add_environment_variable('JVM_LIB_FILE', jvm_lib_file)
75+
env.add_environment_variable('TAKIPI_HOME', sandbox)
76+
env.add_environment_variable('TAKIPI_MACHINE_NAME', node_name)
77+
end
78+
79+
def config_env_vars(credentials)
80+
env = @droplet.environment_variables
81+
82+
secret_key = credentials['secret_key']
83+
env.add_environment_variable 'TAKIPI_SECRET_KEY', secret_key if secret_key
84+
85+
collector_host = credentials['collector_host']
86+
env.add_environment_variable 'TAKIPI_MASTER_HOST', collector_host if collector_host
87+
88+
collector_port = credentials['collector_port']
89+
env.add_environment_variable 'TAKIPI_MASTER_PORT', collector_port if collector_port
90+
end
91+
92+
def application_name(java_opts)
93+
app_name = @configuration['application_name'] || @application.details['application_name']
94+
java_opts.add_system_property('takipi.name', app_name)
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
1.1 KB
Binary file not shown.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
require 'java_buildpack/util/find_single_directory'
20+
21+
describe JavaBuildpack::Framework::TakipiAgent do
22+
include_context 'component_helper'
23+
24+
let(:configuration) do
25+
{
26+
'node_name_prefix' => nil
27+
}
28+
end
29+
30+
it 'does not detect without takipi-n/a service' do
31+
expect(component.detect).to be_nil
32+
end
33+
34+
context do
35+
36+
let(:credentials) { {} }
37+
38+
before do
39+
allow(services).to receive(:one_service?).with(/takipi/, %w[secret_key collector_host]).and_return(true)
40+
allow(services).to receive(:find_service).and_return('credentials' => credentials)
41+
end
42+
43+
it 'expands Takipi agent tarball',
44+
cache_fixture: 'stub-takipi-agent.tar.gz' do
45+
46+
component.compile
47+
48+
expect(sandbox + 'lib/libTakipiAgent.so').to exist
49+
end
50+
51+
it 'preserves find_single_directory results',
52+
cache_fixture: 'stub-takipi-agent.tar.gz',
53+
app_fixture: 'container_play_2.1_dist' do
54+
component.compile
55+
component.send(:extend, JavaBuildpack::Util)
56+
expect(component.send(:find_single_directory)).not_to be_nil
57+
end
58+
59+
context do
60+
let(:credentials) { { 'collector_host' => 'test-host' } }
61+
62+
it 'updates default environment variables' do
63+
component.release
64+
65+
expect(environment_variables)
66+
.to include('LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/.java-buildpack/takipi_agent/lib')
67+
expect(environment_variables).to include('JVM_LIB_FILE=$PWD/.test-java-home/lib/amd64/server/libjvm.so')
68+
expect(environment_variables).to include('TAKIPI_HOME=$PWD/.java-buildpack/takipi_agent')
69+
end
70+
71+
it 'updates user environment variables' do
72+
component.release
73+
74+
expect(environment_variables).to include('TAKIPI_MASTER_HOST=test-host')
75+
end
76+
77+
context 'secret key' do
78+
let(:credentials) { super().merge 'secret_key' => 'test-key' }
79+
80+
it 'secret key set' do
81+
component.release
82+
83+
expect(environment_variables).to include('TAKIPI_SECRET_KEY=test-key')
84+
end
85+
end
86+
87+
context 'configuration overrides' do
88+
89+
let(:configuration) do
90+
{ 'node_name_prefix' => 'test-name',
91+
'application_name' => 'test-name' }
92+
end
93+
94+
it 'update application name' do
95+
component.release
96+
expect(java_opts).to include('-agentpath:$PWD/.java-buildpack/takipi_agent/lib/libTakipiAgent.so')
97+
expect(java_opts).to include('-Dtakipi.name=test-name')
98+
end
99+
100+
end
101+
end
102+
103+
end
104+
105+
end

0 commit comments

Comments
 (0)