-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
monitoring stuff and revised implementation
- Loading branch information
1 parent
60f888c
commit 938fd3a
Showing
4 changed files
with
79 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: luacheck | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: apt | ||
run: sudo apt-get install -y luarocks | ||
- name: luacheck install | ||
run: luarocks install --local luacheck | ||
- name: luacheck run | ||
run: $HOME/.luarocks/bin/luacheck ./ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
globals = { | ||
"minetest", | ||
"find_nodes_in_area_cache", | ||
"jumpdrive" | ||
} | ||
|
||
read_globals = { | ||
-- Stdlib | ||
string = {fields = {"split"}}, | ||
table = {fields = {"copy", "getn"}}, | ||
|
||
-- Minetest | ||
"vector", "ItemStack", | ||
"dump", "VoxelArea", | ||
|
||
-- deps | ||
"monitoring" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,53 @@ | ||
local has_monitoring_mod = minetest.get_modpath("monitoring") | ||
|
||
local old_check_player_privs = minetest.check_player_privs | ||
local hit_count, miss_count, cache_size | ||
|
||
if has_monitoring_mod then | ||
hit_count = monitoring.counter("get_player_privs_cache_hit", "cache hits") | ||
miss_count = monitoring.counter("get_player_privs_cache_miss", "cache misses") | ||
cache_size = monitoring.gauge("get_player_privs_cache_size", "Count of all cached players") | ||
end | ||
|
||
local cache = {} | ||
|
||
minetest.check_player_privs = function(player_or_name, ...) | ||
local playername = player_or_name | ||
if type(player_or_name) == "table" and player_or_name.get_player_name then | ||
playername = player_or_name:get_player_name() | ||
local old_get_player_privs = minetest.get_player_privs | ||
minetest.get_player_privs = function(name) | ||
local privs = cache[name] | ||
if privs == nil then | ||
if has_monitoring_mod then | ||
miss_count.inc() | ||
end | ||
privs = old_get_player_privs(name) | ||
cache[name] = privs | ||
else | ||
hit_count.inc() | ||
end | ||
|
||
local requested_privs = {...} | ||
print(dump(requested_privs)) | ||
return privs | ||
end | ||
|
||
local result = cache[playername] | ||
if result == nil then | ||
-- cache miss | ||
result = {true, {}} | ||
result[1], result[2] = old_check_player_privs(player_or_name, unpack(requested_privs)) | ||
print("db hit", player_or_name, result[1], dump(result[2])) | ||
cache[playername] = { result[1], result[2] } | ||
end | ||
-- invalidation on set_privs and leave-player | ||
|
||
return result[1], result[2] | ||
local old_set_player_privs = minetest.set_player_privs | ||
minetest.set_player_privs = function(name, privs) | ||
cache[name] = nil | ||
old_set_player_privs(name, privs); | ||
end | ||
|
||
local function invalidate() | ||
cache = {} | ||
minetest.after(2, invalidate) | ||
end | ||
minetest.register_on_leaveplayer(function(player) | ||
cache[player:get_player_name()] = nil | ||
end) | ||
|
||
-- monitoring stuff | ||
if has_monitoring_mod then | ||
local function count_entries() | ||
local count = 0 | ||
for _ in ipairs(cache) do | ||
count = count + 1 | ||
end | ||
cache_size.set(count) | ||
minetest.after(5, count_entries) | ||
end | ||
|
||
minetest.after(2, invalidate) | ||
minetest.after(5, count_entries) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
name = check_player_privs_cache | ||
name = get_player_privs_cache | ||
optional_depends = monitoring |