Skip to content

Commit 2d4605d

Browse files
author
eshcherbin
committed
YT-23134: Fix sensor service paths
commit_hash:6c52404e8c00e60be2ab7545af30a4232874971a
1 parent 9b4d079 commit 2d4605d

File tree

6 files changed

+80
-10
lines changed

6 files changed

+80
-10
lines changed

yt/yt/core/ytree/ypath_client.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,16 @@ void ExecuteVerb(
399399
TFuture<TYsonString> AsyncYPathGet(
400400
const IYPathServicePtr& service,
401401
const TYPath& path,
402-
const TAttributeFilter& attributeFilter)
402+
const TAttributeFilter& attributeFilter,
403+
const IAttributeDictionaryPtr& options)
403404
{
404405
auto request = TYPathProxy::Get(path);
405406
if (attributeFilter) {
406407
ToProto(request->mutable_attributes(), attributeFilter);
407408
}
409+
if (options) {
410+
ToProto(request->mutable_options(), *options);
411+
}
408412
return ExecuteVerb(service, request)
409413
.Apply(BIND([] (TYPathProxy::TRspGetPtr response) {
410414
return TYsonString(response->value());
@@ -423,9 +427,10 @@ TString SyncYPathGetKey(const IYPathServicePtr& service, const TYPath& path)
423427
TYsonString SyncYPathGet(
424428
const IYPathServicePtr& service,
425429
const TYPath& path,
426-
const TAttributeFilter& attributeFilter)
430+
const TAttributeFilter& attributeFilter,
431+
const IAttributeDictionaryPtr& options)
427432
{
428-
auto future = AsyncYPathGet(service, path, attributeFilter);
433+
auto future = AsyncYPathGet(service, path, attributeFilter, options);
429434
auto optionalResult = future.TryGetUnique();
430435
YT_VERIFY(optionalResult);
431436
return optionalResult->ValueOrThrow();

yt/yt/core/ytree/ypath_client.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,15 @@ TString SyncYPathGetKey(
258258
TFuture<NYson::TYsonString> AsyncYPathGet(
259259
const IYPathServicePtr& service,
260260
const TYPath& path,
261-
const TAttributeFilter& attributeFilter = {});
261+
const TAttributeFilter& attributeFilter = {},
262+
const IAttributeDictionaryPtr& options = {});
262263

263264
//! Executes |Get| verb assuming #service handles requests synchronously. Throws if an error has occurred.
264265
NYson::TYsonString SyncYPathGet(
265266
const IYPathServicePtr& service,
266267
const TYPath& path,
267-
const TAttributeFilter& attributeFilter = {});
268+
const TAttributeFilter& attributeFilter = {},
269+
const IAttributeDictionaryPtr& options = {});
268270

269271
//! Asynchronously executes |Exists| verb.
270272
TFuture<bool> AsyncYPathExists(

yt/yt/library/profiling/solomon/sensor_service.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
#include "registry.h"
55
#include "private.h"
66

7-
#include <yt/yt/core/concurrency/async_rw_lock.h>
87
#include <yt/yt/core/concurrency/periodic_executor.h>
98

109
#include <yt/yt/core/ytree/fluent.h>
1110
#include <yt/yt/core/ytree/virtual.h>
1211
#include <yt/yt/core/ytree/ypath_client.h>
13-
#include <yt/yt/core/ytree/ypath_detail.h>
1412

1513
namespace NYT::NProfiling {
1614

@@ -178,7 +176,7 @@ class TSensorService
178176

179177
auto node = CreateVirtualNode(std::move(sensorServiceImpl));
180178
try {
181-
auto path = "/" + NYPath::ToYPathLiteral(name);
179+
auto path = TYPath("/" + name);
182180
ForceYPath(Root_, path);
183181
SetNodeByYPath(Root_, path, node);
184182
} catch (const std::exception& ex) {
@@ -196,7 +194,7 @@ class TSensorService
196194
SensorTreeUpdateDuration_.Record(elapsed);
197195

198196
YT_LOG_DEBUG(
199-
"Finished updating sensor service tree"
197+
"Finished updating sensor service tree "
200198
"(TotalSensorCount: %v, AddedSensorCount: %v, MalformedSensorCount: %v, Elapsed: %v)",
201199
sensors.size(),
202200
addedSensorCount,

yt/yt/library/profiling/unittests/exporter_ut.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include "yt/yt/library/profiling/solomon/registry.h"
21
#include <gtest/gtest.h>
32

43
#include <yt/yt/core/concurrency/action_queue.h>
54

65
#include <yt/yt/library/profiling/solomon/exporter.h>
6+
#include <yt/yt/library/profiling/solomon/registry.h>
77

88
namespace NYT::NProfiling {
99
namespace {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include <gtest/gtest.h>
2+
3+
#include <yt/yt/core/ytree/helpers.h>
4+
#include <yt/yt/core/ytree/ypath_client.h>
5+
#include <yt/yt/core/ytree/ypath_proxy.h>
6+
7+
#include <yt/yt/library/profiling/solomon/registry.h>
8+
#include <yt/yt/library/profiling/solomon/exporter.h>
9+
#include <yt/yt/library/profiling/solomon/sensor_service.h>
10+
11+
namespace NYT::NProfiling {
12+
namespace {
13+
14+
using namespace NConcurrency;
15+
using namespace NYPath;
16+
using namespace NYTree;
17+
using namespace NYson;
18+
19+
////////////////////////////////////////////////////////////////////////////////
20+
21+
TEST(TSensorService, GetSensor)
22+
{
23+
auto registry = New<TSolomonRegistry>();
24+
auto config = New<TSolomonExporterConfig>();
25+
config->GridStep = TDuration::Seconds(1);
26+
config->UpdateSensorServiceTreePeriod = TDuration::MilliSeconds(100);
27+
config->EnableSelfProfiling = false;
28+
auto exporter = New<TSolomonExporter>(config, registry);
29+
30+
exporter->Start();
31+
32+
auto gauge = TProfiler(registry, "/foo").Gauge("/bar/baz");
33+
gauge.Update(117.0);
34+
35+
registry->Collect();
36+
auto sensorService = exporter->GetSensorService();
37+
38+
auto valueByName = [&] {
39+
auto options = CreateEphemeralAttributes();
40+
options->Set("name", "yt/foo/bar/baz");
41+
42+
return ConvertTo<double>(SyncYPathGet(sensorService, "", /*attributeFilter*/ {}, options));
43+
}();
44+
45+
EXPECT_EQ(valueByName, 117.0);
46+
47+
TDelayedExecutor::WaitForDuration(2 * config->UpdateSensorServiceTreePeriod);
48+
49+
auto valueByPath = [&] {
50+
auto options = CreateEphemeralAttributes();
51+
options->Set("read_all_projections", false);
52+
53+
return ConvertTo<double>(SyncYPathGet(sensorService, "/yt/foo/bar/baz", /*attributeFilter*/ {}, options));
54+
}();
55+
56+
EXPECT_EQ(valueByPath, 117.0);
57+
58+
exporter->Stop();
59+
}
60+
61+
////////////////////////////////////////////////////////////////////////////////
62+
63+
} // namespace
64+
} // namespace NYT::NProfiling

yt/yt/library/profiling/unittests/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ENDIF()
88

99
SRCS(
1010
sensor_ut.cpp
11+
sensor_service_ut.cpp
1112
name_conflicts_ut.cpp
1213
profiler_ut.cpp
1314
solomon_ut.cpp

0 commit comments

Comments
 (0)