From e6757068bcadf6361dba757ace4b40ba0025bb63 Mon Sep 17 00:00:00 2001 From: Jeff Elsloo Date: Wed, 29 Sep 2021 09:55:36 -0600 Subject: [PATCH] Added support for promoting internal (plugin-initiated) requests. --- doc/admin-guide/plugins/cache_promote.en.rst | 6 +++++- plugins/cache_promote/cache_promote.cc | 2 +- plugins/cache_promote/configs.cc | 4 ++++ plugins/cache_promote/lru_policy.h | 3 ++- plugins/cache_promote/policy.h | 13 +++++++++++++ 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/doc/admin-guide/plugins/cache_promote.en.rst b/doc/admin-guide/plugins/cache_promote.en.rst index 7e3a74926de..62da01ca06f 100644 --- a/doc/admin-guide/plugins/cache_promote.en.rst +++ b/doc/admin-guide/plugins/cache_promote.en.rst @@ -77,7 +77,11 @@ If :option:`--policy` is set to ``lru`` the following options are also available * **plugin.cache_promote.${remap-identifier}.promoted** - count requests promoted, available in all policies. * **plugin.cache_promote.${remap-identifier}.total_requests** - count of all requests. -These two options combined with your usage patterns will control how likely a +.. option:: --internal-enabled + + Allow cache promote to operate on internal (plugin-initiated) requests. + +These options combined with your usage patterns will control how likely a URL is to become promoted to enter the cache. Examples diff --git a/plugins/cache_promote/cache_promote.cc b/plugins/cache_promote/cache_promote.cc index f7600868096..d8fe0a8a1cf 100644 --- a/plugins/cache_promote/cache_promote.cc +++ b/plugins/cache_promote/cache_promote.cc @@ -50,7 +50,7 @@ cont_handle_policy(TSCont contp, TSEvent event, void *edata) switch (event) { // After the cache lookups check if it should be promoted on cache misses case TS_EVENT_HTTP_CACHE_LOOKUP_COMPLETE: - if (!TSHttpTxnIsInternal(txnp)) { + if (!TSHttpTxnIsInternal(txnp) || config->getPolicy()->isInternalEnabled()) { int obj_status; if (TS_ERROR != TSHttpTxnCacheLookupStatusGet(txnp, &obj_status)) { diff --git a/plugins/cache_promote/configs.cc b/plugins/cache_promote/configs.cc index 0cea3dd7461..30015b54e0b 100644 --- a/plugins/cache_promote/configs.cc +++ b/plugins/cache_promote/configs.cc @@ -34,6 +34,7 @@ static const struct option longopt[] = { {const_cast("hits"), required_argument, nullptr, 'h'}, {const_cast("bytes"), required_argument, nullptr, 'B'}, {const_cast("label"), required_argument, nullptr, 'l'}, + {const_cast("internal-enabled"), no_argument, nullptr, 'i'}, // EOF {nullptr, no_argument, nullptr, '\0'}, }; @@ -80,6 +81,9 @@ PromotionConfig::factory(int argc, char *argv[]) // The --sample (-s) option is allowed for all configs, but only after --policy is specified. if (opt == 's') { _policy->setSample(optarg); + } else if (opt == 'i') { + _policy->setInternalEnabled(true); + TSDebug(PLUGIN_NAME, "internal_enabled set to true"); } else { if (!_policy->parseOption(opt, optarg)) { TSError("[%s] The specified policy (%s) does not support the -%c option", PLUGIN_NAME, _policy->policyName(), opt); diff --git a/plugins/cache_promote/lru_policy.h b/plugins/cache_promote/lru_policy.h index 3cf62e7081e..f2532ff4470 100644 --- a/plugins/cache_promote/lru_policy.h +++ b/plugins/cache_promote/lru_policy.h @@ -120,7 +120,8 @@ class LRUPolicy : public PromotionPolicy const std::string id() const override { - return _label + ";LRU=b:" + std::to_string(_buckets) + ",h:" + std::to_string(_hits) + ",B:" + std::to_string(_bytes); + return _label + ";LRU=b:" + std::to_string(_buckets) + ",h:" + std::to_string(_hits) + ",B:" + std::to_string(_bytes) + + ",i:" + std::to_string(_internal_enabled); } void diff --git a/plugins/cache_promote/policy.h b/plugins/cache_promote/policy.h index c0b37ee91a3..e6c468b5bd3 100644 --- a/plugins/cache_promote/policy.h +++ b/plugins/cache_promote/policy.h @@ -102,6 +102,18 @@ class PromotionPolicy { } + bool + isInternalEnabled() const + { + return _internal_enabled; + } + + void + setInternalEnabled(const bool enabled) + { + _internal_enabled = enabled; + } + bool doSample() const; int create_stat(std::string_view name, std::string_view remap_identifier); @@ -113,6 +125,7 @@ class PromotionPolicy // when true stats are incremented. bool _stats_enabled = false; + bool _internal_enabled = false; int _cache_hits_id = -1; int _promoted_id = -1; int _total_requests_id = -1;