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

Two problems in Ocelot Service Discovery using Consul #1304

Closed
cdyhj opened this issue Jul 28, 2020 · 3 comments · Fixed by #1670
Closed

Two problems in Ocelot Service Discovery using Consul #1304

cdyhj opened this issue Jul 28, 2020 · 3 comments · Fixed by #1670
Assignees
Labels
bug Identified as a potential bug merged Issue has been merged to dev and is waiting for the next release Service Discovery Ocelot feature: Service Discovery

Comments

@cdyhj
Copy link

cdyhj commented Jul 28, 2020

Expected Behavior / New Feature

Ocelot uses Consul for service discovery.

Actual Behavior / Motivation for New Feature

Ocelot uses Consul for service discovery.

Steps to Reproduce the Problem

  1. Using Ocelot and Ocelot.Provider.Consul Version 16.0.1
  2. The IP address obtained from the service is the name value of the node, not the actual IP address of the service
  3. The address of the service cannot be loaded when it is loaded for the first time. It can be used normally if it is refreshed again

Modification Ocelot.Provider.Consul

The BuildService method of the Consul class is as follows:

private Service BuildService(ServiceEntry serviceEntry, Node serviceNode)
{
            return new Service(
                serviceEntry.Service.Service,
                new ServiceHostAndPort(serviceEntry.Service.Address, serviceEntry.Service.Port),
                serviceEntry.Service.ID,
                GetVersionFromStrings(serviceEntry.Service.Tags),
                serviceEntry.Service.Tags ?? Enumerable.Empty<string>());
}

And Ocelot.Provider.Consul public Task<List<Service>> Get() of PollConsul class is as follows:

public  Task<List<Service>> Get()
{
    int PollNum = 0;
    if (_services.Count <= 0)
    {
        Poll().Wait();
    }
    return Task.FromResult(_services);
}

Specifications

  • Version: 16.0.1
@stann1
Copy link

stann1 commented Aug 6, 2020

I can confirm. I have Ocelot configured with Consul as service discovery. I have one service configured for load-balancing with "LoadBalancerOptions": { "Type": "RoundRobin" }

When I start the service it always gives 404 Error Code: ServicesAreEmptyError Message: There were no services in NoLoadBalancer errors found in ResponderMiddleware

Note - this issue SOMETIMES disappears after a few minutes. It is only on version 16.0.1. I was running 14.1.0 until now - but had to upgrade because load balancing was not working at all.

My consul config:
"ServiceDiscoveryProvider": { "Scheme": "http", "Host": "consul", "Port": 8500, "ConfigurationKey": "GatewayConfig", "Type": "Consul" }

EDIT: looks like general problem with Consul service discovery, because even when I remove the load balancing it is the same result...

@matteoPhre
Copy link

Same problem here. When I hit an API for the first time, always returns 404 ServicesAreEmptyError Message: services were empty for UsersService errors found in ResponderMiddleware.. If I try to call again the same api, with same headers and same body..everythings fine.

@raman-m raman-m changed the title Two problems in Ocelot's service discovery using consult Two problems in Ocelot Service Discovery using Consul Jun 22, 2023
@raman-m raman-m added bug Identified as a potential bug needs validation Issue has not been replicated or verified yet needs feedback Issue is waiting on feedback before acceptance Service Discovery Ocelot feature: Service Discovery labels Sep 18, 2023
@raman-m
Copy link
Member

raman-m commented Sep 18, 2023

@cdyhj @stann1 @matteoPhre
Hello! FYI
I believe the linked PR #1670 will fix this bug. You can review the code and validate the bug fix. And let me know yout testing results please!

@raman-m raman-m removed needs validation Issue has not been replicated or verified yet needs feedback Issue is waiting on feedback before acceptance labels Sep 18, 2023
raman-m added a commit that referenced this issue Sep 29, 2023
…ements and fix errors (#1670)

* fixing some issues in poll consul:
- Timer is not thread safe, avoiding usage of it
- No Ressources are returned for first call
- Using a providers pool, instead of creating a new provider instance

* line endings

* adding some test cases

* Using a lock instead of SemaphoreSlim

* Improve code readability

* CA2211: Non-constant fields should not be visible

* Use IOcelotLogger to remove warnings & messages of static code analysis (aka IDE0052)

* Fix errors with unit tests discovery. Remove legacy life hacks of discovering tests on .NET Core

* Update unit tests

* Also refactoring the kubernetes provider factory (like consul and eureka)

* shorten references...

* const before...

* Some minor fixes, using Equals Ordinal ignore case and a string constant for provider type definition instead of string litterals. Fixing usings.

* waiting a bit longer then?

* @RaynaldM code review

* renaming PollKubernetes to PollKube

* ... odd...

* ... very odd, we have an issue with configuration update duration...

* IDE0002: Name can be simplified

* All tests passing locally, hopefully it works online

* just a bit of cleanup

* Some missing braces and commas

* Update servicediscovery.rst: Review and update "Consul" section

---------

Co-authored-by: Guillaume Gnaegi <[email protected]>
Co-authored-by: raman-m <[email protected]>
@raman-m raman-m added the merged Issue has been merged to dev and is waiting for the next release label Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Identified as a potential bug merged Issue has been merged to dev and is waiting for the next release Service Discovery Ocelot feature: Service Discovery
Projects
None yet
4 participants