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

Commit 4770050

Browse files
author
Chris Wiechmann
committed
Update OpenTrafficPipeline.conf
1 parent fa7d5fe commit 4770050

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

logstash/pipelines/OpenTrafficPipeline.conf

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,11 @@ filter {
147147
# Without an API name, only API path is used for the API lookup.
148148
mutate { add_field => { "[@metadata][apiName]" => "" } }
149149
}
150-
# Create a cache key for the API either based on the received request path or the configured path.
151-
# For example: /v1/get/pet/687687678 --> CACHE_API_PER_NAME = /v1/get/pet makes sure the API is cached based on the API-Name
150+
# Create a cache key for the API either on the complete received request path or if configured, only using a specific part of the path.
151+
# This prevents API requests with path parameters from not being cached efficiently due to their variable parameter.
152+
# Example: API-Request: /v1/get/pet/687687678, Configured-Path: /v1/get/pet - API-Details cached based on Configured-Path (/v1/get/pet)
152153
ruby {
154+
id => "Set API-Cache-Key prefix"
153155
code => '
154156
cacheAPIPaths = event.get("[@metadata][cacheAPIPaths]");
155157
apiRequestPath = event.get("[transactionSummary][path]");
@@ -158,24 +160,26 @@ filter {
158160
return;
159161
end
160162
apiName = event.get("[transactionSummary][serviceContext][service]");
161-
logger.info("Configured paths and current API-Request path: ", { "cacheAPIPaths" => cacheAPIPaths, "apiRequestPath" => apiRequestPath } );
163+
logger.debug("Configured paths and current API-Request path: ", { "configuredPaths" => cacheAPIPaths, "apiRequestPath" => apiRequestPath } );
162164
event.set("[@metadata][apiCacheKeyPrefix]", apiRequestPath);
163165
for configuredPath in cacheAPIPaths.split(",") do
164166
if(apiRequestPath.start_with?(configuredPath) )
165-
logger.info("Using configured path as primary cache key as it matches to request path. ", { "configuredPath" => configuredPath, "apiRequestPath" => apiRequestPath });
167+
logger.debug("Using configured path as primary cache key because it matches to request path. ", { "configuredPath" => configuredPath, "apiRequestPath" => apiRequestPath });
166168
event.set("[@metadata][apiCacheKeyPrefix]", configuredPath);
167169
break;
168170
end
169171
end
170172
'
171173
}
172174
mutate {
175+
id => "Set API-Cache-Key"
173176
add_field => {
174177
apiCacheKey => "%{[@metadata][apiCacheKeyPrefix]}###%{[processInfo][groupId]}###%{[processInfo][gatewayRegion]}"
175178
}
176179
}
177180
# Lookup the cache with the created API-Key (API-Name---API-Path)
178181
memcached {
182+
id => "Lookup API-Details"
179183
hosts => "${MEMCACHED}"
180184
namespace => "api_details"
181185
get => { "%{apiCacheKey}" => "[apiDetails]" }
@@ -227,9 +231,10 @@ filter {
227231
# If the API has been looked up add it to the cache
228232
if([@metadata][updateAPICache]=="true") {
229233
ruby {
230-
code => 'logger.debug("Adding API-Lookup details to cache: ", "apiDetails" => event.get("[apiDetails]"), "apiCacheKey" => event.get("[apiCacheKey]") );'
234+
code => 'logger.info("Adding API-Lookup details to cache: ", "apiCacheKey" => event.get("[apiCacheKey]"), "apiDetails" => event.get("[apiDetails]") );'
231235
}
232236
memcached {
237+
id => "Add API-Details to cache"
233238
hosts => "${MEMCACHED}"
234239
namespace => "api_details"
235240
ttl => "${LOOKUP_CACHE_TTL:600}"

0 commit comments

Comments
 (0)