Skip to content

Commit

Permalink
Stabilize the C2P resolver URI scheme (grpc#30653)
Browse files Browse the repository at this point in the history
* stabilize the C2P resolver URI scheme

* fix build
  • Loading branch information
apolcyn authored Aug 29, 2022
1 parent 18da150 commit 8e44a16
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,35 @@ void GoogleCloud2ProdResolver::StartXdsResolver() {

class GoogleCloud2ProdResolverFactory : public ResolverFactory {
public:
// TODO(roth): Remove experimental suffix once this code is proven stable,
// and update the scheme in google_c2p_resolver_test.cc when doing so.
absl::string_view scheme() const override { return "google-c2p"; }

bool IsValidUri(const URI& uri) const override {
if (GPR_UNLIKELY(!uri.authority().empty())) {
gpr_log(GPR_ERROR, "google-c2p URI scheme does not support authorities");
return false;
}
return true;
}

OrphanablePtr<Resolver> CreateResolver(ResolverArgs args) const override {
if (!IsValidUri(args.uri)) return nullptr;
return MakeOrphanable<GoogleCloud2ProdResolver>(std::move(args));
}
};

// TODO(apolcyn): remove this class after user code has updated to the
// stable "google-c2p" URI scheme.
class ExperimentalGoogleCloud2ProdResolverFactory : public ResolverFactory {
public:
absl::string_view scheme() const override {
return "google-c2p-experimental";
}

bool IsValidUri(const URI& uri) const override {
if (GPR_UNLIKELY(!uri.authority().empty())) {
gpr_log(GPR_ERROR, "google-c2p URI scheme does not support authorities");
gpr_log(
GPR_ERROR,
"google-c2p-experimental URI scheme does not support authorities");
return false;
}
return true;
Expand All @@ -439,6 +459,8 @@ class GoogleCloud2ProdResolverFactory : public ResolverFactory {
void RegisterCloud2ProdResolver(CoreConfiguration::Builder* builder) {
builder->resolver_registry()->RegisterResolverFactory(
absl::make_unique<GoogleCloud2ProdResolverFactory>());
builder->resolver_registry()->RegisterResolverFactory(
absl::make_unique<ExperimentalGoogleCloud2ProdResolverFactory>());
}

} // namespace grpc_core
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace {

void TryConnectAndDestroy(const char* fake_metadata_server_address) {
grpc::ChannelArguments args;
std::string target = "google-c2p-experimental:///servername_not_used";
std::string target = "google-c2p:///servername_not_used";
args.SetInt("grpc.testing.google_c2p_resolver_pretend_running_on_gcp", 1);
args.SetString("grpc.testing.google_c2p_resolver_metadata_server_override",
fake_metadata_server_address);
Expand Down

0 comments on commit 8e44a16

Please sign in to comment.