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

Commit b0e940a

Browse files
author
Chris Wiechmann
committed
Added support to memcache API-Details instead of perform HTTP-Lookup
with every request
1 parent b080ea8 commit b0e940a

File tree

1 file changed

+48
-32
lines changed

1 file changed

+48
-32
lines changed

logstash/pipeline/pipeline.conf

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -64,55 +64,71 @@ filter {
6464
remove_field => "[transactionSummary][serviceContexts]"
6565
rename => ["[transactionSummary][serviceContext][org]", "[transactionSummary][serviceContext][appOrg]" ]
6666
}
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]) {
67+
# If we have a ServiceConext we have to enrich it with the API-Details
68+
if([transactionSummary][serviceContext]) {
69+
# Create a key for the API
70+
mutate {
71+
add_field => { "apiCacheKey" => "%{[transactionSummary][path]}" }
72+
}
73+
# Lookup the cache with the created API-Key (API-Name---API-Path)
74+
memcached {
75+
hosts => ["memcached"]
76+
namespace => "api_details"
77+
get => { "%{apiCacheKey}" => "[apiDetails]" }
78+
}
79+
# If we have nothing in the cache, perform the Lookup via the HTTP-Builder API
80+
if !([apiDetails]) {
8281
http {
8382
url => "${API_BUILDER_URL}/api/elk/v1/api/lookup/api"
8483
query => {
8584
"apiName" => "%{[transactionSummary][serviceContext][service]}"
8685
"apiPath" => "%{[transactionSummary][path]}"
8786
}
8887
target_body => "apiDetails"
88+
add_field => { "updateAPICache" => "true" }
89+
}
90+
}
91+
# At this point we should have the apiDetails either from the cache or looked up via HTTP
92+
if([apiDetails]) {
93+
mutate {
8994
add_field => {
9095
"[transactionSummary][serviceContext][apiOrg]" => "%{[apiDetails][organizationName]}"
9196
"[transactionSummary][serviceContext][apiVersion]" => "%{[apiDetails][version]}"
9297
"[transactionSummary][serviceContext][apiDeprecated]" => "%{[apiDetails][deprecated]}"
9398
"[transactionSummary][serviceContext][apiState]" => "%{[apiDetails][state]}"
9499
}
95-
remove_field => [ "apiDetails", "headers" ]
96100
}
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" } }
101+
# If the API has been looked up add it to the cache
102+
if([updateAPICache]=="true") {
103+
memcached {
104+
hosts => ["memcached"]
105+
namespace => "api_details"
106+
ttl => 3600
107+
set => { "[apiDetails]" => "%{apiCacheKey}" }
113108
}
114109
}
115110
}
111+
mutate {
112+
remove_field => [ "apiDetails", "headers", "updateAPICache", "apiCacheKey" ]
113+
}
114+
# If the API-Lookup failed - Clone the event which is send to an Error index and shown in Traffic-Monitor
115+
if("_httprequestfailure" in [tags]) {
116+
clone {
117+
clones => ['errorEvent']
118+
}
119+
if [type] == 'errorEvent' {
120+
# Fill the URI based on the given path to have it shown in Traffic-Monitor
121+
mutate { add_field => { "[transactionElements][leg0][protocolInfo][http][uri]" => "%{[transactionSummary][path]}" } }
122+
mutate { replace => { "[transactionElements][leg0][protocolInfo][http][vhost]" => "Logstash Error" } }
123+
mutate { replace => { "[transactionElements][leg0][protocolInfo][http][method]" => "LOGSTASH" } }
124+
mutate { replace => { "[transactionElements][leg0][protocolInfo][http][status]" => "900" } }
125+
mutate { replace => { "[transactionElements][leg0][protocolInfo][http][statusText]" => "ERROR" } }
126+
mutate { replace => { "[transactionElements][leg0][protocolInfo][http][authSubjectId]" => "ID: %{[correlationId]}" } }
127+
mutate { replace => { "[transactionSummary][serviceContext][method]" => "check the logs" } }
128+
# Make sure, the Correlation-ID is unique to avoid an update of the original document
129+
mutate { replace => { "[correlationId]" => "%{[correlationId]}-Error" } }
130+
}
131+
}
116132
}
117133
}
118134
} else if([logtype] == "trace") {

0 commit comments

Comments
 (0)