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

eureka: allow overriding the healthCheckUrlPath #5369

Merged
merged 6 commits into from Jan 24, 2024

Conversation

codefromthecrypt
Copy link
Contributor

@codefromthecrypt codefromthecrypt commented Jan 4, 2024

Motivation:

Zipkin has a custom health check service, in addition to the normal
one of type HealthCheckService. This is used to create a custom json
response and predated our use of Armeria. This custom one is mounted at
the path "/health" while the default is "/internal/health".

We recently added Eureka registration, but were not able to change the
path component without having to supply the scheme, host and port as
well. To work around this is a bit hacky, and I would like to remove it
as it cause log warnings.

This change is already supported upstream for similar reasons. See
https://github.com/Netflix/eureka/blob/2b09d77534eae703a36f79f99b27b4d6ed66c3f8/eureka-client/src/main/java/com/netflix/appinfo/InstanceInfo.java#L663-L666

Modifications:

  • Added a healthCheckUrlPath property to InstanceInfo and
    corresponding builders, using a custom constructor to avoid
    serializing it to JSON.
  • Modified to use this instead of the default path when set.
  • Added an integration test.

Result:

  • Health check paths are overridable.

@codefromthecrypt
Copy link
Contributor Author

For context, here is our custom health check controller for /health

https://github.com/openzipkin/zipkin/blob/9cbe698b5bac7cc8ae89cec5d3aa237625fd3947/zipkin-server/src/main/java/zipkin2/server/internal/health/ZipkinHealthController.java#L46

The work around is to redundantly set the same path in config

https://github.com/openzipkin/zipkin/blob/master/zipkin-server/src/main/resources/zipkin-server-shared.yml#L225

just this isn't nice because it makes this log warning

zipkin  | 2024-01-04 14:26:25:588 [main] WARN RejectedRouteHandler - Virtual host '*' has a duplicate route: /health

p.s. I'll fix lint once I get an impression this would be an acceptable change.

@codefromthecrypt
Copy link
Contributor Author

ps I can see in other tests that it is complicated to compare against the expected local host name. I'll fix that also, if someone nods the change is viable in principle.

@codefromthecrypt codefromthecrypt marked this pull request as draft January 4, 2024 23:56
@codefromthecrypt
Copy link
Contributor Author

draft until decision is made (and I fix up is it is a go!)

Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

Hey, thanks for the PR. 😉
I'm so happy that you've returned to maintain Zipkin!

@codefromthecrypt codefromthecrypt marked this pull request as ready for review January 9, 2024 23:22
@codefromthecrypt codefromthecrypt changed the title eureka: allow overriding the healthCheckPath eureka: allow overriding the healthCheckUrlPath Jan 9, 2024
@codefromthecrypt
Copy link
Contributor Author

ok ready to go. Thanks for the tips @minwoox!

Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

Left a couple of nits. Thanks!

InstanceStatus status,
@Nullable String homePageUrl,
@Nullable String statusPageUrl,
@Nullable String healthCheckUrlPath, // Not in JSON
Copy link
Member

Choose a reason for hiding this comment

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

Global comment. How about just healthCheckPath?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh I matched upstream after looking at it. I like healthCheckPath better so fine with changing it back. wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, then let's leave it as is. Thanks!

secureHealthCheckUrl, oldInfo.getDataCenterInfo(),
oldInfo.getLeaseInfo(), oldInfo.getMetadata());
oldInfo.getHomePageUrl(), oldInfo.getStatusPageUrl(),
oldInfo.getHealthCheckUrlPath(), healthCheckUrl, secureHealthCheckUrl,
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of introducing two fields?

private final InstanceInfo originalInstanceInfo;
@Nullable
private InstanceInfo filledInstanceInfo;

so that we can call the original constructor of the InstanceInfo and make the newly-added one package-private?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I bet your suggestion will work.. lemme think about it and try

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got closer.. I'll make another comment

Copy link
Contributor Author

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

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

notes!

@@ -241,9 +251,10 @@ InstanceInfo build() {
final LeaseInfo leaseInfo = new LeaseInfo(renewalIntervalSeconds, leaseDurationSeconds);
return new InstanceInfo(instanceId, appName, appGroupName, hostname, ipAddr, vipAddress,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

so the constructor needs to be accessible outside the package because interestingly the builder for instanceinfo is not in the same package as instanceinfo! Another way is to move this builder to common, then either re-use it here as-is, or extend or delegate to the common one.

Another way is to make a special copy factory function in instanceinfo like.. InstanceInfo.WithHealthCheckUrlPath

depends on what you feel is best (or something else, @minwoox!)

Copy link
Member

Choose a reason for hiding this comment

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

Oops, I missed it. 😓 Let's leave it as is.
I will make the constructor package-private after #4243 is merged.

final String defaultHostname = server.defaultHostname();
final String hostName = oldInfo.getHostName() != null ? oldInfo.getHostName() : defaultHostname;
appName = oldInfo.getAppName() != null ? oldInfo.getAppName() : hostName;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this field mutation was indescribable in the function name, so I moved it out and made the function static to prevent a recurrence!

Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

Thanks, @codefromthecrypt! 😄

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Looks nice! Thanks, @codefromthecrypt and @minwoox. 🙇‍♂️🙇‍♂️

final String baseURL = sessionProtocol.uriText() + "://" +
hostnameOrIpAddr(hostnameOrIpAddr) + ':' + portWrapper.getPort();
if (oldHealthCheckUrlPath != null) {
return baseURL + oldHealthCheckUrlPath;
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor) Should we check if oldHealthCheckUrlPath starts with / when the value is first set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure good idea

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PTAL

@ikhoon ikhoon added this to the 1.27.0 milestone Jan 23, 2024
Motivation:

Zipkin has a custom health check service, in addition to the normal
one of type `HealthCheckService`. This is used to create a custom json
response and predated our use of Armeria. This custom one is mounted at
the path "/health" while the default is "/internal/health".

We recently added Eureka registration, but were not able to change the
path component without having to supply the scheme, host and port as
well. To work around this is a bit hacky, and I would like to remove it
as it cause log warnings.

This change is already supported upstream for similar reasons. See
https://github.com/Netflix/eureka/blob/2b09d77534eae703a36f79f99b27b4d6ed66c3f8/eureka-client/src/main/java/com/netflix/appinfo/InstanceInfo.java#L663-L666

Modifications:

- Added a `healthCheckUrlPath` property to `InstanceInfo` and
  corresponding builders, using a custom constructor to avoid
  serializing it to JSON.
- Modified to use this instead of the default path when set.
- Added an integration test.

Result:

- Health check paths are overridable.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
@codefromthecrypt
Copy link
Contributor Author

maybe there's a flakey test, can you kick 11's build?

ContentPreviewingFailureTest > shouldCompleteLogWhenExceptionIsThrown(String, int) > [3] path=/unexpected-exception, status=500 FAILED
    java.lang.AssertionError: 
    Expecting actual not to be null
        at com.linecorp.armeria.server.logging.ContentPreviewingFailureTest.shouldCompleteLogWhenExceptionIsThrown(ContentPreviewingFailureTest.java:100)

@minwoox
Copy link
Member

minwoox commented Jan 24, 2024

maybe there's a flakey test, can you kick 11's build?

Oh, please don't worry about it. 😉

Copy link
Contributor

@jrhee17 jrhee17 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! Only left super minor comments regarding style. Thanks @codefromthecrypt 🙇 👍 🙇

…UpdatingListener.java

Co-authored-by: jrhee17 <guins_j@guins.org>
codefromthecrypt and others added 2 commits January 24, 2024 11:00
…UpdatingListener.java

Co-authored-by: jrhee17 <guins_j@guins.org>
…UpdatingListener.java

Co-authored-by: jrhee17 <guins_j@guins.org>
@codefromthecrypt
Copy link
Contributor Author

thanks for the help @jrhee17!

@minwoox minwoox merged commit ac4b0e8 into line:main Jan 24, 2024
13 of 14 checks passed
@minwoox
Copy link
Member

minwoox commented Jan 24, 2024

Thanks, @codefromthecrypt! 😄

@codefromthecrypt codefromthecrypt deleted the eureka-healthCheckPath branch January 24, 2024 11:06
minwoox added a commit to minwoox/armeria that referenced this pull request Feb 15, 2024
…reka using path properties.

Motivation:
Following up on the improvements introduced in line#5369,
it's beneficial to extend the autofill feature to include `homePageUrl` and `statusPageUrl` of an `InstanceInfo`.
This enhancement streamlines configuration by automatically populating these URLs based on corresponding path properties.

Modifications:
- Introduce `homePageUrlPath` and `statusPageUrlPath` properties to `InstanceInfo` and their respective builders.
- Implement autofill functionality for `homePageUrl` and `statusPageUrl` using the configured path properties.

Result:
- `homePageUrl` and `statusPageUrl` of an `InstanceInfo` in Eureka are correctly set if corresponding path properties are configured.
- Close line#5464
jrhee17 pushed a commit that referenced this pull request Feb 19, 2024
…reka using path properties. (#5465)

Motivation:
Following up on the improvements introduced in
#5369, it's beneficial to extend the
autofill feature to include `homePageUrl` and `statusPageUrl` of an
`InstanceInfo`. This enhancement streamlines configuration by
automatically populating these URLs based on corresponding path
properties.

Modifications:
- Introduce `homePageUrlPath` and `statusPageUrlPath` properties to
`InstanceInfo` and their respective builders.
- Implement autofill functionality for `homePageUrl` and `statusPageUrl`
using the configured path properties.

Result:
- `homePageUrl` and `statusPageUrl` of an `InstanceInfo` in Eureka are
correctly set if corresponding path properties are configured.
- Close #5464
jrhee17 pushed a commit to jrhee17/armeria that referenced this pull request Mar 4, 2024
…reka using path properties. (line#5465)

Motivation:
Following up on the improvements introduced in
line#5369, it's beneficial to extend the
autofill feature to include `homePageUrl` and `statusPageUrl` of an
`InstanceInfo`. This enhancement streamlines configuration by
automatically populating these URLs based on corresponding path
properties.

Modifications:
- Introduce `homePageUrlPath` and `statusPageUrlPath` properties to
`InstanceInfo` and their respective builders.
- Implement autofill functionality for `homePageUrl` and `statusPageUrl`
using the configured path properties.

Result:
- `homePageUrl` and `statusPageUrl` of an `InstanceInfo` in Eureka are
correctly set if corresponding path properties are configured.
- Close line#5464
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants