Skip to content

Comments

#1 Create Nacos service discovery provider#2

Merged
raman-m merged 29 commits intomainfrom
main_Ocelot.Discovery.Nacos
May 27, 2025
Merged

#1 Create Nacos service discovery provider#2
raman-m merged 29 commits intomainfrom
main_Ocelot.Discovery.Nacos

Conversation

@MiaoShuYo
Copy link
Contributor

@MiaoShuYo MiaoShuYo commented Mar 19, 2025

@raman-m raman-m changed the title ocelot.discovery.nacos #1 Create Nacos service discovery provider Mar 19, 2025
@raman-m
Copy link
Member

raman-m commented Mar 19, 2025

🆗 Great! Thank you for creation this PR!
I'll review today...

Copy link
Member

@raman-m raman-m left a comment

Choose a reason for hiding this comment

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

Please organize the folder structure more efficiently.
There is no need to create sub-sub folders.

@raman-m
Copy link
Member

raman-m commented Mar 19, 2025

The solution and folder structure now appear satisfactory to me.

Copy link
Member

@raman-m raman-m left a comment

Choose a reason for hiding this comment

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

I've added GitHub Actions workflows. And the latest build job produced a number of warnings (see in Files changed).
Could you fix all of them please?

src/Nacos.cs Outdated

return new Service(
id: instance.InstanceId,
hostAndPort: new ServiceHostAndPort(instance.Ip, instance.Port),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
hostAndPort: new ServiceHostAndPort(instance.Ip, instance.Port),
hostAndPort: new(instance.Ip, instance.Port),

What is the scheme? Is the scheme known at this stage of building service?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When a client fetches a service, it will access the corresponding service based on the address information at the time of registration, so if the registration is for an HTTPS address, then the fetched service is HTTPS, and vice versa.

Copy link
Member

Choose a reason for hiding this comment

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

So, in the Nacos service discovery, scheme (protocol) management is not required, right?
For example, in Kubernetes we can manage the protocol while registering a service instance in the K8s registry.
In the next round of development, we will write acceptance tests that will show real usage in practice.

Copy link
Member

@raman-m raman-m left a comment

Choose a reason for hiding this comment

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

Please fix warnings generated by static code analysis tool during execution of latest GitHub action build.

@raman-m
Copy link
Member

raman-m commented Mar 21, 2025

Miao, what is the current code coverage achieved by unit tests?
Did you measure it?

@MiaoShuYo
Copy link
Contributor Author

Miao, what is the current code coverage achieved by unit tests? Did you measure it?

image

@raman-m
Copy link
Member

raman-m commented Mar 21, 2025

61% coverage is low.
We must achieve 100% because the lib has low amount of lines.

@MiaoShuYo
Copy link
Contributor Author

61% coverage is low. We must achieve 100% because the lib has low amount of lines.

Test coverage 100%
image

@raman-m raman-m force-pushed the main_Ocelot.Discovery.Nacos branch from 4b53651 to d7c7c33 Compare March 22, 2025 09:38
Copy link
Member

@raman-m raman-m left a comment

Choose a reason for hiding this comment

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

I recommend using IOcelotLogger instead of ILogger<Nacos>.

After this minor refactoring, I will verify the actual code coverage through unit tests once again.

Copy link
Member

@raman-m raman-m left a comment

Choose a reason for hiding this comment

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

Thank you for addressing the issues from the previous code review! ❤️

The repository looks much better now with the initial solution and unit testing in place. However, I am concerned that it has not been tested with real HTTP requests. It would be prudent commence acceptance testing at this stage. We need to conduct load testing to ensure that the provider can handle a high number of parallel requests.

  1. I'm going to add a commit with a draft version of the acceptance testing project.
  2. Please find below my additional suggestions for improving the code.

id: instance.InstanceId,
hostAndPort: new(instance.Ip, instance.Port),
name: instance.ServiceName,
version: metadata.GetValueOrDefault("version", "default"),
Copy link
Member

Choose a reason for hiding this comment

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

I cannot get this default value. Could you show me in Nacos docs please that default version is marked as "default"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The version value is not explicitly defined as "default" in the Nacos documentation. The "default" value in the code is a custom fallback in case there is no "version" key in the metadata dictionary.

Copy link
Member

Choose a reason for hiding this comment

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

You confirmed that this is the issue. I am not certain but these values may be applicable: current, latest, default.
Question: How can the default be consumed by Ocelot or Nacos client?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The version can be customized through the configuration file.

src/Nacos.cs Outdated
private static string FormatTag(KeyValuePair<string, string> kv)
=> $"{WebUtility.UrlEncode(kv.Key)}={WebUtility.UrlEncode(kv.Value)}";

private static readonly string[] _reservedKeys = { "version", "group", "cluster", "namespace", "weight" };
Copy link
Member

Choose a reason for hiding this comment

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

It might be better to make this definition public.
Could you provide some links to metadata documentation that explain this?
I suggest writing an XML documentation (in the code) for the definition of the array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the nacos java version of the sdk, these are included by default, but in the nacos .net sdk these are not included by default and need to be added by yourself.

Copy link
Member

Choose a reason for hiding this comment

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

Please make this array publicly accessible, then.

builder.Services
.AddNacosAspNet(builder.Configuration,section)
.AddSingleton(NacosProviderFactory.Get)
.AddSingleton(NacosMiddlewareConfigurationProvider.Get);
Copy link
Member

Choose a reason for hiding this comment

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

Just a word of caution!
It might be premature to define this since you were inspired by the Consul provider and ConsulMiddlewareConfigurationProvider implementation. However, please note that this Consul config provider was developed specifically for the AddConfigStoredInConsul() feature, correct?
Therefore, let's keep it in the code for now, the next phase of acceptance testing will reveal the subsequent steps.

@raman-m
Copy link
Member

raman-m commented Mar 24, 2025

Hello, Miao!
As you've already noticed, I added the acceptance testing project. This is a very draft version, serving as a skeleton for a future well-developed project. The current code is compilable, with no errors after running dotnet build command.
The main testing class is NacosServiceDiscoveryTests

Current pitfalls of the project:

  • The main class, NacosServiceDiscoveryTests, was copied from the KubernetesServiceDiscoveryTests class. As a result, the draft tests currently fail. We could draw inspiration from the ConsulServiceDiscoveryTests class as well.

  • The NacosServiceDiscoveryTests class inherits from ConcurrentSteps, which itself was copied from both ConcurrentSteps and Steps.

  • The remaining classes were copied from the Ocelot.AcceptanceTests codebase. This is far from ideal, and in the future, we must release a separate testing package. Don’t worry, I have a plan for that. For now, let’s save time by reusing code from the Ocelot repository.

Finally, I believe that releasing this package for .NET 6+8 with the draft acceptance testing project is acceptable. However, we must develop real tests, and they must pass.

Let's go!

@raman-m
Copy link
Member

raman-m commented Mar 24, 2025

@MiaoShuYo commented on March 21

Test coverage 100%

🆗 I am curious to know which IDE and code coverage did you utilize for measurement?

@MiaoShuYo
Copy link
Contributor Author

@MiaoShuYo commented on March 21

Test coverage 100%

🆗 I am curious to know which IDE and code coverage did you utilize for measurement?

Rider

@raman-m
Copy link
Member

raman-m commented Mar 26, 2025

Please work on the acceptance tests as they are a required part of the PR process. Afterward, I will assist you in writing documentation. Do not hesitate to ask questions, I understand that acceptance testing can be a challenging milestone.

P.S. Currently I am occupied with the release of the Ocelot version for .NET9. Apologies for being very busy at moment.

@MiaoShuYo
Copy link
Contributor Author

I am very sorry that I recently had an operation due to an accident, so I cannot carry out relevant development for the time being. It is expected to be suspended for three to five months.

@raman-m
Copy link
Member

raman-m commented Mar 31, 2025

Wow, I'm saddened to hear that! I wish you a smooth and speedy recovery. 💟

P.S. Since development will be suspended for the next X months, I need to inform you that the package will not be released. The version for .NET 9 will be released after your return to development. In the meantime, within the next 1–2 months, I’ll try to release a very draft version for the current TFMs: net6.0, net7.0, and net8.0. However, I cannot guarantee that this draft version will function correctly in production. Regardless, I’ll wait for your return to development, as thorough testing of the future package in production will be highly desirable.

@raman-m raman-m requested review from RaynaldM, ggnaegi and raman-m May 27, 2025 14:42
@raman-m
Copy link
Member

raman-m commented May 27, 2025

@MiaoShuYo Hello, Miao!
How are you feeling these days?

FYI, I will review the pull request and merge it as-is because I need some actual code for CI-CD.
Following that I will set up the CI-CD workflows, and I will update the TFMs to net8.0 and net9.0.

Copy link
Member

@raman-m raman-m left a comment

Choose a reason for hiding this comment

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

After updating the packages, I realized that updating the target framework monikers is impossible. So, TFMs remain net6.0 and net8.0 because the integrated nacos-sdk-csharp package explicitly targets these TFMs.

Ready for merging but not for delivery

Please note ❕ Following the merging of this PR we will proceed with following actions →

  • Configure CI-CD (GitHub Actions) for package delivery (assigned to @raman-m).
  • Develop acceptance tests, which are currently absent and are draft (assigned to @MiaoShuYo and @raman-m).

@raman-m raman-m merged commit 3dd718f into main May 27, 2025
1 check passed
@raman-m raman-m deleted the main_Ocelot.Discovery.Nacos branch May 27, 2025 16:33
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.

It is recommended to add support for Nacos

2 participants