Skip to content

Commit 2a3a16a

Browse files
authored
Capture compilation flag telemetry. (#1758)
This would be useful in the future when we need to prioritize features / compiler support, etc. It captures the compiler name and version, as well as the `-fexceptions` settings in the user-agent string. Also refactored the two places in Bigtable where we built a user-agent string.
1 parent 21dd66a commit 2a3a16a

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

google/cloud/bigtable/client_options.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313

1414
#include "google/cloud/bigtable/client_options.h"
15+
#include "google/cloud/internal/build_info.h"
1516
#include "google/cloud/internal/getenv.h"
1617
#include <thread>
1718

@@ -56,7 +57,7 @@ ClientOptions::ClientOptions(std::shared_ptr<grpc::ChannelCredentials> creds)
5657
data_endpoint_("bigtable.googleapis.com"),
5758
admin_endpoint_("bigtableadmin.googleapis.com"),
5859
instance_admin_endpoint_("bigtableadmin.googleapis.com") {
59-
static std::string const user_agent_prefix = "cbt-c++/" + version_string();
60+
static std::string const user_agent_prefix = UserAgentPrefix();
6061
channel_arguments_.SetUserAgentPrefix(user_agent_prefix);
6162
}
6263

@@ -74,6 +75,18 @@ ClientOptions::ClientOptions() : ClientOptions(BigtableDefaultCredentials()) {
7475
}
7576
}
7677

78+
std::string ClientOptions::UserAgentPrefix() {
79+
std::string agent = "cbt-c++/" + version_string();
80+
#if GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS
81+
agent += " ex";
82+
#else
83+
agent += " noex";
84+
#endif // GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS
85+
agent += ' ';
86+
agent += google::cloud::internal::compiler();
87+
return agent;
88+
}
89+
7790
} // namespace BIGTABLE_CLIENT_NS
7891
} // namespace bigtable
7992
} // namespace cloud

google/cloud/bigtable/client_options.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ class ClientOptions {
285285
channel_arguments_.SetSslTargetNameOverride(name);
286286
}
287287

288+
/// Return the user agent prefix used by the library.
289+
static std::string UserAgentPrefix();
290+
288291
private:
289292
/// Return the current endpoint for instance admin RPCs.
290293
friend struct InstanceAdminTraits;

google/cloud/bigtable/client_options_test.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ struct ClientOptionsTestTraits {
3131

3232
namespace {
3333

34+
using ::testing::HasSubstr;
35+
3436
TEST(ClientOptionsTest, ClientOptionsDefaultSettings) {
3537
bigtable::ClientOptions client_options_object = bigtable::ClientOptions();
3638
EXPECT_EQ("bigtable.googleapis.com", client_options_object.data_endpoint());
@@ -300,6 +302,13 @@ TEST(ClientOptionsTest, SetSslTargetNameOverride) {
300302
grpc::string(test_args.args[1].key));
301303
}
302304

305+
TEST(ClientOptionsTest, UserAgentPrefix) {
306+
std::string const actual = bigtable::ClientOptions::UserAgentPrefix();
307+
308+
EXPECT_THAT(actual, HasSubstr("cbt-c++/"));
309+
EXPECT_THAT(actual, ::testing::AnyOf(HasSubstr(" noex "), HasSubstr(" ex ")));
310+
}
311+
303312
} // namespace
304313
} // namespace BIGTABLE_CLIENT_NS
305314
} // namespace bigtable

google/cloud/bigtable/testing/embedded_server_test_fixture.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "google/cloud/bigtable/testing/embedded_server_test_fixture.h"
1616
#include "google/cloud/bigtable/internal/grpc_error_delegate.h"
17+
#include "google/cloud/internal/build_info.h"
1718
#include <thread>
1819

1920
namespace google {
@@ -36,8 +37,8 @@ void EmbeddedServerTestFixture::SetUp() {
3637
StartServer();
3738

3839
grpc::ChannelArguments channel_arguments;
39-
static std::string const prefix = "cbt-c++/" + version_string();
40-
channel_arguments.SetUserAgentPrefix(prefix);
40+
static std::string const user_agent_prefix = ClientOptions::UserAgentPrefix();
41+
channel_arguments.SetUserAgentPrefix(user_agent_prefix);
4142

4243
std::shared_ptr<grpc::Channel> data_channel =
4344
server_->InProcessChannel(channel_arguments);

google/cloud/storage/internal/curl_request_builder.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "google/cloud/storage/internal/curl_request_builder.h"
16+
#include "google/cloud/internal/build_info.h"
1617

1718
namespace google {
1819
namespace cloud {
@@ -133,6 +134,13 @@ std::string CurlRequestBuilder::UserAgentSuffix() const {
133134
static std::string const user_agent_suffix = [] {
134135
std::string agent = "gcs-c++/";
135136
agent += storage::version_string();
137+
#if GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS
138+
agent += " ex";
139+
#else
140+
agent += " noex";
141+
#endif // GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS
142+
agent += ' ';
143+
agent += google::cloud::internal::compiler();
136144
agent += ' ';
137145
agent += curl_version();
138146
return agent;

0 commit comments

Comments
 (0)