Tarantool development patches archive
 help / color / mirror / Atom feed
* [PATCH] lua: make box.stat.net.CONNECTIONS a table
@ 2019-03-27 17:39 Alexander Turenko
  2019-03-28  8:49 ` [tarantool-patches] " Kirill Yukhin
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Turenko @ 2019-03-27 17:39 UTC (permalink / raw)
  To: Vladimir Davydov; +Cc: Alexander Turenko, tarantool-patches

The primary reason of this change is to keep compatibility of 1.10
release series with tarantool/stat-0.3.1, which expects that each
box.stat.net.<...> and box.stat.net().<...> item is a table.

This commit changes CONNECTIONS metric to be a table with 'current'
field, which in turn contains current number of connections.

Fixes #4039.

@TarantoolBot document
Title: box.stat.net.CONNECTIONS becomes a table

The format of box.stat.net.CONNECTIONS and box.stat.net().CONNECTIONS is
changed in order to keep all items being tables, because
tarantool/stat-0.3.1 expects them to be tables (see [1] for more
information).

Example of box.stat.net() **before** this commit:

```
tarantool> box.stat.net()
---
- SENT:
    total: 0
    rps: 0
  CONNECTIONS: 0
  RECEIVED:
    total: 0
    rps: 0
...
```

And after:

```
tarantool> box.stat.net()
---
- SENT:
    total: 0
    rps: 0
  CONNECTIONS:
    current: 0
  RECEIVED:
    total: 0
    rps: 0
...
```

Look at the comment to lbox_stat_net_call() (see the linked commit) for
meaning of total/rps/current fields.

[1]: https://github.com/tarantool/tarantool/issues/4039
---

https://github.com/tarantool/tarantool/issues/4039
https://github.com/tarantool/tarantool/tree/Totktonada/gh-4039-box-stat-net-connections-as-table

 src/box/lua/stat.c         | 31 +++++++++++++++++++++++++++++--
 test/box/stat_net.result   |  8 ++++----
 test/box/stat_net.test.lua |  8 ++++----
 3 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/src/box/lua/stat.c b/src/box/lua/stat.c
index 1015253f4..f6b2812d6 100644
--- a/src/box/lua/stat.c
+++ b/src/box/lua/stat.c
@@ -136,26 +136,53 @@ lbox_stat_reset(struct lua_State *L)
 	return 0;
 }
 
+/**
+ * Push a table with a network metric to a Lua stack.
+ *
+ * Expects one argument with a name of a needed metric. The pushed
+ * table contains some subset of 'total', 'rps', 'current' fields.
+ *
+ * Metrics are the same as in lbox_stat_net_call().
+ */
 static int
 lbox_stat_net_index(struct lua_State *L)
 {
 	luaL_checkstring(L, -1);
 	if (strcmp("CONNECTIONS", lua_tostring(L, -1)) == 0) {
+		lua_newtable(L);
 		lua_pushnumber(L, iproto_connection_count());
+		lua_setfield(L, -2, "current");
 		return 1;
 	}
 	return rmean_foreach(rmean_net, seek_stat_item, L);
 }
 
+/**
+ * Push a table of network metrics to a Lua stack.
+ *
+ * Metrics and their fields are:
+ *
+ * - SENT (packets): total, rps;
+ * - RECEIVED (packets): total, rps;
+ * - CONNECTIONS: current.
+ *
+ * These fields have the following meaning:
+ *
+ * - total -- amount of events since start;
+ * - rps -- amount of events per second, mean over last 5 seconds;
+ * - current -- amount of resources currently hold (say, number of
+ *   open connections).
+ */
 static int
 lbox_stat_net_call(struct lua_State *L)
 {
 	lua_newtable(L);
 	rmean_foreach(rmean_net, set_stat_item, L);
 
-	lua_pushstring(L, "CONNECTIONS");
+	lua_newtable(L); /* box.stat.net().CONNECTIONS */
 	lua_pushnumber(L, iproto_connection_count());
-	lua_settable(L, -3);
+	lua_setfield(L, -2, "current");
+	lua_setfield(L, -2, "CONNECTIONS");
 
 	return 1;
 }
diff --git a/test/box/stat_net.result b/test/box/stat_net.result
index 639a830d8..36a78a8a6 100644
--- a/test/box/stat_net.result
+++ b/test/box/stat_net.result
@@ -55,7 +55,7 @@ box.stat.net.RECEIVED.total > 0
 ---
 - true
 ...
-box.stat.net.CONNECTIONS == 4
+box.stat.net.CONNECTIONS.current == 4
 ---
 - true
 ...
@@ -70,14 +70,14 @@ cn1:close()
 cn2:close()
 ---
 ...
-test_run:wait_cond(function() return box.stat.net.CONNECTIONS == 2 end, WAIT_COND_TIMEOUT)
+test_run:wait_cond(function() return box.stat.net.CONNECTIONS.current == 2 end, WAIT_COND_TIMEOUT)
 ---
 - true
 ...
 cn3:close()
 ---
 ...
-test_run:wait_cond(function() return box.stat.net.CONNECTIONS == 1 end, WAIT_COND_TIMEOUT)
+test_run:wait_cond(function() return box.stat.net.CONNECTIONS.current == 1 end, WAIT_COND_TIMEOUT)
 ---
 - true
 ...
@@ -93,7 +93,7 @@ box.stat.net.RECEIVED.total
 ---
 - 0
 ...
-box.stat.net.CONNECTIONS
+box.stat.net.CONNECTIONS.current
 ---
 - 1
 ...
diff --git a/test/box/stat_net.test.lua b/test/box/stat_net.test.lua
index 997376997..24ecf1386 100644
--- a/test/box/stat_net.test.lua
+++ b/test/box/stat_net.test.lua
@@ -21,7 +21,7 @@ cn.space.tweedledum:select() --small request
 
 box.stat.net.SENT.total > 0
 box.stat.net.RECEIVED.total > 0
-box.stat.net.CONNECTIONS == 4
+box.stat.net.CONNECTIONS.current == 4
 -- box.stat.net.EVENTS.total > 0
 -- box.stat.net.LOCKS.total > 0
 
@@ -29,15 +29,15 @@ WAIT_COND_TIMEOUT = 10
 
 cn1:close()
 cn2:close()
-test_run:wait_cond(function() return box.stat.net.CONNECTIONS == 2 end, WAIT_COND_TIMEOUT)
+test_run:wait_cond(function() return box.stat.net.CONNECTIONS.current == 2 end, WAIT_COND_TIMEOUT)
 cn3:close()
-test_run:wait_cond(function() return box.stat.net.CONNECTIONS == 1 end, WAIT_COND_TIMEOUT)
+test_run:wait_cond(function() return box.stat.net.CONNECTIONS.current == 1 end, WAIT_COND_TIMEOUT)
 
 -- reset
 box.stat.reset()
 box.stat.net.SENT.total
 box.stat.net.RECEIVED.total
-box.stat.net.CONNECTIONS
+box.stat.net.CONNECTIONS.current
 
 space:drop() -- tweedledum
 cn:close()
-- 
2.20.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [tarantool-patches] [PATCH] lua: make box.stat.net.CONNECTIONS a table
  2019-03-27 17:39 [PATCH] lua: make box.stat.net.CONNECTIONS a table Alexander Turenko
@ 2019-03-28  8:49 ` Kirill Yukhin
  0 siblings, 0 replies; 2+ messages in thread
From: Kirill Yukhin @ 2019-03-28  8:49 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Vladimir Davydov, Alexander Turenko

Hello,

On 27 Mar 20:39, Alexander Turenko wrote:
> The primary reason of this change is to keep compatibility of 1.10
> release series with tarantool/stat-0.3.1, which expects that each
> box.stat.net.<...> and box.stat.net().<...> item is a table.
> 
> This commit changes CONNECTIONS metric to be a table with 'current'
> field, which in turn contains current number of connections.
> 
> Fixes #4039.

Your patch is OK. I've checked it into master, 2.1 and 1.10 branches.

--
Regards, Kirill Yukhin

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-03-28  8:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-27 17:39 [PATCH] lua: make box.stat.net.CONNECTIONS a table Alexander Turenko
2019-03-28  8:49 ` [tarantool-patches] " Kirill Yukhin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox