2
2
3
3
#include < ydb-cpp-sdk/client/driver/driver.h>
4
4
5
+ #include < chrono>
6
+ #include < unordered_map>
7
+ #include < variant>
8
+
5
9
namespace Ydb ::RateLimiter {
6
- class CreateResourceRequest ;
7
- class DescribeResourceResult ;
8
- class HierarchicalDrrSettings ;
10
+ class CreateResourceRequest ;
11
+ class DescribeResourceResult ;
12
+ class HierarchicalDrrSettings ;
13
+ class ReplicatedBucketSettings ;
14
+ class MeteringConfig ;
15
+ class MeteringConfig_Metric ;
9
16
} // namespace Ydb::RateLimiter
10
17
11
18
namespace NYdb ::inline V3::NRateLimiter {
12
19
20
+ struct TReplicatedBucketSettings {
21
+ using TSelf = TReplicatedBucketSettings;
22
+
23
+ TReplicatedBucketSettings () = default ;
24
+ TReplicatedBucketSettings (const Ydb::RateLimiter::ReplicatedBucketSettings&);
25
+
26
+ void SerializeTo (Ydb::RateLimiter::ReplicatedBucketSettings&) const ;
27
+
28
+ // Interval between syncs from kesus and between consumption reports.
29
+ // Default value equals 5000 ms and not inherited.
30
+ FLUENT_SETTING_OPTIONAL (std::chrono::milliseconds, ReportInterval);
31
+ };
32
+
33
+ class TLeafBehavior {
34
+ public:
35
+ enum EBehavior {
36
+ REPLICATED_BUCKET,
37
+ };
38
+
39
+ EBehavior GetBehavior () const ;
40
+
41
+ TLeafBehavior (const TReplicatedBucketSettings&);
42
+ TLeafBehavior (const Ydb::RateLimiter::ReplicatedBucketSettings&);
43
+ const TReplicatedBucketSettings& GetReplicatedBucket () const ;
44
+
45
+ void SerializeTo (Ydb::RateLimiter::HierarchicalDrrSettings&) const ;
46
+
47
+ private:
48
+ std::variant<TReplicatedBucketSettings> BehaviorSettings_;
49
+ };
50
+
13
51
// Settings for hierarchical deficit round robin (HDRR) algorithm.
14
52
template <class TDerived >
15
53
struct THierarchicalDrrSettings {
@@ -46,6 +84,91 @@ struct THierarchicalDrrSettings {
46
84
// Default value is inherited from parent or 0.75 for root.
47
85
// Must be nonnegative and less than or equal to 1.
48
86
FLUENT_SETTING_OPTIONAL (double , PrefetchWatermark);
87
+
88
+ // Prevents bucket from going too deep in negative values. If somebody reports value that will exceed
89
+ // this limit the final amount in bucket will be equal to this limit.
90
+ // Should be negative value.
91
+ // Unset means no limit.
92
+ FLUENT_SETTING_OPTIONAL (double , ImmediatelyFillUpTo);
93
+
94
+ // Behavior of leafs in tree.
95
+ // Not inherited.
96
+ FLUENT_SETTING_OPTIONAL (TLeafBehavior, LeafBehavior);
97
+ };
98
+
99
+ struct TMetric {
100
+ using TSelf = TMetric;
101
+ using TLabels = std::unordered_map<std::string, std::string>;
102
+
103
+ TMetric () = default ;
104
+ TMetric (const Ydb::RateLimiter::MeteringConfig_Metric&);
105
+
106
+ void SerializeTo (Ydb::RateLimiter::MeteringConfig_Metric&) const ;
107
+
108
+ // Send this metric to billing.
109
+ // Default value is false (not inherited).
110
+ FLUENT_SETTING_DEFAULT (bool , Enabled, false );
111
+
112
+ // Billing metric period (aligned to hour boundary).
113
+ // Default value is inherited from parent or equals 60 seconds for root.
114
+ FLUENT_SETTING_OPTIONAL (std::chrono::seconds, BillingPeriod);
115
+
116
+ // User-defined labels.
117
+ FLUENT_SETTING (TLabels, Labels);
118
+
119
+ // Billing metric JSON fields (inherited from parent if not set)
120
+ FLUENT_SETTING (std::string, MetricFieldsJson);
121
+ };
122
+
123
+ struct TMeteringConfig {
124
+ using TSelf = TMeteringConfig;
125
+
126
+ TMeteringConfig () = default ;
127
+ TMeteringConfig (const Ydb::RateLimiter::MeteringConfig&);
128
+
129
+ void SerializeTo (Ydb::RateLimiter::MeteringConfig&) const ;
130
+
131
+ // Meter consumed resources and send billing metrics.
132
+ FLUENT_SETTING_DEFAULT (bool , Enabled, false );
133
+
134
+ // Period to report consumption history from clients to kesus
135
+ // Default value is inherited from parent or equals 5000 ms for root.
136
+ FLUENT_SETTING_OPTIONAL (std::chrono::milliseconds, ReportPeriod);
137
+
138
+ // Consumption history period that is sent in one message to metering actor.
139
+ // Default value is inherited from parent or equals 1000 ms for root.
140
+ FLUENT_SETTING_OPTIONAL (std::chrono::milliseconds, MeterPeriod);
141
+
142
+ // Time window to collect data from every client.
143
+ // Any client metering message that is `collect_period` late is discarded (not metered or billed).
144
+ // Default value is inherited from parent or equals 30 seconds for root.
145
+ FLUENT_SETTING_OPTIONAL (std::chrono::seconds, CollectPeriod);
146
+
147
+ // Provisioned consumption limit in units per second.
148
+ // Effective value is limited by corresponding `max_units_per_second`.
149
+ // Default value is 0 (not inherited).
150
+ FLUENT_SETTING_OPTIONAL (double , ProvisionedUnitsPerSecond);
151
+
152
+ // Provisioned allowed burst equals `provisioned_coefficient * provisioned_units_per_second` units.
153
+ // Effective value is limited by corresponding PrefetchCoefficient.
154
+ // Default value is inherited from parent or equals 60 for root.
155
+ FLUENT_SETTING_OPTIONAL (double , ProvisionedCoefficient);
156
+
157
+ // On-demand allowed burst equals `overshoot_coefficient * prefetch_coefficient * max_units_per_second` units.
158
+ // Should be greater or equal to 1.0
159
+ // Default value is inherited from parent or equals 1.1 for root
160
+ FLUENT_SETTING_OPTIONAL (double , OvershootCoefficient);
161
+
162
+ // Consumption within provisioned limit.
163
+ // Informative metric that should be sent to billing (not billed).
164
+ FLUENT_SETTING_OPTIONAL (TMetric, Provisioned);
165
+
166
+ // Consumption that exceeds provisioned limit is billed as on-demand.
167
+ FLUENT_SETTING_OPTIONAL (TMetric, OnDemand);
168
+
169
+ // Consumption that exceeds even on-demand limit.
170
+ // Normally it is free and should not be billed.
171
+ FLUENT_SETTING_OPTIONAL (TMetric, Overshoot);
49
172
};
50
173
51
174
// Settings for create resource request.
@@ -55,13 +178,16 @@ struct TCreateResourceSettings
55
178
{
56
179
TCreateResourceSettings () = default ;
57
180
TCreateResourceSettings (const Ydb::RateLimiter::CreateResourceRequest&);
181
+
182
+ FLUENT_SETTING_OPTIONAL (TMeteringConfig, MeteringConfig);
58
183
};
59
184
60
185
// Settings for alter resource request.
61
186
struct TAlterResourceSettings
62
187
: public TOperationRequestSettings<TAlterResourceSettings>
63
188
, public THierarchicalDrrSettings<TAlterResourceSettings>
64
189
{
190
+ FLUENT_SETTING_OPTIONAL (TMeteringConfig, MeteringConfig);
65
191
};
66
192
67
193
// Settings for drop resource request.
@@ -128,6 +254,14 @@ struct TDescribeResourceResult : public TStatus {
128
254
std::optional<double > GetPrefetchWatermark () const {
129
255
return PrefetchWatermark_;
130
256
}
257
+
258
+ std::optional<double > GetImmediatelyFillUpTo () const {
259
+ return ImmediatelyFillUpTo_;
260
+ }
261
+
262
+ const std::optional<TLeafBehavior>& GetLeafBehavior () const {
263
+ return LeafBehavior_;
264
+ }
131
265
};
132
266
133
267
TDescribeResourceResult (TStatus status, const Ydb::RateLimiter::DescribeResourceResult& result);
@@ -141,9 +275,14 @@ struct TDescribeResourceResult : public TStatus {
141
275
return HierarchicalDrrProps_;
142
276
}
143
277
278
+ const TMeteringConfig& GetMeteringConfig () const {
279
+ return MeteringConfig_;
280
+ }
281
+
144
282
private:
145
283
std::string ResourcePath_;
146
284
THierarchicalDrrProps HierarchicalDrrProps_;
285
+ TMeteringConfig MeteringConfig_;
147
286
};
148
287
149
288
using TAsyncDescribeResourceResult = NThreading::TFuture<TDescribeResourceResult>;
0 commit comments