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

Adjusting ServiceDiscovererEvent contract #1906

Merged
merged 14 commits into from
Nov 15, 2021

Conversation

chemicL
Copy link
Contributor

@chemicL chemicL commented Oct 22, 2021

Motivation:

Current API of ServiceDiscovererEvent is capable of representing the
boolean status of the host being either available or not available. As
seen in the implementation of RoundRobinLoadBalancer, the resulting
states from the Service Discovery system can have more meanings than a
simple boolean. To prepare for enhanecements, the contract has been
adjusted to allow more states and make it possible for further additions
if those are needed by particular implementations.

Modifications:

  • Deprecated ServiceDiscovererEvent#isAvailable method and added a
    default implementation to allow removal in child classes,
  • Added ServiceDiscoveryStatus class,
  • Added ServiceDiscovererEvent#status method with default
    implementation to prevent breaking the existing implementations,
  • Replaced existing uses of isAvailable with comparisons of status
    against the constants in ServiceDiscoveryStatus,
  • Added TODOs in order to reflect the need to adapt the codebase to
    support non-binary statuses.

Result:

ServiceDiscovererEvents are prepared for more advanced, non-binary
statuses. An example is the now introduced EXPIRED event, which can have a
different meaning than UNAVAILABLE. If the ServiceDiscoverer decides
to emit such a status, the subscribers can provide additional
functionality in that case.

Motivation:

Current API of `ServiceDiscovererEvent` is capable of representing the
boolean status of the host being either available or not available. As
seen in the implementation of RoundRobinLoadBalancer`, the resulting
states from the Service Discovery system can have more meanings than a
simple boolean. To prepare for enhanecements, the contract has been
adjusted to allow more states and make it possible for further additions
if those are needed by particular implementations.

Modifications:

- Deprecated `ServiceDiscovererEvent#isAvailable` method and added a
  default implementation to allow removal in child classes,
- Added `ServiceDiscoveryStatus` class,
- Added `ServiceDiscovererEvent#status` method with default
  implementation to prevent breaking the existing implementations,
- Replaced existing uses of `isAvailable` with comparisons of `status`
  against the constants in `ServiceDiscoveryStatus`,
- Added TODOs in order to reflect the need to adapt the codebase to
  support non-binary statuses.

Result:

`ServiceDiscovererEvent`s are prepared for more advanced, non-binary
statuses. An example is the now introduced `EXPIRED` event, which can have a
different meaning than `UNAVAILABLE`. If the `ServiceDiscoverer` decides
to emit such a status, the subscribers can provide additional
functionality in that case.
@chemicL chemicL force-pushed the service-discoverer-event-more-states branch from 250f6aa to 7946f9f Compare October 22, 2021 12:52
@chemicL chemicL added the breaking-change PR with breaking changes, removed APIs or other binary incompatibilities. label Oct 22, 2021
@@ -104,17 +107,18 @@ private ServiceDiscovererUtils() {
private static <T> List<ServiceDiscovererEvent<T>> relativeComplement(
Copy link
Member

Choose a reason for hiding this comment

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

In 0.42 we should move the whole ServiceDiscovererUtils to dns module as pkg-private. Not sure why it had to be in client-api-internal as public.

@chemicL chemicL force-pushed the service-discoverer-event-more-states branch from 37d69db to 952842c Compare October 28, 2021 12:28
@chemicL
Copy link
Contributor Author

chemicL commented Nov 10, 2021

Seems the build failure might be related to caching, as the error should not appear with the current state of the file mentioned.

/home/runner/work/servicetalk/servicetalk/servicetalk-client-api/src/main/java/io/servicetalk/client/api/DefaultServiceDiscovererEvent.java:37: warning - Tag @link: can't find DefaultServiceDiscovererEvent(Object, Status) in io.servicetalk.client.api.DefaultServiceDiscovererEvent

> Task :servicetalk-client-api:javadoc FAILED

Copy link
Member

@idelpivnitskiy idelpivnitskiy left a comment

Choose a reason for hiding this comment

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

The PR is marked as breaking-change, but is expected to land in 0.41. I don't see any breaking changes after the last comments will be addressed. Consider running scripts/japicmp.sh to make sure and remove the label.

LGTM after comments addressed. Feel free to ping if you want me to double-check before merging.

@chemicL
Copy link
Contributor Author

chemicL commented Nov 12, 2021

Seems the build failure might be related to caching, as the error should not appear with the current state of the file mentioned.

/home/runner/work/servicetalk/servicetalk/servicetalk-client-api/src/main/java/io/servicetalk/client/api/DefaultServiceDiscovererEvent.java:37: warning - Tag @link: can't find DefaultServiceDiscovererEvent(Object, Status) in io.servicetalk.client.api.DefaultServiceDiscovererEvent

> Task :servicetalk-client-api:javadoc FAILED

As a matter of fact, it seems to fail only in case of Java 8. Possibly caused by https://bugs.openjdk.java.net/browse/JDK-8031625. I submitted a follow up using the fully qualified name and that fixes the issue.

@chemicL chemicL removed the breaking-change PR with breaking changes, removed APIs or other binary incompatibilities. label Nov 12, 2021
@chemicL chemicL merged commit 237fecb into apple:main Nov 15, 2021
chemicL pushed a commit that referenced this pull request Nov 15, 2021
Motivation:

Current API of `ServiceDiscovererEvent` is capable of representing the
boolean status of the host being either available or not available. As
seen in the implementation of RoundRobinLoadBalancer`, the resulting
states from the Service Discovery system can have more meanings than a
simple boolean. To prepare for enhanecements, the contract has been
adjusted to allow more states and make it possible for further additions
if those are needed by particular implementations.

Modifications:

- Deprecated `ServiceDiscovererEvent#isAvailable` method and added a
  default implementation to allow removal in child classes,
- Added `ServiceDiscovererEvent.Status` class with `AVAILABLE`, `EXPIRED`, and `UNAVAILABLE` statuses,
- Added `ServiceDiscovererEvent#status` method with default
  implementation to prevent breaking the existing implementations,
- Replaced existing uses of `isAvailable` with comparisons of `status`
  against the constants in `ServiceDiscoveryStatus`,
- `DefaultDnsClient` is capable of returning either of `UNAVAILABLE` or `EXPIRED` statuses for missing records, according to setting in `DefaultDnsServiceDiscovererBuilder#missingRecordStatus`.
- `RoundRobinLoadBalancer` is able to act accordingly to received status,
- `RoundRobinLoadBalancer#eagerConnectionShutdown` setting has been adjusted to allow no influence over received status and provides functionality when necessary for mapping `UNAVAILABLE` to `EXPIRED` and vice-versa.

Result:

`ServiceDiscovererEvent`s are prepared for more advanced, non-binary
statuses. An example is the now introduced `EXPIRED` event, which has a
different meaning than `UNAVAILABLE`. If the `ServiceDiscoverer` decides
to emit such a status, the subscribers can provide additional
functionality in that case such as the behavior provided by `RoundRobinLoadBalancer`.
@chemicL
Copy link
Contributor Author

chemicL commented Nov 15, 2021

0.41: ad81b3f

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