Skip to content

Conversation

dio
Copy link
Member

@dio dio commented Jul 3, 2018

Description:
This patch introduces PriorityStateManager to manage priorities/hosts/localities
as requirement prior updating the cluster's PrioritySet.
Since most of the codes are taken from eds.cc, this patch also refactors EDS codes.

This is part of the effort on adding load_assignment field to Cluster as signalled
in #3261.

Risk Level: Medium
Testing: bazel test //test/...
Docs Changes: N/A
Release Notes: N/A

Signed-off-by: Dhi Aurrahman dio@rockybars.com

dio added 4 commits July 3, 2018 19:43
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Copy link
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

Cool! I think it'll be helpful to have some of this code complexity broken out. A couple of drive by comments from me before I vanish for the rest of the week :-)

@@ -63,33 +59,28 @@ void EdsClusterImpl::onConfigUpdate(const ResourceVector& resources, const std::
throw EnvoyException(fmt::format("Unexpected EDS cluster (expecting {}): {}", cluster_name_,
cluster_load_assignment.cluster_name()));
}

auto& priority_state = priority_state_manager_->priority_state_;
priority_state.clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't clearing and creating every time going to be more computationally expensive? It'd be good if we can do this refactor with minimal performance regression

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm taking a ref and clearing it out. Previously, the priority_state is a local variable in this scope.

Copy link
Member

Choose a reason for hiding this comment

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

Does it makes sense to make PriorityStateManager a local variable in onConfigUpdate? It would mean reverting the Config::Utility::checkLocalInfo call, but other than that check, PSM isn't needed beyond the scope on onConfigUpdate.

// Returns the size of the current cluster priority state.
size_t size() const { return priority_state_.size(); }

PriorityState priority_state_;
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe per our == google style this should be private

Copy link
Member Author

Choose a reason for hiding this comment

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

👍


/**
* Manages PriorityState of a cluster. PriorityState is a per-priority binding of a set of hosts
* with its corresponding locality weight map. This is not used at runtime, but useful to store
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, can you clarify what you mean by this not being used at runtime?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably the wording is not right. I meant to say: it is configuration related only, not in data path.

if (locality_lb_endpoint.has_locality() && locality_lb_endpoint.has_load_balancing_weight()) {
// TODO(dio): Add tests as per @alyssawilk's comment here
// https://github.com/envoyproxy/envoy/pull/3261/files#r188292098
priority_state_[priority].second[locality_lb_endpoint.locality()] =
Copy link
Contributor

Choose a reason for hiding this comment

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

Interestingly this looks like it's covered, but there's a few other spots missing. It'd be great to have unit tests as part of this refactor.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

dio added 3 commits July 3, 2018 23:26
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
dio added 3 commits July 4, 2018 10:00
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
@dio
Copy link
Member Author

dio commented Jul 9, 2018

@alyssawilk when you have time please do a more in-depth review 😄. Thank you!

Copy link
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

Sorry for the delay - I was out last week. With a more thorough inspection it looks really solid! Only two other nits from me :-)

health_status == envoy::api::v2::core::HealthStatus::DRAINING ||
health_status == envoy::api::v2::core::HealthStatus::TIMEOUT
? absl::optional<Host::HealthFlag>(Host::HealthFlag::FAILED_EDS_HEALTH)
: absl::nullopt);
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to not do the health flag checks in the function?

}

void PriorityStateManager::updateClusterPrioritySet(
const uint32_t priority, HostVectorSharedPtr current_hosts,
Copy link
Contributor

Choose a reason for hiding this comment

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

&& current_hosts if we're going to take ownership?

dio added 8 commits July 10, 2018 07:07
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
@dio
Copy link
Member Author

dio commented Jul 10, 2018

@alyssawilk @zuercher thanks for your time for reviewing this code! I think I have addressed your comments. When you have time please have a look. Thank you!

Copy link
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

Looks good to me. One small nit.

Network::Address::InstanceConstSharedPtr address,
const envoy::api::v2::endpoint::LocalityLbEndpoints& locality_lb_endpoint,
const envoy::api::v2::endpoint::LbEndpoint& lb_endpoint,
const Upstream::Host::HealthFlag health_checker_flag);
Copy link
Member

Choose a reason for hiding this comment

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

nit: Please add a note to the comment indicating when health_checker_flag is used.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, @zuercher. Added it here: 3d806d2.

dio added 2 commits July 10, 2018 23:35
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
Signed-off-by: Dhi Aurrahman <dio@rockybars.com>
@dio
Copy link
Member Author

dio commented Jul 12, 2018

@alyssawilk @zuercher Please let me know if there is anything else that I should change. Thanks!

Copy link
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

Thanks both for the general code clean up and the refactor to make PriorityStateManager local - I think it made it an even cleaner PR.

@alyssawilk alyssawilk merged commit 9de80f7 into envoyproxy:master Jul 12, 2018
snowp pushed a commit to snowp/envoy that referenced this pull request Jul 12, 2018
* origin/master:
  config: making v2-config-only a boolean flag (envoyproxy#3847)
  lc trie: add exclusive flag. (envoyproxy#3825)
  upstream: introduce PriorityStateManager, refactor EDS (envoyproxy#3783)
  test: deflaking header_integration_test (envoyproxy#3849)
  http: new style WebSockets, where headers and data are processed by the filter chain. (envoyproxy#3776)
  common: minor doc updates (envoyproxy#3845)
  fix master build (envoyproxy#3844)
  logging: Requiring details for RELEASE_ASSERT (envoyproxy#3842)
  test: add test for consistency of RawStatData internal memory representation (envoyproxy#3843)
  common: jittered backoff implementation (envoyproxy#3791)
  format: run buildifier on .bzl files. (envoyproxy#3824)
  Support mutable metadata for endpoints (envoyproxy#3814)
  test: deflaking a test, improving debugability (envoyproxy#3829)
  Update ApiConfigSource docs with grpc_services only for GRPC configs (envoyproxy#3834)
  Add hard-coded /hot_restart_version test (envoyproxy#3832)
  healthchecks: Add interval_jitter_percent healthcheck option (envoyproxy#3816)

Signed-off-by: Snow Pettersen <snowp@squareup.com>
@akonradi
Copy link
Contributor

Opened #3856 to fix some off-the-end indexing in PriorityStateManager::updateClusterPrioritySet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants