Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EventEngine] Change TXT lookup result type to std::vector<std::string> #33030

Merged
merged 2 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/grpc/event_engine/event_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class EventEngine : public std::enable_shared_from_this<EventEngine> {
absl::AnyInvocable<void(absl::StatusOr<std::vector<SRVRecord>>)>;
/// Called with the result of a TXT record lookup
using LookupTXTCallback =
absl::AnyInvocable<void(absl::StatusOr<std::string>)>;
absl::AnyInvocable<void(absl::StatusOr<std::vector<std::string>>)>;

virtual ~DNSResolver() = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "absl/container/flat_hash_set.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/strip.h"
#include "absl/types/optional.h"
Expand Down Expand Up @@ -128,7 +129,7 @@ class EventEngineClientChannelDNSResolver : public PollingResolver {
void OnBalancerHostnamesResolved(
std::string authority,
absl::StatusOr<std::vector<EventEngine::ResolvedAddress>> addresses);
void OnTXTResolved(absl::StatusOr<std::string> service_config);
void OnTXTResolved(absl::StatusOr<std::vector<std::string>> service_config);
// Returns a Result if resolution is complete.
// callers must release the lock and call OnRequestComplete if a Result is
// returned. This is because OnRequestComplete may Orphan the resolver,
Expand Down Expand Up @@ -251,7 +252,7 @@ EventEngineClientChannelDNSResolver::EventEngineDNSRequestWrapper::
resolver_.get(), resolver_->name_to_resolve().c_str());
txt_handle_ = event_engine_resolver_->LookupTXT(
[self = Ref(DEBUG_LOCATION, "OnTXTResolved")](
absl::StatusOr<std::string> service_config) {
absl::StatusOr<std::vector<std::string>> service_config) {
self->OnTXTResolved(std::move(service_config));
},
absl::StrCat("_grpc_config.", resolver_->name_to_resolve()),
Expand Down Expand Up @@ -388,7 +389,7 @@ void EventEngineClientChannelDNSResolver::EventEngineDNSRequestWrapper::
}

void EventEngineClientChannelDNSResolver::EventEngineDNSRequestWrapper::
OnTXTResolved(absl::StatusOr<std::string> service_config) {
OnTXTResolved(absl::StatusOr<std::vector<std::string>> service_config) {
ValidationErrors::ScopedField field(&errors_, "txt lookup");
absl::optional<Resolver::Result> result;
{
Expand All @@ -400,7 +401,21 @@ void EventEngineClientChannelDNSResolver::EventEngineDNSRequestWrapper::
errors_.AddError(service_config.status().message());
service_config_json_ = service_config.status();
} else {
service_config_json_ = absl::StrCat("grpc_config=", *service_config);
constexpr char kServiceConfigAttributePrefix[] = "grpc_config=";
auto result = std::find_if(service_config->begin(), service_config->end(),
[&](absl::string_view s) {
return absl::StartsWith(
s, kServiceConfigAttributePrefix);
});
if (result != service_config->end()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to differ from previous logic where we simply concatenate the grpc_config prefix to all returned values. Instead now it searches for a result with the given prefix. Is there a specific reason ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I think the previous logic is not correct (this code is still under development and not used until EventEngine::DNSResolver is ready) since gRPC's service config data starts with grpc_config= followed by the JSON-formatted data. See: https://github.com/grpc/proposal/blob/master/A2-service-configs-in-dns.md#encoding-in-dns-txt-records.

service_config_json_ =
result->substr(sizeof(kServiceConfigAttributePrefix));
} else {
service_config_json_ = absl::UnavailableError(absl::StrCat(
"failed to find attribute prefix: ", kServiceConfigAttributePrefix,
" in TXT records"));
errors_.AddError(service_config_json_.status().message());
}
}
result = OnResolvedLocked();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ ThreadyEventEngine::ThreadyDNSResolver::LookupTXT(LookupTXTCallback on_resolve,
Duration timeout) {
return impl_->LookupTXT(
[this, on_resolve = std::move(on_resolve)](
absl::StatusOr<std::string> record) mutable {
absl::StatusOr<std::vector<std::string>> record) mutable {
return engine_->Asynchronously([on_resolve = std::move(on_resolve),
record = std::move(record)]() mutable {
on_resolve(std::move(record));
Expand Down