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

Getting a 404 when Consul is enabled #793

Closed
secret-agent-B opened this issue Feb 23, 2019 · 3 comments · Fixed by #1670
Closed

Getting a 404 when Consul is enabled #793

secret-agent-B opened this issue Feb 23, 2019 · 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

@secret-agent-B
Copy link

secret-agent-B commented Feb 23, 2019

I am able to successfully request data from an API when Consul is not enabled but when I turn on Consul, all I get is 404.

My Startup.cs looks like;

            services
                .AddOcelot(this.Configuration)
                .AddConsul()
                .AddConfigStoredInConsul();

Then my configuration looks like this in Consul.

{
  "ReRoutes": [
    {
      "DownstreamPathTemplate": "/{catch-all}",
      "UpstreamPathTemplate": "/ac/{catch-all}",
      "UpstreamHttpMethod": [
        "Get",
        "Post",
        "Put"
      ],
      "AddHeadersToRequest": {},
      "UpstreamHeaderTransform": {},
      "DownstreamHeaderTransform": {},
      "AddClaimsToRequest": {},
      "RouteClaimsRequirement": {
        "role": "User"
      },
      "AddQueriesToRequest": {},
      "RequestIdKey": null,
      "FileCacheOptions": {
        "TtlSeconds": 0,
        "Region": null
      },
      "ReRouteIsCaseSensitive": false,
      "ServiceName": "demo.services.aircraft.api",
      "DownstreamScheme": "http",
      "QoSOptions": {
        "ExceptionsAllowedBeforeBreaking": 0,
        "DurationOfBreak": 0,
        "TimeoutValue": 0
      },
      "LoadBalancerOptions": {
        "Type": null,
        "Key": null,
        "Expiry": 0
      },
      "RateLimitOptions": {
        "ClientWhitelist": [],
        "EnableRateLimiting": false,
        "Period": null,
        "PeriodTimespan": 0.0,
        "Limit": 0
      },
      "AuthenticationOptions": {
        "AuthenticationProviderKey": "demo-is4host",
        "AllowedScopes": [
          "demo-gateway-server"
        ]
      },
      "HttpHandlerOptions": {
        "AllowAutoRedirect": false,
        "UseCookieContainer": false,
        "UseTracing": false,
        "UseProxy": true
      },
      "DownstreamHostAndPorts": [
        {
          "Host": "demo.services.aircraft.api",
          "Port": 80
        }
      ],
      "UpstreamHost": null,
      "Key": null,
      "DelegatingHandlers": [],
      "Priority": 1,
      "Timeout": 0,
      "DangerousAcceptAnyServerCertificateValidator": false,
      "SecurityOptions": {
        "IPAllowedList": [],
        "IPBlockedList": []
      }
    },
    {
      "DownstreamPathTemplate": "/{catchAll}",
      "UpstreamPathTemplate": "/fd/{catchAll}",
      "UpstreamHttpMethod": [
        "Get"
      ],
      "AddHeadersToRequest": {},
      "UpstreamHeaderTransform": {},
      "DownstreamHeaderTransform": {},
      "AddClaimsToRequest": {},
      "RouteClaimsRequirement": {
        "role": "User"
      },
      "AddQueriesToRequest": {},
      "RequestIdKey": null,
      "FileCacheOptions": {
        "TtlSeconds": 0,
        "Region": null
      },
      "ReRouteIsCaseSensitive": false,
      "ServiceName": "demo.services.flightdata.api",
      "DownstreamScheme": "http",
      "QoSOptions": {
        "ExceptionsAllowedBeforeBreaking": 0,
        "DurationOfBreak": 0,
        "TimeoutValue": 0
      },
      "LoadBalancerOptions": {
        "Type": null,
        "Key": null,
        "Expiry": 0
      },
      "RateLimitOptions": {
        "ClientWhitelist": [],
        "EnableRateLimiting": false,
        "Period": null,
        "PeriodTimespan": 0.0,
        "Limit": 0
      },
      "AuthenticationOptions": {
        "AuthenticationProviderKey": "demo-is4host",
        "AllowedScopes": [
          "demo-gateway-server"
        ]
      },
      "HttpHandlerOptions": {
        "AllowAutoRedirect": false,
        "UseCookieContainer": false,
        "UseTracing": false,
        "UseProxy": true
      },
      "DownstreamHostAndPorts": [
        {
          "Host": "demo.services.flightdata.api",
          "Port": 80
        }
      ],
      "UpstreamHost": null,
      "Key": null,
      "DelegatingHandlers": [],
      "Priority": 1,
      "Timeout": 0,
      "DangerousAcceptAnyServerCertificateValidator": false,
      "SecurityOptions": {
        "IPAllowedList": [],
        "IPBlockedList": []
      }
    },
    {
      "DownstreamPathTemplate": "/connect/token",
      "UpstreamPathTemplate": "/is/token",
      "UpstreamHttpMethod": [
        "Post"
      ],
      "AddHeadersToRequest": {},
      "UpstreamHeaderTransform": {},
      "DownstreamHeaderTransform": {},
      "AddClaimsToRequest": {},
      "RouteClaimsRequirement": {},
      "AddQueriesToRequest": {},
      "RequestIdKey": null,
      "FileCacheOptions": {
        "TtlSeconds": 0,
        "Region": null
      },
      "ReRouteIsCaseSensitive": false,
      "ServiceName": null,
      "DownstreamScheme": "http",
      "QoSOptions": {
        "ExceptionsAllowedBeforeBreaking": 0,
        "DurationOfBreak": 0,
        "TimeoutValue": 0
      },
      "LoadBalancerOptions": {
        "Type": null,
        "Key": null,
        "Expiry": 0
      },
      "RateLimitOptions": {
        "ClientWhitelist": [],
        "EnableRateLimiting": false,
        "Period": null,
        "PeriodTimespan": 0.0,
        "Limit": 0
      },
      "AuthenticationOptions": {
        "AuthenticationProviderKey": null,
        "AllowedScopes": []
      },
      "HttpHandlerOptions": {
        "AllowAutoRedirect": false,
        "UseCookieContainer": false,
        "UseTracing": false,
        "UseProxy": true
      },
      "DownstreamHostAndPorts": [
        {
          "Host": "demo.services.is4host",
          "Port": 80
        }
      ],
      "UpstreamHost": null,
      "Key": null,
      "DelegatingHandlers": [],
      "Priority": 1,
      "Timeout": 0,
      "DangerousAcceptAnyServerCertificateValidator": false,
      "SecurityOptions": {
        "IPAllowedList": [],
        "IPBlockedList": []
      }
    },
    {
      "DownstreamPathTemplate": "/accounts/register",
      "UpstreamPathTemplate": "/is/accounts/register",
      "UpstreamHttpMethod": [
        "Post"
      ],
      "AddHeadersToRequest": {},
      "UpstreamHeaderTransform": {},
      "DownstreamHeaderTransform": {},
      "AddClaimsToRequest": {},
      "RouteClaimsRequirement": {},
      "AddQueriesToRequest": {},
      "RequestIdKey": null,
      "FileCacheOptions": {
        "TtlSeconds": 0,
        "Region": null
      },
      "ReRouteIsCaseSensitive": false,
      "ServiceName": null,
      "DownstreamScheme": "http",
      "QoSOptions": {
        "ExceptionsAllowedBeforeBreaking": 0,
        "DurationOfBreak": 0,
        "TimeoutValue": 0
      },
      "LoadBalancerOptions": {
        "Type": null,
        "Key": null,
        "Expiry": 0
      },
      "RateLimitOptions": {
        "ClientWhitelist": [],
        "EnableRateLimiting": false,
        "Period": null,
        "PeriodTimespan": 0.0,
        "Limit": 0
      },
      "AuthenticationOptions": {
        "AuthenticationProviderKey": null,
        "AllowedScopes": []
      },
      "HttpHandlerOptions": {
        "AllowAutoRedirect": false,
        "UseCookieContainer": false,
        "UseTracing": false,
        "UseProxy": true
      },
      "DownstreamHostAndPorts": [
        {
          "Host": "demo.services.is4host",
          "Port": 80
        }
      ],
      "UpstreamHost": null,
      "Key": null,
      "DelegatingHandlers": [],
      "Priority": 1,
      "Timeout": 0,
      "DangerousAcceptAnyServerCertificateValidator": false,
      "SecurityOptions": {
        "IPAllowedList": [],
        "IPBlockedList": []
      }
    },
    {
      "DownstreamPathTemplate": "/.well-known/openid-configuration",
      "UpstreamPathTemplate": "/is/wkoc",
      "UpstreamHttpMethod": [
        "Get"
      ],
      "AddHeadersToRequest": {},
      "UpstreamHeaderTransform": {},
      "DownstreamHeaderTransform": {},
      "AddClaimsToRequest": {},
      "RouteClaimsRequirement": {},
      "AddQueriesToRequest": {},
      "RequestIdKey": null,
      "FileCacheOptions": {
        "TtlSeconds": 0,
        "Region": null
      },
      "ReRouteIsCaseSensitive": false,
      "ServiceName": null,
      "DownstreamScheme": "http",
      "QoSOptions": {
        "ExceptionsAllowedBeforeBreaking": 0,
        "DurationOfBreak": 0,
        "TimeoutValue": 0
      },
      "LoadBalancerOptions": {
        "Type": null,
        "Key": null,
        "Expiry": 0
      },
      "RateLimitOptions": {
        "ClientWhitelist": [],
        "EnableRateLimiting": false,
        "Period": null,
        "PeriodTimespan": 0.0,
        "Limit": 0
      },
      "AuthenticationOptions": {
        "AuthenticationProviderKey": null,
        "AllowedScopes": []
      },
      "HttpHandlerOptions": {
        "AllowAutoRedirect": false,
        "UseCookieContainer": false,
        "UseTracing": false,
        "UseProxy": true
      },
      "DownstreamHostAndPorts": [
        {
          "Host": "demo.services.is4host",
          "Port": 80
        }
      ],
      "UpstreamHost": null,
      "Key": null,
      "DelegatingHandlers": [],
      "Priority": 1,
      "Timeout": 0,
      "DangerousAcceptAnyServerCertificateValidator": false,
      "SecurityOptions": {
        "IPAllowedList": [],
        "IPBlockedList": []
      }
    },
    {
      "DownstreamPathTemplate": "/connect/userinfo",
      "UpstreamPathTemplate": "/is/userinfo",
      "UpstreamHttpMethod": [
        "Get"
      ],
      "AddHeadersToRequest": {},
      "UpstreamHeaderTransform": {},
      "DownstreamHeaderTransform": {},
      "AddClaimsToRequest": {},
      "RouteClaimsRequirement": {},
      "AddQueriesToRequest": {},
      "RequestIdKey": null,
      "FileCacheOptions": {
        "TtlSeconds": 0,
        "Region": null
      },
      "ReRouteIsCaseSensitive": false,
      "ServiceName": null,
      "DownstreamScheme": "http",
      "QoSOptions": {
        "ExceptionsAllowedBeforeBreaking": 0,
        "DurationOfBreak": 0,
        "TimeoutValue": 0
      },
      "LoadBalancerOptions": {
        "Type": null,
        "Key": null,
        "Expiry": 0
      },
      "RateLimitOptions": {
        "ClientWhitelist": [],
        "EnableRateLimiting": false,
        "Period": null,
        "PeriodTimespan": 0.0,
        "Limit": 0
      },
      "AuthenticationOptions": {
        "AuthenticationProviderKey": null,
        "AllowedScopes": []
      },
      "HttpHandlerOptions": {
        "AllowAutoRedirect": false,
        "UseCookieContainer": false,
        "UseTracing": false,
        "UseProxy": true
      },
      "DownstreamHostAndPorts": [
        {
          "Host": "demo.services.is4host",
          "Port": 80
        }
      ],
      "UpstreamHost": null,
      "Key": null,
      "DelegatingHandlers": [],
      "Priority": 1,
      "Timeout": 0,
      "DangerousAcceptAnyServerCertificateValidator": false,
      "SecurityOptions": {
        "IPAllowedList": [],
        "IPBlockedList": []
      }
    }
  ],
  "DynamicReRoutes": [],
  "Aggregates": [],
  "GlobalConfiguration": {
    "RequestIdKey": "demo3-request",
    "ServiceDiscoveryProvider": {
      "Host": "consul",
      "Port": 8500,
      "Type": "Consul",
      "Token": null,
      "ConfigurationKey": null,
      "PollingInterval": 0
    },
    "RateLimitOptions": {
      "ClientIdHeader": "ClientId",
      "QuotaExceededMessage": null,
      "RateLimitCounterPrefix": "ocelot",
      "DisableRateLimitHeaders": false,
      "HttpStatusCode": 429
    },
    "QoSOptions": {
      "ExceptionsAllowedBeforeBreaking": 0,
      "DurationOfBreak": 0,
      "TimeoutValue": 0
    },
    "BaseUrl": null,
    "LoadBalancerOptions": {
      "Type": null,
      "Key": null,
      "Expiry": 0
    },
    "DownstreamScheme": null,
    "HttpHandlerOptions": {
      "AllowAutoRedirect": false,
      "UseCookieContainer": false,
      "UseTracing": false,
      "UseProxy": true
    }
  }
}

Questions:

  1. I don't have a load balancer but I still LeastConnection specified, is that a requirement? We have a very unique environment we have to operate on.

  2. In Consul web interface, I only get 1 service which is "consul". How do I add my other services in there? It'd be useful for me to tell whether a service is up or down from that dashboard.

  3. Right now, I register each service endpoint into the configuration.json manually because I need to be able to set the AuthenticationOptions and RouteClaimsRequirement for each of them and to be able to configure them in one place". Is that something I can configure in Consul then have Ocelot get the information from Consul?

image

Thanks!

@Weidaicheng
Copy link
Contributor

@raime910 Are you sure you configured consul correct? I mean consul configurations. And BTW the DownstreamHostAndPorts section is not needed when you turn on consul.

@bc4250
Copy link

bc4250 commented Jan 16, 2020

.AddConfigStoredInConsul();
@raime910
Is your issue resolved? I encounter the same problem, and remove upper code resolved my issue.

@raman-m
Copy link
Member

raman-m commented Sep 25, 2023

@secret-agent-B Hi Ryan!

image

Based on error from this screenshot,
I would say your problem is related to well-known Consul-Ocelot issue "Services were empty" aka ServicesAreEmptyError.
The PR #1670 should resolve the problem.

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 merged Issue has been merged to dev and is waiting for the next release Service Discovery Ocelot feature: Service Discovery labels 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