@@ -64,33 +64,52 @@ 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
67+ # If we have a ServiceConext we have to enrich it with the API-Details
7968 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]}"
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]) {
81+ http {
82+ url => "${API_BUILDER_URL}/api/elk/v1/api/lookup/api"
83+ query => {
84+ "apiName" => "%{[transactionSummary][serviceContext][service]}"
85+ "apiPath" => "%{[transactionSummary][path]}"
86+ }
87+ target_body => "apiDetails"
88+ add_field => { "[@metadata][updateAPICache]" => "true" }
8589 }
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]}"
90+ }
91+ # At this point we should have the apiDetails either from the cache or looked up via HTTP
92+ if([apiDetails]) {
93+ mutate {
94+ add_field => {
95+ "[transactionSummary][serviceContext][apiOrg]" => "%{[apiDetails][organizationName]}"
96+ "[transactionSummary][serviceContext][apiVersion]" => "%{[apiDetails][version]}"
97+ "[transactionSummary][serviceContext][apiDeprecated]" => "%{[apiDetails][deprecated]}"
98+ "[transactionSummary][serviceContext][apiState]" => "%{[apiDetails][state]}"
99+ }
92100 }
93- remove_field => [ "apiDetails", "headers" ]
101+ # If the API has been looked up add it to the cache
102+ if([@metadata][updateAPICache]=="true") {
103+ memcached {
104+ hosts => "${MEMCACHED}"
105+ namespace => "api_details"
106+ ttl => 3600
107+ set => { "[apiDetails]" => "%{apiCacheKey}" }
108+ }
109+ }
110+ }
111+ mutate {
112+ remove_field => [ "apiDetails", "headers", "updateAPICache", "apiCacheKey" ]
94113 }
95114 # If the API-Lookup failed - Clone the event which is send to an Error index and shown in Traffic-Monitor
96115 if("_httprequestfailure" in [tags]) {
@@ -111,7 +130,6 @@ filter {
111130 }
112131 }
113132 }
114- #}
115133 }
116134 } else if([logtype] == "trace") {
117135 if [message] =~ /^#/ {
0 commit comments