Skip to content
This repository was archived by the owner on Dec 14, 2022. It is now read-only.

Commit 6449afc

Browse files
author
Chris Wiechmann
committed
Logstash pipeline documentation improved and tests fixed
1 parent e9e39e3 commit 6449afc

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

logstash/pipelines/OpenTrafficPipeline.conf

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ filter {
141141
if([transactionSummary][serviceContext][service]) {
142142
mutate { add_field => { "[@metadata][apiName]" => "%{[transactionSummary][serviceContext][service]}" } }
143143
} else {
144+
# Without an API name, only API path is used for the API lookup.
144145
mutate { add_field => { "[@metadata][apiName]" => "" } }
145146
}
146147
# Create a key for the API
@@ -187,9 +188,10 @@ filter {
187188
# Take over configured custom properties for this API
188189
copy => { "[apiDetails][customProperties]" => "[transactionSummary][customProperties]" }
189190
}
190-
# Some native APIs (like Healthcheck) don't have a API-Name and Operation (MethodName), so we take it from the looked up API-Details
191-
# To avoid that every native API must be configured the local API-Lookup-File, we only do it, when really something has been looked up.
192-
# It might also be the case, that the serviceName and operation is set by the Policy. This is then taken over from the leg0 (See below)
191+
# The ServiceName and the operation will be taken over only if a name was found at all. This is not the
192+
# case if the API does not exist in the API Manager and has not been configured locally.
193+
# Furthermore, the ServiceName and Operation will not be applied if the ServiceContext has already been set.
194+
# For example with APIs that run through the API Manager and the filter: Set Service Context was used.
193195
if !([transactionSummary][serviceContext][service] and [apiDetails][name]) {
194196
mutate {
195197
copy => { "[apiDetails][name]" => "[transactionSummary][serviceContext][service]" }
@@ -237,7 +239,7 @@ filter {
237239
remove_field => "[transactionSummary][status]"
238240
}
239241
# Place all transactionSummary information directlly into the root, as it makes no sense to have a
240-
# a transactionSummary object within the transactionSummary index.
242+
# transactionSummary object within the transactionSummary index.
241243
ruby {
242244
code => '
243245
event.remove("[transactionSummary][path]");
@@ -248,10 +250,10 @@ filter {
248250
'
249251
}
250252
}
251-
# Also we need to copy some leg0 information into the summary index
253+
# If a transactionElement.leg0 is processed, copy some leg0 information into the summary index
252254
if [transactionElements][leg0] {
253255
mutate {
254-
# Before copy most of the properties - Remove some stuff we don't need in the summaryIndex
256+
# We don't need all the information in the Summary Index, so some will be removed.
255257
remove_field => [
256258
"[transactionElements][leg0][leg]",
257259
"[transactionElements][leg0][protocolInfo][recvHeader]",
@@ -269,8 +271,8 @@ filter {
269271
}
270272
'
271273
}
272-
# A native API may contain a manually set serviceContext (set by Set Service Context filter or WebServiceHandler)
273-
# If it exists take it over into the summaryIndex
274+
# A native API may contain a serviceName & operation
275+
# If it exists, this ServiceName is copied to the TransactionSummary ServiceContext.
274276
# For managed APIs (API-Manager based) it's the same anyway
275277
if [transactionElements][leg0][serviceName] {
276278
mutate {

logstash/test/http/test-opentrafficlog.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"codec": "json_lines",
77
"testcases": [
88
{
9-
"description": "Test transactionElement event with leg0 having a serviceName and operation set",
9+
"description": "Test transactionElement event with leg0 having a serviceName and operation set, but not serviceContext",
1010
"input": [
1111
"{\"timestamp\":1594673918042,\"correlationId\":\"feca0c5f7f550c81357fdfXX\",\"processInfo\":{\"hostname\":\"ip-172-31-56-150.ec2.internal\",\"domainId\":\"e1ff3aab-3b11-4820-a1be-3763da2beda4\",\"groupId\":\"group-2\",\"groupName\":\"group-a\",\"serviceId\":\"instance-2\",\"serviceName\":\"instance-2\",\"version\":\"7.7.20200530\"},\"transactionElement\":{\"leg\":0,\"duration\":20,\"serviceName\":\"Petstore\",\"operation\":\"getInventory\",\"finalStatus\":\"Pass\",\"protocolInfo\":{\"http\":{\"uri\":\"/petstore/v2/store/inventory\",\"status\":200,\"statusText\":\"OK\",\"method\":\"GET\",\"vhost\":null,\"wafStatus\":0,\"bytesSent\":774,\"bytesReceived\":126,\"remoteName\":\"127.0.0.1\",\"remoteAddr\":\"127.0.0.1\",\"localAddr\":\"127.0.0.1\",\"remotePort\":\"59574\",\"localPort\":\"8065\",\"sslSubject\":null,\"authSubjectId\":\"180b1f32-d72f-40f4-949a-fc3f3f7dec2c\"},\"recvHeader\":\"GET /petstore/v2/store/inventory HTTP/1.0\\r\\nConnection: close\\r\\nHost: localhost\\r\\nKeyId: 6cd55c27-675a-444a-9bc7-ae9a7869184d\\r\\n\\r\\n\",\"sentHeader\":\"HTTP/1.1 200 OK\\r\\nMax-Forwards: 20\\r\\nVia: 1.0 ip-172-31-56-150.ec2.internal (Gateway)\\r\\nConnection: close\\r\\nX-CorrelationID: Id-feca0c5f7f550c81357fdfXX 0\\r\\ncache-control: no-store, no-cache, must-revalidate, proxy-revalidate\\r\\nDate: Mon, 13 Jul 2020 20:58:38 GMT\\r\\netag: W/\\\"52-LxypU3mP2zpjiEr7yZRKlgVdx3c\\\"\\r\\nexpires: 0\\r\\npragma: no-cache\\r\\nrequest-id: c190fa5f-a192-4e57-8eec-c75a6f52b90d\\r\\nresponse-time: 2\\r\\nserver: API Builder/4.28.10\\r\\nstart-time: 1594673918059\\r\\nsurrogate-control: no-store\\r\\nVary: Accept-Encoding\\r\\nx-content-type-options: nosniff\\r\\nx-frame-options: DENY\\r\\nx-xss-protection: 1; mode=block\\r\\ncontent-md5: 43364b0ef391a24f9a0e587356726c0d\\r\\ncontent-type: application/json; charset=utf-8\\r\\n\\r\\n\",\"recvPayload\":null,\"sentPayload\":null}}}"
1212
],
@@ -43,11 +43,9 @@
4343
"serviceId": "instance-2",
4444
"version": "7.7.20200530"
4545
},
46-
"transactionSummary": {
47-
"serviceContext": {
48-
"method": "getInventory",
49-
"service": "Petstore"
50-
}
46+
"serviceContext": {
47+
"method": "getInventory",
48+
"service": "Petstore"
5149
}
5250
},
5351
{

0 commit comments

Comments
 (0)