This is an automated email from the ASF dual-hosted git repository. zwoop pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 28c4840ec2cea5f59f85187043a98b3743357309 Author: Leif Hedstrom <[email protected]> AuthorDate: Fri Jul 19 13:28:16 2019 -0600 Removes the balancer plugin. See #5395 --- doc/admin-guide/plugins/balancer.en.rst | 87 -------- doc/admin-guide/plugins/index.en.rst | 4 - .../ja/LC_MESSAGES/admin-guide/introduction.en.po | 9 - .../LC_MESSAGES/admin-guide/plugins/balancer.en.po | 134 ------------ .../ja/LC_MESSAGES/admin-guide/plugins/index.en.po | 4 - plugins/Makefile.am | 1 - plugins/experimental/balancer/Makefile.inc | 23 --- plugins/experimental/balancer/balancer.cc | 196 ------------------ plugins/experimental/balancer/balancer.h | 50 ----- plugins/experimental/balancer/hash.cc | 230 --------------------- plugins/experimental/balancer/roundrobin.cc | 72 ------- .../gold_tests/pluginTest/url_sig/url_sig.test.py | 26 +-- 12 files changed, 13 insertions(+), 823 deletions(-) diff --git a/doc/admin-guide/plugins/balancer.en.rst b/doc/admin-guide/plugins/balancer.en.rst deleted file mode 100644 index 8283c38..0000000 --- a/doc/admin-guide/plugins/balancer.en.rst +++ /dev/null @@ -1,87 +0,0 @@ -.. _admin-plugins-balancer: - -Balancer Plugin -*************** - -.. Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - -.. note:: - - All of the the features in this plugin (and more) are found in - :file:`parent.config`. As a result, this plugin is likely to be deprecated. - -The ``balancer`` balances requests across multiple origin servers. -To use this plugin, configure it in a :file:`remap.config` rule, specifying -a balancing policy and a set of origin servers. For example:: - - map http://foo.com http://foo.com \ - @plugin=balancer.so @pparam=--policy=hash,url @pparam=one.bar.com @pparam=two.bar.com - -The ``replacement`` URL in the mapping rule is not used. The argument -to the ``--policy`` option is a comma-separated list of keywords. -The first keyword is the name of a balancing policy. The subsequent -keywords are used to refine the requested policy. - -The remaining plugin arguments are balancer targets. Typically, -these will be the host names of origin servers that requests should -be balanced across. The target name may contain a colon-separated -port number. - -Hash Balancing Policy ---------------------- - -The ``hash`` balancing policy performs a consistent hash across the -set of origins. This minimizes the number of hash entries that must -be moved when the set of origin servers changes. An optional list -of hash fields follows the ``hash`` keyword. Each specified hash -field is hashed to select an outbound origin server. - -The following fields can be supplied to the hash: - -key - The request cache key. Note that the cache key will only be - set if you have already chained a plugin that sets a custom - cache key. - -url - The request URL. This is the default hash field that is used if - no other fields are specified. - -srcaddr - The source IP address of the request. - -dstaddr - The destination IP address of the request. - -Round Robin Balancing Policy ----------------------------- - -The ``roundrobin`` balancing policy simply allocates requests to -origin servers in order. Over time, the number of requests received -by each origin should be approximately the same. - -Health Checking ---------------- - -The ``balancer`` plugin does not check the health of the origin -servers, however the plugin is fully reloadable so health checking -is usually simple to implement. Most production environments already -have mechanisms to check service health. It is recommended that you -write a simple script to monitor this information and rewrite -:file:`remap.config` when appropriate. Running :option:`traffic_ctl config reload` -will reload the ``balancer`` plugin with the new set of origin servers. diff --git a/doc/admin-guide/plugins/index.en.rst b/doc/admin-guide/plugins/index.en.rst index 3d422dc..ff078b4 100644 --- a/doc/admin-guide/plugins/index.en.rst +++ b/doc/admin-guide/plugins/index.en.rst @@ -144,7 +144,6 @@ directory of the |TS| source tree. Experimental plugins can be compiled by passi :hidden: Access Control <access_control.en> - Balancer <balancer.en> Buffer Upload <buffer_upload.en> Certifier <certifier.en> Cert Reporting Tool <cert_reporting_tool.en> @@ -173,9 +172,6 @@ directory of the |TS| source tree. Experimental plugins can be compiled by passi :doc:`Access Control <access_control.en>` Access control plugin that handles various access control use-cases. -:doc:`Balancer <balancer.en>` - Balances requests across multiple origin servers. - :doc:`Buffer Upload <buffer_upload.en>` Buffers POST data before connecting to the Origin server. diff --git a/doc/locale/ja/LC_MESSAGES/admin-guide/introduction.en.po b/doc/locale/ja/LC_MESSAGES/admin-guide/introduction.en.po index 78e2928..6a0a120 100644 --- a/doc/locale/ja/LC_MESSAGES/admin-guide/introduction.en.po +++ b/doc/locale/ja/LC_MESSAGES/admin-guide/introduction.en.po @@ -200,15 +200,6 @@ msgstr "" "場合 Traffic Server の内部的な API やアーキテクチャ的な制限が実装を難しくし" "ていることもあります。" -#: ../../../admin-guide/introduction.en.rst:106 -#, fuzzy -msgid "" -"Load Balancing - note that there is an experimental plugin for this, :ref:" -"`admin-plugins-balancer`." -msgstr "" -"ロードバランシング - このための実験的なプラクインがあることに注意してくださ" -"い。 :ref:`balancer-plugin`" - #: ../../../admin-guide/introduction.en.rst:112 msgid "Traffic Server Components" msgstr "Traffic Server Components" diff --git a/doc/locale/ja/LC_MESSAGES/admin-guide/plugins/balancer.en.po b/doc/locale/ja/LC_MESSAGES/admin-guide/plugins/balancer.en.po deleted file mode 100644 index d20a8f6..0000000 --- a/doc/locale/ja/LC_MESSAGES/admin-guide/plugins/balancer.en.po +++ /dev/null @@ -1,134 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: Apache Traffic Server 6.2\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2016-06-30 14:07+0900\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" -"Language-Team: LANGUAGE <[email protected]>\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Generated-By: Babel 2.2.0\n" - -#: ../../../admin-guide/plugins/balancer.en.rst:4 -msgid "Balancer Plugin" -msgstr "" - -#: ../../../admin-guide/plugins/balancer.en.rst:24 -msgid "" -"The ``balancer`` balances requests across multiple origin servers. To use " -"this plugin, configure it in a :file:`remap.config` rule, specifying a " -"balancing policy and a set of origin servers. For example::" -msgstr "" - -#: ../../../admin-guide/plugins/balancer.en.rst:31 -msgid "" -"The ``replacement`` URL in the mapping rule is not used. The argument to " -"the ``--policy`` option is a comma-separated list of keywords. The first " -"keyword is the name of a balancing policy. The subsequent keywords are used " -"to refine the requested policy." -msgstr "" - -#: ../../../admin-guide/plugins/balancer.en.rst:36 -msgid "" -"The remaining plugin arguments are balancer targets. Typically, these will " -"be the host names of origin servers that requests should be balanced " -"across. The target name may contain a colon-separated port number." -msgstr "" - -#: ../../../admin-guide/plugins/balancer.en.rst:42 -msgid "Hash Balancing Policy" -msgstr "" - -#: ../../../admin-guide/plugins/balancer.en.rst:44 -msgid "" -"The ``hash`` balancing policy performs a consistent hash across the set of " -"origins. This minimizes the number of hash entries that must be moved when " -"the set of origin servers changes. An optional list of hash fields follows " -"the ``hash`` keyword. Each specified hash field is hashed to select an " -"outbound origin server." -msgstr "" - -#: ../../../admin-guide/plugins/balancer.en.rst:50 -msgid "The following fields can be supplied to the hash:" -msgstr "" - -#: ../../../admin-guide/plugins/balancer.en.rst:55 -msgid "key" -msgstr "" - -#: ../../../admin-guide/plugins/balancer.en.rst:53 -msgid "" -"The request cache key. Note that the cache key will only be set if you have " -"already chained a plugin that sets a custom cache key." -msgstr "" - -#: ../../../admin-guide/plugins/balancer.en.rst:59 -msgid "url" -msgstr "" - -#: ../../../admin-guide/plugins/balancer.en.rst:58 -msgid "" -"The request URL. This is the default hash field that is used if no other " -"fields are specified." -msgstr "" - -#: ../../../admin-guide/plugins/balancer.en.rst:62 -msgid "srcaddr" -msgstr "" - -#: ../../../admin-guide/plugins/balancer.en.rst:62 -msgid "The source IP address of the request." -msgstr "" - -#: ../../../admin-guide/plugins/balancer.en.rst:65 -msgid "dstaddr" -msgstr "" - -#: ../../../admin-guide/plugins/balancer.en.rst:65 -msgid "The destination IP address of the request." -msgstr "" - -#: ../../../admin-guide/plugins/balancer.en.rst:68 -msgid "Round Robin Balancing Policy" -msgstr "" - -#: ../../../admin-guide/plugins/balancer.en.rst:70 -msgid "" -"The ``roundrobin`` balancing policy simply allocates requests to origin " -"servers in order. Over time, the number of requests received by each origin " -"should be approximately the same." -msgstr "" - -#: ../../../admin-guide/plugins/balancer.en.rst:75 -msgid "Health Checking" -msgstr "" - -#: ../../../admin-guide/plugins/balancer.en.rst:77 -msgid "" -"The ``balancer`` plugin does not check the health of the origin servers, " -"however the plugin is fully reloadable so health checking is usually simple " -"to implement. Most production environments already have mechanisms to check " -"service health. It is recommended that you write a simple script to monitor " -"this information and rewrite :file:`remap.config` when appropriate. " -"Running :option:`traffic_ctl config reload` will reload the ``balancer`` " -"plugin with the new set of origin servers." -msgstr "" diff --git a/doc/locale/ja/LC_MESSAGES/admin-guide/plugins/index.en.po b/doc/locale/ja/LC_MESSAGES/admin-guide/plugins/index.en.po index ac06ffd..2eb3788 100644 --- a/doc/locale/ja/LC_MESSAGES/admin-guide/plugins/index.en.po +++ b/doc/locale/ja/LC_MESSAGES/admin-guide/plugins/index.en.po @@ -179,10 +179,6 @@ msgid "" msgstr "" #: ../../../admin-guide/plugins/index.en.rst:135 -msgid ":doc:`Balancer <balancer.en>`" -msgstr "" - -#: ../../../admin-guide/plugins/index.en.rst:135 msgid "Balances requests across multiple origin servers." msgstr "" diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 18a08ac..d868692 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -58,7 +58,6 @@ if BUILD_EXPERIMENTAL_PLUGINS include experimental/access_control/Makefile.inc include experimental/acme/Makefile.inc -include experimental/balancer/Makefile.inc include experimental/buffer_upload/Makefile.inc include experimental/cert_reporting_tool/Makefile.inc include experimental/collapsed_forwarding/Makefile.inc diff --git a/plugins/experimental/balancer/Makefile.inc b/plugins/experimental/balancer/Makefile.inc deleted file mode 100644 index 6c93be5..0000000 --- a/plugins/experimental/balancer/Makefile.inc +++ /dev/null @@ -1,23 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -pkglib_LTLIBRARIES += experimental/balancer/balancer.la - -experimental_balancer_balancer_la_SOURCES = \ - experimental/balancer/balancer.cc\ - experimental/balancer/roundrobin.cc \ - experimental/balancer/hash.cc \ - experimental/balancer/balancer.h diff --git a/plugins/experimental/balancer/balancer.cc b/plugins/experimental/balancer/balancer.cc deleted file mode 100644 index 4bce592..0000000 --- a/plugins/experimental/balancer/balancer.cc +++ /dev/null @@ -1,196 +0,0 @@ -/** @file - - A brief file description - - @section license License - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -#include "balancer.h" -#include <ts/remap.h> -#include <cstdio> -#include <getopt.h> -#include <cstring> -#include <cstdlib> -#include <iterator> - -// Using ink_inet API is cheating, but I was too lazy to write new IPv6 address parsing routines ;) -#include "tscore/ink_inet.h" - -// The policy type is the first comma-separated token. -static BalancerInstance * -MakeBalancerInstance(const char *opt) -{ - const char *end = strchr(opt, ','); - size_t len = end ? std::distance(opt, end) : strlen(opt); - - if (len == lengthof("hash") && strncmp(opt, "hash", len) == 0) { - return MakeHashBalancer(end ? end + 1 : nullptr); - } else if (len == lengthof("roundrobin") && strncmp(opt, "roundrobin", len) == 0) { - return MakeRoundRobinBalancer(end ? end + 1 : nullptr); - } else { - TSError("[balancer] Invalid balancing policy '%.*s'", (int)len, opt); - return nullptr; - } -} - -static BalancerTarget -MakeBalancerTarget(const char *strval) -{ - BalancerTarget target = BalancerTarget(); - - union { - struct sockaddr_storage storage; - struct sockaddr sa; - } address; - - memset(&address, 0, sizeof(address)); - - // First, check whether we have an address literal. - if (ats_ip_pton(strval, &address.sa) == 0) { - char namebuf[INET6_ADDRSTRLEN]; - - target.port = ats_ip_port_host_order(&address.sa); - target.name = ats_ip_ntop(&address.sa, namebuf, sizeof(namebuf)); - } else { - const char *colon = strrchr(strval, ':'); - - if (colon) { - size_t len = std::distance(strval, colon); - - target.port = strtol(colon + 1, nullptr, 10); - target.name = std::string(strval, len); - } else { - target.port = 0; - target.name = strval; - } - } - - if (target.port > UINT16_MAX) { - TSError("[balancer] Ignoring invalid port number for target '%s'", strval); - target.port = 0; - } - - return target; -} - -TSReturnCode -TSRemapInit(TSRemapInterface * /* api */, char * /* errbuf */, int /* bufsz */) -{ - return TS_SUCCESS; -} - -/////////////////////////////////////////////////////////////////////////////// -// One instance per remap.config invocation. -// -TSReturnCode -TSRemapNewInstance(int argc, char *argv[], void **instance, char *errbuf, int errbuf_size) -{ - static const struct option longopt[] = { - {const_cast<char *>("policy"), required_argument, nullptr, 'p'}, - {nullptr, 0, nullptr, 0}, - }; - - BalancerInstance *balancer = nullptr; - - // The first two arguments are the "from" and "to" URL string. We need to - // skip them, but we also require that there be an option to masquerade as - // argv[0], so we increment the argument indexes by 1 rather than by 2. - argc--; - argv++; - - for (;;) { - int opt; - - opt = getopt_long(argc, (char *const *)argv, "", longopt, nullptr); - switch (opt) { - case 'p': - if (!balancer) { - balancer = MakeBalancerInstance(optarg); - } else { - TSError("[balancer] Duplicate --policy options, ignored %s", optarg); - } - break; - case -1: - break; - default: - snprintf(errbuf, errbuf_size, "invalid balancer option '%d'", opt); - delete balancer; - return TS_ERROR; - } - - if (opt == -1) { - break; - } - } - - if (!balancer) { - strncpy(errbuf, "missing balancer policy", errbuf_size); - return TS_ERROR; - } - - // Pick up the remaining options as balance targets. - for (int i = optind; i < argc; ++i) { - BalancerTarget target = MakeBalancerTarget(argv[i]); - - balancer->push_target(target); - if (target.port) { - TSDebug("balancer", "added target -> %s:%u", target.name.c_str(), target.port); - } else { - TSDebug("balancer", "added target -> %s", target.name.c_str()); - } - } - - *instance = balancer; - return TS_SUCCESS; -} - -void -TSRemapDeleteInstance(void *instance) -{ - delete (BalancerInstance *)instance; -} - -TSRemapStatus -TSRemapDoRemap(void *instance, TSHttpTxn txn, TSRemapRequestInfo *rri) -{ - BalancerInstance *balancer = (BalancerInstance *)instance; - const BalancerTarget &target = balancer->balance(txn, rri); - - if (TSIsDebugTagSet("balancer")) { - char *url; - int len; - - url = TSHttpTxnEffectiveUrlStringGet(txn, &len); - if (target.port) { - TSDebug("balancer", "%s:%u <- %.*s", target.name.c_str(), target.port, len, url); - } else { - TSDebug("balancer", "%s <- %.*s", target.name.c_str(), len, url); - } - - TSfree(url); - } - - TSUrlHostSet(rri->requestBufp, rri->requestUrl, target.name.data(), target.name.size()); - - if (target.port) { - TSUrlPortSet(rri->requestBufp, rri->requestUrl, target.port); - } - - return TSREMAP_DID_REMAP; -} diff --git a/plugins/experimental/balancer/balancer.h b/plugins/experimental/balancer/balancer.h deleted file mode 100644 index 54bedd1..0000000 --- a/plugins/experimental/balancer/balancer.h +++ /dev/null @@ -1,50 +0,0 @@ -/** @file - * - * A brief file description - * - * @section license License - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include <ts/ts.h> -#include <ts/remap.h> -#include <string> - -// Return the length of a string literal. -template <int N> -unsigned -lengthof(const char (&)[N]) -{ - return N - 1; -} - -struct BalancerTarget { - std::string name; - unsigned port; -}; - -struct BalancerInstance { - virtual ~BalancerInstance() {} - virtual void push_target(const BalancerTarget &) = 0; - virtual const BalancerTarget &balance(TSHttpTxn, TSRemapRequestInfo *) = 0; -}; - -BalancerInstance *MakeHashBalancer(const char *); -BalancerInstance *MakeRoundRobinBalancer(const char *); diff --git a/plugins/experimental/balancer/hash.cc b/plugins/experimental/balancer/hash.cc deleted file mode 100644 index c6ff0a6..0000000 --- a/plugins/experimental/balancer/hash.cc +++ /dev/null @@ -1,230 +0,0 @@ -/** @file - * - * A brief file description - * - * @section license License - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "balancer.h" -#include <cstdlib> -#include <openssl/md5.h> -#include <netinet/in.h> -#include <cstring> -#include <map> -#include <string> -#include <vector> - -namespace -{ -size_t -sockaddrlen(const struct sockaddr *sa) -{ - switch (sa->sa_family) { - case AF_INET: - return sizeof(struct sockaddr_in); - case AF_INET6: - return sizeof(struct sockaddr_in6); - default: - TSReleaseAssert(0 && "unsupported socket type"); - } - - return 0; -} - -struct md5_key { - md5_key() {} - md5_key(const BalancerTarget &target, unsigned i) - { - MD5_CTX ctx; - - MD5_Init(&ctx); - MD5_Update(&ctx, target.name.data(), target.name.size()); - MD5_Update(&ctx, &target.port, sizeof(target.port)); - MD5_Update(&ctx, &i, sizeof(i)); - MD5_Final(this->key, &ctx); - } - - bool - operator<(const md5_key &rhs) const - { - return memcmp(this->key, rhs.key, sizeof(this->key)) < 0; - } - - unsigned char key[MD5_DIGEST_LENGTH]; -}; - -using HashComponent = void (*)(TSHttpTxn, TSRemapRequestInfo *, MD5_CTX *); - -// Hash on the source (client) IP address. -void -HashTxnSrcaddr(TSHttpTxn txn, TSRemapRequestInfo *, MD5_CTX *ctx) -{ - struct sockaddr const *sa; - - sa = TSHttpTxnClientAddrGet(txn); - if (sa) { - MD5_Update(ctx, sa, sockaddrlen(sa)); - TSDebug("balancer", "%s(addr[%zu]]", __func__, sockaddrlen(sa)); - } -} - -// Hash on the destination (server) IP address; -void -HashTxnDstaddr(TSHttpTxn txn, TSRemapRequestInfo *, MD5_CTX *ctx) -{ - struct sockaddr const *sa; - - sa = TSHttpTxnIncomingAddrGet(txn); - if (sa) { - MD5_Update(ctx, sa, sockaddrlen(sa)); - TSDebug("balancer", "%s(addr[%zu]]", __func__, sockaddrlen(sa)); - } -} - -// Hash on the request URL. -void -HashTxnUrl(TSHttpTxn txn, TSRemapRequestInfo *, MD5_CTX *ctx) -{ - char *url; - int len; - - url = TSHttpTxnEffectiveUrlStringGet(txn, &len); - if (url && len) { - MD5_Update(ctx, url, len); - TSDebug("balancer", "%s(%.*s)", __func__, len, url); - } - - TSfree(url); -} - -// Hash on the cache key. This is not typically set at remap time, unless by another plugin. -void -HashTxnKey(TSHttpTxn txn, TSRemapRequestInfo *rri, MD5_CTX *ctx) -{ - TSMLoc url = TS_NULL_MLOC; - char *str = nullptr; - int len; - - if (TSUrlCreate(rri->requestBufp, &url) != TS_SUCCESS) { - goto done; - } - - if (TSHttpTxnCacheLookupUrlGet(txn, rri->requestBufp, url) != TS_SUCCESS) { - TSDebug("balancer", "no cache key"); - goto done; - } - - str = TSUrlStringGet(rri->requestBufp, url, &len); - if (str && len) { - TSDebug("balancer", "%s(%.*s)", __func__, len, str); - MD5_Update(ctx, str, len); - } - -done: - if (url != TS_NULL_MLOC) { - TSHandleMLocRelease(rri->requestBufp, TS_NULL_MLOC, url); - } - - TSfree(str); -} - -struct HashBalancer : public BalancerInstance { - typedef std::map<md5_key, BalancerTarget> hash_ring_type; - using hash_part_type = std::vector<HashComponent>; - - enum { - iterations = 10, - }; - - HashBalancer() { this->hash_parts.push_back(HashTxnUrl); } - void - push_target(const BalancerTarget &target) override - { - for (unsigned i = 0; i < iterations; ++i) { - this->hash_ring.insert(std::make_pair(md5_key(target, i), target)); - } - } - - const BalancerTarget & - balance(TSHttpTxn txn, TSRemapRequestInfo *rri) override - { - md5_key key; - MD5_CTX ctx; - hash_ring_type::const_iterator loc; - - // We'd better have some hash functions set by now ... - TSReleaseAssert(!hash_parts.empty()); - - MD5_Init(&ctx); - - for (hash_part_type::const_iterator i = this->hash_parts.begin(); i != this->hash_parts.end(); ++i) { - (*i)(txn, rri, &ctx); - } - - MD5_Final(key.key, &ctx); - - // OK, now look up this hash in the hash ring. lower_bound() finds the first element that is not less than the - // target, so the element we find is the first key that is greater than our target. To visualize this in the - // hash ring, that means that each node owns the preceding keyspace (ie. the node is at the end of each keyspace - // range). This means that when we wrap, the first node owns the wrapping portion of the keyspace. - loc = this->hash_ring.lower_bound(key); - if (loc == this->hash_ring.end()) { - loc = this->hash_ring.begin(); - } - - return loc->second; - } - - hash_ring_type hash_ring; - hash_part_type hash_parts; -}; - -} // namespace - -BalancerInstance * -MakeHashBalancer(const char *options) -{ - HashBalancer *hash = new HashBalancer(); - char *opt; - char *tmp; - - TSDebug("balancer", "making hash balancer with options '%s'", options); - - if (options) { - hash->hash_parts.clear(); // clear the default hash type if we have options - options = tmp = strdup(options); - while ((opt = strsep(&tmp, ",")) != nullptr) { - if (strcmp(opt, "key") == 0) { - hash->hash_parts.push_back(HashTxnKey); - } else if (strcmp(opt, "url") == 0) { - hash->hash_parts.push_back(HashTxnUrl); - } else if (strcmp(opt, "srcaddr") == 0) { - hash->hash_parts.push_back(HashTxnSrcaddr); - } else if (strcmp(opt, "dstaddr") == 0) { - hash->hash_parts.push_back(HashTxnDstaddr); - } else { - TSError("[balancer] Ignoring invalid hash field '%s'", opt); - } - } - - free((void *)options); - } - - return hash; -} diff --git a/plugins/experimental/balancer/roundrobin.cc b/plugins/experimental/balancer/roundrobin.cc deleted file mode 100644 index 6090ab9..0000000 --- a/plugins/experimental/balancer/roundrobin.cc +++ /dev/null @@ -1,72 +0,0 @@ -/** @file - * - * A brief file description - * - * @section license License - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "balancer.h" -#include <cstdlib> -#include <cstring> -#include <map> -#include <string> -#include <vector> - -namespace -{ -struct RoundRobinBalancer : public BalancerInstance { - RoundRobinBalancer() : targets() {} - void - push_target(const BalancerTarget &target) override - { - this->targets.push_back(target); - } - - const BalancerTarget & - balance(TSHttpTxn, TSRemapRequestInfo *) override - { - return this->targets[++next % this->targets.size()]; - } - - std::vector<BalancerTarget> targets; - unsigned next = 0; -}; - -} // namespace - -BalancerInstance * -MakeRoundRobinBalancer(const char *options) -{ - RoundRobinBalancer *hash = new RoundRobinBalancer(); - char *opt; - char *tmp; - - TSDebug("balancer", "making round robin balancer with options '%s'", options); - - if (options) { - options = tmp = strdup(options); - while ((opt = strsep(&tmp, ",")) != nullptr) { - TSError("[balancer] Ignoring invalid round robin field '%s'", opt); - } - - free((void *)options); - } - - return hash; -} diff --git a/tests/gold_tests/pluginTest/url_sig/url_sig.test.py b/tests/gold_tests/pluginTest/url_sig/url_sig.test.py index 69d8c62..3c96e89 100644 --- a/tests/gold_tests/pluginTest/url_sig/url_sig.test.py +++ b/tests/gold_tests/pluginTest/url_sig/url_sig.test.py @@ -28,7 +28,6 @@ Test.ContinueOnFail = True # Skip if plugins not present. Test.SkipUnless(Condition.PluginExists('url_sig.so')) -Test.SkipUnless(Condition.PluginExists('balancer.so')) # Set up to check the output after the tests have run. # @@ -89,8 +88,7 @@ ts.Disk.remap_config.AddLine( # Use pristine URL, incoming URL changed. # ts.Disk.remap_config.AddLine( - 'map http://seven.eight.nine/ http://dummy' + - ' @plugin=balancer.so @pparam=--policy=hash,url @pparam=127.0.0.1:{}'.format(server.Variables.Port) + + 'map http://seven.eight.nine/ http://127.0.0.1:{}'.format(server.Variables.Port) + ' @plugin=url_sig.so @pparam={}/url_sig.config @pparam=PristineUrl'.format(Test.TestDirectory) ) @@ -232,17 +230,19 @@ tr.Processes.Default.Command = ( LogTee ) + def sign(payload, key): - secret=bytes(key,'utf-8') - data=bytes(payload, 'utf-8') - md=bytes(hmac.new(secret, data, digestmod=hashlib.sha1).digest().hex(), 'utf-8') - return md.decode("utf-8") + secret = bytes(key, 'utf-8') + data = bytes(payload, 'utf-8') + md = bytes(hmac.new(secret, data, digestmod=hashlib.sha1).digest().hex(), 'utf-8') + return md.decode("utf-8") + # No client / SHA1 / P=1 / URL not pristine / URL not altered. # -path="foo/abcde/qrstuvwxyz?E=33046618506&A=1&K=7&P=1&S=" -to_sign="127.0.0.1:{}/".format(server.Variables.Port) + path -url="http://one.two.three/" + path + sign(to_sign, "dqsgopTSM_doT6iAysasQVUKaPykyb6e") +path = "foo/abcde/qrstuvwxyz?E=33046618506&A=1&K=7&P=1&S=" +to_sign = "127.0.0.1:{}/".format(server.Variables.Port) + path +url = "http://one.two.three/" + path + sign(to_sign, "dqsgopTSM_doT6iAysasQVUKaPykyb6e") tr = Test.AddTestRun() tr.Processes.Default.ReturnCode = 0 @@ -252,9 +252,9 @@ tr.Processes.Default.Command = ( # No client / SHA1 / P=1 / URL not pristine / URL not altered -- HTTPS. # -path="foo/abcde/qrstuvwxyz?E=33046618506&A=1&K=7&P=1&S=" -to_sign="127.0.0.1:{}/".format(server.Variables.Port) + path -url="https://127.0.0.1:{}/".format(ts.Variables.ssl_port) + path + sign(to_sign, "dqsgopTSM_doT6iAysasQVUKaPykyb6e") +path = "foo/abcde/qrstuvwxyz?E=33046618506&A=1&K=7&P=1&S=" +to_sign = "127.0.0.1:{}/".format(server.Variables.Port) + path +url = "https://127.0.0.1:{}/".format(ts.Variables.ssl_port) + path + sign(to_sign, "dqsgopTSM_doT6iAysasQVUKaPykyb6e") tr = Test.AddTestRun() tr.Processes.Default.ReturnCode = 0
