Skip to content

Commit 7267b72

Browse files
authored
Merge d059fcd into f5719d8
2 parents f5719d8 + d059fcd commit 7267b72

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

ydb/library/workload/log/log.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include "log.h"
2+
#include <util/random/entropy.h>
3+
#include <util/random/mersenne.h>
24
#include <ydb/public/api/protos/ydb_formats.pb.h>
35
#include <library/cpp/json/json_value.h>
46
#include <library/cpp/resource/resource.h>
@@ -252,6 +254,11 @@ class TRandomLogGenerator {
252254
return result.str();
253255
}
254256

257+
TInstant UniformInstant(ui64 from, ui64 to) const {
258+
TMersenne<ui64> rnd(Seed());
259+
return TInstant::FromValue(rnd.Uniform(from, to));
260+
}
261+
255262
TInstant RandomInstant() const {
256263
auto result = TInstant::Now() - TDuration::Seconds(Params.TimestampSubtract);
257264
i64 millisecondsDiff = 60 * 1000 * NormalRandom<double>(0., Params.TimestampStandardDeviationMinutes);
@@ -279,7 +286,7 @@ class TRandomLogGenerator {
279286
for (size_t row = 0; row < count; ++row) {
280287
result.emplace_back();
281288
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();
283290
result.back().Level = RandomNumber<ui32>(10);
284291
result.back().ServiceName = RandomWord(false);
285292
result.back().Component = RandomWord(true);
@@ -419,7 +426,19 @@ void TLogWorkloadParams::ConfigureOpts(NLastGetopt::TOpts& opts, const ECommandT
419426
opts.AddLongOption("rows", "Number of rows to upsert")
420427
.DefaultValue(RowsCnt).StoreResult(&RowsCnt);
421428
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+
423442
opts.AddLongOption("timestamp_subtract", "Value in seconds to subtract from timestamp. For each timestamp, this value in seconds is subtracted")
424443
.DefaultValue(0).StoreResult(&TimestampSubtract);
425444
opts.AddLongOption("null-percent", "Percent of nulls in generated data")

ydb/library/workload/log/log.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class TLogWorkloadParams : public TWorkloadParams {
2424
ui64 IntColumnsCnt = 0;
2525
ui64 KeyColumnsCnt = 0;
2626
ui64 TimestampStandardDeviationMinutes = 0;
27+
std::optional<ui64> TimestampDateFrom{std::nullopt};
28+
std::optional<ui64> TimestampDateTo{std::nullopt};
2729
ui64 TimestampTtlMinutes = 0;
2830
ui64 TimestampSubtract = 0;
2931
ui64 RowsCnt = 1;

0 commit comments

Comments
 (0)