Skip to content

Commit d12e4e0

Browse files
authored
[SQL Storage indexer] Avoid storing in cache requests with package query parameter (#1378)
This PR avoids storing in the search cache requests that contain the "package=<package>" query parameter. Due to the potential for a large volume of unique requests, the cache could be easily filled just with those requests or causing evictions. Moreover, these requests (just querying for a package) typically have rapid response times, which means not using the cache is acceptable.
1 parent a77fb30 commit d12e4e0

3 files changed

Lines changed: 25 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### Added
1414
* New Security subcategory "asset_inventory" [#1357](https://github.com/elastic/package-registry/pull/1357)
15+
* Update default value for the batch size used in SQL storage indexer. [#1372](https://github.com/elastic/package-registry/pull/1372)
16+
* Skip adding to cache requests containing package query parameter. [#1378](https://github.com/elastic/package-registry/pull/1378)
1517

1618
### Deprecated
1719

dev/launch_epr_service_storage_indexer.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ CURRENT_DIR="$(pwd)"
1111
SCRIPT_DIR="$( cd -- "$(dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
1212

1313
usage() {
14-
echo "$0 [-b <bucket_name>] [-p <epr_address>] [-e <emulator_address>] [-i <index_path>] [-c <config_path>] [-s] [-C] [-h]"
14+
echo "$0 [-b <bucket_name>] [-p <epr_address>] [-e <emulator_address>] [-i <index_path>] [-c <config_path>] [-s] [-C] [-d] [-h]"
1515
echo -e "\t-b <bucket_name>: Bucket name. Default: example"
1616
echo -e "\t-p <epr_address>: Address of the package registry service. Default: localhost:8080"
1717
echo -e "\t-e <emulator_address>: Address of the emulator host (fake GCS server). Default: localhost:4443"
@@ -20,6 +20,7 @@ usage() {
2020
echo -e "\t-c <config_path>: Path to the configurastion file. Default: \"\""
2121
echo -e "\t-s : Enable SQL Storage indexer. By default Storage Indexer is enabled."
2222
echo -e "\t-C : Enable Search Cache. Just supported with SQL Storage indexer. By default Search Cache is disabled."
23+
echo -e "\t-d: Enable debug mode. Default: false"
2324
echo -e "\t-h: Show this message"
2425
}
2526

@@ -30,8 +31,9 @@ EMULATOR_HOST="localhost:4443"
3031
CONFIG_PATH="${SCRIPT_DIR}/../config.yml"
3132
ENABLE_STORAGE_SQL_INDEXER=0
3233
ENABLE_SEARCH_CACHE=0
34+
ENABLE_DEBUG_MODE=0
3335

34-
while getopts ":b:p:i:e:c:sCh" o; do
36+
while getopts ":b:p:i:e:c:sdCh" o; do
3537
case "${o}" in
3638
b)
3739
BUCKET_NAME="${OPTARG}"
@@ -54,6 +56,9 @@ while getopts ":b:p:i:e:c:sCh" o; do
5456
C)
5557
ENABLE_SEARCH_CACHE=1
5658
;;
59+
d)
60+
ENABLE_DEBUG_MODE=1
61+
;;
5762
h)
5863
usage
5964
exit 0
@@ -103,7 +108,9 @@ fi
103108
export EPR_DISABLE_PACKAGE_VALIDATION="true"
104109
export EPR_ADDRESS="${ADDRESS}"
105110

106-
# export EPR_LOG_LEVEL="debug"
111+
if [[ "${ENABLE_DEBUG_MODE}" == 1 ]]; then
112+
export EPR_LOG_LEVEL="debug"
113+
fi
107114
export EPR_CONFIG="${CONFIG_PATH}"
108115
# export EPR_SQL_INDEXER_DATABASE_FOLDER_PATH=/tmp
109116
# export EPR_SQL_INDEXER_SEARCH_CACHE_SIZE=100

search.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,19 @@ func searchHandlerWithProxyMode(logger *zap.Logger, indexer Indexer, proxyMode *
7979
serveJSONResponse(r.Context(), w, cacheTime, data)
8080

8181
if cache != nil {
82-
val := cache.Add(r.URL.String(), data)
83-
logger.Debug("added to cache request", zap.String("cache.url", r.URL.String()), zap.Int("cache.size", cache.Len()), zap.Bool("cache.eviction", val))
82+
switch {
83+
case filter.PackageName != "" && !filter.AllVersions:
84+
// Due to the potential for a large volume of unique requests,
85+
// the cache could be easily filled just with those requests or causing evictions.
86+
// Moreover, these requests (just querying for a package) typically have rapid response times,
87+
// which means not using the cache is acceptable. Example:
88+
// - `/search?package=foo` request is not added to the cache
89+
// - `/search?package=foo&all=true` request is is added
90+
logger.Debug("skipped add to cache for search request with package query parameter", zap.String("cache.url", r.URL.String()), zap.Int("cache.size", cache.Len()))
91+
default:
92+
val := cache.Add(r.URL.String(), data)
93+
logger.Debug("added to cache request", zap.String("cache.url", r.URL.String()), zap.Int("cache.size", cache.Len()), zap.Bool("cache.eviction", val))
94+
}
8495
}
8596
}
8697
}

0 commit comments

Comments
 (0)