Skip to content

Commit

Permalink
cloud: Add cache redirector support
Browse files Browse the repository at this point in the history
Signed-off-by: Abhishek Kumar <[email protected]>
  • Loading branch information
octonawish-akcodes committed Aug 11, 2023
1 parent 08e3e27 commit 2523e3d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions cloud
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,7 @@ function cloud_function_withdraw() {
# --updated-topic=NAME
# --updated_urls_topic=NAME
# --cache-bucket-name=NAME
# --cache-redirector-url=URL
# --spool-collection-path=PATH
# --extra-cc=ADDRS
# --smtp-to-addrs=ADDRS --smtp-password-secret=NAME
Expand All @@ -1340,6 +1341,7 @@ function cloud_functions_env() {
smtp_topic smtp_subscription \
pgpass_secret \
cache_bucket_name \
cache_redirector_url \
database \
clean_test_databases \
empty_test_databases \
Expand Down Expand Up @@ -1368,6 +1370,7 @@ function cloud_functions_env() {
[KCIDB_SMTP_PASSWORD_SECRET]="$smtp_password_secret"
[KCIDB_SMTP_FROM_ADDR]="[email protected]"
[KCIDB_CACHE_BUCKET_NAME]="$cache_bucket_name"
[KCIDB_CACHE_REDIRECTOR_URL]="$cache_redirector_url"
)
if [ -n "$extra_cc" ]; then
env[KCIDB_EXTRA_CC]="$extra_cc"
Expand Down Expand Up @@ -1413,6 +1416,7 @@ function cloud_functions_env() {
# --updated-urls-topic=NAME
# --updated-topic=NAME
# --spool-collection-path=PATH
# --cache-redirect-function-name=NAME
# --env-yaml=YAML
function cloud_functions_deploy() {
params="$(getopt_vars project prefix source \
Expand All @@ -1421,6 +1425,7 @@ function cloud_functions_deploy() {
updated_urls_topic \
updated_topic \
spool_collection_path \
cache_redirect_function_name \
env_yaml \
-- "$@")"
eval "$params"
Expand Down Expand Up @@ -1477,7 +1482,7 @@ function cloud_functions_deploy() {
--max-instances=1 \
--timeout 540

cloud_function_deploy "$project" "${prefix}cache_redirect" \
cloud_function_deploy "$project" "${cache_redirect_function_name}" \
"$source" \
--entry-point kcidb_cache_redirect \
--env-vars-file "$env_yaml_file" \
Expand All @@ -1502,14 +1507,16 @@ function cloud_functions_deploy() {
}

# Withdraw Cloud Functions
# Args: project prefix
# Args: project prefix, cache_redirect_function_name
function cloud_functions_withdraw() {
declare -r project="$1"; shift
declare -r prefix="$1"; shift
declare -r cache_redirect_function_name="$1"; shift
cloud_function_withdraw "$project" "${prefix}pick_notifications"
cloud_function_withdraw "$project" "${prefix}send_notification"
cloud_function_withdraw "$project" "${prefix}spool_notifications"
cloud_function_withdraw "$project" "${prefix}cache_urls"
cloud_function_withdraw "$project" "${cache_redirect_function_name}"
cloud_function_withdraw "$project" "${prefix}load_queue"
}

Expand Down Expand Up @@ -1797,6 +1804,9 @@ function execute_command() {
declare -r load_queue_trigger_topic="${prefix}load_queue_trigger"
declare -r cache_bucket_name="${project}_${prefix}cache"
declare -r pick_notifications_trigger_topic="${prefix}pick_notifications_trigger"
declare -r cache_redirect_function_name="${prefix}cache_redirect"
declare cache_redirector_url="https://${CLOUD_FUNCTION_REGION}-${project}.cloud"
declare -r cache_redirector_url+="functions.net/${cache_redirect_function_name}"
declare -r updated_urls_topic="${prefix}updated_urls"
declare -r new_topic="${prefix}new"
declare -r new_load_subscription="${prefix}new_load"
Expand Down Expand Up @@ -1923,6 +1933,7 @@ function execute_command() {
declare -r -a env_args=(
--log-level="$log_level"
--cache-bucket-name="$cache_bucket_name"
--cache-redirector-url="$cache_redirector_url"
--optimize="$optimize"
--heavy-asserts="$heavy_asserts"
--new-topic="$new_topic"
Expand Down Expand Up @@ -1996,6 +2007,7 @@ function execute_command() {
"$pick_notifications_trigger_topic" \
--updated-urls-topic="$updated_urls_topic" \
--updated-topic="$updated_topic" \
--cache-redirect-function-name="$cache_redirect_function_name" \
--spool-collection-path="$spool_collection_path" \
--env-yaml="${env_yaml}"
sections_run "$sections" scheduler_deploy \
Expand All @@ -2017,7 +2029,8 @@ function execute_command() {
sections_run "$sections" submitters_withdraw \
"$project" "$new_topic" "${submitters[@]}"
sections_run "$sections" scheduler_withdraw "$project" "$prefix"
sections_run "$sections" cloud_functions_withdraw "$project" "$prefix"
sections_run "$sections" cloud_functions_withdraw "$project" "$prefix" \
--cache-redirect-function-name="$cache_redirect_function_name"
sections_run "$sections" storage_withdraw "$cache_bucket_name"
sections_run "$sections" firestore_withdraw \
"$project" "$spool_collection_path"
Expand Down
2 changes: 1 addition & 1 deletion test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def check_url_in_cache(url):
def test_url_caching_with_cloud_function(empty_deployment):
"""kcidb cache client workflow test"""

# It's a test, pylint: disable=too-many-locals
# Make empty_deployment appear used to silence pylint warning
assert empty_deployment is None

pub_client = kcidb.mq.URLListPublisher(
Expand Down

0 comments on commit 2523e3d

Please sign in to comment.