You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ki...@apache.org on 2016/10/14 01:59:09 UTC
[trafficserver] 01/02: TS-4592: Add support for process ID and txn
ID in ts_lua
This is an automated email from the ASF dual-hosted git repository.
kichan pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git
commit 28df44603225476c9e8223e2d25d0698fc7aef88
Author: Kit Chan <ki...@apache.org>
AuthorDate: Tue Oct 11 08:41:08 2016 -0700
TS-4592: Add support for process ID and txn ID in ts_lua
---
doc/admin-guide/plugins/ts_lua.en.rst | 36 +++++++++++++++++++++++++++++++
plugins/experimental/ts_lua/ts_lua_http.c | 17 +++++++++++++++
plugins/experimental/ts_lua/ts_lua_misc.c | 19 ++++++++++++++++
3 files changed, 72 insertions(+)
diff --git a/doc/admin-guide/plugins/ts_lua.en.rst b/doc/admin-guide/plugins/ts_lua.en.rst
index 7c8027a..9794ffc 100644
--- a/doc/admin-guide/plugins/ts_lua.en.rst
+++ b/doc/admin-guide/plugins/ts_lua.en.rst
@@ -131,6 +131,22 @@ is always available within lua script. This package can be introduced into Lua l
`TOP <#ts-lua-plugin>`_
+ts.process_id
+-------------
+**syntax:** *val = ts.process_id()*
+
+**context:** global
+
+**description:** This function returns the global process id.
+
+Here is an example:
+
+::
+
+ local pid = ts.process_id() -- a436bae6-082c-4805-86af-78a5916c4a91
+
+`TOP <#ts-lua-plugin>`_
+
ts.now
------
**syntax:** *val = ts.now()*
@@ -2100,6 +2116,26 @@ This function is usually called in do_global_read_request function
`TOP <#ts-lua-plugin>`_
+ts.http.id
+----------
+**syntax:** *ts.http.id()*
+
+**context:** do_remap/do_os_response or do_global_* or later
+
+**description:** This function can be used to tell id of a transaction
+
+Here is an example:
+
+::
+
+ function do_global_read_request()
+ local id = ts.http.id()
+ ts.debug(id)
+ return 0
+ end
+
+`TOP <#ts-lua-plugin>`_
+
ts.http.is_internal_request
---------------------------
**syntax:** *ts.http.is_internal_request()*
diff --git a/plugins/experimental/ts_lua/ts_lua_http.c b/plugins/experimental/ts_lua/ts_lua_http.c
index 2ab7001..4e7cc3e 100644
--- a/plugins/experimental/ts_lua/ts_lua_http.c
+++ b/plugins/experimental/ts_lua/ts_lua_http.c
@@ -86,6 +86,7 @@ static void ts_lua_inject_cache_lookup_result_variables(lua_State *L);
static int ts_lua_http_resp_cache_transformed(lua_State *L);
static int ts_lua_http_resp_cache_untransformed(lua_State *L);
+static int ts_lua_http_get_id(lua_State *L);
static int ts_lua_http_is_internal_request(lua_State *L);
static int ts_lua_http_skip_remapping_set(lua_State *L);
static int ts_lua_http_transaction_count(lua_State *L);
@@ -186,6 +187,9 @@ ts_lua_inject_http_resp_transform_api(lua_State *L)
static void
ts_lua_inject_http_misc_api(lua_State *L)
{
+ lua_pushcfunction(L, ts_lua_http_get_id);
+ lua_setfield(L, -2, "id");
+
lua_pushcfunction(L, ts_lua_http_is_internal_request);
lua_setfield(L, -2, "is_internal_request");
@@ -522,6 +526,19 @@ ts_lua_http_resp_cache_untransformed(lua_State *L)
}
static int
+ts_lua_http_get_id(lua_State *L)
+{
+ ts_lua_http_ctx *http_ctx;
+
+ GET_HTTP_CONTEXT(http_ctx, L);
+
+ uint64_t id = TSHttpTxnIdGet(http_ctx->txnp);
+ lua_pushnumber(L, id);
+
+ return 1;
+}
+
+static int
ts_lua_http_is_internal_request(lua_State *L)
{
ts_lua_http_ctx *http_ctx;
diff --git a/plugins/experimental/ts_lua/ts_lua_misc.c b/plugins/experimental/ts_lua/ts_lua_misc.c
index b3481dc..e82e1ca 100644
--- a/plugins/experimental/ts_lua/ts_lua_misc.c
+++ b/plugins/experimental/ts_lua/ts_lua_misc.c
@@ -18,6 +18,7 @@
#include "ts_lua_util.h"
+static int ts_lua_get_process_id(lua_State *L);
static int ts_lua_get_now_time(lua_State *L);
static int ts_lua_debug(lua_State *L);
static int ts_lua_error(lua_State *L);
@@ -33,6 +34,10 @@ static void ts_lua_inject_misc_variables(lua_State *L);
void
ts_lua_inject_misc_api(lua_State *L)
{
+ /* ts.process_id() */
+ lua_pushcfunction(L, ts_lua_get_process_id);
+ lua_setfield(L, -2, "process_id");
+
/* ts.now() */
lua_pushcfunction(L, ts_lua_get_now_time);
lua_setfield(L, -2, "now");
@@ -66,6 +71,20 @@ ts_lua_inject_misc_variables(lua_State *L)
}
static int
+ts_lua_get_process_id(lua_State *L)
+{
+ const char *s;
+ TSUuid process = TSProcessUuidGet();
+ if (process) {
+ s = TSUuidStringGet(process);
+ } else {
+ s = "";
+ }
+ lua_pushstring(L, s);
+ return 1;
+}
+
+static int
ts_lua_get_now_time(lua_State *L)
{
lua_Number now;
--
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.