Skip to content

Commit 2bf0f3d

Browse files
authored
Topics: add partition-level metrics (25-3-1) (#26173)
2 parents 3996124 + 1e4ab68 commit 2bf0f3d

File tree

17 files changed

+236
-18
lines changed

17 files changed

+236
-18
lines changed

ydb/core/persqueue/pqtablet/partition/partition_init.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#include "offload_actor.h"
33
#include "partition.h"
44
#include "partition_compactification.h"
5-
#include <ydb/core/persqueue/pqtablet/common/logging.h>
65
#include "partition_util.h"
6+
#include <ydb/core/persqueue/pqtablet/common/logging.h>
7+
#include <ydb/core/persqueue/pqtablet/common/constants.h>
78

89
#include <memory>
910

@@ -1101,7 +1102,7 @@ void TPartition::Initialize(const TActorContext& ctx) {
11011102
}
11021103

11031104
bool TPartition::DetailedMetricsAreEnabled() const {
1104-
return AppData()->FeatureFlags.GetEnableMetricsLevel() && (Config.HasMetricsLevel() && Config.GetMetricsLevel() == Ydb::MetricsLevel::Detailed);
1105+
return AppData()->FeatureFlags.GetEnableMetricsLevel() && (Config.HasMetricsLevel() && Config.GetMetricsLevel() == METRICS_LEVEL_DETAILED);
11051106
}
11061107

11071108
void TPartition::SetupTopicCounters(const TActorContext& ctx) {

ydb/core/persqueue/pqtablet/partition/user_info.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "user_info.h"
2+
#include <ydb/core/persqueue/pqtablet/common/constants.h>
23

34
namespace NKikimr {
45
namespace NPQ {
@@ -438,7 +439,7 @@ void TUsersInfoStorage::ResetDetailedMetrics() {
438439
}
439440

440441
bool TUsersInfoStorage::DetailedMetricsAreEnabled() const {
441-
return AppData()->FeatureFlags.GetEnableMetricsLevel() && (Config.HasMetricsLevel() && Config.GetMetricsLevel() == Ydb::MetricsLevel::Detailed);
442+
return AppData()->FeatureFlags.GetEnableMetricsLevel() && (Config.HasMetricsLevel() && Config.GetMetricsLevel() == METRICS_LEVEL_DETAILED);
442443
}
443444

444445
const TUserInfo* TUsersInfoStorage::GetIfExists(const TString& user) const {

ydb/core/persqueue/public/constants.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ namespace NKikimr::NPQ {
77
static const TString CLIENTID_COMPACTION_CONSUMER = "__ydb_compaction_consumer";
88
static const TString CLIENTID_WITHOUT_CONSUMER = "$without_consumer";
99

10+
static constexpr ui32 METRICS_LEVEL_DISABLED = 0;
11+
static constexpr ui32 METRICS_LEVEL_DATABASE = 1;
12+
static constexpr ui32 METRICS_LEVEL_OBJECT = 2;
13+
static constexpr ui32 METRICS_LEVEL_DETAILED = 3;
14+
1015
}

ydb/core/persqueue/ut/counters_ut.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <ydb/core/mon/mon.h>
66
#include <ydb/core/persqueue/ut/common/pq_ut_common.h>
77
#include <ydb/core/persqueue/public/counters/percentile_counter.h>
8+
#include <ydb/core/persqueue/pqtablet/common/constants.h>
89
#include <ydb/core/persqueue/pqtablet/partition/partition.h>
910
#include <ydb/core/sys_view/service/sysview_service.h>
1011
#include <ydb/core/testlib/fake_scheme_shard.h>
@@ -126,7 +127,7 @@ void PartitionLevelCounters(bool featureFlagEnabled, bool firstClassCitizen, TSt
126127

127128
tc.Runtime->GetAppData(0).FeatureFlags.SetEnableMetricsLevel(featureFlagEnabled);
128129

129-
PQTabletPrepare({ .metricsLevel = 1 }, {}, tc);
130+
PQTabletPrepare({ .metricsLevel = METRICS_LEVEL_OBJECT }, {}, tc);
130131
CmdWrite(0, "sourceid0", TestData(), tc, false, {}, true);
131132
CmdWrite(0, "sourceid1", TestData(), tc, false);
132133
CmdWrite(0, "sourceid2", TestData(), tc, false);
@@ -166,7 +167,7 @@ void PartitionLevelCounters(bool featureFlagEnabled, bool firstClassCitizen, TSt
166167
{
167168
// Turn on per partition counters, check counters.
168169

169-
PQTabletPrepare({ .metricsLevel = 2 }, {}, tc);
170+
PQTabletPrepare({ .metricsLevel = METRICS_LEVEL_DETAILED }, {}, tc);
170171

171172
// partition, sourceId, data, text
172173
CmdWrite({ .Partition = 0, .SourceId = "sourceid3", .Data = TestData(), .TestContext = tc, .Error = false });
@@ -237,7 +238,7 @@ void PartitionLevelCounters(bool featureFlagEnabled, bool firstClassCitizen, TSt
237238
{
238239
// Disable per partition counters, the counters should be empty.
239240

240-
PQTabletPrepare({ .metricsLevel = 1 }, {}, tc);
241+
PQTabletPrepare({ .metricsLevel = METRICS_LEVEL_OBJECT }, {}, tc);
241242
TString counters = getCountersHtml();
242243
TString referenceCounters = NResource::Find(TStringBuilder() << referenceDir << "_turned_off.html");
243244
counters = zeroUnreliableValues(counters) + (featureFlagEnabled ? "\n" : "");

ydb/core/protos/pqconfig.proto

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import "ydb/public/api/protos/draft/persqueue_error_codes.proto";
22

33
import "ydb/public/api/protos/annotations/sensitive.proto";
4-
import "ydb/public/api/protos/ydb_common.proto";
54

65
import "ydb/core/protos/base.proto";
76
import "ydb/core/protos/msgbus_kv.proto";
@@ -447,7 +446,7 @@ message TPQTabletConfig {
447446

448447
optional bool EnableCompactification = 39 [default = false];
449448

450-
optional Ydb.MetricsLevel MetricsLevel = 40;
449+
optional uint32 MetricsLevel = 40;
451450

452451
// The ID of the Monitoring project that will be used as the value of `project` label for detailed metrics level.
453452
optional string MonitoringProjectId = 41;

ydb/core/ydb_convert/topic_description.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ bool FillConsumer(Ydb::Topic::Consumer& out, const NKikimrPQ::TPQTabletConfig_TC
4343
bool FillTopicDescription(Ydb::Topic::DescribeTopicResult& out, const NKikimrSchemeOp::TPersQueueGroupDescription& inDesc,
4444
const NKikimrSchemeOp::TDirEntry& inDirEntry, const TMaybe<TString>& cdcName,
4545
Ydb::StatusIds_StatusCode& status, TString& error) {
46-
46+
4747
const NKikimrPQ::TPQConfig pqConfig = AppData()->PQConfig;
4848

4949
Ydb::Scheme::Entry *selfEntry = out.mutable_self();
@@ -160,6 +160,10 @@ bool FillTopicDescription(Ydb::Topic::DescribeTopicResult& out, const NKikimrSch
160160
}
161161
}
162162

163+
if (config.HasMetricsLevel()) {
164+
out.set_metrics_level(config.GetMetricsLevel());
165+
}
166+
163167
for (const auto& consumer : config.GetConsumers()) {
164168
if (!FillConsumer(*out.add_consumers(), consumer, status, error)) {
165169
return false;

ydb/public/api/protos/ydb_common.proto

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,3 @@ message VirtualTimestamp {
2727
uint64 plan_step = 1;
2828
uint64 tx_id = 2;
2929
}
30-
31-
enum MetricsLevel {
32-
Database = 0;
33-
Object = 1;
34-
Detailed = 2;
35-
}

ydb/public/api/protos/ydb_persqueue_v1.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,9 @@ message TopicSettings {
11841184
}
11851185
// remote mirror rule for this topic.
11861186
RemoteMirrorRule remote_mirror_rule = 11;
1187+
1188+
// Set or reset metrics level.
1189+
optional uint32 metrics_level = 16;
11871190
}
11881191

11891192
message AutoPartitioningSettings {

ydb/public/api/protos/ydb_topic.proto

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import "ydb/public/api/protos/annotations/sensitive.proto";
77
import "ydb/public/api/protos/annotations/validation.proto";
88

99
import "google/protobuf/duration.proto";
10+
import "google/protobuf/empty.proto";
1011
import "google/protobuf/timestamp.proto";
1112

1213
package Ydb.Topic;
@@ -992,6 +993,9 @@ message CreateTopicRequest {
992993

993994
// Metering mode for the topic in a serverless database.
994995
MeteringMode metering_mode = 12;
996+
997+
// Metrics level. If the level is unset, use database setting.
998+
optional uint32 metrics_level = 13;
995999
}
9961000

9971001
// Create topic response sent from server to client.
@@ -1125,6 +1129,9 @@ message DescribeTopicResult {
11251129
// How much bytes were written statistics.
11261130
MultipleWindowsStat bytes_written = 4;
11271131
}
1132+
1133+
// Metrics level.
1134+
optional uint32 metrics_level = 16;
11281135
}
11291136

11301137
// Describe partition request sent from client to server.
@@ -1252,7 +1259,6 @@ message PartitionStats {
12521259
int32 partition_node_id = 8 [deprecated=true]; //Use PartitionLocation
12531260
}
12541261

1255-
12561262
// Update existing topic request sent from client to server.
12571263
message AlterTopicRequest {
12581264
Ydb.Operations.OperationParams operation_params = 1;
@@ -1297,6 +1303,12 @@ message AlterTopicRequest {
12971303

12981304
// Set metering mode for topic in serverless database.
12991305
MeteringMode set_metering_mode = 14;
1306+
1307+
// Set or reset metrics level.
1308+
oneof metrics_level {
1309+
uint32 set_metrics_level = 15;
1310+
google.protobuf.Empty reset_metrics_level = 16;
1311+
}
13001312
}
13011313

13021314
// Update topic response sent from server to client.

ydb/public/lib/ydb_cli/commands/ydb_service_topic.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ namespace NYdb::NConsoleClient {
3535
std::pair<TString, NYdb::NTopic::ECodec>("zstd", NYdb::NTopic::ECodec::ZSTD),
3636
};
3737

38+
TVector<ui32> ExistingMetricsLevels = {2, 3};
39+
40+
THashMap<ui32, TString> MetricsLevelsDescriptions = {
41+
{0, "No metrics."},
42+
{1, "Database level metrics."},
43+
{2, "Database and topic level metrics."},
44+
{3, "Database, topic, and partition level metrics."},
45+
};
46+
3847
THashMap<TString, NTopic::EMeteringMode> ExistingMeteringModes = {
3948
std::pair<TString, NTopic::EMeteringMode>("request-units", NTopic::EMeteringMode::RequestUnits),
4049
std::pair<TString, NTopic::EMeteringMode>("reserved-capacity", NTopic::EMeteringMode::ReservedCapacity),
@@ -159,6 +168,29 @@ namespace NYdb::NConsoleClient {
159168
AllowedCodecs_ = supportedCodecs;
160169
}
161170

171+
void TCommandWithMetricsLevel::AddMetricsLevels(TClientCommand::TConfig& config) {
172+
TStringStream description;
173+
description << "Available metrics levels: ";
174+
NColorizer::TColors colors = NColorizer::AutoColors(Cout);
175+
for (const auto& level: ExistingMetricsLevels) {
176+
auto findResult = MetricsLevelsDescriptions.find(level);
177+
Y_ABORT_UNLESS(findResult != MetricsLevelsDescriptions.end(),
178+
"Couldn't find description for %s metrics level", (TStringBuilder() << level).c_str());
179+
description << "\n " << colors.BoldColor() << level << colors.OldColor()
180+
<< "\n " << findResult->second;
181+
if (level == 2 /* database and topic level metrics */) {
182+
description << colors.CyanColor() << " (default)" << colors.OldColor();
183+
}
184+
}
185+
config.Opts->AddLongOption("metrics-level", description.Str())
186+
.Optional()
187+
.StoreResult(&MetricsLevel_);
188+
}
189+
190+
TMaybe<NTopic::EMetricsLevel> TCommandWithMetricsLevel::GetMetricsLevel() const {
191+
return MetricsLevel_;
192+
}
193+
162194
void TCommandWithSupportedCodecs::ParseCodecs() {
163195
TVector<NTopic::ECodec> parsedCodecs;
164196
TVector<TString> split = SplitString(SupportedCodecsStr_, ",");
@@ -323,6 +355,7 @@ namespace NYdb::NConsoleClient {
323355
SetFreeArgTitle(0, "<topic-path>", "Topic path");
324356
AddAllowedCodecs(config, AllowedCodecs);
325357
AddAllowedMeteringModes(config);
358+
AddMetricsLevels(config);
326359

327360
config.Opts->AddLongOption("auto-partitioning-max-partitions-count", "Maximum number of partitions for topic")
328361
.Optional()
@@ -379,6 +412,10 @@ namespace NYdb::NConsoleClient {
379412
settings.AddAttribute("_partitions_per_tablet", ToString(*PartitionsPerTablet_));
380413
}
381414

415+
if (auto level = GetMetricsLevel(); level.Defined()) {
416+
settings.MetricsLevel(*level);
417+
}
418+
382419
auto status = topicClient.CreateTopic(TopicName, settings).GetValueSync();
383420
NStatusHelpers::ThrowOnErrorOrPrintIssues(status);
384421
return EXIT_SUCCESS;
@@ -406,6 +443,7 @@ namespace NYdb::NConsoleClient {
406443
SetFreeArgTitle(0, "<topic-path>", "Topic path");
407444
AddAllowedCodecs(config, AllowedCodecs);
408445
AddAllowedMeteringModes(config);
446+
AddMetricsLevels(config);
409447

410448
config.Opts->AddLongOption("auto-partitioning-max-partitions-count", "Maximum number of partitions for topic")
411449
.Optional()
@@ -476,6 +514,10 @@ namespace NYdb::NConsoleClient {
476514
settings.SetRetentionStorageMb(*RetentionStorageMb_);
477515
}
478516

517+
if (MetricsLevel_.Defined()) {
518+
settings.SetMetricsLevel(*MetricsLevel_);
519+
}
520+
479521
return settings;
480522
}
481523

0 commit comments

Comments
 (0)