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

Add Nacos Support #5409

Merged
merged 63 commits into from
Nov 7, 2024
Merged

Add Nacos Support #5409

merged 63 commits into from
Nov 7, 2024

Conversation

KonaEspresso94
Copy link
Contributor

@KonaEspresso94 KonaEspresso94 commented Jan 25, 2024

Motivation:

Nacos is a service discovery application extensively used. By providing native support for Nacos, it will be beneficial to Armeria users.

#5360 #5365

Modification:

  • Add a nacos module.
  • Add NacosClient.
    Its internal implementation includes LoginClient for obtaining an accessToken through basic Nacos authentication, QueryInstancesClient for querying service instances, and RegisterInstanceClient for handling the registration and deregistration of instances.
  • Implement NacosEndpointGroup and NacosUpdatingListener.
  • Configure unit tests using Testcontainers and the Nacos image to facilitate actual call testing.

Result:

Closes #5365

Nacos discovery and instance registration functionalities are now integrated into Armeria.


In writing this code, I was strongly influenced by the implementation on the consul and eureka modules.
I appreciate your review and feedback. Thank you.

@CLAassistant
Copy link

CLAassistant commented Jan 25, 2024

CLA assistant check
All committers have signed the CLA.

KonaEspresso94 and others added 2 commits January 27, 2024 16:59
…stead of QueryParams, making it easier to append additional parameters (e.g., accessToken).
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.

The overall direction looks great.


private static final String NACOS_ACCESS_TOKEN_CACHE_KEY = "NACOS_ACCESS_TOKEN_CACHE_KEY";
private final AsyncLoadingCache<String, LoginResult> tokenCache = Caffeine.newBuilder()
.maximumSize(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional) It seems overkill to use Caffeine only for 1 element.
What do you think of creating a function that triggers loginInternal() if access tokens are expired while invoking login()?

If you find it more difficult than Caffeine approach, I'm okay to keep this as is.

@KonaEspresso94 KonaEspresso94 marked this pull request as draft February 9, 2024 13:58
@KonaEspresso94
Copy link
Contributor Author

@ikhoon

Thank you for your review comments. I've applied your suggestions into the code.

  • LoginClient now implements SimpleDecoratingHttpClient. Contexts related to 'nacos basic authentication' have been hidden as much as possible from other clients.
  • Caching access token by own implementation instead of Caffeine cache.
  • Changed the query string that was being created each time in LoginClient and QueryInstanceClient to be reused efficiently.
  • NacosUpdatingListener and RegisterInstanceClient are not guaranteed to always have the same endpoint used as parameter. Eventually, we will need to create a StringBuilder or QueryParamsBuilder. However, I have minimized the parameter of the API by turning immutable parameters into properties, such as in the above two clients.
  • Fixed some missing final.

The implementation to replace the Caffein, I made it as simple as possible. So now the login api can be called concurrently. Considering the usability of NacosUpdatingListener and NacosEndpointGroup, I think it's unlikely that concurrent calls will actually happen, and if they do, it won't be an issue. But I'm not sure. I'd be interested in your thoughts.

Thank you!

@KonaEspresso94 KonaEspresso94 marked this pull request as ready for review February 11, 2024 11:13
@github-actions github-actions bot added the Stale label Apr 15, 2024
@trustin
Copy link
Member

trustin commented May 8, 2024

@KonaEspresso94 Gentle ping - looking forward to having this feature merged 🙇

…r. + Properly pass the builder to the next chains in a builder-like manner (even if it's a mutable single object).
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.

Thanks, @KonaEspresso94. 🚀🙇‍♂️
Left a minor suggestion.

nacosClientBuilder.authorization(username, password);
return this;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

There is useHealthyEndpoints() method on the client side.
Should we also support health status when registering an instance?
https://nacos.io/en-us/docs/open-api.html#2.1

public String toString() {
return MoreObjects.toStringHelper(this)
.omitNullValues()
.add("accessToken", accessToken)
Copy link
Contributor

@ikhoon ikhoon Jul 25, 2024

Choose a reason for hiding this comment

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

Changed to use AuthToken because sensitive information should be excluded from serialization.

@ikhoon ikhoon modified the milestones: 1.30.0, 1.31.0 Aug 2, 2024
@github-actions github-actions bot added the Stale label Sep 3, 2024
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.

@KonaEspresso94 Sorry about the late review. Thanks a lot! 👍 👍 👍

@ikhoon ikhoon removed the Stale label Nov 7, 2024
@ikhoon ikhoon merged commit 0b36df3 into line:main Nov 7, 2024
12 of 14 checks passed
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.

Service discovery with Nacos
6 participants