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

Commit b080ea8

Browse files
author
Chris Wiechmann
committed
[skip ci] Adding memcached
1 parent 3550252 commit b080ea8

File tree

2 files changed

+55
-44
lines changed

2 files changed

+55
-44
lines changed

docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ services:
8888
depends_on:
8989
- elasticsearch1
9090
- elk-traffic-monitor-api
91+
- memcached
92+
networks:
93+
- elastic
94+
95+
# Memcached is used by the Logstash pipeline to cache API-Lookup information that are used to get the API-Organization
96+
memcached:
97+
image: memcached:1.6.6-alpine
98+
links:
99+
- elasticsearch1
91100
networks:
92101
- elastic
93102

logstash/pipeline/pipeline.conf

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -64,54 +64,56 @@ filter {
6464
remove_field => "[transactionSummary][serviceContexts]"
6565
rename => ["[transactionSummary][serviceContext][org]", "[transactionSummary][serviceContext][appOrg]" ]
6666
}
67-
# Future plan is to perform side-calls only if not yet already cached
68-
#mutate {
69-
# add_field => { "apiCacheKey" => "%{[transactionSummary][serviceContext][service]}---%{[transactionSummary][path]}" }
70-
#}
71-
#memcached {
72-
# namespace => "api_details"
73-
# ttl => 300
74-
# get => { "apiCacheKey" => "[transactionSummary][serviceContext][serviceOrg]" }
75-
# remove_field => [ "apiCacheKey" ]
76-
#}
77-
#if ![transactionSummary][serviceContext][serviceOrg] {
78-
# Perform a side-call to load organization details for the API
79-
if([transactionSummary][serviceContext]) {
80-
http {
81-
url => "${API_BUILDER_URL}/api/elk/v1/api/lookup/api"
82-
query => {
83-
"apiName" => "%{[transactionSummary][serviceContext][service]}"
84-
"apiPath" => "%{[transactionSummary][path]}"
85-
}
86-
target_body => "apiDetails"
87-
add_field => {
88-
"[transactionSummary][serviceContext][apiOrg]" => "%{[apiDetails][organizationName]}"
89-
"[transactionSummary][serviceContext][apiVersion]" => "%{[apiDetails][version]}"
90-
"[transactionSummary][serviceContext][apiDeprecated]" => "%{[apiDetails][deprecated]}"
91-
"[transactionSummary][serviceContext][apiState]" => "%{[apiDetails][state]}"
92-
}
93-
remove_field => [ "apiDetails", "headers" ]
94-
}
95-
# If the API-Lookup failed - Clone the event which is send to an Error index and shown in Traffic-Monitor
96-
if("_httprequestfailure" in [tags]) {
97-
clone {
98-
clones => ['errorEvent']
67+
# Create a key for the API
68+
mutate {
69+
add_field => { "apiCacheKey" => "%{[transactionSummary][serviceContext][service]}---%{[transactionSummary][path]}" }
70+
}
71+
memcached {
72+
hosts => ["memcached"]
73+
namespace => "api_details"
74+
ttl => 300
75+
get => { "apiCacheKey" => "[transactionSummary][serviceContext][apiOrg]" }
76+
remove_field => [ "apiCacheKey" ]
77+
}
78+
# If the apiOrg is already set, the information has been loaded before from memcached
79+
if ![transactionSummary][serviceContext][apiOrg] {
80+
# Perform a side-call to load organization details for the API
81+
if([transactionSummary][serviceContext]) {
82+
http {
83+
url => "${API_BUILDER_URL}/api/elk/v1/api/lookup/api"
84+
query => {
85+
"apiName" => "%{[transactionSummary][serviceContext][service]}"
86+
"apiPath" => "%{[transactionSummary][path]}"
87+
}
88+
target_body => "apiDetails"
89+
add_field => {
90+
"[transactionSummary][serviceContext][apiOrg]" => "%{[apiDetails][organizationName]}"
91+
"[transactionSummary][serviceContext][apiVersion]" => "%{[apiDetails][version]}"
92+
"[transactionSummary][serviceContext][apiDeprecated]" => "%{[apiDetails][deprecated]}"
93+
"[transactionSummary][serviceContext][apiState]" => "%{[apiDetails][state]}"
94+
}
95+
remove_field => [ "apiDetails", "headers" ]
9996
}
100-
if [type] == 'errorEvent' {
101-
# Fill the URI based on the given path to have it shown in Traffic-Monitor
102-
mutate { add_field => { "[transactionElements][leg0][protocolInfo][http][uri]" => "%{[transactionSummary][path]}" } }
103-
mutate { replace => { "[transactionElements][leg0][protocolInfo][http][vhost]" => "Logstash Error" } }
104-
mutate { replace => { "[transactionElements][leg0][protocolInfo][http][method]" => "LOGSTASH" } }
105-
mutate { replace => { "[transactionElements][leg0][protocolInfo][http][status]" => "900" } }
106-
mutate { replace => { "[transactionElements][leg0][protocolInfo][http][statusText]" => "ERROR" } }
107-
mutate { replace => { "[transactionElements][leg0][protocolInfo][http][authSubjectId]" => "ID: %{[correlationId]}" } }
108-
mutate { replace => { "[transactionSummary][serviceContext][method]" => "check the logs" } }
109-
# Make sure, the Correlation-ID is unique to avoid an update of the original document
110-
mutate { replace => { "[correlationId]" => "%{[correlationId]}-Error" } }
97+
# If the API-Lookup failed - Clone the event which is send to an Error index and shown in Traffic-Monitor
98+
if("_httprequestfailure" in [tags]) {
99+
clone {
100+
clones => ['errorEvent']
101+
}
102+
if [type] == 'errorEvent' {
103+
# Fill the URI based on the given path to have it shown in Traffic-Monitor
104+
mutate { add_field => { "[transactionElements][leg0][protocolInfo][http][uri]" => "%{[transactionSummary][path]}" } }
105+
mutate { replace => { "[transactionElements][leg0][protocolInfo][http][vhost]" => "Logstash Error" } }
106+
mutate { replace => { "[transactionElements][leg0][protocolInfo][http][method]" => "LOGSTASH" } }
107+
mutate { replace => { "[transactionElements][leg0][protocolInfo][http][status]" => "900" } }
108+
mutate { replace => { "[transactionElements][leg0][protocolInfo][http][statusText]" => "ERROR" } }
109+
mutate { replace => { "[transactionElements][leg0][protocolInfo][http][authSubjectId]" => "ID: %{[correlationId]}" } }
110+
mutate { replace => { "[transactionSummary][serviceContext][method]" => "check the logs" } }
111+
# Make sure, the Correlation-ID is unique to avoid an update of the original document
112+
mutate { replace => { "[correlationId]" => "%{[correlationId]}-Error" } }
113+
}
111114
}
112115
}
113116
}
114-
#}
115117
}
116118
} else if([logtype] == "trace") {
117119
if [message] =~ /^#/ {

0 commit comments

Comments
 (0)