Skip to content

Commit c255a91

Browse files
committed
Intermediate changes
commit_hash:30e75a336c73b67430370de2655cb84a61d5cf4e
1 parent 1fd7d34 commit c255a91

File tree

4 files changed

+20
-216
lines changed

4 files changed

+20
-216
lines changed

yt/yt/library/profiling/solomon/tag_registry-inl.h

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

yt/yt/library/profiling/solomon/tag_registry.cpp

Lines changed: 20 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -10,138 +10,48 @@ namespace NYT::NProfiling {
1010

1111
////////////////////////////////////////////////////////////////////////////////
1212

13-
namespace {
14-
15-
static constexpr int MaxLabelSize = 200;
16-
static constexpr int HalfMaxLabelSize = MaxLabelSize / 2;
17-
18-
struct TSanitizeParameters
19-
{
20-
int ForbiddenCharCount;
21-
int ResultingLength;
22-
23-
bool IsSanitizationRequired() const
24-
{
25-
return ForbiddenCharCount > 0 || ResultingLength > MaxLabelSize;
26-
}
27-
};
28-
29-
bool IsAllowedMonitoringTagValueChar(unsigned char c)
30-
{
31-
return 31 < c &&
32-
c < 127 &&
33-
c != '|' &&
34-
c != '*' &&
35-
c != '?' &&
36-
c != '"' &&
37-
c != '\'' &&
38-
c != '\\' &&
39-
c != '`';
40-
}
41-
42-
TSanitizeParameters ScanForSanitize(const std::string& value)
43-
{
44-
int forbiddenCharCount = 0;
45-
for (unsigned char c : value) {
46-
forbiddenCharCount += static_cast<int>(!IsAllowedMonitoringTagValueChar(c));
47-
}
48-
49-
return {
50-
.ForbiddenCharCount = forbiddenCharCount,
51-
.ResultingLength = static_cast<int>(value.size() + forbiddenCharCount * 2),
52-
};
53-
}
54-
55-
std::string SanitizeMonitoringTagValue(const std::string& value, int resultingLength)
13+
TTagIdList TTagRegistry::Encode(const TTagList& tags)
5614
{
57-
bool needTrim = resultingLength > MaxLabelSize;
58-
59-
std::string result;
60-
result.resize(std::min(resultingLength, MaxLabelSize));
61-
62-
int resultIndex = 0;
63-
for (int index = 0; resultIndex < (needTrim ? HalfMaxLabelSize : resultingLength); ++index) {
64-
unsigned char c = value[index];
65-
66-
if (IsAllowedMonitoringTagValueChar(value[index])) {
67-
result[resultIndex++] = c;
68-
} else {
69-
result[resultIndex++] = '%';
70-
result[resultIndex++] = IntToHexLowercase[c >> 4];
71-
result[resultIndex++] = IntToHexLowercase[c & 0x0f];
72-
}
73-
}
74-
75-
if (!needTrim) {
76-
return result;
77-
}
78-
79-
resultIndex = MaxLabelSize - 1;
80-
for (int index = ssize(value) - 1; resultIndex > HalfMaxLabelSize + 2; --index) {
81-
unsigned char c = value[index];
15+
TTagIdList ids;
8216

83-
if (IsAllowedMonitoringTagValueChar(value[index])) {
84-
result[resultIndex--] = c;
17+
for (const auto& tag : tags) {
18+
if (auto it = TagByName_.find(tag); it != TagByName_.end()) {
19+
ids.push_back(it->second);
8520
} else {
86-
result[resultIndex--] = IntToHexLowercase[c & 0x0f];
87-
result[resultIndex--] = IntToHexLowercase[c >> 4];
88-
result[resultIndex--] = '%';
21+
TagById_.push_back(tag);
22+
TagByName_[tag] = TagById_.size();
23+
ids.push_back(TagById_.size());
8924
}
9025
}
9126

92-
result[HalfMaxLabelSize] = '.';
93-
result[HalfMaxLabelSize + 1] = '.';
94-
result[HalfMaxLabelSize + 2] = '.';
95-
96-
return result;
27+
return ids;
9728
}
9829

99-
TTag SanitizeMonitoringTag(const TTag& tag, int resultingLength)
30+
TTagId TTagRegistry::Encode(const TTag& tag)
10031
{
101-
return {tag.first, SanitizeMonitoringTagValue(tag.second, resultingLength)};
32+
if (auto it = TagByName_.find(tag); it != TagByName_.end()) {
33+
return it->second;
34+
} else {
35+
TagById_.push_back(tag);
36+
TagByName_[tag] = TagById_.size();
37+
return TagById_.size();
38+
}
10239
}
10340

104-
} // namespace
105-
106-
////////////////////////////////////////////////////////////////////////////////
107-
10841
TTagIdList TTagRegistry::Encode(const TTagSet& tags)
10942
{
11043
return Encode(tags.Tags());
11144
}
11245

113-
TTagIdList TTagRegistry::Encode(const TTagList& tags)
114-
{
115-
TTagIdList ids;
116-
for (const auto& tag : tags) {
117-
ids.push_back(Encode(tag));
118-
}
119-
120-
return ids;
121-
}
122-
123-
TTagId TTagRegistry::Encode(const TTag& tag)
124-
{
125-
if (auto sanitizeParameters = ScanForSanitize(tag.second);
126-
sanitizeParameters.IsSanitizationRequired())
127-
{
128-
return EncodeSanitized(SanitizeMonitoringTag(tag, sanitizeParameters.ResultingLength));
129-
} else {
130-
return EncodeSanitized(tag);
131-
}
132-
}
133-
13446
TCompactVector<std::optional<TTagId>, TypicalTagCount> TTagRegistry::TryEncode(const TTagList& tags) const
13547
{
13648
TCompactVector<std::optional<TTagId>, TypicalTagCount> ids;
13749

13850
for (const auto& tag : tags) {
139-
if (auto sanitizeParameters = ScanForSanitize(tag.second);
140-
sanitizeParameters.IsSanitizationRequired())
141-
{
142-
ids.push_back(TryEncodeSanitized(SanitizeMonitoringTag(tag, sanitizeParameters.ResultingLength)));
51+
if (auto it = TagByName_.find(tag); it != TagByName_.end()) {
52+
ids.push_back(it->second);
14353
} else {
144-
ids.push_back(TryEncodeSanitized(tag));
54+
ids.push_back({});
14555
}
14656
}
14757

@@ -183,15 +93,6 @@ void TTagRegistry::DumpTags(NProto::TSensorDump* dump)
18393
}
18494
}
18595

186-
std::optional<TTagId> TTagRegistry::TryEncodeSanitized(const TTag& tag) const
187-
{
188-
if (auto it = TagByName_.find(tag); it != TagByName_.end()) {
189-
return it->second;
190-
} else {
191-
return std::nullopt;
192-
}
193-
}
194-
19596
////////////////////////////////////////////////////////////////////////////////
19697

19798
void TTagWriter::WriteLabel(TTagId tag)

yt/yt/library/profiling/solomon/tag_registry.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ class TTagRegistry
3030
void DumpTags(NProto::TSensorDump* dump);
3131

3232
private:
33-
template <class TTagPerfect>
34-
TTagId EncodeSanitized(TTagPerfect&& tag);
35-
std::optional<TTagId> TryEncodeSanitized(const TTag& tag) const;
36-
3733
// TODO(prime@): maybe do something about the fact that tags are never freed.
3834
THashMap<TTag, TTagId> TagByName_;
3935
std::deque<TTag> TagById_;
@@ -64,7 +60,3 @@ class TTagWriter
6460
////////////////////////////////////////////////////////////////////////////////
6561

6662
} // namespace NYT::NProfiling
67-
68-
#define TAG_REGISTRY_INL_H
69-
#include "tag_registry-inl.h"
70-
#undef TAG_REGISTRY_INL_H

yt/yt/library/profiling/unittests/solomon_ut.cpp

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -962,64 +962,6 @@ TEST_P(TOmitNameLabelSuffixTest, GaugeSummary)
962962
ASSERT_NEAR(gauges[Format("yt.davg%v{}", omitNameLabelSuffix ? "" : ".avg")], 40 + 1 / 3.0, 1e-6);
963963
}
964964

965-
TEST(TSolomonRegistry, IncorrectSolomonLabels)
966-
{
967-
auto impl = New<TSolomonRegistry>();
968-
impl->SetWindowSize(12);
969-
970-
TString longTag;
971-
longTag.reserve(210);
972-
for (int index = 0; index < 210; ++index) {
973-
longTag.append('a' + index % 26);
974-
}
975-
TString longTagEncoded;
976-
longTagEncoded.reserve(200);
977-
longTagEncoded.append(longTag.begin(), 100).append("...");
978-
for (int index = 103; index < 200; ++index) {
979-
longTagEncoded.append('a' + (index - 103 + 9) % 26);
980-
}
981-
982-
TString incorrectSymbolsTag = "aaa|*?\"'\\`bbb";
983-
incorrectSymbolsTag.back() = 0xff;
984-
TString incorrectSymbolsTagEncoded = "aaa%7c%2a%3f%22%27%5c%60bb%ff";
985-
986-
TString longWithIncorrectSymbolsTag(200, 'a');
987-
longWithIncorrectSymbolsTag[98] = 0xff;
988-
longWithIncorrectSymbolsTag[199] = 0x00;
989-
TString longWithIncorrectSymbolsTagEncoded;
990-
longWithIncorrectSymbolsTagEncoded.append(TString(98, 'a'))
991-
.append("%f...")
992-
.append(TString(94, 'a'))
993-
.append("%00");
994-
995-
auto profiler = TProfiler(impl, "/debug")
996-
.WithTag("tag0", longTag)
997-
.WithTag("tag1", incorrectSymbolsTag)
998-
.WithTag("tag2", longWithIncorrectSymbolsTag);
999-
auto c0 = profiler.Counter("/c");
1000-
c0.Increment(1);
1001-
1002-
auto result = CollectSensors(impl);
1003-
1004-
for (const auto& label : result.Labels) {
1005-
auto equal = [&label] (TStringBuf tag) {
1006-
return std::equal(label.begin(), label.begin() + 4, tag.begin());
1007-
};
1008-
1009-
auto labelValue = label.substr(5, label.size() - 5);
1010-
1011-
if (equal("tag0")) {
1012-
ASSERT_EQ(labelValue, longTagEncoded);
1013-
} else if (equal("tag1")) {
1014-
ASSERT_EQ(labelValue, incorrectSymbolsTagEncoded);
1015-
} else if (equal("tag2")) {
1016-
ASSERT_EQ(labelValue, longWithIncorrectSymbolsTagEncoded);
1017-
} else {
1018-
ASSERT_TRUE(false);
1019-
}
1020-
}
1021-
}
1022-
1023965
////////////////////////////////////////////////////////////////////////////////
1024966

1025967
} // namespace

0 commit comments

Comments
 (0)