Skip to content

Commit 3786379

Browse files
committed
feat(storage): inject feature tracker into client config and REST transport (#2657)
1 parent c0484ab commit 3786379

4 files changed

Lines changed: 43 additions & 3 deletions

File tree

google/cloud/storage/client.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "google/cloud/storage/idempotency_policy.h"
1717
#include "google/cloud/storage/internal/base64.h"
1818
#include "google/cloud/storage/internal/connection_factory.h"
19+
#include "google/cloud/storage/internal/feature_tracker.h"
1920
#include "google/cloud/storage/options.h"
2021
#include "google/cloud/internal/curl_handle.h"
2122
#include "google/cloud/internal/curl_options.h"
@@ -624,8 +625,8 @@ Options DefaultOptions(Options opts) {
624625
rest_defaults.set<rest::CAPathOption>(o.get<internal::CAPathOption>());
625626
}
626627

627-
return google::cloud::internal::MergeOptions(std::move(o),
628-
std::move(rest_defaults));
628+
return internal::SetupFeatureTracker(google::cloud::internal::MergeOptions(
629+
std::move(o), std::move(rest_defaults)));
629630
}
630631

631632
Options DefaultOptionsWithCredentials(Options opts) {

google/cloud/storage/internal/async/default_options.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "google/cloud/storage/async/resume_policy.h"
1919
#include "google/cloud/storage/async/retry_policy.h"
2020
#include "google/cloud/storage/async/writer_connection.h"
21+
#include "google/cloud/storage/internal/feature_tracker.h"
2122
#include "google/cloud/storage/internal/grpc/default_options.h"
2223
#include <limits>
2324

@@ -77,7 +78,8 @@ Options DefaultOptionsAsync(Options opts) {
7778
.set<storage::EnableCrc32cValidationOption>(true)
7879
.set<storage::MaximumRangeSizeOption>(128 * 1024 * 1024L)
7980
.set<storage::EnableMultiStreamOptimizationOption>(true));
80-
return Adjust(DefaultOptionsGrpc(std::move(opts)));
81+
return storage::internal::SetupFeatureTracker(
82+
Adjust(DefaultOptionsGrpc(std::move(opts))));
8183
}
8284

8385
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END

google/cloud/storage/internal/rest/stub.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#include "google/cloud/storage/internal/rest/stub.h"
1616
#include "google/cloud/storage/internal/bucket_access_control_parser.h"
1717
#include "google/cloud/storage/internal/bucket_metadata_parser.h"
18+
#include "google/cloud/storage/internal/feature_tracker.h"
19+
#include "google/cloud/storage/options.h"
20+
#include "google/cloud/storage/internal/base64.h"
1821
#include "google/cloud/storage/internal/bucket_requests.h"
1922
#include "google/cloud/storage/internal/generate_message_boundary.h"
2023
#include "google/cloud/storage/internal/hmac_key_metadata_parser.h"
@@ -116,6 +119,18 @@ void AddCustomHeaders(Options const& options, RestRequestBuilder& builder) {
116119

117120
Status AddHeaders(Options const& options, RestRequestBuilder& builder) {
118121
AddCustomHeaders(options, builder);
122+
bool const enable_reports =
123+
!options.has<EnableFeatureReportsOption>() ||
124+
options.get<EnableFeatureReportsOption>();
125+
if (enable_reports && options.has<FeatureTrackerOption>()) {
126+
auto const& tracker = options.get<FeatureTrackerOption>();
127+
if (tracker) {
128+
auto const val = tracker->HeaderValue();
129+
if (!val.empty()) {
130+
builder.AddHeader(kFeatureTrackerHeaderName, val);
131+
}
132+
}
133+
}
119134
return {};
120135
}
121136

google/cloud/storage/internal/rest/stub_test.cc

Lines changed: 22 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/rest/stub.h"
16+
#include "google/cloud/storage/internal/feature_tracker.h"
1617
#include "google/cloud/storage/internal/hash_function.h"
1718
#include "google/cloud/storage/testing/canonical_errors.h"
1819
#include "google/cloud/internal/api_client_header.h"
@@ -1028,6 +1029,27 @@ TEST(RestStubTest, UploadChunkIntermediate) {
10281029
StatusIs(PermanentError().code(), PermanentError().message()));
10291030
}
10301031

1032+
TEST(RestStubTest, FeatureTrackerHeaderAppearsInRequest) {
1033+
auto tracker = std::make_shared<FeatureTracker>();
1034+
tracker->RegisterFeature(TrackedFeature::kPCU);
1035+
auto options = Options{}.set<FeatureTrackerOption>(tracker);
1036+
1037+
auto mock = std::make_shared<MockRestClient>();
1038+
EXPECT_CALL(
1039+
*mock,
1040+
Get(An<RestContext&>(),
1041+
ResultOf(
1042+
"request includes feature tracker header",
1043+
[](RestRequest const& r) { return r.headers(); },
1044+
Contains(Pair(kFeatureTrackerHeaderName,
1045+
ElementsAre(tracker->HeaderValue()))))))
1046+
.WillOnce(Return(PermanentError()));
1047+
1048+
auto tested = std::make_unique<RestStub>(options, mock, mock);
1049+
RestContext context;
1050+
tested->ListBuckets(context, options, ListBucketsRequest());
1051+
}
1052+
10311053
} // namespace
10321054
} // namespace internal
10331055
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END

0 commit comments

Comments
 (0)