Skip to content

Commit f34ff39

Browse files
fixed style and issues
1 parent 74d7882 commit f34ff39

File tree

3 files changed

+63
-61
lines changed

3 files changed

+63
-61
lines changed

ydb/library/yql/providers/common/solomon_accessor/client/solomon_accessor_client.cpp

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using namespace yandex::monitoring::api::v3;
1515

1616
namespace {
1717

18-
Downsampling::GapFilling ParseGapFilling(const TString &fill)
18+
Downsampling::GapFilling ParseGapFilling(const TString& fill)
1919
{
2020
if (fill.equal("NULL")) {
2121
return Downsampling::GAP_FILLING_NULL;
@@ -29,7 +29,7 @@ Downsampling::GapFilling ParseGapFilling(const TString &fill)
2929
return Downsampling::GAP_FILLING_UNSPECIFIED;
3030
}
3131

32-
Downsampling::GridAggregation ParseGridAggregation(const TString &aggregation)
32+
Downsampling::GridAggregation ParseGridAggregation(const TString& aggregation)
3333
{
3434
if (aggregation.equal("MAX")) {
3535
return Downsampling::GRID_AGGREGATION_MAX;
@@ -52,7 +52,7 @@ Downsampling::GridAggregation ParseGridAggregation(const TString &aggregation)
5252
return Downsampling::GRID_AGGREGATION_UNSPECIFIED;
5353
}
5454

55-
MetricType ParseMetricType(const TString &type)
55+
MetricType ParseMetricType(const TString& type)
5656
{
5757
if (type.equal("DGAUGE")) {
5858
return MetricType::DGAUGE;
@@ -77,13 +77,14 @@ class TSolomonAccessorClient : public ISolomonAccessorClient, public std::enable
7777
std::shared_ptr<NYdb::ICredentialsProvider> credentialsProvider
7878
)
7979
: DefaultReplica("sas")
80-
, DefaultPort(443)
8180
, Settings(std::move(settings))
8281
, CredentialsProvider(credentialsProvider)
82+
, GrpcClient(std::make_shared<NYdbGrpc::TGRpcClientLow>())
83+
, HttpGateway(IHTTPGateway::Make())
8384
{}
8485

8586
public:
86-
NThreading::TFuture<TListMetricsResult> ListMetrics(const TString &selectors, int pageSize, int page) override final
87+
NThreading::TFuture<TListMetricsResult> ListMetrics(const TString& selectors, int pageSize, int page) override final
8788
{
8889
const auto request = BuildListMetricsRequest(selectors, pageSize, page);
8990

@@ -92,30 +93,29 @@ class TSolomonAccessorClient : public ISolomonAccessorClient, public std::enable
9293

9394
auto resultPromise = NThreading::NewPromise<TListMetricsResult>();
9495

95-
const auto httpGateway = IHTTPGateway::Make();
96-
9796
std::weak_ptr<const TSolomonAccessorClient> weakSelf = shared_from_this();
9897
// hold context until reply
9998
auto cb = [weakSelf, resultPromise](NYql::IHTTPGateway::TResult&& result) mutable
10099
{
101100
if (auto self = weakSelf.lock()) {
102101
resultPromise.SetValue(self->ProcessHttpResponse(std::move(result)));
102+
} else {
103+
resultPromise.SetValue(TListMetricsResult("Client is being shutted down"));
103104
}
104-
resultPromise.SetValue(TListMetricsResult("Client is being shutted down"));
105105
};
106106

107-
httpGateway->Download(
107+
HttpGateway->Download(
108108
request,
109109
headers,
110110
0,
111-
1ull << 30,
111+
ListSizeLimit,
112112
std::move(cb)
113113
);
114114

115115
return resultPromise.GetFuture();
116116
}
117117

118-
NThreading::TFuture<TGetDataResult> GetData(const std::vector<TString> &selectors) override final
118+
NThreading::TFuture<TGetDataResult> GetData(const std::vector<TString>& selectors) override final
119119
{
120120
const auto request = BuildGetDataRequest(selectors);
121121

@@ -127,10 +127,9 @@ class TSolomonAccessorClient : public ISolomonAccessorClient, public std::enable
127127
NYdbGrpc::TGRpcClientConfig grpcConf;
128128
grpcConf.Locator = GetGrpcSolomonEndpoint();
129129
grpcConf.EnableSsl = Settings.GetUseSsl();
130-
const auto grpcClient = std::make_unique<NYdbGrpc::TGRpcClientLow>();
131-
const auto connection = grpcClient->CreateGRpcServiceConnection<DataService>(grpcConf);
130+
const auto connection = GrpcClient->CreateGRpcServiceConnection<DataService>(grpcConf);
132131

133-
auto context = grpcClient->CreateContext();
132+
auto context = GrpcClient->CreateContext();
134133
if (!context) {
135134
throw yexception() << "Client is being shutted down";
136135
}
@@ -142,8 +141,9 @@ class TSolomonAccessorClient : public ISolomonAccessorClient, public std::enable
142141
{
143142
if (auto self = weakSelf.lock()) {
144143
resultPromise.SetValue(self->ProcessGrpcResponse(std::move(status), std::move(result)));
144+
} else {
145+
resultPromise.SetValue(TGetDataResult("Client is being shutted down"));
145146
}
146-
resultPromise.SetValue(TGetDataResult("Client is being shutted down"));
147147
};
148148

149149
connection->DoRequest<ReadRequest, ReadResponse>(
@@ -179,13 +179,10 @@ class TSolomonAccessorClient : public ISolomonAccessorClient, public std::enable
179179

180180
TString GetGrpcSolomonEndpoint() const
181181
{
182-
return Settings.GetEndpoint() + std::to_string(DefaultPort);
182+
return Settings.GetEndpoint() + "443";
183183
}
184184

185-
TString BuildListMetricsRequest(
186-
const TString &selectors,
187-
int pageSize,
188-
int page) const
185+
TString BuildListMetricsRequest(const TString& selectors, int pageSize, int page) const
189186
{
190187
TUrlBuilder builder(GetHttpSolomonEndpoint());
191188

@@ -203,7 +200,7 @@ class TSolomonAccessorClient : public ISolomonAccessorClient, public std::enable
203200
return builder.Build();
204201
}
205202

206-
ReadRequest BuildGetDataRequest(const std::vector<TString> &selectors) const
203+
ReadRequest BuildGetDataRequest(const std::vector<TString>& selectors) const
207204
{
208205
ReadRequest request;
209206

@@ -214,15 +211,14 @@ class TSolomonAccessorClient : public ISolomonAccessorClient, public std::enable
214211

215212
if (Settings.GetDownsampling().GetDisabled()) {
216213
request.mutable_downsampling()->set_disabled(true);
217-
}
218-
else {
214+
} else {
219215
const auto downsampling = Settings.GetDownsampling();
220216
request.mutable_downsampling()->set_grid_interval(downsampling.GetGridMs());
221217
request.mutable_downsampling()->set_grid_aggregation(ParseGridAggregation(downsampling.GetAggregation()));
222218
request.mutable_downsampling()->set_gap_filling(ParseGapFilling(downsampling.GetFill()));
223219
}
224220

225-
for (const auto &metric : selectors) {
221+
for (const auto& metric : selectors) {
226222
auto query = request.mutable_queries()->Add();
227223
*query->mutable_value() = TStringBuilder{} << "{" << metric << "}";
228224
query->set_hidden(false);
@@ -233,7 +229,7 @@ class TSolomonAccessorClient : public ISolomonAccessorClient, public std::enable
233229

234230
TListMetricsResult ProcessHttpResponse(NYql::IHTTPGateway::TResult&& response) const
235231
{
236-
std::vector<Metric> result;
232+
std::vector<TMetric> result;
237233

238234
if (response.Content.HttpResponseCode < 200 || response.Content.HttpResponseCode >= 300) {
239235
return TListMetricsResult(TStringBuilder{} << "Error while sending request to monitoring api: " << response.Content.data());
@@ -250,11 +246,11 @@ class TSolomonAccessorClient : public ISolomonAccessorClient, public std::enable
250246
return TListMetricsResult{"Invalid result from monitoring api"};
251247
}
252248

253-
for (const auto &metricObj : json["result"].GetArray()) {
249+
for (const auto& metricObj : json["result"].GetArray()) {
254250
try {
255251
result.emplace_back(metricObj);
256252
} catch (const std::exception& e) {
257-
return TStringBuilder{} << "Failed to parse response from monitoring: " << e.what();
253+
return TStringBuilder{} << "Failed to parse result response from monitoring: " << e.what();
258254
}
259255
}
260256

@@ -263,53 +259,59 @@ class TSolomonAccessorClient : public ISolomonAccessorClient, public std::enable
263259

264260
TGetDataResult ProcessGrpcResponse(NYdbGrpc::TGrpcStatus&& status, ReadResponse &&response) const
265261
{
266-
std::vector<Timeseries> result;
262+
std::vector<TTimeseries> result;
267263

268264
if (!status.Ok()) {
269265
return TStringBuilder{} << "Error while sending request to monitoring api: " << status.Msg;
270266
}
271267

272-
for (const auto &responseValue : response.response_per_query()) {
268+
for (const auto& responseValue : response.response_per_query()) {
273269
YQL_ENSURE(responseValue.has_timeseries_vector());
274270
YQL_ENSURE(responseValue.timeseries_vector().values_size() == 1); // one response per one set of selectors
275271

276-
const auto &queryResponse = responseValue.timeseries_vector().values()[0];
272+
const auto& queryResponse = responseValue.timeseries_vector().values()[0];
277273

278-
std::vector<int64_t> timestampValues;
279-
std::vector<double> timeseriesValues;
274+
std::vector<int64_t> timestamps;
275+
std::vector<double> values;
276+
277+
timestamps.reserve(queryResponse.timestamp_values().values_size());
278+
values.reserve(queryResponse.double_values().values_size());
280279

281280
for (int64_t value : queryResponse.timestamp_values().values()) {
282-
timestampValues.push_back(value);
281+
timestamps.push_back(value);
283282
}
284283
for (double value : queryResponse.double_values().values()) {
285-
timeseriesValues.push_back(value);
284+
values.push_back(value);
286285
}
287286

288-
result.emplace_back(queryResponse.name(), queryResponse.type(), std::move(timestampValues), std::move(timeseriesValues));
287+
result.emplace_back(queryResponse.name(), queryResponse.type(), std::move(timestamps), std::move(values));
289288
}
290289

291290
return std::move(result);
292291
}
293292

294293
private:
295294
const TString DefaultReplica;
296-
const int DefaultPort;
295+
const size_t ListSizeLimit = 1ull << 30;
296+
297+
const NYql::NSo::NProto::TDqSolomonSource Settings;
298+
const std::shared_ptr<NYdb::ICredentialsProvider> CredentialsProvider;
297299

298-
NYql::NSo::NProto::TDqSolomonSource Settings;
299-
std::shared_ptr<NYdb::ICredentialsProvider> CredentialsProvider;
300+
const std::shared_ptr<NYdbGrpc::TGRpcClientLow> GrpcClient;
301+
const std::shared_ptr<IHTTPGateway> HttpGateway;
300302
};
301303

302304
} // namespace
303305

304-
Metric::Metric(const NJson::TJsonValue &value)
306+
TMetric::TMetric(const NJson::TJsonValue& value)
305307
{
306308
YQL_ENSURE(value.IsMap());
307309

308310
if (value.Has("labels")) {
309311
auto labels = value["labels"];
310312
YQL_ENSURE(labels.IsMap());
311313

312-
for (const auto &[key, value] : labels.GetMapSafe()) {
314+
for (const auto& [key, value] : labels.GetMapSafe()) {
313315
YQL_ENSURE(value.IsString());
314316
Labels[key] = value.GetString();
315317
}
@@ -326,22 +328,22 @@ Metric::Metric(const NJson::TJsonValue &value)
326328
}
327329
}
328330

329-
ISolomonAccessorClient::TListMetricsResult::TListMetricsResult(const TString &error)
331+
ISolomonAccessorClient::TListMetricsResult::TListMetricsResult(const TString& error)
330332
: Success(false)
331333
, ErrorMsg(error)
332334
{}
333335

334-
ISolomonAccessorClient::TListMetricsResult::TListMetricsResult(std::vector<Metric> &&result)
336+
ISolomonAccessorClient::TListMetricsResult::TListMetricsResult(std::vector<TMetric>&& result)
335337
: Success(true)
336338
, Result(std::move(result))
337339
{}
338340

339-
ISolomonAccessorClient::TGetDataResult::TGetDataResult(const TString &error)
341+
ISolomonAccessorClient::TGetDataResult::TGetDataResult(const TString& error)
340342
: Success(false)
341343
, ErrorMsg(error)
342344
{}
343345

344-
ISolomonAccessorClient::TGetDataResult::TGetDataResult(std::vector<Timeseries> &&result)
346+
ISolomonAccessorClient::TGetDataResult::TGetDataResult(std::vector<TTimeseries>&& result)
345347
: Success(true)
346348
, Result(std::move(result))
347349
{}

ydb/library/yql/providers/common/solomon_accessor/client/solomon_accessor_client.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,25 @@
33
#include <library/cpp/json/json_reader.h>
44
#include <library/cpp/threading/future/core/future.h>
55
#include <ydb-cpp-sdk/client/types/credentials/credentials.h>
6+
#include <ydb/library/yql/providers/common/solomon_accessor/grpc/solomon_accessor_pb.pb.h>
67
#include <ydb/library/yql/providers/solomon/proto/dq_solomon_shard.pb.h>
78

89
namespace NYql::NSo {
910

10-
class Metric {
11+
class TMetric {
1112
public:
12-
Metric(const NJson::TJsonValue &value);
13+
TMetric(const NJson::TJsonValue& value);
1314

1415
public:
1516
std::map<TString, TString> Labels;
16-
int Type;
17+
yandex::monitoring::api::v3::MetricType Type;
1718
TString CreatedAt;
1819
};
1920

20-
class Timeseries {
21+
class TTimeseries {
2122
public:
2223
TString Name;
23-
int Type;
24+
yandex::monitoring::api::v3::MetricType Type;
2425
std::vector<int64_t> Timestamps;
2526
std::vector<double> Values;
2627
};
@@ -38,29 +39,29 @@ class ISolomonAccessorClient {
3839

3940
class TListMetricsResult {
4041
public:
41-
TListMetricsResult(const TString &);
42-
TListMetricsResult(std::vector<Metric> &&);
42+
TListMetricsResult(const TString&);
43+
TListMetricsResult(std::vector<TMetric>&&);
4344

4445
public:
4546
bool Success;
4647
TString ErrorMsg;
47-
std::vector<Metric> Result;
48+
std::vector<TMetric> Result;
4849
};
4950

5051
class TGetDataResult {
5152
public:
52-
TGetDataResult(const TString &);
53-
TGetDataResult(std::vector<Timeseries> &&);
53+
TGetDataResult(const TString&);
54+
TGetDataResult(std::vector<TTimeseries>&&);
5455

5556
public:
5657
bool Success;
5758
TString ErrorMsg;
58-
std::vector<Timeseries> Result;
59+
std::vector<TTimeseries> Result;
5960
};
6061

6162
public:
62-
virtual NThreading::TFuture<TListMetricsResult> ListMetrics(const TString &selectors, int pageSize, int page) = 0;
63-
virtual NThreading::TFuture<TGetDataResult> GetData(const std::vector<TString> &selectors) = 0;
63+
virtual NThreading::TFuture<TListMetricsResult> ListMetrics(const TString& selectors, int pageSize, int page) = 0;
64+
virtual NThreading::TFuture<TGetDataResult> GetData(const std::vector<TString>& selectors) = 0;
6465
};
6566

66-
} // namespace NYql
67+
} // namespace NYql::NSo

ydb/library/yql/providers/common/solomon_accessor/grpc/solomon_accessor_pb.proto

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,11 @@ message ResponsePerQuery {
134134
repeated TimeseriesValue values = 1;
135135
}
136136

137-
//Name of the query.
137+
// Name of the query.
138138
string query_name = 1;
139139

140-
//Result values for the query.
140+
// Result values for the query.
141141
oneof result_values {
142-
143142
// Timeseries vector.
144143
TimeseriesVector timeseries_vector = 2;
145144
}

0 commit comments

Comments
 (0)