diff options
| author | qyryq <[email protected]> | 2025-10-03 14:54:48 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-10-03 14:54:48 +0300 |
| commit | 337ad331d577c2bf3d4e92fb73a77dc37cf8fc7f (patch) | |
| tree | d223c2b07910e6f32df1b56f3c47041ebe04dec0 | |
| parent | 15c0bb60646a0f1751ee47094a820c79ba534a5c (diff) | |
Topic APIs for metrics level (#25512)
Co-authored-by: Bulat <[email protected]>
17 files changed, 236 insertions, 19 deletions
diff --git a/ydb/core/persqueue/pqtablet/partition/partition_init.cpp b/ydb/core/persqueue/pqtablet/partition/partition_init.cpp index 02364848476..a8bd99cae96 100644 --- a/ydb/core/persqueue/pqtablet/partition/partition_init.cpp +++ b/ydb/core/persqueue/pqtablet/partition/partition_init.cpp @@ -2,8 +2,9 @@ #include "offload_actor.h" #include "partition.h" #include "partition_compactification.h" -#include <ydb/core/persqueue/pqtablet/common/logging.h> #include "partition_util.h" +#include <ydb/core/persqueue/pqtablet/common/logging.h> +#include <ydb/core/persqueue/pqtablet/common/constants.h> #include <memory> @@ -1101,7 +1102,7 @@ void TPartition::Initialize(const TActorContext& ctx) { } bool TPartition::DetailedMetricsAreEnabled() const { - return AppData()->FeatureFlags.GetEnableMetricsLevel() && (Config.HasMetricsLevel() && Config.GetMetricsLevel() == Ydb::MetricsLevel::Detailed); + return AppData()->FeatureFlags.GetEnableMetricsLevel() && (Config.HasMetricsLevel() && Config.GetMetricsLevel() == METRICS_LEVEL_DETAILED); } void TPartition::SetupTopicCounters(const TActorContext& ctx) { diff --git a/ydb/core/persqueue/pqtablet/partition/user_info.cpp b/ydb/core/persqueue/pqtablet/partition/user_info.cpp index 08831f1a492..bffb31da4fb 100644 --- a/ydb/core/persqueue/pqtablet/partition/user_info.cpp +++ b/ydb/core/persqueue/pqtablet/partition/user_info.cpp @@ -1,4 +1,5 @@ #include "user_info.h" +#include <ydb/core/persqueue/pqtablet/common/constants.h> namespace NKikimr { namespace NPQ { @@ -500,7 +501,7 @@ void TUsersInfoStorage::ResetDetailedMetrics() { } bool TUsersInfoStorage::DetailedMetricsAreEnabled() const { - return AppData()->FeatureFlags.GetEnableMetricsLevel() && (Config.HasMetricsLevel() && Config.GetMetricsLevel() == Ydb::MetricsLevel::Detailed); + return AppData()->FeatureFlags.GetEnableMetricsLevel() && (Config.HasMetricsLevel() && Config.GetMetricsLevel() == METRICS_LEVEL_DETAILED); } const TUserInfo* TUsersInfoStorage::GetIfExists(const TString& user) const { diff --git a/ydb/core/persqueue/public/constants.h b/ydb/core/persqueue/public/constants.h index 25c485fb7b6..96e63c21c4b 100644 --- a/ydb/core/persqueue/public/constants.h +++ b/ydb/core/persqueue/public/constants.h @@ -7,4 +7,9 @@ namespace NKikimr::NPQ { static const TString CLIENTID_COMPACTION_CONSUMER = "__ydb_compaction_consumer"; static const TString CLIENTID_WITHOUT_CONSUMER = "$without_consumer"; +static constexpr ui32 METRICS_LEVEL_DISABLED = 0; +static constexpr ui32 METRICS_LEVEL_DATABASE = 1; +static constexpr ui32 METRICS_LEVEL_OBJECT = 2; +static constexpr ui32 METRICS_LEVEL_DETAILED = 3; + } diff --git a/ydb/core/persqueue/ut/counters_ut.cpp b/ydb/core/persqueue/ut/counters_ut.cpp index 510c6005890..801e352416a 100644 --- a/ydb/core/persqueue/ut/counters_ut.cpp +++ b/ydb/core/persqueue/ut/counters_ut.cpp @@ -5,6 +5,7 @@ #include <ydb/core/mon/mon.h> #include <ydb/core/persqueue/ut/common/pq_ut_common.h> #include <ydb/core/persqueue/public/counters/percentile_counter.h> +#include <ydb/core/persqueue/pqtablet/common/constants.h> #include <ydb/core/persqueue/pqtablet/partition/partition.h> #include <ydb/core/sys_view/service/sysview_service.h> #include <ydb/core/testlib/fake_scheme_shard.h> @@ -126,7 +127,7 @@ void PartitionLevelCounters(bool featureFlagEnabled, bool firstClassCitizen, TSt tc.Runtime->GetAppData(0).FeatureFlags.SetEnableMetricsLevel(featureFlagEnabled); - PQTabletPrepare({ .metricsLevel = 1 }, {}, tc); + PQTabletPrepare({ .metricsLevel = METRICS_LEVEL_OBJECT }, {}, tc); CmdWrite(0, "sourceid0", TestData(), tc, false, {}, true); CmdWrite(0, "sourceid1", TestData(), tc, false); CmdWrite(0, "sourceid2", TestData(), tc, false); @@ -166,7 +167,7 @@ void PartitionLevelCounters(bool featureFlagEnabled, bool firstClassCitizen, TSt { // Turn on per partition counters, check counters. - PQTabletPrepare({ .metricsLevel = 2 }, {}, tc); + PQTabletPrepare({ .metricsLevel = METRICS_LEVEL_DETAILED }, {}, tc); // partition, sourceId, data, text CmdWrite({ .Partition = 0, .SourceId = "sourceid3", .Data = TestData(), .TestContext = tc, .Error = false }); @@ -237,7 +238,7 @@ void PartitionLevelCounters(bool featureFlagEnabled, bool firstClassCitizen, TSt { // Disable per partition counters, the counters should be empty. - PQTabletPrepare({ .metricsLevel = 1 }, {}, tc); + PQTabletPrepare({ .metricsLevel = METRICS_LEVEL_OBJECT }, {}, tc); TString counters = getCountersHtml(); TString referenceCounters = NResource::Find(TStringBuilder() << referenceDir << "_turned_off.html"); counters = zeroUnreliableValues(counters) + (featureFlagEnabled ? "\n" : ""); diff --git a/ydb/core/protos/pqconfig.proto b/ydb/core/protos/pqconfig.proto index 60e1d1b925d..6065c01bf44 100644 --- a/ydb/core/protos/pqconfig.proto +++ b/ydb/core/protos/pqconfig.proto @@ -1,7 +1,6 @@ import "ydb/public/api/protos/draft/persqueue_error_codes.proto"; import "ydb/public/api/protos/annotations/sensitive.proto"; -import "ydb/public/api/protos/ydb_common.proto"; import "ydb/core/protos/base.proto"; import "ydb/core/protos/msgbus_kv.proto"; @@ -448,7 +447,7 @@ message TPQTabletConfig { optional bool EnableCompactification = 39 [default = false]; - optional Ydb.MetricsLevel MetricsLevel = 40; + optional uint32 MetricsLevel = 40; // The ID of the Monitoring project that will be used as the value of `project` label for detailed metrics level. optional string MonitoringProjectId = 41; diff --git a/ydb/core/ydb_convert/topic_description.cpp b/ydb/core/ydb_convert/topic_description.cpp index a0ca5856704..fa9cd08aec4 100644 --- a/ydb/core/ydb_convert/topic_description.cpp +++ b/ydb/core/ydb_convert/topic_description.cpp @@ -164,6 +164,10 @@ bool FillTopicDescription(Ydb::Topic::DescribeTopicResult& out, const NKikimrSch } } + if (config.HasMetricsLevel()) { + out.set_metrics_level(config.GetMetricsLevel()); + } + for (const auto& consumer : config.GetConsumers()) { if (!FillConsumer(*out.add_consumers(), consumer, status, error)) { return false; diff --git a/ydb/public/api/protos/ydb_common.proto b/ydb/public/api/protos/ydb_common.proto index 1be2cbe5727..9e865646b43 100644 --- a/ydb/public/api/protos/ydb_common.proto +++ b/ydb/public/api/protos/ydb_common.proto @@ -27,9 +27,3 @@ message VirtualTimestamp { uint64 plan_step = 1; uint64 tx_id = 2; } - -enum MetricsLevel { - Database = 0; - Object = 1; - Detailed = 2; -} diff --git a/ydb/public/api/protos/ydb_persqueue_v1.proto b/ydb/public/api/protos/ydb_persqueue_v1.proto index c26c419ab1c..fb3905fad30 100644 --- a/ydb/public/api/protos/ydb_persqueue_v1.proto +++ b/ydb/public/api/protos/ydb_persqueue_v1.proto @@ -1187,6 +1187,9 @@ message TopicSettings { } // remote mirror rule for this topic. RemoteMirrorRule remote_mirror_rule = 11; + + // Set or reset metrics level. + optional uint32 metrics_level = 16; } message AutoPartitioningSettings { diff --git a/ydb/public/api/protos/ydb_topic.proto b/ydb/public/api/protos/ydb_topic.proto index c1797777764..091c27fc30a 100644 --- a/ydb/public/api/protos/ydb_topic.proto +++ b/ydb/public/api/protos/ydb_topic.proto @@ -6,8 +6,8 @@ import "ydb/public/api/protos/ydb_issue_message.proto"; import "ydb/public/api/protos/annotations/sensitive.proto"; import "ydb/public/api/protos/annotations/validation.proto"; -import "google/protobuf/empty.proto"; import "google/protobuf/duration.proto"; +import "google/protobuf/empty.proto"; import "google/protobuf/timestamp.proto"; package Ydb.Topic; @@ -156,7 +156,7 @@ message StreamWriteMessage { // Message sequence number, provided by client for deduplication. // Starts at 1 int64 seq_no = 1; - // Creation timestamp + // Creation timestamp. google.protobuf.Timestamp created_at = 2; // Compressed client message body. bytes data = 3; @@ -1002,6 +1002,9 @@ message CreateTopicRequest { // Metering mode for the topic in a serverless database. MeteringMode metering_mode = 12; + + // Metrics level. If the level is unset, use database setting. + optional uint32 metrics_level = 13; } // Create topic response sent from server to client. @@ -1135,6 +1138,9 @@ message DescribeTopicResult { // How much bytes were written statistics. MultipleWindowsStat bytes_written = 4; } + + // Metrics level. + optional uint32 metrics_level = 16; } // Describe partition request sent from client to server. @@ -1262,7 +1268,6 @@ message PartitionStats { int32 partition_node_id = 8 [deprecated=true]; //Use PartitionLocation } - // Update existing topic request sent from client to server. message AlterTopicRequest { Ydb.Operations.OperationParams operation_params = 1; @@ -1307,6 +1312,12 @@ message AlterTopicRequest { // Set metering mode for topic in serverless database. MeteringMode set_metering_mode = 14; + + // Set or reset metrics level. + oneof metrics_level { + uint32 set_metrics_level = 15; + google.protobuf.Empty reset_metrics_level = 16; + } } // Update topic response sent from server to client. diff --git a/ydb/public/lib/ydb_cli/commands/ydb_service_topic.cpp b/ydb/public/lib/ydb_cli/commands/ydb_service_topic.cpp index a43d1350818..4874203211e 100644 --- a/ydb/public/lib/ydb_cli/commands/ydb_service_topic.cpp +++ b/ydb/public/lib/ydb_cli/commands/ydb_service_topic.cpp @@ -35,6 +35,15 @@ namespace NYdb::NConsoleClient { std::pair<TString, NYdb::NTopic::ECodec>("zstd", NYdb::NTopic::ECodec::ZSTD), }; + TVector<ui32> ExistingMetricsLevels = {2, 3}; + + THashMap<ui32, TString> MetricsLevelsDescriptions = { + {0, "No metrics."}, + {1, "Database level metrics."}, + {2, "Database and topic level metrics."}, + {3, "Database, topic, and partition level metrics."}, + }; + THashMap<TString, NTopic::EMeteringMode> ExistingMeteringModes = { std::pair<TString, NTopic::EMeteringMode>("request-units", NTopic::EMeteringMode::RequestUnits), std::pair<TString, NTopic::EMeteringMode>("reserved-capacity", NTopic::EMeteringMode::ReservedCapacity), @@ -159,6 +168,29 @@ namespace NYdb::NConsoleClient { AllowedCodecs_ = supportedCodecs; } + void TCommandWithMetricsLevel::AddMetricsLevels(TClientCommand::TConfig& config) { + TStringStream description; + description << "Available metrics levels: "; + NColorizer::TColors colors = NColorizer::AutoColors(Cout); + for (const auto& level: ExistingMetricsLevels) { + auto findResult = MetricsLevelsDescriptions.find(level); + Y_ABORT_UNLESS(findResult != MetricsLevelsDescriptions.end(), + "Couldn't find description for %s metrics level", (TStringBuilder() << level).c_str()); + description << "\n " << colors.BoldColor() << level << colors.OldColor() + << "\n " << findResult->second; + if (level == 2 /* database and topic level metrics */) { + description << colors.CyanColor() << " (default)" << colors.OldColor(); + } + } + config.Opts->AddLongOption("metrics-level", description.Str()) + .Optional() + .StoreResult(&MetricsLevel_); + } + + TMaybe<NTopic::EMetricsLevel> TCommandWithMetricsLevel::GetMetricsLevel() const { + return MetricsLevel_; + } + void TCommandWithSupportedCodecs::ParseCodecs() { TVector<NTopic::ECodec> parsedCodecs; TVector<TString> split = SplitString(SupportedCodecsStr_, ","); @@ -323,6 +355,7 @@ namespace NYdb::NConsoleClient { SetFreeArgTitle(0, "<topic-path>", "Topic path"); AddAllowedCodecs(config, AllowedCodecs); AddAllowedMeteringModes(config); + AddMetricsLevels(config); config.Opts->AddLongOption("auto-partitioning-max-partitions-count", "Maximum number of partitions for topic") .Optional() @@ -379,6 +412,10 @@ namespace NYdb::NConsoleClient { settings.AddAttribute("_partitions_per_tablet", ToString(*PartitionsPerTablet_)); } + if (auto level = GetMetricsLevel(); level.Defined()) { + settings.MetricsLevel(*level); + } + auto status = topicClient.CreateTopic(TopicName, settings).GetValueSync(); NStatusHelpers::ThrowOnErrorOrPrintIssues(status); return EXIT_SUCCESS; @@ -406,6 +443,7 @@ namespace NYdb::NConsoleClient { SetFreeArgTitle(0, "<topic-path>", "Topic path"); AddAllowedCodecs(config, AllowedCodecs); AddAllowedMeteringModes(config); + AddMetricsLevels(config); config.Opts->AddLongOption("auto-partitioning-max-partitions-count", "Maximum number of partitions for topic") .Optional() @@ -476,6 +514,10 @@ namespace NYdb::NConsoleClient { settings.SetRetentionStorageMb(*RetentionStorageMb_); } + if (MetricsLevel_.Defined()) { + settings.SetMetricsLevel(*MetricsLevel_); + } + return settings; } diff --git a/ydb/public/lib/ydb_cli/commands/ydb_service_topic.h b/ydb/public/lib/ydb_cli/commands/ydb_service_topic.h index 17ff190b027..75b20723da6 100644 --- a/ydb/public/lib/ydb_cli/commands/ydb_service_topic.h +++ b/ydb/public/lib/ydb_cli/commands/ydb_service_topic.h @@ -38,6 +38,15 @@ namespace NYdb::NConsoleClient { NTopic::EMeteringMode MeteringMode_ = NTopic::EMeteringMode::Unspecified; }; + class TCommandWithMetricsLevel { + protected: + void AddMetricsLevels(TClientCommand::TConfig& config); + TMaybe<NTopic::EMetricsLevel> GetMetricsLevel() const; + + private: + NTopic::EMetricsLevel MetricsLevel_; + }; + class TCommandWithAutoPartitioning { protected: void AddAutoPartitioning(TClientCommand::TConfig& config, bool withDefault); @@ -61,7 +70,12 @@ namespace NYdb::NConsoleClient { TCommandTopic(); }; - class TCommandTopicCreate: public TYdbCommand, public TCommandWithTopicName, public TCommandWithSupportedCodecs, public TCommandWithMeteringMode, public TCommandWithAutoPartitioning { + class TCommandTopicCreate: public TYdbCommand, + public TCommandWithTopicName, + public TCommandWithSupportedCodecs, + public TCommandWithMeteringMode, + public TCommandWithAutoPartitioning, + public TCommandWithMetricsLevel { public: TCommandTopicCreate(); void Config(TConfig& config) override; @@ -75,9 +89,15 @@ namespace NYdb::NConsoleClient { TMaybe<ui32> MaxActivePartitions_; ui32 PartitionWriteSpeedKbps_; TMaybe<ui32> PartitionsPerTablet_; + TMaybe<NTopic::EMetricsLevel> MetricsLevel_; }; - class TCommandTopicAlter: public TYdbCommand, public TCommandWithTopicName, public TCommandWithSupportedCodecs, public TCommandWithMeteringMode, public TCommandWithAutoPartitioning { + class TCommandTopicAlter: public TYdbCommand, + public TCommandWithTopicName, + public TCommandWithSupportedCodecs, + public TCommandWithMeteringMode, + public TCommandWithAutoPartitioning, + public TCommandWithMetricsLevel { public: TCommandTopicAlter(); void Config(TConfig& config) override; @@ -92,6 +112,7 @@ namespace NYdb::NConsoleClient { TMaybe<ui32> PartitionWriteSpeedKbps_; + TMaybe<NTopic::EMetricsLevel> MetricsLevel_; NYdb::NTopic::TAlterTopicSettings PrepareAlterSettings(NYdb::NTopic::TDescribeTopicResult& describeResult); }; diff --git a/ydb/public/sdk/cpp/include/ydb-cpp-sdk/client/topic/control_plane.h b/ydb/public/sdk/cpp/include/ydb-cpp-sdk/client/topic/control_plane.h index b593ad423b4..35d3db2ba04 100644 --- a/ydb/public/sdk/cpp/include/ydb-cpp-sdk/client/topic/control_plane.h +++ b/ydb/public/sdk/cpp/include/ydb-cpp-sdk/client/topic/control_plane.h @@ -36,6 +36,13 @@ enum class EAutoPartitioningStrategy: uint32_t { Paused = 4, }; +// 0 - unspecified +// 1 - disabeld +// 2 - database level metrics +// 3 - object level metrics +// 4 - detailed metrics +using EMetricsLevel = uint32_t; + class TConsumer { public: TConsumer(const Ydb::Topic::Consumer&); @@ -309,6 +316,8 @@ public: const TTopicStats& GetTopicStats() const; + std::optional<EMetricsLevel> GetMetricsLevel() const; + void SerializeTo(Ydb::Topic::CreateTopicRequest& request) const; private: @@ -332,6 +341,7 @@ private: NScheme::TVirtualTimestamp CreationTimestamp_; std::vector<NScheme::TPermissions> Permissions_; std::vector<NScheme::TPermissions> EffectivePermissions_; + std::optional<EMetricsLevel> MetricsLevel_; }; class TConsumerDescription { @@ -571,6 +581,8 @@ struct TCreateTopicSettings : public TOperationRequestSettings<TCreateTopicSetti FLUENT_SETTING(TAttributes, Attributes); + FLUENT_SETTING_OPTIONAL(EMetricsLevel, MetricsLevel); + TCreateTopicSettings& SetSupportedCodecs(std::vector<ECodec>&& codecs) { SupportedCodecs_ = std::move(codecs); return *this; @@ -743,7 +755,20 @@ struct TAlterTopicSettings : public TOperationRequestSettings<TAlterTopicSetting return *this; } + TAlterTopicSettings& SetMetricsLevel(EMetricsLevel level) { + MetricsLevel_ = level; + return *this; + } + TAlterTopicSettings& ResetMetricsLevel() { + MetricsLevel_ = true; + return *this; + } + std::optional<TAlterPartitioningSettings> AlterPartitioningSettings_; + std::variant< + bool, // Reset + EMetricsLevel // Set + > MetricsLevel_ = false; }; inline TPartitioningSettingsBuilder TCreateTopicSettings::BeginConfigurePartitioningSettings() { diff --git a/ydb/public/sdk/cpp/src/client/topic/impl/topic.cpp b/ydb/public/sdk/cpp/src/client/topic/impl/topic.cpp index 6b290ee90b5..ceb7a56d655 100644 --- a/ydb/public/sdk/cpp/src/client/topic/impl/topic.cpp +++ b/ydb/public/sdk/cpp/src/client/topic/impl/topic.cpp @@ -54,6 +54,7 @@ TTopicDescription::TTopicDescription(Ydb::Topic::DescribeTopicResult&& result) , PartitionWriteBurstBytes_(Proto_.partition_write_burst_bytes()) , MeteringMode_(TProtoAccessor::FromProto(Proto_.metering_mode())) , TopicStats_(Proto_.topic_stats()) + , MetricsLevel_(Proto_.has_metrics_level() ? std::optional(static_cast<EMetricsLevel>(Proto_.metrics_level())) : std::optional<EMetricsLevel>()) { Owner_ = Proto_.self().owner(); CreationTimestamp_ = NScheme::TVirtualTimestamp(Proto_.self().created_at()); @@ -193,6 +194,9 @@ void TTopicDescription::SerializeTo(Ydb::Topic::CreateTopicRequest& request) con *request.mutable_attributes() = Proto_.attributes(); *request.mutable_consumers() = Proto_.consumers(); request.set_metering_mode(Proto_.metering_mode()); + if (Proto_.has_metrics_level()) { + request.set_metrics_level(Proto_.metrics_level()); + } } const Ydb::Topic::DescribeTopicResult& TTopicDescription::GetProto() const { @@ -219,6 +223,10 @@ const TTopicStats& TTopicDescription::GetTopicStats() const { return TopicStats_; } +std::optional<EMetricsLevel> TTopicDescription::GetMetricsLevel() const { + return MetricsLevel_; +} + const std::vector<NScheme::TPermissions>& TTopicDescription::GetPermissions() const { return Permissions_; } @@ -664,6 +672,7 @@ TCreateTopicSettings::TCreateTopicSettings(const Ydb::Topic::CreateTopicRequest& , PartitionWriteSpeedBytesPerSecond_(proto.partition_write_speed_bytes_per_second()) , PartitionWriteBurstBytes_(proto.partition_write_burst_bytes()) , Attributes_(DeserializeAttributes(proto.attributes())) + , MetricsLevel_(proto.has_metrics_level() ? std::optional(static_cast<EMetricsLevel>(proto.metrics_level())) : std::nullopt) { Consumers_ = DeserializeConsumers(*this, proto.consumers()); } @@ -678,6 +687,9 @@ void TCreateTopicSettings::SerializeTo(Ydb::Topic::CreateTopicRequest& request) request.set_partition_write_burst_bytes(PartitionWriteBurstBytes_); *request.mutable_consumers() = SerializeConsumers(Consumers_); *request.mutable_attributes() = SerializeAttributes(Attributes_); + if (MetricsLevel_) { + request.set_metrics_level(*MetricsLevel_); + } } } // namespace NYdb::NTopic diff --git a/ydb/public/sdk/cpp/src/client/topic/impl/topic_impl.h b/ydb/public/sdk/cpp/src/client/topic/impl/topic_impl.h index 2b801d24b8e..262f62e7c20 100644 --- a/ydb/public/sdk/cpp/src/client/topic/impl/topic_impl.h +++ b/ydb/public/sdk/cpp/src/client/topic/impl/topic_impl.h @@ -150,6 +150,12 @@ public: ConvertAlterConsumerToProto(consumer, consumerProto); } + if (auto level = std::get_if<EMetricsLevel>(&settings.MetricsLevel_)) { + request.set_set_metrics_level(*level); + } else if (auto reset = std::get_if<bool>(&settings.MetricsLevel_); *reset) { + request.mutable_reset_metrics_level(); + } + return request; } diff --git a/ydb/public/sdk/cpp/tests/integration/topic/describe_topic.cpp b/ydb/public/sdk/cpp/tests/integration/topic/describe_topic.cpp index 919293fd1b2..e8ac9874647 100644 --- a/ydb/public/sdk/cpp/tests/integration/topic/describe_topic.cpp +++ b/ydb/public/sdk/cpp/tests/integration/topic/describe_topic.cpp @@ -119,4 +119,78 @@ TEST_F(Describe, TEST_NAME(Location)) { } } +TEST_F(Describe, TEST_NAME(MetricsLevel)) { + TTopicClient client(MakeDriver()); + + // const std::uint32_t MetricsLevelDisabled = 0; + // const std::uint32_t MetricsLevelDatabase = 1; + const std::uint32_t MetricsLevelObject = 2; + const std::uint32_t MetricsLevelDetailed = 3; + + auto createTopic = [&](std::string topic, EMetricsLevel metricsLevel) { + auto res = client.CreateTopic(topic, TCreateTopicSettings().MetricsLevel(metricsLevel)).GetValueSync(); + ASSERT_TRUE(res.IsSuccess()); + }; + + auto setMetricsLevel = [&](std::string topic, EMetricsLevel metricsLevel) { + auto res = client.AlterTopic(topic, TAlterTopicSettings().SetMetricsLevel(metricsLevel)).GetValueSync(); + ASSERT_TRUE(res.IsSuccess()); + }; + + auto resetMetricsLevel = [&](std::string topic) { + auto res = client.AlterTopic(topic, TAlterTopicSettings().ResetMetricsLevel()).GetValueSync(); + ASSERT_TRUE(res.IsSuccess()); + }; + + auto checkFlag = [&](std::string topic, std::optional<EMetricsLevel> expectedMetricsLevel) { + auto res = client.DescribeTopic(topic, {}).GetValueSync(); + Y_ENSURE(res.IsSuccess()); + return res.GetTopicDescription().GetMetricsLevel() == expectedMetricsLevel; + }; + + { + const std::string topic("topic-with-counters"); + createTopic(topic, MetricsLevelDetailed); + checkFlag(topic, MetricsLevelDetailed); + setMetricsLevel(topic, MetricsLevelObject); + Y_ENSURE(checkFlag(topic, MetricsLevelObject)); + + { + // Empty alter should change nothing. + auto res = client.AlterTopic(topic).GetValueSync(); + ASSERT_TRUE(res.IsSuccess()); + Y_ENSURE(checkFlag(topic, MetricsLevelObject)); + } + + { + resetMetricsLevel(topic); + Y_ENSURE(checkFlag(topic, {})); + } + } + + { + const std::string topic("topic-without-counters-by-default"); + auto res = client.CreateTopic(topic).GetValueSync(); + ASSERT_TRUE(res.IsSuccess()); + Y_ENSURE(checkFlag(topic, {})); + setMetricsLevel(topic, MetricsLevelDetailed); + Y_ENSURE(checkFlag(topic, MetricsLevelDetailed)); + + { + // Empty alter should change nothing. + auto res = client.AlterTopic(topic).GetValueSync(); + ASSERT_TRUE(res.IsSuccess()); + Y_ENSURE(checkFlag(topic, MetricsLevelDetailed)); + } + } + + { + const std::string topic("topic-without-counters"); + createTopic(topic, MetricsLevelObject); + Y_ENSURE(checkFlag(topic, MetricsLevelObject)); + setMetricsLevel(topic, MetricsLevelDetailed); + Y_ENSURE(checkFlag(topic, MetricsLevelDetailed)); + } +} + } diff --git a/ydb/public/sdk/cpp/tests/integration/topic/utils/describe.cpp b/ydb/public/sdk/cpp/tests/integration/topic/utils/describe.cpp index 91f7d01c74f..7934c2f0c17 100644 --- a/ydb/public/sdk/cpp/tests/integration/topic/utils/describe.cpp +++ b/ydb/public/sdk/cpp/tests/integration/topic/utils/describe.cpp @@ -42,6 +42,8 @@ void DescribeTopicTest(ITopicTestSetup& setup, TTopicClient& client, bool requir Y_ENSURE(partitionLocation.GetNodeId() > 0); Y_ENSURE(partitionLocation.GetGeneration() >= 0); // greater-or-equal 0 } + + Y_ENSURE(!description.GetMetricsLevel().has_value()); } } diff --git a/ydb/services/lib/actors/pq_schema_actor.cpp b/ydb/services/lib/actors/pq_schema_actor.cpp index c06136095d7..d7b85b0a192 100644 --- a/ydb/services/lib/actors/pq_schema_actor.cpp +++ b/ydb/services/lib/actors/pq_schema_actor.cpp @@ -957,6 +957,12 @@ namespace NKikimr::NGRpcProxy::V1 { } } + if (settings.has_metrics_level()) { + pqTabletConfig->SetMetricsLevel(settings.metrics_level()); + } else { + pqTabletConfig->ClearMetricsLevel(); + } + return CheckConfig(*pqTabletConfig, supportedClientServiceTypes, error, pqConfig, Ydb::StatusIds::BAD_REQUEST); } @@ -1156,6 +1162,10 @@ namespace NKikimr::NGRpcProxy::V1 { } } + if (request.has_metrics_level()) { + pqTabletConfig->SetMetricsLevel(request.metrics_level()); + } + return TYdbPqCodes(CheckConfig(*pqTabletConfig, supportedClientServiceTypes, error, pqConfig, Ydb::StatusIds::BAD_REQUEST), Ydb::PersQueue::ErrorCode::VALIDATION_ERROR); } @@ -1401,6 +1411,12 @@ namespace NKikimr::NGRpcProxy::V1 { } } + if (request.has_set_metrics_level()) { + pqTabletConfig->SetMetricsLevel(request.set_metrics_level()); + } else if (request.has_reset_metrics_level()) { + pqTabletConfig->ClearMetricsLevel(); + } + return CheckConfig(*pqTabletConfig, supportedClientServiceTypes, error, pqConfig, Ydb::StatusIds::ALREADY_EXISTS); } } |
