Skip to content
Snippets Groups Projects
Commit 68f43fa7 authored by Alexander Turenko's avatar Alexander Turenko Committed by Kirill Yukhin
Browse files

lua: make box.stat.net.CONNECTIONS a table

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
parent a3bce424
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
......@@ -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
...
......
......@@ -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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment