wafris 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/lua/dist/wafris_core.lua +22 -3
- data/lib/wafris/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cbb8c27a7af9771ecf6c07a34fd7da75f4ebacf4fd21dba0b37551a8b2ca2cd
|
4
|
+
data.tar.gz: 492a0f193e4c976a612106b5a0bb8c25aa008f170ec8111fa9504bd1cf585faf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b50f3ad94a373c55285d5e800e55a483f7311a45d18c80d42464931f265edae1bc36a39f97ecf803a99065e5f12b106cc1739cd3716b3219f3a1a60f31b1a6c5
|
7
|
+
data.tar.gz: d23d85b065a338c454216d37755ec6d112d4392f9415e7e13df30c4610c96ab58a15a046211332a273cee3da12bdeae2fc3c4f09722239e5cd3b414fa09d4351
|
@@ -1,4 +1,4 @@
|
|
1
|
-
local function get_time_bucket_from_timestamp(unix_time_milliseconds)
|
1
|
+
local function get_time_bucket_from_timestamp(unix_time_milliseconds, minutes_flag)
|
2
2
|
local function calculate_years_number_of_days(yr)
|
3
3
|
return (yr % 4 == 0 and (yr % 100 ~= 0 or yr % 400 == 0)) and 366 or 365
|
4
4
|
end
|
@@ -45,7 +45,12 @@ local function get_time_bucket_from_timestamp(unix_time_milliseconds)
|
|
45
45
|
local hours = math.floor(unix_time / 3600 % 24)
|
46
46
|
-- local minutes, seconds = math.floor(unix_time / 60 % 60), math.floor(unix_time % 60)
|
47
47
|
-- hours = hours > 12 and hours - 12 or hours == 0 and 12 or hours
|
48
|
-
|
48
|
+
if minutes_flag == false then
|
49
|
+
return string.format("%04d-%02d-%02d-%02d", year, month, days, hours)
|
50
|
+
elseif minutes_flag == true then
|
51
|
+
local minutes = math.floor(unix_time / 60 % 60)
|
52
|
+
return string.format("%04d-%02d-%02d-%02d-%02d", year, month, days, hours, minutes)
|
53
|
+
end
|
49
54
|
end
|
50
55
|
|
51
56
|
-- For: Relationship of IP to time of Request (Stream)
|
@@ -66,6 +71,17 @@ local function increment_timebucket_for(type, timebucket, property)
|
|
66
71
|
redis.call("ZINCRBY", type .. "leader-sset:" .. timebucket, 1, property)
|
67
72
|
end
|
68
73
|
|
74
|
+
local function increment_hourly_request_counters(unix_time_milliseconds)
|
75
|
+
for i = 1, 60 do
|
76
|
+
local timebucket_in_milliseconds = unix_time_milliseconds + 60000 * (i - 1)
|
77
|
+
local timebucket = get_time_bucket_from_timestamp(timebucket_in_milliseconds, true)
|
78
|
+
local key = "w:v0:hr-ct:" .. timebucket
|
79
|
+
redis.call("INCR", key)
|
80
|
+
-- Expire the key after 61 minutes if it has no expiry
|
81
|
+
redis.call("EXPIRE", key, 3660, "NX")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
69
85
|
-- Configuration
|
70
86
|
local max_requests = 100000
|
71
87
|
local max_requests_per_ip = 10000
|
@@ -80,7 +96,10 @@ local host = ARGV[6]
|
|
80
96
|
|
81
97
|
-- Initialize local variables
|
82
98
|
local request_id = get_request_id(nil, client_ip, max_requests)
|
83
|
-
local current_timebucket = get_time_bucket_from_timestamp(unix_time_milliseconds)
|
99
|
+
local current_timebucket = get_time_bucket_from_timestamp(unix_time_milliseconds, false)
|
100
|
+
|
101
|
+
-- CARD DATA COLLECTION
|
102
|
+
increment_hourly_request_counters(unix_time_milliseconds)
|
84
103
|
|
85
104
|
-- GRAPH DATA COLLECTION
|
86
105
|
add_to_HLL_request_count(current_timebucket, request_id)
|
data/lib/wafris/version.rb
CHANGED