Skip to content

Commit c104187

Browse files
committed
Add New Relic support
This change adds support for bound New Relic services. The framework notices a bound service in VCAP_SERVICES. During the compile phase, the New Relic agent JAR is download and a default New Relic configuration file is copied into place. During the release phase, a number of JAVA_OPTS are configured such that the New Relic service is used during the application's runtime. [#53027669]
1 parent e56d41d commit c104187

20 files changed

Lines changed: 589 additions & 23 deletions

File tree

Gemfile.lock

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ GEM
77
crack (0.4.1)
88
safe_yaml (~> 0.9.0)
99
diff-lcs (1.2.4)
10-
multi_json (1.7.7)
11-
parser (2.0.0.pre2)
10+
multi_json (1.7.9)
11+
parser (2.0.0.pre6)
1212
ast (~> 1.1)
1313
slop (~> 3.4, >= 3.4.5)
14-
powerpack (0.0.1)
14+
powerpack (0.0.3)
1515
rainbow (1.1.4)
1616
rake (10.1.0)
1717
redcarpet (3.0.0)
@@ -20,24 +20,24 @@ GEM
2020
rspec-expectations (~> 2.14.0)
2121
rspec-mocks (~> 2.14.0)
2222
rspec-core (2.14.4)
23-
rspec-expectations (2.14.0)
23+
rspec-expectations (2.14.1)
2424
diff-lcs (>= 1.1.3, < 2.0)
25-
rspec-mocks (2.14.1)
26-
rubocop (0.10.0)
25+
rspec-mocks (2.14.3)
26+
rubocop (0.11.1)
2727
backports (~> 3.3.3)
28-
parser (= 2.0.0.pre2)
29-
powerpack (= 0.0.1)
28+
parser (~> 2.0.0.pre6)
29+
powerpack (~> 0.0.3)
3030
rainbow (>= 1.1.4)
31-
safe_yaml (0.9.4)
31+
safe_yaml (0.9.5)
3232
simplecov (0.7.1)
3333
multi_json (~> 1.0)
3434
simplecov-html (~> 0.7.1)
3535
simplecov-html (0.7.1)
36-
slop (3.4.5)
36+
slop (3.4.6)
3737
webmock (1.13.0)
3838
addressable (>= 2.2.7)
3939
crack (>= 0.3.2)
40-
yard (0.8.6.2)
40+
yard (0.8.7)
4141

4242
PLATFORMS
4343
ruby

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ The buildpack supports configuration and extension through the use of Git reposi
2828
* [Spring Boot CLI](docs/container-spring-boot-cli.md) ([Configuration](docs/container-spring-boot-cli.md#configuration))
2929
* [Tomcat](docs/container-tomcat.md) ([Configuration](docs/container-tomcat.md#configuration))
3030
* Standard Frameworks
31+
* [`JAVA_OPTS`](docs/framework-java_opts.md) ([Configuration](docs/framework-java_opts.md#configuration))
32+
* [New Relic](docs/framework-new-relic.md) ([Configuration](docs/framework-new-relic.md#configuration))
3133
* [Play Auto Reconfiguration](docs/framework-play-auto-reconfiguration.md) ([Configuration](docs/framework-play-auto-reconfiguration.md#configuration))
3234
* [Play JPA Plugin](docs/framework-play-jpa-plugin.md) ([Configuration](docs/framework-play-jpa-plugin.md#configuration))
3335
* [Spring Auto Reconfiguration](docs/framework-spring-auto-reconfiguration.md) ([Configuration](docs/framework-spring-auto-reconfiguration.md#configuration))
34-
* [`JAVA_OPTS`](docs/framework-java_opts.md) ([Configuration](docs/framework-java_opts.md#configuration))
3536
* Standard JREs
3637
* [OpenJDK](docs/jre-openjdk.md) ([Configuration](docs/jre-openjdk.md#configuration))
3738
* Extending

config/components.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jres:
2525
- "JavaBuildpack::Jre::OpenJdk"
2626
frameworks:
2727
- "JavaBuildpack::Framework::JavaOpts"
28+
- "JavaBuildpack::Framework::NewRelic"
2829
- "JavaBuildpack::Framework::PlayAutoReconfiguration"
2930
- "JavaBuildpack::Framework::PlayJpaPlugin"
3031
- "JavaBuildpack::Framework::SpringAutoReconfiguration"

config/newrelic.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Cloud Foundry Java Buildpack
2+
# Copyright (c) 2013 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 New Relic framework
17+
---
18+
version: 2.21.+
19+
repository_root: "http://download.pivotal.io.s3.amazonaws.com/new-relic/lucid/x86_64"

docs/extending-containers.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ To add a container, the class file must be located in [`lib/java_buildpack/conta
1212
# @option context [String] :java_home the directory that acts as +JAVA_HOME+
1313
# @option context [Array<String>] :java_opts an array that Java options can be added to
1414
# @option context [String] :lib_directory the directory that additional libraries are placed in
15+
# @option context [Hash] :vcap_application The contents of the +VCAP_APPLICATION+ environment variable
16+
# @option context [Hash] :vcap_services The contents of the +VCAP_SERVICES+ environment variable
1517
# @option context [Hash] :configuration the configuration provided by the user
1618
def initialize(context)
1719

docs/extending-frameworks.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ To add a framework, the class file must be located in [`lib/java_buildpack/frame
1212
# @option context [String] :java_home the directory that acts as +JAVA_HOME+
1313
# @option context [Array<String>] :java_opts an array that Java options can be added to
1414
# @option context [String] :lib_directory the directory that additional libraries are placed in
15+
# @option context [Hash] :vcap_application The contents of the +VCAP_APPLICATION+ environment variable
16+
# @option context [Hash] :vcap_services The contents of the +VCAP_SERVICES+ environment variable
1517
# @option context [Hash] :configuration the configuration provided by the user
1618
def initialize(context)
1719

docs/extending-jres.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ To add a JRE, the class file must be located in [`lib/java_buildpack/jre`][jre_d
1212
# @option context [String] :java_home the directory that acts as +JAVA_HOME+
1313
# @option context [Array<String>] :java_opts an array that Java options can be added to
1414
# @option context [String] :lib_directory the directory that additional libraries are placed in
15+
# @option context [Hash] :vcap_application The contents of the +VCAP_APPLICATION+ environment variable
16+
# @option context [Hash] :vcap_services The contents of the +VCAP_SERVICES+ environment variable
1517
# @option context [Hash] :configuration the configuration provided by the user
1618
def initialize(context)
1719

docs/framework-new-relic.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# New Relic Framework
2+
The New Relic Framework causes an application to be automatically configured to work with a bound [New Relic Service][new_relic].
3+
4+
[new_relic]: https://newrelic.com
5+
6+
<table>
7+
<tr>
8+
<td><strong>Detection Criterion</strong></td><td>Existence of a single bound New Relic service</td>
9+
</tr>
10+
<tr>
11+
<td><strong>Tags</strong></td><td><tt>new-relic-&lt;version&gt;</tt></td>
12+
</tr>
13+
</table>
14+
Tags are printed to standard output by the buildpack detect script
15+
16+
## Configuration
17+
The container can be configured by modifying the [`config/newrelic.yml`][newrelic_yml] file. The container uses the [`Repository` utility support][util_repositories] and so it supports the [version syntax][version_syntax] defined there.
18+
19+
[newrelic_yml]: ../config/newrelic.yml
20+
[util_repositories]: util-repositories.md
21+
[version_syntax]: util-repositories.md#version-syntax-and-ordering
22+
23+
| Name | Description
24+
| ---- | -----------
25+
| `repository_root` | The URL of the New Relic repository index ([details][util_repositories]).
26+
| `version` | The version of New Relic to use. Candidate versions can be found in [this listing][new_relic_index_yml].
27+
28+
[new_relic_index_yml]: http://download.pivotal.io.s3.amazonaws.com/new-relic/lucid/x86_64/index.yml

docs/util-repository-builders.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The repositories that are currently referenced by the buildpack are easily repli
77
| Auto Reconfiguration | <https://github.com/cloudfoundry/builder-auto-reconfiguration>
88
| Groovy | <https://github.com/cloudfoundry/builder-groovy>
99
| MySQL JDBC | <https://github.com/cloudfoundry/builder-mysql-jdbc>
10+
| New Relic | <https://github.com/cloudfoundry/builder-new-relic>
1011
| OpenJDK | <https://github.com/cloudfoundry/builder-openjdk>
1112
| PostgreSQL JDBC | <https://github.com/cloudfoundry/builder-postgresql-jdbc>
1213
| Spring Boot CLI | <https://github.com/cloudfoundry/builder-spring-boot-cli>

lib/java_buildpack/buildpack.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,20 @@ def initialize(app_dir)
119119
java_home = ''
120120
java_opts = []
121121
@lib_directory = Buildpack.lib_directory app_dir
122+
vcap_application = ENV['VCAP_APPLICATION']
123+
vcap_services = ENV['VCAP_SERVICES']
122124

123125
basic_context = {
124126
app_dir: app_dir,
125127
java_home: java_home,
126128
java_opts: java_opts,
127-
lib_directory: @lib_directory
129+
lib_directory: @lib_directory,
130+
vcap_application: vcap_application ? YAML.load(vcap_application) : {},
131+
vcap_services: vcap_services ? YAML.load(vcap_services) : {}
128132
}
129133

130134
@jres = Buildpack.construct_components(components, 'jres', basic_context, @logger)
131-
132135
@frameworks = Buildpack.construct_components(components, 'frameworks', basic_context, @logger)
133-
134136
@containers = Buildpack.construct_components(components, 'containers', basic_context, @logger)
135137
end
136138

0 commit comments

Comments
 (0)