Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ def envoy_api_deps(skip_targets):
native.git_repository(
name = "envoy_api",
remote = REPO_LOCATIONS["envoy_api"],
commit = "8047d578919175cdcaddad8364511d77db5bba87",
commit = "422332bf5fb251904dd53ed8cbb5f28e892ed69d",
)
native.bind(
name = "envoy_base",
actual = "@envoy_api//api:base",
actual = "@envoy_api//api:base_cc",
)
native.bind(
name = "envoy_eds",
actual = "@envoy_api//api:eds",
actual = "@envoy_api//api:eds_cc",
)
native.bind(
name = "http_api_protos",
Expand Down
20 changes: 20 additions & 0 deletions source/common/config/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,25 @@ void Utility::sdsConfigToEdsConfig(const Upstream::SdsConfig& sds_config,
google::protobuf::util::TimeUtil::MillisecondsToDuration(sds_config.refresh_delay_.count()));
}

const google::protobuf::Value& Utility::metadataValue(const envoy::api::v2::Metadata& metadata,
const std::string& filter,
const std::string& key) {
const auto filter_it = metadata.filter_metadata().find(filter);
if (filter_it == metadata.filter_metadata().end()) {
return google::protobuf::Value::default_instance();
}
const auto fields_it = filter_it->second.fields().find(key);
if (fields_it == filter_it->second.fields().end()) {
return google::protobuf::Value::default_instance();
}
return fields_it->second;
}

google::protobuf::Value& Utility::mutableMetadataValue(envoy::api::v2::Metadata& metadata,
const std::string& filter,
const std::string& key) {
return (*(*metadata.mutable_filter_metadata())[filter].mutable_fields())[key];
}

} // namespace Config
} // namespace Envoy
22 changes: 22 additions & 0 deletions source/common/config/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ class Utility {
*/
static void sdsConfigToEdsConfig(const Upstream::SdsConfig& sds_config,
envoy::api::v2::ConfigSource& eds_config);

/**
* Lookup value of a key for a given filter in Metadata.
* @param metadata reference.
* @param filter name.
* @param key for filter metadata.
* @return const google::protobuf::Value& value if found, empty if not found.
*/
static const google::protobuf::Value& metadataValue(const envoy::api::v2::Metadata& metadata,
const std::string& filter,
const std::string& key);

/**
* Obtain mutable reference to metadata value for a given filter and key.
* @param metadata reference.
* @param filter name.
* @param key for filter metadata.
* @return google::protobuf::Value&. A Value message is created if not found.
*/
static google::protobuf::Value& mutableMetadataValue(envoy::api::v2::Metadata& metadata,
const std::string& filter,
const std::string& key);
};

} // Config
Expand Down
4 changes: 3 additions & 1 deletion source/common/upstream/eds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ void EdsClusterImpl::onConfigUpdate(const ResourceVector& resources) {
const std::string& zone = locality_lb_endpoint.locality().zone();

for (const auto& lb_endpoint : locality_lb_endpoint.lb_endpoints()) {
const bool canary =
Config::Utility::metadataValue(lb_endpoint.metadata(), "envoy.lb", "canary").bool_value();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we add "envoy.lb" and "canary" to some type of MetadataConstants class or something? We will be referencing well known metadata in various places in the code and it would be good to put the well known things in a central place.

new_hosts.emplace_back(new HostImpl(
info_, "", Network::Address::InstanceConstSharedPtr{new Network::Address::Ipv4Instance(
lb_endpoint.endpoint().address().socket_address().ip_address(),
lb_endpoint.endpoint().address().socket_address().port().value())},
lb_endpoint.canary().value(), lb_endpoint.load_balancing_weight().value(), zone));
canary, lb_endpoint.load_balancing_weight().value(), zone));
}
}

Expand Down
5 changes: 2 additions & 3 deletions source/common/upstream/sds_subscription.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ void SdsSubscription::parseResponse(const Http::Message& response) {
auto* address = lb_endpoint->mutable_endpoint()->mutable_address()->mutable_socket_address();
address->set_ip_address(host->getString("ip_address"));
address->mutable_port()->set_value(host->getInteger("port"));
// TODO(htuch): This will eventually be generalized metadata/labels, see
// https://github.com/lyft/envoy-api/issues/81.
lb_endpoint->mutable_canary()->set_value(canary);
Config::Utility::mutableMetadataValue(*lb_endpoint->mutable_metadata(), "envoy.lb", "canary")
.set_bool_value(canary);
lb_endpoint->mutable_load_balancing_weight()->set_value(weight);
}

Expand Down
8 changes: 8 additions & 0 deletions test/common/config/utility_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,13 @@ TEST(UtilityTest, SdsConfigToEdsConfig) {
EXPECT_EQ(30000, Utility::apiConfigSourceRefreshDelay(api_config_source).count());
}

TEST(UtilityTest, MetadataValue) {
envoy::api::v2::Metadata metadata;
Utility::mutableMetadataValue(metadata, "envoy.lb", "canary").set_bool_value(true);
EXPECT_TRUE(Utility::metadataValue(metadata, "envoy.lb", "canary").bool_value());
EXPECT_FALSE(Utility::metadataValue(metadata, "foo", "bar").bool_value());
EXPECT_FALSE(Utility::metadataValue(metadata, "envoy.lb", "bar").bool_value());
}

} // namespace Config
} // namespace Envoy