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

Allow filtering of services in discovery client route locator #185

Closed
pravinkumarb84 opened this issue Feb 8, 2018 · 15 comments
Closed
Milestone

Comments

@pravinkumarb84
Copy link

Do we have implementation for ignoredServices and ignoredPatterns in gateway as in zuul?

@ryanjbaxter
Copy link
Contributor

The gateway isnt proactive like Zuul is and automatically creates routes based on service discovery they have to be explicitly configured (as far as I know). Can you provide an example of where this would be necessary?

@spencergibb
Copy link
Member

I'd rather have some metadata that is set that would tell the integration to setup a route (edge=true) or something. @ryanjbaxter internal only services come to mind.

@spencergibb spencergibb changed the title ignoredServices and ignoredPatterns in gateway as in zuul Allow filtering of services in discovery client route locator Mar 1, 2018
@spencergibb spencergibb added this to the 2.0.0.RC1 milestone Apr 24, 2018
@spencergibb
Copy link
Member

You can now specify an expression that works on the ServiceInstace to test if the particular service should be included in as a route.

Setting spring.cloud.gateway.discovery.locator.include-expression=metadata['edge'] == 'true' will test for a metadata field named edge whose value is true.

@gewure
Copy link

gewure commented Jul 15, 2019

The gateway isnt proactive like Zuul is and automatically creates routes based on service discovery they have to be explicitly configured (as far as I know). Can you provide an example of where this would be necessary?

In my Zoo i have some services that should be gatewayed' and others that don't and should be ingnored-services as in zuul. How to achieve a functionality like in zuul?

@ryanjbaxter
Copy link
Contributor

You can now specify an expression that works on the ServiceInstace to test if the particular service should be included in as a route.

Setting spring.cloud.gateway.discovery.locator.include-expression=metadata['edge'] == 'true' will test for a metadata field named edge whose value is true.

@gewure
Copy link

gewure commented Jul 25, 2019

You can now specify an expression that works on the ServiceInstace to test if the particular service should be included in as a route.

Setting spring.cloud.gateway.discovery.locator.include-expression=metadata['edge'] == 'true' will test for a metadata field named edge whose value is true.

im sorry, i don't get it.
e.g. if i have 3 services, eureka name: "backend", "stream", "oldbackend" and i want to include discovery of backend and stream, but not of oldbackend.. i would set:

spring.cloud.gateway.discovery.locator.include-expression=metadata['backend','stream'] == 'true'

?

@spencergibb
Copy link
Member

No, you would include a bit of metadata in the discovery configuration of each service that you want in gateway such as 'edge=true'. Then gateway will only include those.

@gewure
Copy link

gewure commented Jul 25, 2019

No, you would include a bit of metadata in the discovery configuration of each service that you want in gateway such as 'edge=true'. Then gateway will only include those.

i see.

.. so for my "backend" and "stream" service i'd do

spring:
  cloud:
    discovery:
      client:
        simple:
          local:
            metadata:
              isongateway: true

in the bootstrap.yml of the backend and stream service and then check on the gateway via spring.cloud.gateway.discovery.locator.include-expression=metadata['isongateway']=='true' --- and all other services, though still discovered by eureka, are not reachable via gateway.

@gewure
Copy link

gewure commented Jul 28, 2019

@spencergibb @ryanjbaxter this works nice, thanks for support. keep up the good work!

@xiaoshao
Copy link

@spencergibb @ryanjbaxter What is about the IgnoredPatterns? There is some rest interface is internal in some service.

@spencergibb
Copy link
Member

@xiaoshao if you have read thru this issue, you'll see that is not necessary and there is no ignore services in gateway

@Alos
Copy link

Alos commented Dec 2, 2023

@spencergibb @ryanjbaxter do you know if the spring.cloud.gateway.discovery.locator.include-expression works for all DiscoveryClient implementations? i.e Would Spring Cloud Kubernetes discovery work with this?

@spencergibb
Copy link
Member

It works on the API but the implementation, so yes, it should work.

@Alos
Copy link

Alos commented Dec 2, 2023

I'm having issues getting it to work. I've configured the following in the gateway:

  cloud:
    gateway:
      discovery:
        locator:
          enabled: true
          url-expression: "'http://'+serviceId+':8080'"
          include-expression: metadata['edge']=='true'

Does that look OK to you? Is there a bean or class that gets the metadata that I can debug or turn on logging to confirm that the DiscoverClient passes the metadata to the gateway locator? I guess its the DiscoveryClientRouteDefinitionLocator?

@spencergibb
Copy link
Member

Please open a new issue and we will continue it there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants