Skip to content

Commit 06146ca

Browse files
committed
Intermediate changes
commit_hash:22b4cddd0210b5fc08b8327407d825258ad7cc4b
1 parent 888ab4d commit 06146ca

File tree

3 files changed

+72
-18
lines changed

3 files changed

+72
-18
lines changed

yt/yt/library/profiling/solomon/remote.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ void FromProto(THistogramSnapshot* histogram, const NProto::THistogramSnapshot&
7373
TRemoteRegistry::TRemoteRegistry(TSolomonRegistry* registry)
7474
: Registry_(registry)
7575
{
76-
TagRename_.emplace_back();
7776
}
7877

7978
void TRemoteRegistry::Transfer(const NProto::TSensorDump& dump)
@@ -89,11 +88,20 @@ void TRemoteRegistry::Transfer(const NProto::TSensorDump& dump)
8988
}
9089
}
9190

92-
for (TTagId tagId = TagRename_.size(); tagId < dump.tags().size(); tagId++) {
91+
TTagIdList tagRename(dump.tags().size());
92+
for (TTagId tagId = 1; tagId < dump.tags().size(); tagId++) {
9393
const auto& remoteTag = dump.tags()[tagId];
94-
TagRename_.push_back(Registry_->TagRegistry_.Encode(TTag{remoteTag.key(), remoteTag.value()}));
94+
tagRename[tagId] = Registry_->TagRegistry_.Encode(TTag{remoteTag.key(), remoteTag.value()});
9595
}
9696

97+
auto renameTags = [&tagRename] (const TTagIdList& tags) {
98+
TTagIdList renamed;
99+
for (auto tag : tags) {
100+
renamed.push_back(tagRename[tag]);
101+
}
102+
return renamed;
103+
};
104+
97105
auto oldSensors = std::move(Sensors_);
98106
Sensors_ = {};
99107

@@ -114,7 +122,7 @@ void TRemoteRegistry::Transfer(const NProto::TSensorDump& dump)
114122
for (const auto& tagId : projection.tag_ids()) {
115123
tagIds.push_back(tagId);
116124
}
117-
tagIds = RenameTags(tagIds);
125+
tagIds = renameTags(tagIds);
118126

119127
auto transferValue = [&] (auto cube, ESensorType type, auto value) {
120128
sensorSet->InitializeType(type);
@@ -197,15 +205,6 @@ void TRemoteRegistry::DoDetach(const THashMap<std::string, TRemoteSensorSet>& se
197205
}
198206
}
199207

200-
TTagIdList TRemoteRegistry::RenameTags(const TTagIdList& tags)
201-
{
202-
TTagIdList renamed;
203-
for (auto tag : tags) {
204-
renamed.push_back(TagRename_[tag]);
205-
}
206-
return renamed;
207-
}
208-
209208
////////////////////////////////////////////////////////////////////////////////
210209

211210
} // namespace NYT::NProfiling

yt/yt/library/profiling/solomon/remote.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
#include <util/generic/hash_set.h>
1111

12-
#include <deque>
13-
1412
namespace NYT::NProfiling {
1513

1614
////////////////////////////////////////////////////////////////////////////////
@@ -36,16 +34,13 @@ class TRemoteRegistry final
3634
private:
3735
TSolomonRegistry* Registry_ = nullptr;
3836

39-
std::deque<TTagId> TagRename_;
40-
4137
struct TRemoteSensorSet
4238
{
4339
THashSet<std::pair<ESensorType, TTagIdList>> UsedTags;
4440
};
4541

4642
THashMap<std::string, TRemoteSensorSet> Sensors_;
4743

48-
TTagIdList RenameTags(const TTagIdList& tags);
4944
void DoDetach(const THashMap<std::string, TRemoteSensorSet>& sensors);
5045
};
5146

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,66 @@ TEST(TSolomonRegistry, TestRemoteTransfer)
812812
ASSERT_TRUE(sensors.Counters.empty());
813813
}
814814

815+
TEST(TSolomonRegistry, TestRemoteTransferWithDistinctTags)
816+
{
817+
auto impl = New<TSolomonRegistry>();
818+
impl->SetWindowSize(12);
819+
820+
TRemoteRegistry remoteRegistry(impl.Get());
821+
const auto& tagRegistry = impl->GetTagRegistry();
822+
823+
auto buildSensorDump = [] (const std::string& tagsPrefix, int tagsCount, const std::string& sensor, i64 value) {
824+
NProto::TSensorDump dump;
825+
826+
dump.add_tags();
827+
for (TTagId tagId = 1; tagId <= tagsCount; ++tagId) {
828+
auto value = std::to_string(tagId);
829+
830+
auto* tag = dump.add_tags();
831+
tag->set_key(tagsPrefix + value);
832+
tag->set_value(value);
833+
}
834+
835+
auto* cube = dump.add_cubes();
836+
cube->set_name(sensor);
837+
838+
auto* projection = cube->add_projections();
839+
for (TTagId tagId = 1; tagId <= tagsCount; ++tagId) {
840+
projection->add_tag_ids(tagId);
841+
}
842+
projection->set_has_value(true);
843+
projection->set_counter(value);
844+
845+
return dump;
846+
};
847+
848+
auto transferAndCollect = [&] (const std::string& tagsPrefix, int tagsCount, const std::string& sensor, i64 value) {
849+
auto dump = buildSensorDump(tagsPrefix, tagsCount, sensor, value);
850+
remoteRegistry.Transfer(dump);
851+
852+
impl->Collect();
853+
return ReadSensors(impl);
854+
};
855+
856+
// First collect to prepare registry for subsequent transfers.
857+
impl->Collect();
858+
859+
auto sensors = transferAndCollect("a", 3, "s1", 1);
860+
ASSERT_EQ(1, std::ssize(sensors.Counters));
861+
ASSERT_EQ(1, sensors.Counters["s1{a1=1;a2=2;a3=3}"]);
862+
ASSERT_EQ(3, tagRegistry.GetSize());
863+
864+
sensors = transferAndCollect("b", 2, "s2", 2);
865+
ASSERT_EQ(1, std::ssize(sensors.Counters));
866+
ASSERT_EQ(2, sensors.Counters["s2{b1=1;b2=2}"]);
867+
ASSERT_EQ(5, tagRegistry.GetSize());
868+
869+
sensors = transferAndCollect("b", 4, "s2", 3);
870+
ASSERT_EQ(1, std::ssize(sensors.Counters));
871+
ASSERT_EQ(3, sensors.Counters["s2{b1=1;b2=2;b3=3;b4=4}"]);
872+
ASSERT_EQ(7, tagRegistry.GetSize());
873+
}
874+
815875
TEST(TSolomonRegistry, ExtensionTag)
816876
{
817877
auto impl = New<TSolomonRegistry>();

0 commit comments

Comments
 (0)