Skip to content

Commit

Permalink
lib.ptree: deduplicate symlink counter aggregation
Browse files Browse the repository at this point in the history
This fixes a problem where this branch caused PCI counters to not be aggregated
altogether (note: missing RRD archives for NIC stats).
  • Loading branch information
eugeneia committed Oct 25, 2019
1 parent 20c303c commit f987802
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/lib/ptree/ptree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -347,25 +347,42 @@ function Manager:monitor_worker_counters(id)
local events = inotify.recursive_directory_inventory_events(dir, cancel)
for ev in events.get, events do
if has_suffix(ev.name, '.counter') then
local stat = S.lstat(ev.name)
local name = strip_prefix(ev.name, dir..'/')
local qualified_name = '/'..pid..'/'..name
local counters = self.counters[name]
if blacklisted(name) or not stat or stat.islnk then
if blacklisted(name) then
-- Pass.
elseif ev.kind == 'creat' then
if not counters then
counters = { aggregated=counter.create(name), active={},
rrd={}, aggregated_rrd=self:make_rrd(name),
archived=ffi.new('uint64_t[1]') }
archived=ffi.new('uint64_t[1]'),
truename = {} }
self.counters[name] = counters
end
counters.active[pid] = counter.open(qualified_name)
counters.rrd[pid] = self:make_rrd(qualified_name)
local stat = S.lstat(ev.name)
if stat then
local truename = (stat.islnk and S.readlink(ev.name)) or ev.name
local is_unique = true
for _, aggregated in pairs(counters.truename) do
-- Check here if the counter is already aggregated (this is
-- to avoid falsely re-aggregating symlinks to counters.)
if truenname == aggregated then
is_unique = false
end
end
if is_unique then
-- Counter is not yet in the aggregated set, add it.
counters.active[pid] = counter.open(qualified_name)
counters.rrd[pid] = self:make_rrd(qualified_name)
counters.truename[pid] = truename
end
end
elseif ev.kind == 'rm' then
local val = counter.read(assert(counters.active[pid]))
counters.active[pid] = nil
counters.rrd[pid] = nil
counters.truename[pid] = nil
counters.archived[0] = counters.archived[0] + val
counter.delete(qualified_name)
S.unlink(strip_suffix(qualified_name, ".counter")..".rrd")
Expand Down

0 comments on commit f987802

Please sign in to comment.