Skip to content

wip: Watch stack module#2100

Merged
olix0r merged 6 commits intover/concretemasfrom
ver/watchmas
Dec 29, 2022
Merged

wip: Watch stack module#2100
olix0r merged 6 commits intover/concretemasfrom
ver/watchmas

Conversation

@olix0r
Copy link
Member

@olix0r olix0r commented Dec 29, 2022

No description provided.

use tracing::Instrument;

pub trait UpdateWatch<T> {
type Service: Clone + Default;
Copy link
Contributor

@hawkw hawkw Dec 29, 2022

Choose a reason for hiding this comment

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

i put the Clone and Default bounds here because we'll get a much more obvious type error (when trying to implement UpdateWatch, rather than on the NewService impl) if they're missing

Copy link
Contributor

Choose a reason for hiding this comment

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

we probably should also put the Send + Sync bounds here since this trait is only used by NewSpawnWatch anyway...

Since `UpdateWatch` is only ever used by `SpawnWatch`, and `SpawnWatch`
requires these bounds, they may as well go on the trait directly. This
way, we'll get much more reasonable errors when trying to implement
`UpdateWatch`, rather than just having `NewService` impls fail to exist.
@olix0r olix0r marked this pull request as ready for review December 29, 2022 18:43
@olix0r olix0r requested a review from a team as a code owner December 29, 2022 18:43
Copy link
Contributor

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

it's neat that the watch logic can be factored out, this looks good to me! i left a few minor nits/questions, but this looks good overall!

.push(svc::NewLazy::layer()),
let route = svc::layers()
// Maintain a per-route distributor over concrete
// backends from the (above) concrete cache.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is the cache still above this (in the file)? does the comment need to be updated?

}

impl<K, S> Default for Distribute<K, S> {
/// Returns an empty distribution. This distribution will never become ready/
Copy link
Contributor

Choose a reason for hiding this comment

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

whoops, typo on my part:

Suggested change
/// Returns an empty distribution. This distribution will never become ready/
/// Returns an empty distribution. This distribution will never become ready.

}

#[derive(Clone, Debug)]
pub struct NewSpawnWatch<P, N> {
Copy link
Contributor

Choose a reason for hiding this comment

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

probably worth a comment somewhere in the file explaining what this does?

fn update(&mut self, target: &T) -> Option<Self::Service>;
}

#[derive(Clone, Debug)]
Copy link
Contributor

Choose a reason for hiding this comment

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

this will only implement Clone/Debug if P is Clone/Debug, because of the PhantomData...should we have a manual impl?

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 probably

type Future = S::Future;

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
if matches!(self.rx.has_changed(), Ok(true)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should poll_ready error if the background task is dead? AFAICT it could disappear on us abruptly if the underlying target watch closes, and wouldn't be recoverable (we would need to start a new resolution)...

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 don't think there's any need to error--we have a handle to the service we can continue using.

@olix0r olix0r merged commit 2243b02 into ver/concretemas Dec 29, 2022
@olix0r olix0r deleted the ver/watchmas branch December 29, 2022 22:22
hawkw added a commit that referenced this pull request Dec 29, 2022
This branch adds an implementation of a middleware that watches a
`watch::Receiver` of targets and builds a new service when the watch is
updated. The current state of the inner service is broadcast over a
second watch to any clones of the `SpawnWatch` service.

This is the same code added in PR #2100, but rebased onto `main`, with
documentation and tests added.
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.

2 participants