Repository: trafficserver Updated Branches: refs/heads/master 4fbde42c1 -> 90e001201
TS-3454: add support for dscp and milestone api for lua plugin Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/90e00120 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/90e00120 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/90e00120 Branch: refs/heads/master Commit: 90e001201232b27dd55c555b270bda232234cdc2 Parents: 4fbde42 Author: Kit Chan <[email protected]> Authored: Wed Mar 18 22:34:55 2015 -0700 Committer: Kit Chan <[email protected]> Committed: Wed Mar 18 22:34:55 2015 -0700 ---------------------------------------------------------------------- CHANGES | 2 + doc/reference/plugins/ts_lua.en.rst | 68 +++++++++++ plugins/experimental/ts_lua/Makefile.am | 1 + plugins/experimental/ts_lua/ts_lua_http.c | 2 + .../experimental/ts_lua/ts_lua_http_config.c | 40 +++++++ .../experimental/ts_lua/ts_lua_http_milestone.c | 114 +++++++++++++++++++ .../experimental/ts_lua/ts_lua_http_milestone.h | 27 +++++ 7 files changed, 254 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90e00120/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index dbc0f0d..5f7e1ec 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ -*- coding: utf-8 -*- Changes with Apache Traffic Server 5.3.0 + *) [TS-3454] add support for dscp and milestone api for lua plugin. + *) [TS-3452] Better debug messages for SSL_ERROR_SSL errors *) [TS-3439] Chunked responses don't honor keep-alive. http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90e00120/doc/reference/plugins/ts_lua.en.rst ---------------------------------------------------------------------- diff --git a/doc/reference/plugins/ts_lua.en.rst b/doc/reference/plugins/ts_lua.en.rst index 4eb7261..b0b490f 100644 --- a/doc/reference/plugins/ts_lua.en.rst +++ b/doc/reference/plugins/ts_lua.en.rst @@ -2185,6 +2185,28 @@ ts.http.server_packet_tos_set `TOP <#ts-lua-plugin>`_ +ts.http.client_packet_dscp_set +------------------------- +**syntax:** *ts.http.client_packet_dscp_set(NUMBER)* + +**context:** do_remap or do_global_* or later. + +**description:** This function can be used to set packet dscp for client connection. + + +`TOP <#ts-lua-plugin>`_ + +ts.http.server_packet_dscp_set +------------------------- +**syntax:** *ts.http.server_packet_dscp_set(NUMBER)* + +**context:** do_remap or do_global_* or later. + +**description:** This function can be used to set packet dscp for server connection. + + +`TOP <#ts-lua-plugin>`_ + ts.http.cntl_get ---------------- **syntax:** *val = ts.http.cntl_get(CNTL_TYPE)* @@ -2231,6 +2253,52 @@ Http control channel constants TS_LUA_HTTP_CNTL_GET_INTERCEPT_RETRY_MODE TS_LUA_HTTP_CNTL_SET_INTERCEPT_RETRY_MODE + +`TOP <#ts-lua-plugin>`_ + +ts.http.milestone_get +---------------- +**syntax:** *val = ts.http.milestone_get(MILESTONE_TYPE)* + +**context:** do_remap or do_global_* or later. + +**description:** This function can be used to retireve the various milestone times. They are how long the +transaction took to traverse portions of the HTTP state machine. Each milestone value is a fractional number +of seconds since the beginning of the transaction. + +:: + + val = ts.http.milestone_get(TS_LUA_MILESTONE_SM_START) + +`TOP <#ts-lua-plugin>`_ + +Milestone constants +------------------------------ +**context:** do_remap or do_global_* or later + +:: + + TS_LUA_MILESTONE_UA_BEGIN + TS_LUA_MILESTONE_UA_READ_HEADER_DONE + TS_LUA_MILESTONE_UA_BEGIN_WRITE + TS_LUA_MILESTONE_UA_CLOSE + TS_LUA_MILESTONE_SERVER_FIRST_CONNECT + TS_LUA_MILESTONE_SERVER_CONNECT + TS_LUA_MILESTONE_SERVER_CONNECT_END + TS_LUA_MILESTONE_SERVER_BEGIN_WRITE + TS_LUA_MILESTONE_SERVER_FIRST_READ + TS_LUA_MILESTONE_SERVER_READ_HEADER_DONE + TS_LUA_MILESTONE_SERVER_CLOSE + TS_LUA_MILESTONE_CACHE_OPEN_READ_BEGIN + TS_LUA_MILESTONE_CACHE_OPEN_READ_END + TS_LUA_MILESTONE_CACHE_OPEN_WRITE_BEGIN + TS_LUA_MILESTONE_CACHE_OPEN_WRITE_END + TS_LUA_MILESTONE_DNS_LOOKUP_BEGIN + TS_LUA_MILESTONE_DNS_LOOKUP_END + TS_LUA_MILESTONE_SM_START + TS_LUA_MILESTONE_SM_FINISH + + `TOP <#ts-lua-plugin>`_ ts.mgmt.get_counter http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90e00120/plugins/experimental/ts_lua/Makefile.am ---------------------------------------------------------------------- diff --git a/plugins/experimental/ts_lua/Makefile.am b/plugins/experimental/ts_lua/Makefile.am index a04be48..4d2a711 100644 --- a/plugins/experimental/ts_lua/Makefile.am +++ b/plugins/experimental/ts_lua/Makefile.am @@ -41,6 +41,7 @@ tslua_la_SOURCES = \ ts_lua_util.c \ ts_lua_remap.c \ ts_lua_http_cntl.c \ + ts_lua_http_milestone.c \ ts_lua_http_config.c \ ts_lua_mgmt.c \ ts_lua_package.c \ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90e00120/plugins/experimental/ts_lua/ts_lua_http.c ---------------------------------------------------------------------- diff --git a/plugins/experimental/ts_lua/ts_lua_http.c b/plugins/experimental/ts_lua/ts_lua_http.c index 627162a..0c9bb87 100644 --- a/plugins/experimental/ts_lua/ts_lua_http.c +++ b/plugins/experimental/ts_lua/ts_lua_http.c @@ -21,6 +21,7 @@ #include "ts_lua_http_intercept.h" #include "ts_lua_http_config.h" #include "ts_lua_http_cntl.h" +#include "ts_lua_http_milestone.h" typedef enum { @@ -69,6 +70,7 @@ ts_lua_inject_http_api(lua_State * L) ts_lua_inject_http_intercept_api(L); ts_lua_inject_http_config_api(L); ts_lua_inject_http_cntl_api(L); + ts_lua_inject_http_milestone_api(L); ts_lua_inject_http_misc_api(L); lua_setfield(L, -2, "http"); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90e00120/plugins/experimental/ts_lua/ts_lua_http_config.c ---------------------------------------------------------------------- diff --git a/plugins/experimental/ts_lua/ts_lua_http_config.c b/plugins/experimental/ts_lua/ts_lua_http_config.c index e598b70..31222c8 100644 --- a/plugins/experimental/ts_lua/ts_lua_http_config.c +++ b/plugins/experimental/ts_lua/ts_lua_http_config.c @@ -178,6 +178,8 @@ static int ts_lua_http_client_packet_mark_set(lua_State * L); static int ts_lua_http_server_packet_mark_set(lua_State * L); static int ts_lua_http_client_packet_tos_set(lua_State * L); static int ts_lua_http_server_packet_tos_set(lua_State * L); +static int ts_lua_http_client_packet_dscp_set(lua_State * L); +static int ts_lua_http_server_packet_dscp_set(lua_State * L); void ts_lua_inject_http_config_api(lua_State * L) @@ -216,6 +218,12 @@ ts_lua_inject_http_config_api(lua_State * L) lua_pushcfunction(L, ts_lua_http_server_packet_tos_set); lua_setfield(L, -2, "server_packet_tos_set"); + + lua_pushcfunction(L, ts_lua_http_client_packet_dscp_set); + lua_setfield(L, -2, "client_packet_dscp_set"); + + lua_pushcfunction(L, ts_lua_http_server_packet_dscp_set); + lua_setfield(L, -2, "server_packet_dscp_set"); } static void @@ -446,3 +454,35 @@ ts_lua_http_server_packet_tos_set(lua_State * L) return 0; } +static int +ts_lua_http_client_packet_dscp_set(lua_State * L) +{ + int value; + ts_lua_http_ctx *http_ctx; + + http_ctx = ts_lua_get_http_ctx(L); + + value = luaL_checkinteger(L, 1); + + TSDebug(TS_LUA_DEBUG_TAG, "client packet dscp set"); + TSHttpTxnClientPacketDscpSet(http_ctx->txnp, value); + + return 0; +} + +static int +ts_lua_http_server_packet_dscp_set(lua_State * L) +{ + int value; + ts_lua_http_ctx *http_ctx; + + http_ctx = ts_lua_get_http_ctx(L); + + value = luaL_checkinteger(L, 1); + + TSDebug(TS_LUA_DEBUG_TAG, "server packet dscp set"); + TSHttpTxnServerPacketDscpSet(http_ctx->txnp, value); + + return 0; +} + http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90e00120/plugins/experimental/ts_lua/ts_lua_http_milestone.c ---------------------------------------------------------------------- diff --git a/plugins/experimental/ts_lua/ts_lua_http_milestone.c b/plugins/experimental/ts_lua/ts_lua_http_milestone.c new file mode 100644 index 0000000..8202b26 --- /dev/null +++ b/plugins/experimental/ts_lua/ts_lua_http_milestone.c @@ -0,0 +1,114 @@ +/* + 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 "ts_lua_util.h" + +typedef enum +{ + TS_LUA_MILESTONE_UA_BEGIN = TS_MILESTONE_UA_BEGIN, + TS_LUA_MILESTONE_UA_READ_HEADER_DONE = TS_MILESTONE_UA_READ_HEADER_DONE, + TS_LUA_MILESTONE_UA_BEGIN_WRITE = TS_MILESTONE_UA_BEGIN_WRITE, + TS_LUA_MILESTONE_UA_CLOSE = TS_MILESTONE_UA_CLOSE, + TS_LUA_MILESTONE_SERVER_FIRST_CONNECT = TS_MILESTONE_SERVER_FIRST_CONNECT, + TS_LUA_MILESTONE_SERVER_CONNECT = TS_MILESTONE_SERVER_CONNECT, + TS_LUA_MILESTONE_SERVER_CONNECT_END = TS_MILESTONE_SERVER_CONNECT_END, + TS_LUA_MILESTONE_SERVER_BEGIN_WRITE = TS_MILESTONE_SERVER_BEGIN_WRITE, + TS_LUA_MILESTONE_SERVER_FIRST_READ = TS_MILESTONE_SERVER_FIRST_READ, + TS_LUA_MILESTONE_SERVER_READ_HEADER_DONE = TS_MILESTONE_SERVER_READ_HEADER_DONE, + TS_LUA_MILESTONE_SERVER_CLOSE = TS_MILESTONE_SERVER_CLOSE, + TS_LUA_MILESTONE_CACHE_OPEN_READ_BEGIN = TS_MILESTONE_CACHE_OPEN_READ_BEGIN, + TS_LUA_MILESTONE_CACHE_OPEN_READ_END = TS_MILESTONE_CACHE_OPEN_READ_END, + TS_LUA_MILESTONE_CACHE_OPEN_WRITE_BEGIN = TS_MILESTONE_CACHE_OPEN_WRITE_BEGIN, + TS_LUA_MILESTONE_CACHE_OPEN_WRITE_END = TS_MILESTONE_CACHE_OPEN_WRITE_END, + TS_LUA_MILESTONE_DNS_LOOKUP_BEGIN = TS_MILESTONE_DNS_LOOKUP_BEGIN, + TS_LUA_MILESTONE_DNS_LOOKUP_END = TS_MILESTONE_DNS_LOOKUP_END, + TS_LUA_MILESTONE_SM_START = TS_MILESTONE_SM_START, + TS_LUA_MILESTONE_SM_FINISH = TS_MILESTONE_SM_FINISH +} TSLuaMilestoneType; + + +ts_lua_var_item ts_lua_milestone_type_vars[] = { + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_UA_BEGIN), + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_UA_READ_HEADER_DONE), + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_UA_BEGIN_WRITE), + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_UA_CLOSE), + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_SERVER_FIRST_CONNECT), + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_SERVER_CONNECT), + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_SERVER_CONNECT_END), + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_SERVER_BEGIN_WRITE), + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_SERVER_FIRST_READ), + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_SERVER_READ_HEADER_DONE), + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_SERVER_CLOSE), + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_CACHE_OPEN_READ_BEGIN), + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_CACHE_OPEN_READ_END), + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_CACHE_OPEN_WRITE_BEGIN), + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_CACHE_OPEN_WRITE_END), + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_DNS_LOOKUP_BEGIN), + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_DNS_LOOKUP_END), + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_SM_START), + TS_LUA_MAKE_VAR_ITEM(TS_LUA_MILESTONE_SM_FINISH) +}; + + +static void ts_lua_inject_http_milestone_variables(lua_State * L); + +static int ts_lua_http_milestone_get(lua_State * L); + + +void +ts_lua_inject_http_milestone_api(lua_State * L) +{ + ts_lua_inject_http_milestone_variables(L); + + lua_pushcfunction(L, ts_lua_http_milestone_get); + lua_setfield(L, -2, "milestone_get"); +} + +static void +ts_lua_inject_http_milestone_variables(lua_State * L) +{ + size_t i; + + for (i = 0; i < sizeof(ts_lua_milestone_type_vars) / sizeof(ts_lua_var_item); i++) { + lua_pushinteger(L, ts_lua_milestone_type_vars[i].nvar); + lua_setglobal(L, ts_lua_milestone_type_vars[i].svar); + } +} + +static int +ts_lua_http_milestone_get(lua_State * L) +{ + int milestone_type; + TSHRTime value; + TSHRTime epoch; + ts_lua_http_ctx *http_ctx; + + http_ctx = ts_lua_get_http_ctx(L); + + milestone_type = luaL_checkinteger(L, 1); + + if (TS_SUCCESS == TSHttpTxnMilestoneGet(http_ctx->txnp, TS_MILESTONE_SM_START, &epoch)) { + if (TS_SUCCESS == TSHttpTxnMilestoneGet(http_ctx->txnp, milestone_type, &value)) { + lua_pushnumber(L, (double)(value - epoch) / 1000000000); + return 1; + } + } + + return 0; +} http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90e00120/plugins/experimental/ts_lua/ts_lua_http_milestone.h ---------------------------------------------------------------------- diff --git a/plugins/experimental/ts_lua/ts_lua_http_milestone.h b/plugins/experimental/ts_lua/ts_lua_http_milestone.h new file mode 100644 index 0000000..64b5a94 --- /dev/null +++ b/plugins/experimental/ts_lua/ts_lua_http_milestone.h @@ -0,0 +1,27 @@ +/* + 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. +*/ + + +#ifndef _TS_LUA_HTTP_MILESTONE_H +#define _TS_LUA_HTTP_MILESTONE_H + +#include "ts_lua_common.h" + +void ts_lua_inject_http_milestone_api(lua_State * L); + +#endif
