@@ -147,9 +147,11 @@ filter {
147
147
# Without an API name, only API path is used for the API lookup.
148
148
mutate { add_field => { "[@metadata][apiName]" => "" } }
149
149
}
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)
152
153
ruby {
154
+ id => "Set API-Cache-Key prefix"
153
155
code => '
154
156
cacheAPIPaths = event.get("[@metadata][cacheAPIPaths]");
155
157
apiRequestPath = event.get("[transactionSummary][path]");
@@ -158,24 +160,26 @@ filter {
158
160
return;
159
161
end
160
162
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 } );
162
164
event.set("[@metadata][apiCacheKeyPrefix]", apiRequestPath);
163
165
for configuredPath in cacheAPIPaths.split(",") do
164
166
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 });
166
168
event.set("[@metadata][apiCacheKeyPrefix]", configuredPath);
167
169
break;
168
170
end
169
171
end
170
172
'
171
173
}
172
174
mutate {
175
+ id => "Set API-Cache-Key"
173
176
add_field => {
174
177
apiCacheKey => "%{[@metadata][apiCacheKeyPrefix]}###%{[processInfo][groupId]}###%{[processInfo][gatewayRegion]}"
175
178
}
176
179
}
177
180
# Lookup the cache with the created API-Key (API-Name---API-Path)
178
181
memcached {
182
+ id => "Lookup API-Details"
179
183
hosts => "${MEMCACHED}"
180
184
namespace => "api_details"
181
185
get => { "%{apiCacheKey}" => "[apiDetails]" }
@@ -227,9 +231,10 @@ filter {
227
231
# If the API has been looked up add it to the cache
228
232
if([@metadata][updateAPICache]=="true") {
229
233
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 ]") );'
231
235
}
232
236
memcached {
237
+ id => "Add API-Details to cache"
233
238
hosts => "${MEMCACHED}"
234
239
namespace => "api_details"
235
240
ttl => "${LOOKUP_CACHE_TTL:600}"
0 commit comments