Skip to content

Commit e0d2941

Browse files
DMevadanebhale
authored andcommitted
Update Introscope Agent Framework
Before this commit, the Introscope agent framework had support for the new agent manager uril, but it was missing a few cases. The framework was also disabled by default, so changes had to be made to enable it (e.g. the config/introscope_agent.yml had an empty repository_root). The biggest change was for the agentManager.url.1 property. Since it is now just a url, separate properties for host, port, and ssl do not need to be maintained. All information is encapsulated in the url. The user provides the url, and to allow backwards-compatability, the previous EM connection properties will also be populated with the various components from the agentManager url. After this commit, the buildpack simplifies the user-input so that the user only needs to provide the url, and not the host-name and port. This way, the detection criteria has also been changed so that the url must be provided, and not the host-name. The previous versions of the buildpack were missing support for different socket factories, and with this commit, all socket factories and connection methods (tcp, ssl, http, https) are now supported. Finally, the introscope agent has been enabled out of the box, and the repository root now contains a link to the index.yml file. The documentation has also been updated to reflect these changes. [#470]
1 parent bf9cb4f commit e0d2941

File tree

5 files changed

+118
-66
lines changed

5 files changed

+118
-66
lines changed

config/components.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ frameworks:
4848
- "JavaBuildpack::Framework::DynatraceAppmonAgent"
4949
- "JavaBuildpack::Framework::DynatraceOneAgent"
5050
- "JavaBuildpack::Framework::GoogleStackdriverDebugger"
51-
# - "JavaBuildpack::Framework::IntroscopeAgent"
51+
- "JavaBuildpack::Framework::IntroscopeAgent"
5252
- "JavaBuildpack::Framework::JavaMemoryAssistant"
5353
- "JavaBuildpack::Framework::Jmx"
5454
- "JavaBuildpack::Framework::JrebelAgent"

config/introscope_agent.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515

1616
# Configuration for the CA Wily framework
1717
---
18-
repository_root: ""
19-
version: 9.7.+
18+
repository_root: "https://ca.bintray.com/apm-agents"
19+
version: 10.+
2020
default_agent_name: ! '$(ruby -e "require ''json'' ; puts JSON.parse(ENV[''VCAP_APPLICATION''])[''application_name'']")'

docs/framework-introscope_agent.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Introscope Agent Framework
2-
The Introscope Agent Framework causes an application to be automatically configured to work with a bound [Introscope service][]. **Note:** This framework is disabled by default.
1+
# CA Introscope APM Framework
2+
The CA Introscope APM Framework causes an application to be automatically configured to work with a bound [Introscope service][].
33

44
<table>
55
<tr>
@@ -24,9 +24,8 @@ The credential payload of the service may contain the following entries:
2424
| Name | Description
2525
| ---- | -----------
2626
| `agent-name` | (Optional) The name that should be given to this instance of the Introscope agent
27-
| `host-name` | The host name of the Introscope Enterprise Manager server
28-
| `ssl` | (Optional) Whether or not to use an SSL connection to the Introscope Enterprise Manager server
29-
| `port` | (Optional) The port of the Introscope Enterprise Manager server
27+
| `url` | The url of the Introscope Enterprise Manager server
28+
3029

3130
To provide more complex values such as the `agent-name`, using the interactive mode when creating a user-provided service will manage the character escaping automatically. For example, the default `agent-name` could be set with a value of `agent-$(expr "$VCAP_APPLICATION" : '.*application_name[": ]*\([[:word:]]*\).*')` to calculate a value from the Cloud Foundry application name.
3231

lib/java_buildpack/framework/introscope_agent.rb

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,15 @@ def release
4141
.add_system_property('introscope.agent.hostName', agent_host_name)
4242
.add_system_property('com.wily.introscope.agent.agentName', agent_name(credentials))
4343
.add_system_property('introscope.agent.defaultProcessName', default_process_name)
44-
.add_system_property('introscope.agent.enterprisemanager.transport.tcp.host.DEFAULT', host_name(credentials))
45-
.add_system_property('agentManager.url.1', agent_manager(credentials))
4644

47-
add_port(credentials, java_opts)
48-
add_socket_factory(credentials, java_opts)
45+
add_url(credentials, java_opts)
4946
end
5047

5148
protected
5249

5350
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
5451
def supports?
55-
@application.services.one_service? FILTER, 'host-name'
52+
@application.services.one_service? FILTER, 'url'
5653
end
5754

5855
private
@@ -61,17 +58,6 @@ def supports?
6158

6259
private_constant :FILTER
6360

64-
def add_port(credentials, java_opts)
65-
port = port(credentials)
66-
java_opts.add_system_property('introscope.agent.enterprisemanager.transport.tcp.port.DEFAULT', port) if port
67-
end
68-
69-
def add_socket_factory(credentials, java_opts)
70-
return unless ssl?(credentials)
71-
java_opts.add_system_property('introscope.agent.enterprisemanager.transport.tcp.socketfactory.DEFAULT',
72-
'com.wily.isengard.postofficehub.link.net.SSLSocketFactory')
73-
end
74-
7561
def agent_host_name
7662
@application.details['application_uris'][0]
7763
end
@@ -80,12 +66,27 @@ def agent_jar
8066
@droplet.sandbox + 'Agent.jar'
8167
end
8268

83-
def agent_manager(credentials)
84-
agent_manager = ssl?(credentials) ? 'https://' : 'http://'
85-
agent_manager += host_name(credentials)
69+
def add_url(credentials, java_opts)
70+
agent_manager = url(credentials)
8671

87-
port = port(credentials)
88-
port ? "#{agent_manager}:#{port}" : agent_manager
72+
host, port, socket_factory = parse_url(agent_manager)
73+
java_opts.add_system_property('agentManager.url.1', agent_manager)
74+
java_opts.add_system_property('introscope.agent.enterprisemanager.transport.tcp.host.DEFAULT', host)
75+
java_opts.add_system_property('introscope.agent.enterprisemanager.transport.tcp.port.DEFAULT', port)
76+
java_opts.add_system_property('introscope.agent.enterprisemanager.transport.tcp.socketfactory.DEFAULT',
77+
socket_factory)
78+
end
79+
80+
# Parse the agent manager url, split first by '://', and then with ':'
81+
# components is of the format [host, port, socket_factory]
82+
def parse_url(url)
83+
components = url.split('://')
84+
components.unshift('') if components.length == 1
85+
components[1] = components[1].split(':')
86+
components.flatten!
87+
components.push(protocol_mapping(components[0]))
88+
components.shift
89+
components
8990
end
9091

9192
def agent_name(credentials)
@@ -100,18 +101,22 @@ def default_process_name
100101
@application.details['application_name']
101102
end
102103

103-
def host_name(credentials)
104-
credentials['host-name']
105-
end
104+
def protocol_mapping(protocol)
105+
socket_factory_base = 'com.wily.isengard.postofficehub.link.net.'
106106

107-
def port(credentials)
108-
credentials['port']
109-
end
107+
protocol_socket_factory = {
108+
'' => socket_factory_base + 'DefaultSocketFactory',
109+
'ssl' => socket_factory_base + 'SSLSocketFactory',
110+
'http' => socket_factory_base + 'HttpTunnelingSocketFactory',
111+
'https' => socket_factory_base + 'HttpsTunnelingSocketFactory'
112+
}
110113

111-
def ssl?(credentials)
112-
credentials['ssl'].to_b
114+
protocol_socket_factory[protocol] || protocol
113115
end
114116

117+
def url(credentials)
118+
credentials['url']
119+
end
115120
end
116121
end
117122
end

spec/java_buildpack/framework/introscope_agent_spec.rb

Lines changed: 77 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,74 +38,122 @@
3838
let(:credentials) { {} }
3939

4040
before do
41-
allow(services).to receive(:one_service?).with(/introscope/, 'host-name').and_return(true)
41+
allow(services).to receive(:one_service?).with(/introscope/, 'url').and_return(true)
4242
allow(services).to receive(:find_service).and_return('credentials' => credentials)
4343
end
4444

4545
it 'detects with introscope-n/a service' do
4646
expect(component.detect).to eq("introscope-agent=#{version}")
4747
end
4848

49-
it 'expands Introscope agent zip',
50-
cache_fixture: 'stub-introscope-agent.tar' do
49+
it 'expands Introscope agent zip', cache_fixture: 'stub-introscope-agent.tar' do
5150

5251
component.compile
5352

5453
expect(sandbox + 'Agent.jar').to exist
5554
end
5655

5756
context do
57+
let(:credentials) { { 'agent-name' => 'another-test-agent-name', 'url' => 'default-host:5001' } }
5858

59-
let(:credentials) { { 'host-name' => 'test-host-name' } }
59+
it 'adds agent-name from credentials to JAVA_OPTS if specified' do
60+
component.release
61+
62+
expect(java_opts).to include('-Dcom.wily.introscope.agent.agentName=another-test-agent-name')
63+
end
64+
end
65+
66+
context do
6067

61-
it 'updates JAVA_OPTS' do
68+
let(:credentials) { { 'url' => 'test-host-name:5001' } }
69+
70+
it 'parses the url and sets host port and default socket factory' do
6271
component.release
6372

6473
expect(java_opts).to include('-javaagent:$PWD/.java-buildpack/introscope_agent/Agent.jar')
6574
expect(java_opts).to include('-Dcom.wily.introscope.agentProfile=$PWD/.java-buildpack/introscope_agent/core' \
6675
'/config/IntroscopeAgent.profile')
6776
expect(java_opts).to include('-Dintroscope.agent.defaultProcessName=test-application-name')
6877
expect(java_opts).to include('-Dintroscope.agent.hostName=test-application-uri-0')
78+
79+
expect(java_opts).to include('-DagentManager.url.1=test-host-name:5001')
6980
expect(java_opts).to include('-Dintroscope.agent.enterprisemanager.transport.tcp.host.DEFAULT=test-host-name')
70-
expect(java_opts).to include('-DagentManager.url.1=http://test-host-name')
81+
expect(java_opts).to include('-Dintroscope.agent.enterprisemanager.transport.tcp.port.DEFAULT=5001')
82+
expect(java_opts).to include('-Dintroscope.agent.enterprisemanager.transport.tcp.socketfactory.DEFAULT=' \
83+
'com.wily.isengard.postofficehub.link.net.DefaultSocketFactory')
84+
7185
expect(java_opts).to include('-Dcom.wily.introscope.agent.agentName=$(expr "$VCAP_APPLICATION" : ' \
7286
'\'.*application_name[": ]*\\([A-Za-z0-9_-]*\\).*\')')
7387
end
88+
end
89+
90+
context do
91+
let(:credentials) { { 'url' => 'ssl://test-host-name:5443' } }
7492

75-
context do
76-
let(:credentials) { super().merge 'agent-name' => 'another-test-agent-name' }
93+
it 'parses the url and sets host, port, and ssl socket factory' do
94+
component.release
95+
96+
expect(java_opts).to include('-javaagent:$PWD/.java-buildpack/introscope_agent/Agent.jar')
97+
expect(java_opts).to include('-Dcom.wily.introscope.agentProfile=$PWD/.java-buildpack/introscope_agent/core' \
98+
'/config/IntroscopeAgent.profile')
99+
expect(java_opts).to include('-Dintroscope.agent.defaultProcessName=test-application-name')
100+
expect(java_opts).to include('-Dintroscope.agent.hostName=test-application-uri-0')
77101

78-
it 'adds agent-name from credentials to JAVA_OPTS if specified' do
79-
component.release
102+
expect(java_opts).to include('-DagentManager.url.1=ssl://test-host-name:5443')
103+
expect(java_opts).to include('-Dintroscope.agent.enterprisemanager.transport.tcp.host.DEFAULT=test-host-name')
104+
expect(java_opts).to include('-Dintroscope.agent.enterprisemanager.transport.tcp.port.DEFAULT=5443')
105+
expect(java_opts).to include('-Dintroscope.agent.enterprisemanager.transport.tcp.socketfactory.DEFAULT=' \
106+
'com.wily.isengard.postofficehub.link.net.SSLSocketFactory')
80107

81-
expect(java_opts).to include('-Dcom.wily.introscope.agent.agentName=another-test-agent-name')
82-
end
108+
expect(java_opts).to include('-Dcom.wily.introscope.agent.agentName=$(expr "$VCAP_APPLICATION" : ' \
109+
'\'.*application_name[": ]*\\([A-Za-z0-9_-]*\\).*\')')
83110
end
111+
end
84112

85-
context do
86-
let(:credentials) { super().merge 'port' => 'test-port' }
113+
context do
114+
let(:credentials) { { 'url' => 'http://test-host-name:8081' } }
87115

88-
it 'adds port from credentials to JAVA_OPTS if specified' do
89-
component.release
116+
it 'parses the url and sets host, port, and http socket factory' do
117+
component.release
90118

91-
expect(java_opts).to include('-Dintroscope.agent.enterprisemanager.transport.tcp.port.DEFAULT=test-port')
92-
expect(java_opts).to include('-DagentManager.url.1=http://test-host-name:test-port')
93-
end
119+
expect(java_opts).to include('-javaagent:$PWD/.java-buildpack/introscope_agent/Agent.jar')
120+
expect(java_opts).to include('-Dcom.wily.introscope.agentProfile=$PWD/.java-buildpack/introscope_agent/core' \
121+
'/config/IntroscopeAgent.profile')
122+
expect(java_opts).to include('-Dintroscope.agent.defaultProcessName=test-application-name')
123+
expect(java_opts).to include('-Dintroscope.agent.hostName=test-application-uri-0')
124+
125+
expect(java_opts).to include('-DagentManager.url.1=http://test-host-name:8081')
126+
expect(java_opts).to include('-Dintroscope.agent.enterprisemanager.transport.tcp.host.DEFAULT=test-host-name')
127+
expect(java_opts).to include('-Dintroscope.agent.enterprisemanager.transport.tcp.port.DEFAULT=8081')
128+
expect(java_opts).to include('-Dintroscope.agent.enterprisemanager.transport.tcp.socketfactory.DEFAULT=' \
129+
'com.wily.isengard.postofficehub.link.net.HttpTunnelingSocketFactory')
130+
131+
expect(java_opts).to include('-Dcom.wily.introscope.agent.agentName=$(expr "$VCAP_APPLICATION" : ' \
132+
'\'.*application_name[": ]*\\([A-Za-z0-9_-]*\\).*\')')
94133
end
134+
end
95135

96-
context do
97-
let(:credentials) { super().merge 'ssl' => 'true' }
136+
context do
137+
let(:credentials) { { 'url' => 'https://test-host-name:8444' } }
98138

99-
it 'adds ssl socket factory from credentials to JAVA_OPTS if specified' do
100-
component.release
139+
it 'parses the url and sets host, port, and https socket factory' do
140+
component.release
101141

102-
expect(java_opts).to include('-Dintroscope.agent.enterprisemanager.transport.tcp.socketfactory.DEFAULT=' \
103-
'com.wily.isengard.postofficehub.link.net.SSLSocketFactory')
104-
expect(java_opts).to include('-DagentManager.url.1=https://test-host-name')
105-
end
142+
expect(java_opts).to include('-javaagent:$PWD/.java-buildpack/introscope_agent/Agent.jar')
143+
expect(java_opts).to include('-Dcom.wily.introscope.agentProfile=$PWD/.java-buildpack/introscope_agent/core' \
144+
'/config/IntroscopeAgent.profile')
145+
expect(java_opts).to include('-Dintroscope.agent.defaultProcessName=test-application-name')
146+
expect(java_opts).to include('-Dintroscope.agent.hostName=test-application-uri-0')
147+
148+
expect(java_opts).to include('-DagentManager.url.1=https://test-host-name:8444')
149+
expect(java_opts).to include('-Dintroscope.agent.enterprisemanager.transport.tcp.host.DEFAULT=test-host-name')
150+
expect(java_opts).to include('-Dintroscope.agent.enterprisemanager.transport.tcp.port.DEFAULT=8444')
151+
expect(java_opts).to include('-Dintroscope.agent.enterprisemanager.transport.tcp.socketfactory.DEFAULT=' \
152+
'com.wily.isengard.postofficehub.link.net.HttpsTunnelingSocketFactory')
153+
154+
expect(java_opts).to include('-Dcom.wily.introscope.agent.agentName=$(expr "$VCAP_APPLICATION" : ' \
155+
'\'.*application_name[": ]*\\([A-Za-z0-9_-]*\\).*\')')
106156
end
107157
end
108-
109158
end
110-
111159
end

0 commit comments

Comments
 (0)