mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-30 16:09:32 +00:00
Add test to avoid RRD overlapping paths
This commit is contained in:
parent
c1057bbc7f
commit
f31451d0bb
4 changed files with 89 additions and 8 deletions
|
|
@ -58,6 +58,8 @@ end
|
|||
|
||||
-- ##############################################
|
||||
|
||||
-- When performing the derivative between two points, the delta must be calculated
|
||||
-- and accounted for the first point time
|
||||
function test_simple_derivative(test)
|
||||
local test_data = {
|
||||
{{v=1000}, now},
|
||||
|
|
@ -76,10 +78,10 @@ function test_simple_derivative(test)
|
|||
|
||||
local rv = test_utils.timestampAsKey(test_utils.makeTimeStamp(res.series, res.start, schema.options.step))[1]
|
||||
|
||||
local t2 = test_data[2][2]
|
||||
local t1 = test_data[1][2]
|
||||
|
||||
if not(rv[t2] == 1000) then
|
||||
return test:assertion_failed("rv[t2=".. t2 .."] == 1000")
|
||||
if not(rv[t1] == 1000) then
|
||||
return test:assertion_failed("rv[t1=".. t1 .."] == 1000")
|
||||
end
|
||||
|
||||
return test:success()
|
||||
|
|
|
|||
78
scripts/lua/modules/timeseries/tests/rrd_paths_test.lua
Normal file
78
scripts/lua/modules/timeseries/tests/rrd_paths_test.lua
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
--
|
||||
-- (C) 2018 - ntop.org
|
||||
--
|
||||
|
||||
local ts_utils = require("ts_utils")
|
||||
local test_utils = require("test_utils")
|
||||
local rrd = require("rrd")
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local test_tag_values = {
|
||||
"1", "1.2.3.4", "abcd", "11:22:33:44:55:66", "99"
|
||||
}
|
||||
|
||||
local prefixes_to_skip = {
|
||||
test = true,
|
||||
mac = true, -- Collides with host, but a MAC address is different from an IP address
|
||||
}
|
||||
|
||||
local suffixes_to_skip = {
|
||||
ndpi_categories = true, -- Collides with nDPI protocol, but we assume that they hold different values
|
||||
l4protos = true, -- Collides with nDPI protocol, but we assume that they hold different values
|
||||
}
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local function skipSchema(schema_name)
|
||||
local parts = string.split(schema_name, ":") or {}
|
||||
if #parts ~= 2 then
|
||||
return(true)
|
||||
end
|
||||
|
||||
if prefixes_to_skip[parts[1]] or suffixes_to_skip[parts[2]] then
|
||||
return(true)
|
||||
end
|
||||
|
||||
return(false)
|
||||
end
|
||||
|
||||
-- Ensure that we do not have collisions on RRD file paths
|
||||
function test_unique_paths(test)
|
||||
local schemas = ts_utils.getLoadedSchemas()
|
||||
local unique_paths = {}
|
||||
|
||||
for _, schema in pairs(schemas) do
|
||||
if skipSchema(schema.name) then
|
||||
goto continue
|
||||
end
|
||||
|
||||
-- build the tags
|
||||
local tags = {}
|
||||
for tag_idx, tag_key in ipairs(schema._tags) do
|
||||
tags[tag_key] = test_tag_values[tag_idx]
|
||||
end
|
||||
|
||||
local fpath = rrd.schema_get_full_path(schema, tags)
|
||||
if not (unique_paths[fpath] == nil) then
|
||||
return test:assertion_failed("unique_paths[" .. fpath .. "] == nil: schema=".. schema.name ..", existing_schema=" .. unique_paths[fpath])
|
||||
end
|
||||
unique_paths[fpath] = schema.name
|
||||
|
||||
::continue::
|
||||
end
|
||||
|
||||
return test:success()
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
function run(tester)
|
||||
local rv = tester.run_test("rrd_paths:unique", test_unique_paths)
|
||||
|
||||
return rv
|
||||
end
|
||||
|
||||
return {
|
||||
run = run
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@ local tests = {
|
|||
require("utils_test"),
|
||||
require("influxdb2series"),
|
||||
require("influxdb_queries"),
|
||||
require("rrd_paths_test"),
|
||||
}
|
||||
|
||||
-- ##############################################
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue