Skip to content

Commit 4446775

Browse files
committed
Merge branch '556-skywalking'
2 parents 830f4c3 + 4767204 commit 4446775

8 files changed

Lines changed: 310 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ The buildpack supports extension through the use of Git repository forking. The
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+
* [SkyWalking Agent](docs/framework-sky_walking_agent.md) ([Configuration](docs/framework-sky_walking_agent.md#configuration))
101102
* [Takipi Agent](docs/framework-takipi_agent.md) ([Configuration](docs/framework-takipi_agent.md#configuration))
102103
* [YourKit Profiler](docs/framework-your_kit_profiler.md) ([Configuration](docs/framework-your_kit_profiler.md#configuration))
103104
* Standard JREs

config/components.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ frameworks:
6464
- "JavaBuildpack::Framework::ProtectAppSecurityProvider"
6565
- "JavaBuildpack::Framework::SpringAutoReconfiguration"
6666
- "JavaBuildpack::Framework::SpringInsight"
67+
- "JavaBuildpack::Framework::SkyWalkingAgent"
6768
- "JavaBuildpack::Framework::YourKitProfiler"
6869
- "JavaBuildpack::Framework::TakipiAgent"
6970
- "JavaBuildpack::Framework::JavaSecurity"

config/sky_walking_agent.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Cloud Foundry Java Buildpack
2+
# Copyright 2013-2018 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 Spring Auto Reconfiguration framework.
17+
# Note that the repository is shared with the Play Auto Reconfiguration framework and should be kept in step to
18+
# avoid conflicts.
19+
---
20+
version: 3.+
21+
default_application_name: $(ruby -e "require 'json' ; a = JSON.parse(ENV['VCAP_APPLICATION']);
22+
puts \"#{a['space_name']}:#{a['application_name']}\"")
23+
repository_root: https://java-buildpack.cloudfoundry.org/sky-walking
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# SkyWalking Agent Framework
2+
The SkyWalking Agent Framework causes an application to be automatically configured to work with a bound [SkyWalking Service][] **Note:** This framework is disabled by default.
3+
4+
<table>
5+
<tr>
6+
<td><strong>Detection Criterion</strong></td><td>Existence of a single bound SkyWalking service. The existence of an SkyWalking 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>sky-walking</code> or <code>skywalking</code> as a substring.
7+
</td>
8+
</tr>
9+
<tr>
10+
<td><strong>Tags</strong></td><td><tt>sky-walking-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 SkyWalking using a user-provided service, it must have name or tag with `sky-walking` or `skywalking` in it. The credential payload can contain the following entries. **Note:** Credentials marked as "(Optional)" may be required for some versions of the SkyWalking agent. Please see the [SkyWalking Java Agent Configuration Properties][] for the version of the agent used by your application for more details.
17+
18+
| Name | Description
19+
| ---- | -----------
20+
| `application-name` | (Optional) The application's name
21+
| `sample-n-per-3-secs` | (Optional) The number of sampled traces per 3 seconds. Negative number means sample traces as many as possible, most likely 100%
22+
| `span-limit-per-segment` | (Optional) The max amount of spans in a single segment
23+
| `ignore-suffix` | (Optional) Ignore the segments if their operation names start with these suffix
24+
| `open-debugging-class` | (Optional) If true, skywalking agent will save all instrumented classes files in `/debugging` folder.Skywalking team may ask for these files in order to resolve compatible problem
25+
| `servers` | Server addresses .Examples: Single collector:servers="127.0.0.1:8080",Collector cluster:servers="10.2.45.126:8080,10.2.45.127:7600"
26+
| `logging-level` | (Optional) Logging level
27+
28+
## Configuration
29+
For general information on configuring the buildpack, including how to specify configuration values through environment variables, refer to [Configuration and Extension][].
30+
31+
The framework can be configured by modifying the [`config/sky_walking_agent.yml`][] file in the buildpack fork. The framework uses the [`Repository` utility support][repositories] and so it supports the [version syntax][] defined there.
32+
33+
| Name | Description
34+
| ---- | -----------
35+
| `default_application_name` | This is omitted by default but can be added to specify the application name in the SkyWalking dashboard. This can be overridden by an `application-name` entry in the credentials payload. If neither are supplied the default is the `application_name` as specified by Cloud Foundry.
36+
| `repository_root` | The URL of the SkyWalking repository index ([details][repositories]).
37+
| `version` | The version of SkyWalking to use. Candidate versions can be found in [this listing][].
38+
39+
### Additional Resources
40+
The framework can also be configured by overlaying a set of resources on the default distribution. To do this, add files to the `resources/sky_walking_agent` directory in the buildpack fork.
41+
42+
[`config/sky_walking_agent.yml`]: ../config/sky_walking_agent.yml
43+
[SkyWalking Java Agent Configuration Properties]: https://github.com/apache/incubator-skywalking/blob/master/docs/en/Deploy-skywalking-agent.md
44+
[SkyWalking Service]: http://skywalking.io
45+
[Configuration and Extension]: ../README.md#configuration-and-extension
46+
[repositories]: extending-repositories.md
47+
[this listing]: https://download.run.pivotal.io/sky-walking/index.yml
48+
[version syntax]: extending-repositories.md#version-syntax-and-ordering
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# frozen_string_literal: true
2+
3+
# Cloud Foundry Java Buildpack
4+
# Copyright 2013-2018 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
require 'fileutils'
19+
require 'java_buildpack/component/versioned_dependency_component'
20+
require 'java_buildpack/framework'
21+
22+
module JavaBuildpack
23+
module Framework
24+
25+
# Encapsulates the functionality for enabling Sky walking APM support.
26+
class SkyWalkingAgent < JavaBuildpack::Component::VersionedDependencyComponent
27+
28+
# (see JavaBuildpack::Component::BaseComponent#compile)
29+
def compile
30+
download_tar(true, @droplet.sandbox, 'sky_walking_agent')
31+
@droplet.copy_resources
32+
end
33+
34+
# (see JavaBuildpack::Component::BaseComponent#release)
35+
def release
36+
credentials = @application.services.find_service(FILTER, 'servers')['credentials']
37+
java_opts = @droplet.java_opts
38+
java_opts.add_javaagent(@droplet.sandbox + 'skywalking-agent.jar')
39+
40+
application_name java_opts, credentials
41+
sample_n_per_3_secs java_opts, credentials
42+
span_limit_per_segment java_opts, credentials
43+
ignore_suffix java_opts, credentials
44+
open_debugging_class java_opts, credentials
45+
servers java_opts, credentials
46+
logging_level java_opts, credentials
47+
end
48+
49+
protected
50+
51+
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
52+
def supports?
53+
@application.services.one_service? FILTER, 'servers'
54+
end
55+
56+
private
57+
58+
FILTER = /sky[-]?walking/
59+
60+
private_constant :FILTER
61+
62+
def servers(java_opts, credentials)
63+
servers = credentials['servers']
64+
raise "'servers' credential must be set" unless servers
65+
java_opts.add_system_property 'skywalking.collector.servers', servers
66+
end
67+
68+
def application_name(java_opts, credentials)
69+
name = credentials['application-name'] || @configuration['default_application_name'] ||
70+
@application.details['application_name']
71+
java_opts.add_system_property('skywalking.agent.application_code', name.to_s)
72+
end
73+
74+
def sample_n_per_3_secs(java_opts, credentials)
75+
sample_n_per_3_secs = credentials['sample-n-per-3-secs']
76+
java_opts.add_system_property 'skywalking.agent.sample_n_per_3_secs', sample_n_per_3_secs if sample_n_per_3_secs
77+
end
78+
79+
def span_limit_per_segment(java_opts, credentials)
80+
span_lmt_per_seg = credentials['span-limit-per-segment']
81+
java_opts.add_system_property 'skywalking.agent.span_limit_per_segment', span_lmt_per_seg if span_lmt_per_seg
82+
end
83+
84+
def ignore_suffix(java_opts, credentials)
85+
ignore_suffix = credentials['ignore-suffix']
86+
java_opts.add_system_property 'skywalking.agent.ignore_suffix', ignore_suffix if ignore_suffix
87+
end
88+
89+
def open_debugging_class(java_opts, credentials)
90+
is_debug_class = credentials['is-open-debugging-class']
91+
java_opts.add_system_property 'skywalking.agent.is_open_debugging_class', is_debug_class if is_debug_class
92+
end
93+
94+
def logging_level(java_opts, credentials)
95+
logging_level = credentials['logging-level']
96+
java_opts.add_system_property 'skywalking.logging.level', logging_level if logging_level
97+
end
98+
99+
end
100+
101+
end
102+
end

rakelib/versions_task.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def initialize
6262
'dyadic_ekm_security_provider' => 'Dyadic EKM Security Provider',
6363
'dynatrace_appmon_agent' => 'Dynatrace Appmon Agent',
6464
'dynatrace_one_agent' => 'Dynatrace OneAgent',
65-
'geode_store' => 'Apache Geode Tomcat Session Store',
65+
'geode_store' => 'Geode Tomcat Session Store',
6666
'google_stackdriver_debugger' => 'Google Stackdriver Debugger',
6767
'groovy' => 'Groovy',
6868
'introscope_agent' => 'CA Introscope APM Framework',
@@ -80,6 +80,7 @@ def initialize
8080
'postgresql_jdbc' => 'PostgreSQL JDBC Driver',
8181
'protect_app_security_provider' => 'Gemalto ProtectApp Security Provider',
8282
'redis_store' => 'Redis Session Store',
83+
'sky_walking_agent' => 'SkyWalking',
8384
'spring_auto_reconfiguration' => 'Spring Auto-reconfiguration',
8485
'spring_boot_cli' => 'Spring Boot CLI',
8586
'takipi_agent' => 'Takipi Agent',
169 Bytes
Binary file not shown.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# frozen_string_literal: true
2+
3+
# Cloud Foundry Java Buildpack
4+
# Copyright 2013-2018 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
require 'spec_helper'
19+
require 'component_helper'
20+
require 'java_buildpack/framework/sky_walking_agent'
21+
22+
describe JavaBuildpack::Framework::SkyWalkingAgent do
23+
include_context 'with component help'
24+
25+
let(:configuration) do
26+
{ 'default_application_name' => nil }
27+
end
28+
29+
it 'does not detect without skywalking-n/a service' do
30+
expect(component.detect).to be_nil
31+
end
32+
33+
context do
34+
35+
let(:credentials) { {} }
36+
37+
before do
38+
allow(services).to receive(:one_service?).with(/sky[-]?walking/, 'servers').and_return(true)
39+
allow(services).to receive(:find_service).and_return('credentials' => credentials)
40+
end
41+
42+
it 'detects with skywalking-n/a service' do
43+
expect(component.detect).to eq("sky-walking-agent=#{version}")
44+
end
45+
46+
it 'expands Skywalking agent tar',
47+
cache_fixture: 'stub-skywalking-agent.tar.gz' do
48+
49+
component.compile
50+
51+
expect(sandbox + 'skywalking-agent.jar').to exist
52+
end
53+
54+
it 'raises error if servers not specified' do
55+
expect { component.release }.to raise_error(/'servers' credential must be set/)
56+
end
57+
58+
context do
59+
60+
let(:credentials) { { 'servers' => 'test-servers' } }
61+
62+
it 'updates JAVA_OPTS' do
63+
component.release
64+
65+
expect(java_opts).to include('-javaagent:$PWD/.java-buildpack/sky_walking_agent/skywalking-agent.jar')
66+
expect(java_opts).to include('-Dskywalking.collector.servers=test-servers')
67+
expect(java_opts).to include('-Dskywalking.agent.application_code=test-application-name')
68+
end
69+
70+
context do
71+
let(:credentials) { super().merge 'sample-n-per-3-secs' => '10' }
72+
73+
it 'adds sample_n_per_3_secs from credentials to JAVA_OPTS if specified' do
74+
component.release
75+
76+
expect(java_opts).to include('-Dskywalking.agent.sample_n_per_3_secs=10')
77+
end
78+
end
79+
80+
context do
81+
let(:credentials) { super().merge 'application-name' => 'another-test-application-name' }
82+
83+
it 'adds application_name from credentials to JAVA_OPTS if specified' do
84+
component.release
85+
86+
expect(java_opts).to include('-Dskywalking.agent.application_code=another-test-application-name')
87+
end
88+
end
89+
90+
context do
91+
let(:credentials) { super().merge 'span-limit-per-segment' => '300' }
92+
93+
it 'adds span_limit_per_segment from credentials to JAVA_OPTS if specified' do
94+
component.release
95+
96+
expect(java_opts).to include('-Dskywalking.agent.span_limit_per_segment=300')
97+
end
98+
end
99+
100+
context do
101+
let(:credentials) { super().merge 'ignore-suffix' => '.html' }
102+
103+
it 'adds ignore_suffix to JAVA_OPTS if specified' do
104+
component.release
105+
106+
expect(java_opts).to include('-Dskywalking.agent.ignore_suffix=.html')
107+
end
108+
end
109+
110+
context do
111+
let(:credentials) { super().merge 'is-open-debugging-class' => 'true' }
112+
113+
it 'adds is_open_debugging_class to JAVA_OPTS if specified' do
114+
component.release
115+
116+
expect(java_opts).to include('-Dskywalking.agent.is_open_debugging_class=true')
117+
end
118+
end
119+
120+
context do
121+
let(:credentials) { super().merge 'logging-level' => 'DEBUG' }
122+
123+
it 'adds logging_level to JAVA_OPTS if specified' do
124+
component.release
125+
126+
expect(java_opts).to include('-Dskywalking.logging.level=DEBUG')
127+
end
128+
end
129+
end
130+
131+
end
132+
133+
end

0 commit comments

Comments
 (0)