Skip to content

Commit 79ce978

Browse files
author
Aaron Meihm
committed
use cm_sketch from streaming_algorithms, other fixes
Removes lua count-min sketch implementation and xxhash dependency in favor of using cm_sketch functionality from streaming_algorithms.
1 parent 08d3d7a commit 79ce978

File tree

8 files changed

+8
-296
lines changed

8 files changed

+8
-296
lines changed

CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ aws
6868
bloom_filter
6969
circular_buffer
7070
cjson
71-
cms
7271
compat
7372
cuckoo_filter
7473
elasticsearch
@@ -96,7 +95,6 @@ ssl
9695
struct
9796
syslog
9897
systemd
99-
xxhash
10098
zlib
10199
)
102100

cms/CMakeLists.txt

-8
This file was deleted.

cms/index.md

-4
This file was deleted.

cms/modules/cms/cms.lua

-196
This file was deleted.

moz_security/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
cmake_minimum_required(VERSION 3.0)
66
project(moz-security VERSION 0.0.6 LANGUAGES C)
77
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Mozilla Infrastructure Security Analysis")
8+
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${PACKAGE_PREFIX}-streaming-algorithms (>= 0.0.2)")
9+
string(REGEX REPLACE "[()]" "" CPACK_RPM_PACKAGE_REQUIRES ${CPACK_DEBIAN_PACKAGE_DEPENDS})
810
include(sandbox_module)
911

1012
add_test(NAME ${MODULE_NAME}_hindsight

moz_security/sandboxes/heka/analysis/moz_security_hh_cms.lua

+6-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ threshold_cap = 10 -- Threshold will be calculated average + (calculated average
3737
require "string"
3838
require "table"
3939

40-
local c = require "cms.cms"
4140
local ostime = require "os".time
4241

4342
local sample_min_id = read_config("sample_min_id") or error("sample_min_id must be configured")
@@ -51,7 +50,7 @@ local id_fieldc = read_config("id_field_capture")
5150
local cms_epsilon = read_config("cms_epsilon") or 1 / 10000
5251
local cms_delta = read_config("cms_delta") or 0.0001
5352

54-
local cms = c.new(cms_epsilon, cms_delta)
53+
local cms = require "streaming_algorithms.cm_sketch".new(cms_epsilon, cms_delta)
5554

5655
local alist = {}
5756

@@ -84,7 +83,7 @@ function sampler:reset()
8483
end
8584

8685
function sampler:calc()
87-
if not cms or self.n < sample_min_id or self.evcount < sample_min_ev then
86+
if self.n < sample_min_id or self.evcount < sample_min_ev then
8887
return
8988
end
9089
if self.validtick < sample_ticks then
@@ -94,7 +93,7 @@ function sampler:calc()
9493
local cnt = 0
9594
local t = 0
9695
for k,v in pairs(self.s) do
97-
t = t + cms.check(k)
96+
t = t + cms:point_query(k)
9897
cnt = cnt + 1
9998
end
10099
self.threshold = t / cnt
@@ -108,7 +107,7 @@ function sampler:add(x)
108107
if self.start_time + sample_window < ostime() then
109108
self:reset()
110109
alist:reset()
111-
cms = c.new(cms_epsilon, cms_delta)
110+
cms:clear()
112111
end
113112
self.evcount = self.evcount + 1
114113
self.validtick = self.validtick + 1
@@ -129,12 +128,12 @@ function process_message()
129128
if not id then return -1, "no id_field" end
130129
if id_fieldc then
131130
id = string.match(id, id_fieldc)
132-
if not id then return 1 end -- no error as the capture may intentionally reject entries
131+
if not id then return 0 end -- no error as the capture may intentionally reject entries
133132
end
134133

135134
sampler:add(id)
136135
sampler:calc()
137-
local q = cms.add(id)
136+
local q = cms:update(id)
138137
if sampler.threshold ~= 0 and q > sampler.threshold then
139138
alist:add(id, q)
140139
end

xxhash/CMakeLists.txt

-17
This file was deleted.

xxhash/CMakeLists.txt.xxhash

-62
This file was deleted.

0 commit comments

Comments
 (0)