|
1 | 1 | #include "log.h" |
| 2 | +#include <util/random/entropy.h> |
| 3 | +#include <util/random/mersenne.h> |
2 | 4 | #include <ydb/public/api/protos/ydb_formats.pb.h> |
3 | 5 | #include <library/cpp/json/json_value.h> |
4 | 6 | #include <library/cpp/resource/resource.h> |
@@ -252,6 +254,11 @@ class TRandomLogGenerator { |
252 | 254 | return result.str(); |
253 | 255 | } |
254 | 256 |
|
| 257 | + TInstant UniformInstant(ui64 from, ui64 to) const { |
| 258 | + TMersenne<ui64> rnd(Seed()); |
| 259 | + return TInstant::FromValue(rnd.Uniform(from, to)); |
| 260 | + } |
| 261 | + |
255 | 262 | TInstant RandomInstant() const { |
256 | 263 | auto result = TInstant::Now() - TDuration::Seconds(Params.TimestampSubtract); |
257 | 264 | i64 millisecondsDiff = 60 * 1000 * NormalRandom<double>(0., Params.TimestampStandardDeviationMinutes); |
@@ -279,7 +286,7 @@ class TRandomLogGenerator { |
279 | 286 | for (size_t row = 0; row < count; ++row) { |
280 | 287 | result.emplace_back(); |
281 | 288 | result.back().LogId = CreateGuidAsString().c_str(); |
282 | | - result.back().Ts = RandomInstant(); |
| 289 | + result.back().Ts = Params.TimestampDateFrom.has_value() ? UniformInstant(*Params.TimestampDateFrom, *Params.TimestampDateTo) : RandomInstant(); |
283 | 290 | result.back().Level = RandomNumber<ui32>(10); |
284 | 291 | result.back().ServiceName = RandomWord(false); |
285 | 292 | result.back().Component = RandomWord(true); |
@@ -419,7 +426,19 @@ void TLogWorkloadParams::ConfigureOpts(NLastGetopt::TOpts& opts, const ECommandT |
419 | 426 | opts.AddLongOption("rows", "Number of rows to upsert") |
420 | 427 | .DefaultValue(RowsCnt).StoreResult(&RowsCnt); |
421 | 428 | opts.AddLongOption("timestamp_deviation", "Standard deviation. For each timestamp, a random variable with a specified standard deviation in minutes is added.") |
422 | | - .DefaultValue(TimestampStandardDeviationMinutes).StoreResult(&TimestampStandardDeviationMinutes); |
| 429 | + // .DefaultValue(TimestampStandardDeviationMinutes) |
| 430 | + .Optional() |
| 431 | + .StoreResult(&TimestampStandardDeviationMinutes); |
| 432 | + |
| 433 | + opts.AddLongOption("date-from", "Left boundary of the interval to generate " |
| 434 | + "timestamp uniformly from specified interval. Presents as seconds since epoch. Once this option passed, 'date-to' " |
| 435 | + "should be passed as well. This option is mutually exclusive with 'timestamp_deviation'") |
| 436 | + .Optional().StoreResult(&TimestampDateFrom); |
| 437 | + opts.AddLongOption("date-to", "Right boundary of the interval to generate " |
| 438 | + "timestamp uniformly from specified interval. Presents as seconds since epoch. Once this option passed, 'date-from' " |
| 439 | + "should be passed as well. This option is mutually exclusive with 'timestamp_deviation'") |
| 440 | + .Optional().StoreResult(&TimestampDateTo); |
| 441 | + |
423 | 442 | opts.AddLongOption("timestamp_subtract", "Value in seconds to subtract from timestamp. For each timestamp, this value in seconds is subtracted") |
424 | 443 | .DefaultValue(0).StoreResult(&TimestampSubtract); |
425 | 444 | opts.AddLongOption("null-percent", "Percent of nulls in generated data") |
|
0 commit comments