From d8e4addd3a7e3a0d02270960d4b4c0b05c91ff0e Mon Sep 17 00:00:00 2001 From: Dohun Kim Date: Mon, 2 Mar 2026 12:58:45 +0000 Subject: [PATCH 1/2] Add support for adding tags to an Instance in InstanceConfig --- google/cloud/bigtable/instance_config.h | 10 ++++++++++ google/cloud/bigtable/instance_config_test.cc | 20 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/google/cloud/bigtable/instance_config.h b/google/cloud/bigtable/instance_config.h index c564067e8c4e3..1e9845d70675f 100644 --- a/google/cloud/bigtable/instance_config.h +++ b/google/cloud/bigtable/instance_config.h @@ -67,6 +67,16 @@ class InstanceConfig { return *this; } + InstanceConfig& insert_tag(std::string const& key, std::string const& value) { + (*proto_.mutable_instance()->mutable_tags())[key] = value; + return *this; + } + + InstanceConfig& emplace_tag(std::string const& key, std::string value) { + (*proto_.mutable_instance()->mutable_tags())[key] = std::move(value); + return *this; + } + // NOLINT: accessors can (and should) be snake_case. google::bigtable::admin::v2::CreateInstanceRequest const& as_proto() const& { return proto_; diff --git a/google/cloud/bigtable/instance_config_test.cc b/google/cloud/bigtable/instance_config_test.cc index 97afec1310caa..d6d2a47457ea2 100644 --- a/google/cloud/bigtable/instance_config_test.cc +++ b/google/cloud/bigtable/instance_config_test.cc @@ -75,6 +75,26 @@ TEST(InstanceConfigTest, SetLabels) { EXPECT_EQ("qux", proto.instance().labels().at("baz")); } + +TEST(InstanceConfigTest, SetTags) { + InstanceConfig config("my-instance", "pretty name", + { + {"cluster-1", {"somewhere", 7, ClusterConfig::SSD}}, + }); + + config.insert_tag("tagKeys/123", "tagValues/654").emplace_tag("tagKeys/345", "tagValues/987"); + + auto proto = config.as_proto(); + EXPECT_EQ("my-instance", proto.instance_id()); + EXPECT_EQ("pretty name", proto.instance().display_name()); + ASSERT_EQ(1, proto.clusters_size()); + + ASSERT_EQ(2, proto.instance().tags_size()); + EXPECT_EQ("tagValues/654", proto.instance().tags().at("tagKeys/123")); + EXPECT_EQ("tagValues/987", proto.instance().tags().at("tagKeys/345")); +} + + } // namespace GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END } // namespace bigtable From 48a782d647558e986ae4586e9fc328fcd5565275 Mon Sep 17 00:00:00 2001 From: Dohun Kim Date: Tue, 3 Mar 2026 12:50:57 +0000 Subject: [PATCH 2/2] add AI review suggestion of support for rvalue in emplace_tag --- google/cloud/bigtable/instance_config.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/google/cloud/bigtable/instance_config.h b/google/cloud/bigtable/instance_config.h index 1e9845d70675f..0d99b8a46d7c0 100644 --- a/google/cloud/bigtable/instance_config.h +++ b/google/cloud/bigtable/instance_config.h @@ -77,6 +77,12 @@ class InstanceConfig { return *this; } + InstanceConfig& emplace_tag(std::string&& key, std::string value) { + (*proto_.mutable_instance()->mutable_tags())[std::move(key)] = + std::move(value); + return *this; + } + // NOLINT: accessors can (and should) be snake_case. google::bigtable::admin::v2::CreateInstanceRequest const& as_proto() const& { return proto_;