Tarantool development patches archive
 help / color / mirror / Atom feed
From: Alexander Turenko <alexander.turenko@tarantool.org>
To: Vladimir Davydov <vdavydov.dev@gmail.com>
Cc: Alexander Turenko <alexander.turenko@tarantool.org>,
	tarantool-patches@freelists.org
Subject: [PATCH] lua: make box.stat.net.CONNECTIONS a table
Date: Wed, 27 Mar 2019 20:39:44 +0300	[thread overview]
Message-ID: <f5618eb3830b4b4a1d7304f266bf8ad9dbb68ada.1553708282.git.alexander.turenko@tarantool.org> (raw)

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

             reply	other threads:[~2019-03-27 17:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-27 17:39 Alexander Turenko [this message]
2019-03-28  8:49 ` [tarantool-patches] " Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f5618eb3830b4b4a1d7304f266bf8ad9dbb68ada.1553708282.git.alexander.turenko@tarantool.org \
    --to=alexander.turenko@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH] lua: make box.stat.net.CONNECTIONS a table' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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