Skip to content

Commit d83bccd

Browse files
author
Jonas Kunz
authored
Merge pull request #4 from oberschlauberger/feature/elastic-apm
Add Elastic APM demo
2 parents f2a806a + e606eb3 commit d83bccd

20 files changed

+813
-0
lines changed

ocelot-meets-elastic-apm/.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PROMETHEUS_PORT_CUSTOMER_SERVICE=9091

ocelot-meets-elastic-apm/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Ocelot meets Elastic APM
2+
3+
In this demo setup we instrument the Spring pet clinic application with inspectIT Ocelot agents and collect the monitoring data in Elasticsearch. In this configuration, Ocelot exports traces in Jaeger format and pushes them to Elastic's APM server via its Jaeger integration. Metrics are exposed in Prometheus/OpenMetrics format and collected by Elastic Metricbeat.
4+
5+
To run this Demo do the following:
6+
- Make sure docker and docker-compose are installed on your system
7+
- Start the demo with the following command:
8+
```
9+
docker-compose up -d
10+
```
11+
- Wait until the whole stack is running, this might take a couple of minutes
12+
- Check the results in Kibana, depending on your Docker setup you may need to adjust the host for the following links to work:
13+
- [APM and traces in Kibana](http://127.0.0.1:5601/app/apm#/services?rangeFrom=now-15m&rangeTo=now&refreshPaused=true&refreshInterval=0)
14+
- [Ocelot metrics in Kibana](http://127.0.0.1:5601/app/infra#/infrastructure/metrics-explorer?metricsExplorer=(chartOptions:(stack:!f,type:line,yAxisMode:fromZero),options:(aggregation:rate,groupBy:prometheus.labels.service,metrics:!((aggregation:rate,color:color0,field:prometheus.metrics.http_in_responsetime_sum))),timerange:(from:now-15m,interval:%3E%3D10s,to:now)))
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apm-server:
2+
hosts: ["apm-server:8200"]
3+
rum:
4+
enabled: true
5+
jaeger:
6+
http:
7+
enabled: true
8+
host: "apm-server:14268"
9+
10+
output:
11+
elasticsearch:
12+
hosts: elasticsearch:9200
13+
14+
queue.mem.events: 4096
15+
16+
max_procs: 4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
- name: "Gateway"
2+
sources:
3+
- "/gateway"
4+
- "/all"
5+
attributes:
6+
service: "api-gateway"
7+
- name: "Services"
8+
sources:
9+
- "/services"
10+
- "/all"
11+
attributes:
12+
service: ".*-service"
13+
- name: "Default Mapping"
14+
sources:
15+
- "/all"
16+
attributes:
17+
service: ".*"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
inspectit:
2+
instrumentation:
3+
data:
4+
pet_type:
5+
up-propagation: GLOBAL
6+
down-propagation: GLOBAL
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
inspectit:
2+
tags:
3+
extra:
4+
application: PetClinic
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# See https://github.com/inspectIT/inspectit-oce/blob/0.1.M1/inspectit-oce-core/src/main/resources/config/default.yml
2+
# for all the configuration options.
3+
inspectit:
4+
metrics:
5+
# root setting for the polling frequency of all metrics
6+
# when a metrics has no frequency defined separately, this frequency will be used
7+
frequency: 15s
8+
config:
9+
http:
10+
frequency: 10s
11+
logging:
12+
debug: false # set to true to see more details in the agents logs
13+
exporters:
14+
tracing:
15+
jaeger:
16+
enabled: true
17+
url: http://apm-server:14268/api/traces
18+
service-name: ${inspectit.service-name}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
inspectit:
2+
metrics:
3+
definitions:
4+
'[http/in/responsetime]':
5+
views:
6+
'[http/in/count]':
7+
tags:
8+
pet_type: true
9+
'[http/in/responsetime/sum]':
10+
tags:
11+
pet_type: true
12+
13+
instrumentation:
14+
rules:
15+
16+
http_server_servlet_api:
17+
metrics:
18+
'[http/in/responsetime]':
19+
value: http_duration
20+
data-tags:
21+
pet_type: pet_type
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Parametrizes HTTP paths to be used in metrics
2+
inspectit:
3+
instrumentation:
4+
rules:
5+
6+
parametrize_paths:
7+
scopes:
8+
servletapi_servlet_service: true
9+
servletapi_filter_doFilter: true
10+
httpurlconnection_getInputStream: true
11+
apache_http_client_doExecute: true
12+
httpurlconnection_connect: true
13+
httpurlconnection_getOutputStream: true
14+
entry:
15+
parametrized_http_path:
16+
action: string_replace_all
17+
constant-input: { regex: "\\/\\d+(?=\\/|$)" , replacement: "/{id}"}
18+
data-input: { string: http_raw_path}
19+
only-if-not-null: http_raw_path
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
inspectit:
2+
tracing:
3+
auto-tracing:
4+
frequency: 10ms
5+
6+
instrumentation:
7+
data:
8+
get_input_stream_invoked:
9+
down-propagation: JVM_LOCAL
10+
11+
actions:
12+
string_concat_3:
13+
input:
14+
a: String
15+
b: String
16+
c: String
17+
value: new StringBuilder(a).append(b).append(c).toString()
18+
a_get_simple_method_name:
19+
input:
20+
_methodName: String
21+
_class: Class
22+
value: new StringBuilder(_class.getSimpleName()).append('.').append(_methodName).toString()
23+
24+
rules:
25+
# use the existing rules from the default configuration but enable tracing
26+
http_server_servlet_api:
27+
tracing:
28+
start-span: true
29+
name: span_name
30+
kind: SERVER
31+
start-span-conditions:
32+
only-if-true: http_is_entry
33+
attributes:
34+
'http.method': http_method
35+
'http.status_code': http_status
36+
pet-type: pet_type
37+
auto-trace: true
38+
entry:
39+
span_name:
40+
action: string_concat_3
41+
data-input:
42+
a: http_method
43+
c: parametrized_http_path
44+
constant-input:
45+
b: " "
46+
47+
http_client_apache_client:
48+
tracing:
49+
start-span: true
50+
name: span_name
51+
kind: CLIENT
52+
start-span-conditions:
53+
only-if-true: http_is_entry
54+
entry:
55+
span_name:
56+
action: string_concat_3
57+
data-input:
58+
a: http_method
59+
c: parametrized_http_path
60+
constant-input:
61+
b: " "
62+
span_type:
63+
action: set
64+
constant-input: {value: "web"}
65+
66+
67+
httpurlconnection_tracing_start:
68+
scopes:
69+
httpurlconnection_connect: true
70+
httpurlconnection_getOutputStream: true
71+
tracing:
72+
auto-trace: false
73+
start-span: true
74+
continue-span: span_obj
75+
store-span: span_obj
76+
end-span: false
77+
name: span_name
78+
kind: CLIENT
79+
entry:
80+
span_obj:
81+
action: read_attachment_on_this
82+
constant-input: {key: "span"}
83+
http_raw_path:
84+
action: httpurlconnection_get_path
85+
http_method:
86+
action: httpurlconnection_get_method
87+
span_name:
88+
action: string_concat_3
89+
data-input:
90+
a: http_method
91+
c: parametrized_http_path
92+
constant-input:
93+
b: " "
94+
post-entry:
95+
span_obj:
96+
action: replace_attachment_on_this
97+
constant-input: {key: "span"}
98+
data-input: {value: span_obj}
99+
100+
httpurlconnection_tracing_end:
101+
scopes:
102+
httpurlconnection_getInputStream: true
103+
tracing:
104+
auto-trace: false
105+
start-span: true
106+
continue-span: span_obj
107+
store-span: span_obj
108+
end-span: true
109+
continue-span-conditions:
110+
only-if-true: httpurlconn_get_is_entry
111+
start-span-conditions:
112+
only-if-true: httpurlconn_get_is_entry
113+
name: span_name
114+
kind: CLIENT
115+
entry:
116+
httpurlconn_get_is_entry:
117+
action: test_and_set_this_marker
118+
constant-input: {marker: "get_input_stream_invoked"}
119+
span_obj:
120+
action: read_attachment_on_this
121+
constant-input: {key: "span"}
122+
http_raw_path:
123+
action: httpurlconnection_get_path
124+
http_method:
125+
action: httpurlconnection_get_method
126+
span_name:
127+
action: string_concat_3
128+
data-input:
129+
a: http_method
130+
c: parametrized_http_path
131+
constant-input:
132+
b: " "
133+
post-entry:
134+
span_obj:
135+
action: replace_attachment_on_this
136+
constant-input: {key: "span"}
137+
data-input: {value: span_obj}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
inspectit:
2+
instrumentation:
3+
scopes:
4+
s_gateway_controller_validate_pet:
5+
type:
6+
name: org.springframework.samples.petclinic.api.boundary.web.ApiGatewayController
7+
methods:
8+
- name: validatePet
9+
matcher-mode: STARTS_WITH
10+
11+
actions:
12+
a_extract_pet_type:
13+
imports:
14+
- org.springframework.samples.petclinic.api.dto
15+
input:
16+
_arg0: PetDetails
17+
value-body: |
18+
return _arg0.getType().getName();
19+
20+
rules:
21+
r_extract_pet_type:
22+
scopes:
23+
s_gateway_controller_validate_pet: true
24+
tracing:
25+
start-span: true
26+
attributes:
27+
pet-type: pet_type
28+
resource: simple_method_name
29+
entry:
30+
pet_type:
31+
action: a_extract_pet_type
32+
simple_method_name:
33+
action: a_get_simple_method_name
34+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
inspectit:
2+
instrumentation:
3+
4+
scopes:
5+
hsqldb_prepared_statement_execute:
6+
type:
7+
name: org.hsqldb.jdbc.JDBCPreparedStatement
8+
methods:
9+
- name: execute
10+
matcher-mode: STARTS_WITH
11+
12+
data:
13+
db_name: {down-propagation: NONE, is-tag: false}
14+
sql: {down-propagation: NONE, is-tag: false}
15+
16+
actions:
17+
# Extracts the SQL from a PreparedStatement for HSQLDB
18+
hsqldb_prepared_statement_get_sql:
19+
imports:
20+
- org.hsqldb.jdbc
21+
- java.lang.reflect
22+
input:
23+
_this: JDBCPreparedStatement
24+
_class: Class
25+
value-body: |
26+
Field sqlField = _class.getDeclaredField("sql");
27+
sqlField.setAccessible(true);
28+
return sqlField.get(_this);
29+
30+
rules:
31+
# We also trace JDBC calls including their target database
32+
servicegraph_record_jdbc_calls:
33+
tracing:
34+
start-span: true
35+
attributes:
36+
'sql.database': db_name
37+
dd_service: db_name
38+
dd_type: span_type
39+
dd_resource: sql
40+
start-span-conditions:
41+
only-if-true: servicegraph_is_entry
42+
entry:
43+
db_name:
44+
action: get_jdbc_statement_connection_name
45+
span_type:
46+
action: set
47+
constant-input: {value: "sql"}
48+
49+
# Extract the sql and add it to the trace
50+
hsqldb_get_prep_statement_sql:
51+
scopes:
52+
hsqldb_prepared_statement_execute: true
53+
entry:
54+
sql:
55+
action: hsqldb_prepared_statement_get_sql

0 commit comments

Comments
 (0)