Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions doc/admin-guide/plugins/header_rewrite.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ are supported::

%{NEXT-HOP:HOST} Name of the current selected parent.
%{NEXT-HOP:PORT} Port of the current selected parent.
%{NEXT-HOP:STRATEGY} Name of the current strategy (can be "" if not using a strategy)

Note that the ``<part>`` of NEXT-HOP will likely not be available unless
an origin server connection is attempted at which point it will available
Expand Down Expand Up @@ -1083,6 +1084,18 @@ if necessary.
The header's ``<value>`` may be a literal string, or take advantage of
`String concatenations`_ to calculate a dynamic value for the header.

set-next-hop-strategy
~~~~~~~~~~~~~~~~~~~~~
::

set-next-hop-strategy <name>

Replaces/Sets the current next hop parent selection strategy with
the matching strategy specified in `strategies.yaml`

Setting to "null" removes the current strategy which will fall back
to other methods (ie: parent.config or remap to url).

set-redirect
~~~~~~~~~~~~
::
Expand Down
44 changes: 44 additions & 0 deletions doc/admin-guide/plugins/lua.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,50 @@ Here is an example:

`TOP <#ts-lua-plugin>`_

ts.http.get_next_hop_strategy
-----------------------------
**syntax:** *ts.http.get_next_hop_strategy()*

**context:** function @ TS_LUA_HOOK_READ_REQUEST_HDR or do_remap()

**description** Returns the name of the current next hop selection strategy, or nil string if no strategy is in use.

Here is an example:

::

function do_remap()
local strategy = ts.http.get_next_hop_strategy()
ts.debug("Using strategy: " .. strategy)
end

`TOP <#ts-lua-plugin>`_

ts.http.set_next_hop_strategy
-----------------------------
**syntax:** *ts.http.set_next_hop_strategy(str)*

**context:** function @ TS_LUA_HOOK_READ_REQUEST_HDR or do_remap()

**description** Looks for the named strategy and sets the current
transaction to use that strategy.

Use empty string or "null" to clear the strategy and fall back to
parent.config or the remap to url.

Here is an example:

::

function do_remap()
local uri = ts.client_request.get_uri()
if uri == "otherhost" then
ts.http.set_next_hop_strategy("otherhost")
end
end

`TOP <#ts-lua-plugin>`_

ts.sha256
---------
**syntax:** *digest = ts.sha256(str)*
Expand Down
1 change: 1 addition & 0 deletions doc/admin-guide/plugins/regex_remap.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ remap.config. The following options are available ::

@caseless - Make regular expressions case insensitive
@lowercase_substitutions - Turn on (enable) lower case substitutions
@strategy - Specify a strategy from strategies.yaml. "null" or "" will clear the strategy.


This can be useful to force a particular response for some URLs, e.g. ::
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.. 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:: ../../../common.defs

.. default-domain:: cpp

TSHttpNextHopStrategyNameGet
****************************

Synopsis
========

.. code-block:: cpp

#include <ts/ts.h>

.. function:: char const* TSHttpNextHopStrategyNameGet(void const* strategy)

Description
===========

Gets the name associated with the provided strategy.
This may be nullptr indicating that parent.config is in use.

.. note::

This returned pointer must not be freed and the contents must not
be changed.
Strategy pointers held by plugins will become invalid when ATS
configs are reloaded and should be reset with :func:`TSRemapNewInstance`

See Also
========

:func:`TSHttpTxnNextHopStrategyGet`
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
.. 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:: ../../../common.defs

.. default-domain:: cpp

TSHttpTxnNextHopNamedStrategyGet
********************************

Synopsis
========

.. code-block:: cpp

#include <ts/ts.h>

.. function:: void const* TSHttpTxnNextHopNamedStrategyGet(TSHttpTxn txnp, const char *name)

Description
===========

Gets a pointer to the specified :arg:`name` NextHopSelectionStrategy.
This may be nullptr indicating that no strategy exists with the given name.

This function uses the transaction :arg:`txnp` to get access to the
NextHopStrategyFactory associated with the current configuration.

.. note::

This returned pointer must not be freed and the contents must not
be changed.
Strategy pointers held by plugins will become invalid when ATS
configs are reloaded and should be reset with :func:`TSRemapNewInstance`

See Also
========

:func:`TSHttpTxnNextHopStrategySet`
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.. 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:: ../../../common.defs

.. default-domain:: cpp

TSHttpTxnNextHopStrategyGet
***************************

Synopsis
========

.. code-block:: cpp

#include <ts/ts.h>

.. function:: void const* TSHttpTxnNextHopStrategyGet(TSHttpTxn txnp)

Description
===========

Gets a pointer to the current transaction :arg:`txnp` NextHopSelectionStrategy.
This may be nullptr indicating that parent.config is in use.

.. note::

This strategy pointer must not be freed and the contents must not
be changed.
Strategy pointers held by plugins will become invalid when ATS
configs are reloaded and should be reset with :func:`TSRemapNewInstance`

See Also
========

:func:`TSHttpTxnNextHopStrategySet`
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
.. 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:: ../../../common.defs

.. default-domain:: cpp

TSHttpTxnNextHopNameGet
***********************

Synopsis
========

.. code-block:: cpp

#include <ts/ts.h>

.. function:: void TSHttpTxnNextHopStrategySet(TSHttpTxn txnp, void const* strategy)

Description
===========

Sets the next hop strategy for the transaction :arg:`txnp`
This :arg:`strategy` pointer must be a valid strategy and can be
nullptr to indicate that parent.config will be used instead.

Plugins can get a strategy by name by calling
:func:`TSHttpTxnNextHopStrategyGet` to get the current transaction's
active strategy or :func:`TSHttpTxnNextHopNamedStrategyGet` to
look up a strategy by name using the transaction's pointer to the
NextHopStrategyFactory strategy database.

.. note::

This strategy pointer must not be freed and the contents must not
be changed.
Strategy pointers held by plugins will become invalid when ATS
configs are reloaded and should be reset with :func:`TSRemapNewInstance`

See Also
========

:func:`TSHttpTxnNextHopStrategyGet`, :func:`TSHttpTxnNextHopNamedStrategyGet`.
10 changes: 5 additions & 5 deletions include/proxy/http/HttpTransact.h
Original file line number Diff line number Diff line change
Expand Up @@ -724,11 +724,11 @@ class HttpTransact
// able to defer some work in building the request
TransactFunc_t pending_work = nullptr;

HttpRequestData request_data;
ParentConfigParams *parent_params = nullptr;
std::shared_ptr<NextHopSelectionStrategy> next_hop_strategy = nullptr;
ParentResult parent_result;
CacheControlResult cache_control;
HttpRequestData request_data;
ParentConfigParams *parent_params = nullptr;
NextHopSelectionStrategy *next_hop_strategy = nullptr;
ParentResult parent_result;
CacheControlResult cache_control;

StateMachineAction_t next_action = StateMachineAction_t::UNDEFINED; // out
StateMachineAction_t api_next_action = StateMachineAction_t::UNDEFINED; // out
Expand Down
7 changes: 5 additions & 2 deletions include/proxy/http/remap/NextHopStrategyFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ class NextHopStrategyFactory
NextHopStrategyFactory() = delete;
NextHopStrategyFactory(const char *file);
~NextHopStrategyFactory();
std::shared_ptr<NextHopSelectionStrategy> strategyInstance(const char *name);

// The lifetime of this is attached to UrlRewrite which is reference
// counted and attached to an HttpSM.
NextHopSelectionStrategy *strategyInstance(const char *name) const;

bool strategies_loaded;

private:
std::string fn;
void loadConfigFile(const std::string &file, std::stringstream &doc, std::unordered_set<std::string> &include_once);
void createStrategy(const std::string &name, const NHPolicyType policy_type, ts::Yaml::Map &node);
std::unordered_map<std::string, std::shared_ptr<NextHopSelectionStrategy>> _strategies;
std::unordered_map<std::string, NextHopSelectionStrategy *> _strategies;
};
6 changes: 3 additions & 3 deletions include/proxy/http/remap/UrlMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ class url_mapping
bool ip_allow_check_enabled_p = false;
acl_filter_rule *filter = nullptr; // acl filtering (linked list of rules)
LINK(url_mapping, link); // For use with the main Queue linked list holding all the mapping
std::shared_ptr<NextHopSelectionStrategy> strategy = nullptr;
std::string remapKey;
std::atomic<uint64_t> _hitCount = 0; // counter can overflow
NextHopSelectionStrategy *strategy = nullptr;
std::string remapKey;
std::atomic<uint64_t> _hitCount = 0; // counter can overflow

int
getRank() const
Expand Down
Loading