Skip to content

Commit 2764b01

Browse files
authored
24-3: Add created_by to Operations API (#6463) (#8708)
1 parent ae19a36 commit 2764b01

File tree

12 files changed

+140
-17
lines changed

12 files changed

+140
-17
lines changed

ydb/core/grpc_services/rpc_export_base.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@ struct TExportConv {
4646
}
4747

4848
if (exprt.HasStartTime()) {
49-
*operation.mutable_start_time() = exprt.GetStartTime();
49+
*operation.mutable_create_time() = exprt.GetStartTime();
5050
}
5151
if (exprt.HasEndTime()) {
5252
*operation.mutable_end_time() = exprt.GetEndTime();
5353
}
5454

55+
if (exprt.HasUserSID()) {
56+
operation.set_created_by(exprt.GetUserSID());
57+
}
58+
5559
using namespace Ydb::Export;
5660
switch (exprt.GetSettingsCase()) {
5761
case NKikimrExport::TExport::kExportToYtSettings:

ydb/core/grpc_services/rpc_import_base.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ struct TImportConv {
4343
}
4444

4545
if (import.HasStartTime()) {
46-
*operation.mutable_start_time() = import.GetStartTime();
46+
*operation.mutable_create_time() = import.GetStartTime();
4747
}
4848
if (import.HasEndTime()) {
4949
*operation.mutable_end_time() = import.GetEndTime();
5050
}
5151

52+
if (import.HasUserSID()) {
53+
operation.set_created_by(import.GetUserSID());
54+
}
55+
5256
using namespace Ydb::Import;
5357
switch (import.GetSettingsCase()) {
5458
case NKikimrImport::TImport::kImportFromS3Settings:

ydb/core/protos/export.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ message TExport {
2020
Ydb.Export.ExportToYtSettings ExportToYtSettings = 5;
2121
Ydb.Export.ExportToS3Settings ExportToS3Settings = 6;
2222
}
23+
optional string UserSID = 10;
2324
}
2425

2526
message TCreateExportRequest {

ydb/core/protos/import.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ message TImport {
1919
oneof Settings {
2020
Ydb.Import.ImportFromS3Settings ImportFromS3Settings = 6;
2121
}
22+
optional string UserSID = 9;
2223
}
2324

2425
message TCreateImportRequest {

ydb/core/tx/schemeshard/schemeshard_export.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ void TSchemeShard::FromXxportInfo(NKikimrExport::TExport& exprt, const TExportIn
9191
*exprt.MutableEndTime() = SecondsToProtoTimeStamp(exportInfo->EndTime.Seconds());
9292
}
9393

94+
if (exportInfo->UserSID) {
95+
exprt.SetUserSID(*exportInfo->UserSID);
96+
}
97+
9498
switch (exportInfo->State) {
9599
case TExportInfo::EState::CreateExportDir:
96100
case TExportInfo::EState::CopyTables:

ydb/core/tx/schemeshard/schemeshard_import.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ void TSchemeShard::FromXxportInfo(NKikimrImport::TImport& import, const TImportI
5555
*import.MutableEndTime() = SecondsToProtoTimeStamp(importInfo->EndTime.Seconds());
5656
}
5757

58+
if (importInfo->UserSID) {
59+
import.SetUserSID(*importInfo->UserSID);
60+
}
61+
5862
switch (importInfo->State) {
5963
case TImportInfo::EState::Waiting:
6064
switch (GetMinState(importInfo)) {

ydb/core/tx/schemeshard/ut_export/ut_export.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,5 +1817,42 @@ partitioning_settings {
18171817
min_partitions_count: 10
18181818
)"));
18191819
}
1820+
1821+
Y_UNIT_TEST(UserSID) {
1822+
TTestBasicRuntime runtime;
1823+
TTestEnv env(runtime);
1824+
ui64 txId = 100;
1825+
1826+
TestCreateTable(runtime, ++txId, "/MyRoot", R"(
1827+
Name: "Table"
1828+
Columns { Name: "key" Type: "Utf8" }
1829+
Columns { Name: "value" Type: "Utf8" }
1830+
KeyColumnNames: ["key"]
1831+
)");
1832+
env.TestWaitNotification(runtime, txId);
1833+
1834+
TPortManager portManager;
1835+
const ui16 port = portManager.GetPort();
1836+
1837+
TS3Mock s3Mock({}, TS3Mock::TSettings(port));
1838+
UNIT_ASSERT(s3Mock.Start());
18201839

1840+
const TString request = Sprintf(R"(
1841+
ExportToS3Settings {
1842+
endpoint: "localhost:%d"
1843+
scheme: HTTP
1844+
items {
1845+
source_path: "/MyRoot/Table"
1846+
destination_prefix: ""
1847+
}
1848+
}
1849+
)", port);
1850+
const TString userSID = "user@builtin";
1851+
TestExport(runtime, ++txId, "/MyRoot", request, userSID);
1852+
1853+
const auto desc = TestGetExport(runtime, txId, "/MyRoot");
1854+
const auto& entry = desc.GetResponse().GetEntry();
1855+
UNIT_ASSERT_VALUES_EQUAL(entry.GetProgress(), Ydb::Export::ExportProgress::PROGRESS_PREPARING);
1856+
UNIT_ASSERT_VALUES_EQUAL(entry.GetUserSID(), userSID);
1857+
}
18211858
}

ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3429,6 +3429,48 @@ Y_UNIT_TEST_SUITE(TImportTests) {
34293429
UNIT_ASSERT(entry.HasEndTime());
34303430
UNIT_ASSERT_LT(entry.GetStartTime().seconds(), entry.GetEndTime().seconds());
34313431
}
3432+
3433+
Y_UNIT_TEST(UserSID) {
3434+
TTestBasicRuntime runtime;
3435+
TTestEnv env(runtime);
3436+
ui64 txId = 100;
3437+
3438+
const auto data = GenerateTestData(R"(
3439+
columns {
3440+
name: "key"
3441+
type { optional_type { item { type_id: UTF8 } } }
3442+
}
3443+
columns {
3444+
name: "value"
3445+
type { optional_type { item { type_id: UTF8 } } }
3446+
}
3447+
primary_key: "key"
3448+
)", {{"a", 1}});
3449+
3450+
TPortManager portManager;
3451+
const ui16 port = portManager.GetPort();
3452+
3453+
TS3Mock s3Mock(ConvertTestData(data), TS3Mock::TSettings(port));
3454+
UNIT_ASSERT(s3Mock.Start());
3455+
3456+
const TString request = Sprintf(R"(
3457+
ImportFromS3Settings {
3458+
endpoint: "localhost:%d"
3459+
scheme: HTTP
3460+
items {
3461+
source_prefix: ""
3462+
destination_path: "/MyRoot/Table"
3463+
}
3464+
}
3465+
)", port);
3466+
const TString userSID = "user@builtin";
3467+
TestImport(runtime, ++txId, "/MyRoot", request, userSID);
3468+
3469+
const auto desc = TestGetImport(runtime, txId, "/MyRoot");
3470+
const auto& entry = desc.GetResponse().GetEntry();
3471+
UNIT_ASSERT_VALUES_EQUAL(entry.GetProgress(), Ydb::Import::ImportProgress::PROGRESS_PREPARING);
3472+
UNIT_ASSERT_VALUES_EQUAL(entry.GetUserSID(), userSID);
3473+
}
34323474
}
34333475

34343476
Y_UNIT_TEST_SUITE(TImportWithRebootsTests) {

ydb/public/api/protos/ydb_operation.proto

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,12 @@ message Operation {
122122
// For operations in progress, it might indicate the current cost of the operation (if supported).
123123
CostInfo cost_info = 7;
124124

125-
// The time at which this operation was started (if supported).
126-
google.protobuf.Timestamp start_time = 8;
125+
// The time at which this operation was created (if supported).
126+
google.protobuf.Timestamp create_time = 8;
127127

128128
// The time at which this operation was completed, doesn't matter successful or not (if supported).
129129
google.protobuf.Timestamp end_time = 9;
130+
131+
// User SID (Security ID) of the user who created this operation (if supported).
132+
string created_by = 10;
130133
}

ydb/public/lib/ydb_cli/common/print_operation.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ namespace {
3737
}
3838
}
3939

40-
if (operation.StartTime() != TInstant::Zero()) {
41-
freeText << "Start time: " << operation.StartTime().ToStringUpToSeconds() << Endl;
40+
if (!operation.CreatedBy().Empty()) {
41+
freeText << "Created by: " << operation.CreatedBy() << Endl;
42+
}
43+
44+
if (operation.CreateTime() != TInstant::Zero()) {
45+
freeText << "Create time: " << operation.CreateTime().ToStringUpToSeconds() << Endl;
4246
}
4347

4448
if (operation.EndTime() != TInstant::Zero()) {
@@ -122,8 +126,12 @@ namespace {
122126

123127
freeText << "TypeV3: " << (settings.UseTypeV3_ ? "true" : "false") << Endl;
124128

125-
if (operation.StartTime() != TInstant::Zero()) {
126-
freeText << "Start time: " << operation.StartTime().ToStringUpToSeconds() << Endl;
129+
if (!operation.CreatedBy().Empty()) {
130+
freeText << "Created by: " << operation.CreatedBy() << Endl;
131+
}
132+
133+
if (operation.CreateTime() != TInstant::Zero()) {
134+
freeText << "Create time: " << operation.CreateTime().ToStringUpToSeconds() << Endl;
127135
}
128136

129137
if (operation.EndTime() != TInstant::Zero()) {
@@ -184,8 +192,12 @@ namespace {
184192
freeText << "Number of retries: " << settings.NumberOfRetries_.GetRef() << Endl;
185193
}
186194

187-
if (operation.StartTime() != TInstant::Zero()) {
188-
freeText << "Start time: " << operation.StartTime().ToStringUpToSeconds() << Endl;
195+
if (!operation.CreatedBy().Empty()) {
196+
freeText << "Created by: " << operation.CreatedBy() << Endl;
197+
}
198+
199+
if (operation.CreateTime() != TInstant::Zero()) {
200+
freeText << "Create time: " << operation.CreateTime().ToStringUpToSeconds() << Endl;
189201
}
190202

191203
if (operation.EndTime() != TInstant::Zero()) {

0 commit comments

Comments
 (0)