Skip to content

Commit 2100473

Browse files
nfrmtkStekPerepolnen
authored andcommitted
Make scalar map join benchmark spit out same tuples amount as others (ydb-platform#24840)
1 parent 5dc5519 commit 2100473

File tree

6 files changed

+81
-64
lines changed

6 files changed

+81
-64
lines changed

ydb/core/mon/audit/audit.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "audit.h"
2-
#include "auditable_actions.cpp"
2+
#include "audit_blacklist.cpp"
33

44
#include <ydb/core/audit/audit_log.h>
55
#include <ydb/core/audit/audit_config/audit_config.h>
@@ -50,9 +50,9 @@ namespace {
5050
return reason;
5151
}
5252

53-
inline TUrlMatcher CreateAuditableActionsMatcher() {
53+
inline TUrlMatcher CreateBlacklistMatcher() {
5454
TUrlMatcher policy;
55-
for (const auto& pattern : AUDITABLE_ACTIONS) {
55+
for (const auto& pattern : AUDIT_BLACKLIST) {
5656
policy.AddPattern(pattern);
5757
}
5858
return policy;
@@ -73,8 +73,8 @@ void TAuditCtx::AddAuditLogPart(TStringBuf name, const TString& value) {
7373
Parts.emplace_back(name, value);
7474
}
7575

76-
bool TAuditCtx::AuditableRequest(const NHttp::THttpIncomingRequestPtr& request) {
77-
// only modifying methods are audited
76+
bool TAuditCtx::AuditableRequest(const NHttp::THttpIncomingRequestPtr& request) const {
77+
// modifying methods are always audited
7878
const TString method(request->Method);
7979
static const THashSet<TString> MODIFYING_METHODS = {"POST", "PUT", "DELETE"};
8080
if (MODIFYING_METHODS.contains(method)) {
@@ -86,13 +86,13 @@ bool TAuditCtx::AuditableRequest(const NHttp::THttpIncomingRequestPtr& request)
8686
return false;
8787
}
8888

89-
// force audit for specific URLs
90-
static auto FORCE_AUDIT_MATCHER = CreateAuditableActionsMatcher();
91-
if (FORCE_AUDIT_MATCHER.Match(request->URL)) {
92-
return true;
89+
// skip audit for URLs from blacklist
90+
static auto BLACKLIST_MATCHER = CreateBlacklistMatcher();
91+
if (BLACKLIST_MATCHER.Match(request->URL)) {
92+
return false;
9393
}
9494

95-
return false;
95+
return true;
9696
}
9797

9898
void TAuditCtx::InitAudit(const NHttp::TEvHttpProxy::TEvHttpIncomingRequest::TPtr& ev) {

ydb/core/mon/audit/audit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ class TAuditCtx {
2727
void LogOnCompleted(const NHttp::THttpOutgoingResponsePtr& response);
2828
void SetSubjectType(NACLibProto::ESubjectType subjectType);
2929
static bool AuditEnabled(NKikimrConfig::TAuditConfig::TLogClassConfig::ELogPhase logPhase, NACLibProto::ESubjectType subjectType);
30+
bool AuditableRequest(const NHttp::THttpIncomingRequestPtr& request) const;
3031

3132
private:
3233
void AddAuditLogPart(TStringBuf name, const TString& value);
33-
bool AuditableRequest(const NHttp::THttpIncomingRequestPtr& request);
3434

3535
TAuditParts Parts;
3636
bool Auditable = false;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "url_matcher.h"
2+
3+
#include <util/generic/string.h>
4+
#include <util/generic/vector.h>
5+
6+
namespace NMonitoring::NAudit {
7+
8+
// Audit logging is enabled for all requests that either
9+
// 1) use modifying HTTP methods (POST, PUT, DELETE), or
10+
// 2) target endpoints not listed in AUDIT_BLACKLIST.
11+
// The blacklist excludes frequently queried read-only endpoints with no security value.
12+
const TVector<TUrlPattern> AUDIT_BLACKLIST = {
13+
{.Path = "/counters"},
14+
{.Path = "/counters/*"},
15+
{.Path = "/viewer"},
16+
{.Path = "/viewer/*"},
17+
};
18+
19+
}

ydb/core/mon/audit/audit_ut.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,58 @@
55

66
using namespace NMonitoring::NAudit;
77

8+
namespace {
9+
10+
struct TRequestHolder {
11+
NHttp::THttpIncomingRequestPtr Request;
12+
TVector<TString> Storage;
13+
14+
TStringBuf Store(TString value) {
15+
Storage.push_back(std::move(value));
16+
return Storage.back();
17+
}
18+
};
19+
20+
NHttp::THttpIncomingRequestPtr MakeRequest(TString method, TString url) {
21+
NHttp::THttpIncomingRequestPtr Request = new NHttp::THttpIncomingRequest();
22+
Request->Method = std::move(method);
23+
Request->URL = std::move(url);
24+
return Request;
25+
}
26+
27+
} // namespace
28+
829
Y_UNIT_TEST_SUITE(TAuditTest) {
930
Y_UNIT_TEST(AuditDisabledWithoutAppData) {
1031
UNIT_ASSERT(!TAuditCtx::AuditEnabled(NKikimrConfig::TAuditConfig::TLogClassConfig::Completed, NACLibProto::SUBJECT_TYPE_ANONYMOUS));
1132
}
33+
34+
Y_UNIT_TEST(ModifyingMethodsAlwaysAuditable) {
35+
TAuditCtx ctx;
36+
UNIT_ASSERT(ctx.AuditableRequest(MakeRequest("POST", "/path")));
37+
UNIT_ASSERT(ctx.AuditableRequest(MakeRequest("PUT", "/path")));
38+
UNIT_ASSERT(ctx.AuditableRequest(MakeRequest("DELETE", "/path")));
39+
40+
UNIT_ASSERT(ctx.AuditableRequest(MakeRequest("POST", "/counters")));
41+
UNIT_ASSERT(ctx.AuditableRequest(MakeRequest("PUT", "/counters")));
42+
UNIT_ASSERT(ctx.AuditableRequest(MakeRequest("DELETE", "/counters")));
43+
}
44+
45+
Y_UNIT_TEST(OptionsRequestsAreNotAudited) {
46+
TAuditCtx ctx;
47+
UNIT_ASSERT(!ctx.AuditableRequest(MakeRequest("OPTIONS", "/path")));
48+
}
49+
50+
Y_UNIT_TEST(BlacklistedPathsAreNotAudited) {
51+
TAuditCtx ctx;
52+
UNIT_ASSERT(!ctx.AuditableRequest(MakeRequest("GET", "/counters")));
53+
UNIT_ASSERT(!ctx.AuditableRequest(MakeRequest("GET", "/viewer/subpage")));
54+
UNIT_ASSERT(!ctx.AuditableRequest(MakeRequest("GET", "/viewer?mode=overview")));
55+
}
56+
57+
Y_UNIT_TEST(OtherGetRequestsAreAudited) {
58+
TAuditCtx ctx;
59+
UNIT_ASSERT(ctx.AuditableRequest(MakeRequest("GET", "/other")));
60+
UNIT_ASSERT(ctx.AuditableRequest(MakeRequest("GET", "/viewerstats?mode=overview")));
61+
}
1262
}

ydb/core/mon/audit/auditable_actions.cpp

Lines changed: 0 additions & 52 deletions
This file was deleted.

ydb/core/mon/audit/ya.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ RECURSE_FOR_TESTS(
55
LIBRARY()
66

77
SRCS(
8-
auditable_actions.cpp
8+
audit_blacklist.cpp
99
audit.cpp
1010
url_matcher.cpp
1111
)

0 commit comments

Comments
 (0)