Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
6671032f
Commit
6671032f
authored
Jan 29, 2020
by
antirez
Browse files
ACL LOG: group similar entries in a given time delta.
parent
61dffd86
Changes
1
Show whitespace changes
Inline
Side-by-side
src/acl.c
View file @
6671032f
...
@@ -1465,6 +1465,7 @@ void ACLLoadUsersAtStartup(void) {
...
@@ -1465,6 +1465,7 @@ void ACLLoadUsersAtStartup(void) {
#define ACL_LOG_CTX_TOPLEVEL 0
#define ACL_LOG_CTX_TOPLEVEL 0
#define ACL_LOG_CTX_LUA 1
#define ACL_LOG_CTX_LUA 1
#define ACL_LOG_CTX_MULTI 2
#define ACL_LOG_CTX_MULTI 2
#define ACL_LOG_GROUPING_MAX_TIME_DELTA 60000
/* This structure defines an entry inside the ACL log. */
/* This structure defines an entry inside the ACL log. */
typedef
struct
ACLLogEntry
{
typedef
struct
ACLLogEntry
{
...
@@ -1477,6 +1478,28 @@ typedef struct ACLLogEntry {
...
@@ -1477,6 +1478,28 @@ typedef struct ACLLogEntry {
sds
cinfo
;
/* Client info (last client if updated). */
sds
cinfo
;
/* Client info (last client if updated). */
}
ACLLogEntry
;
}
ACLLogEntry
;
/* This function will check if ACL entries 'a' and 'b' are similar enough
* that we should actually update the existing entry in our ACL log instead
* of creating a new one. */
int
ACLLogMatchEntry
(
ACLLogEntry
*
a
,
ACLLogEntry
*
b
)
{
if
(
a
->
reason
!=
b
->
reason
)
return
0
;
if
(
a
->
context
!=
b
->
context
)
return
0
;
mstime_t
delta
=
a
->
ctime
-
b
->
ctime
;
if
(
delta
<
0
)
delta
=
-
delta
;
if
(
delta
>
ACL_LOG_GROUPING_MAX_TIME_DELTA
)
return
0
;
if
(
sdscmp
(
a
->
object
,
b
->
object
)
!=
0
)
return
0
;
if
(
sdscmp
(
a
->
username
,
b
->
username
)
!=
0
)
return
0
;
return
1
;
}
/* Release an ACL log entry. */
void
ACLFreeLogEntry
(
ACLLogEntry
*
le
)
{
sdsfree
(
le
->
object
);
sdsfree
(
le
->
username
);
sdsfree
(
le
->
cinfo
);
zfree
(
le
);
}
/* Adds a new entry in the ACL log, making sure to delete the old entry
/* Adds a new entry in the ACL log, making sure to delete the old entry
* if we reach the maximum length allowed for the log. This function attempts
* if we reach the maximum length allowed for the log. This function attempts
* to find similar entries in the current log in order to bump the counter of
* to find similar entries in the current log in order to bump the counter of
...
@@ -1504,9 +1527,41 @@ void addACLLogEntry(client *c, int reason, int keypos) {
...
@@ -1504,9 +1527,41 @@ void addACLLogEntry(client *c, int reason, int keypos) {
le
->
context
=
ACL_LOG_CTX_TOPLEVEL
;
le
->
context
=
ACL_LOG_CTX_TOPLEVEL
;
}
}
/* Try to match this entry with past ones, to see if we can just
* update an existing entry instead of creating a new one. */
long
toscan
=
10
;
/* Do a limited work trying to find duplicated. */
listIter
li
;
listNode
*
ln
;
listRewind
(
ACLLog
,
&
li
);
ACLLogEntry
*
match
=
NULL
;
while
(
toscan
--
&&
(
ln
=
listNext
(
&
li
))
!=
NULL
)
{
ACLLogEntry
*
current
=
listNodeValue
(
ln
);
if
(
ACLLogMatchEntry
(
current
,
le
))
{
match
=
current
;
listDelNode
(
ACLLog
,
ln
);
listAddNodeHead
(
ACLLog
,
current
);
break
;
}
}
/* If there is a match update the entry, otherwise add it as a
* new one. */
if
(
match
)
{
/* We update a few fields of the existing entry and bump the
* counter of events for this entry. */
sdsfree
(
match
->
cinfo
);
match
->
cinfo
=
le
->
cinfo
;
match
->
ctime
=
le
->
ctime
;
match
->
count
++
;
/* Release the old entry. */
le
->
cinfo
=
NULL
;
ACLFreeLogEntry
(
le
);
}
else
{
/* Add it to our list of entires. We'll have to trim the list
/* Add it to our list of entires. We'll have to trim the list
* to its maximum size. */
* to its maximum size. */
listAddNodeHead
(
ACLLog
,
le
);
listAddNodeHead
(
ACLLog
,
le
);
}
}
}
/* =============================================================================
/* =============================================================================
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment