question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consul tags are used as Spring Cloud metadata while Consul metadata is ignored in include-expression

See original GitHub issue

Describe the bug

spring.cloud.consul.discovery.metadata in services is ignored by spring.cloud.gateway.include-expression which instead uses tags as metadata.

I don’t know if the behaviour is intentional, but is incredible confusing and goes against all of limited examples(1,2) of how to do route filtering with include-expression in scg.

If nothing else, this issue can serve as some documentation for others who are searching to understand how they can restrict routes using metadata without needing to purchase Consul Enterprise to get access to Namespaces.

Sample

Configure the spring cloud gateway to use include-expression: metadata['edge'] == 'true' to include service routes that have metadata key value pair of “edge”,“true”.

spring:
    application:
        name: api-gateway
    cloud:
        consul:
            host: 192.168.1.100
            port: 8500
            discovery:
                instanceId: ${spring.application.name}:${random.value}

        # Basic gateway service mapping
        gateway:
            discovery:
                locator:
                  enabled: true
                  include-expression: metadata['edge'] == 'true' 
                predicates:
                  - name: Path
                    args:
                      pattern: "'/api/' + serviceId + '/**'"
                  filters:
                  - name: RewritePath
                    args:
                      regexp: "'/api/' + serviceId + '/(?<remaining>.*)'"
                      replacement: "'/${remaining}'"

The obvious thing to do is to send some metadata that says “edge” is “true” as part of service registration with consul…

spring:
    application:
        name: webservice
        consul:
            host: 192.168.1.100
            port: 8500
            config:
                enabled: true
                format: YAML
            discovery:
                instanceId: ${spring.application.name}:${random.value}
                metadata: 
                     edge: true

However, this DOES NOT WORK. The metadata is registered and present in the service configuration, but the gateway does not recognize this as a service matching the include-expression.

We must replace this:

                metadata: # Doesn't work with scg include-expression
                     edge: true

with this:

                tags: edge=true # this WORKS

Consul service tags are being used as metadata by scg for the purpose of evaluating include-expression.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
spencergibbcommented, Nov 2, 2020

in hoxton tags are still default you need to set spring.cloud.consul.discovery.tags-as-metadata=false

0reactions
deftdawgcommented, Nov 10, 2020

@spencergibb tags-as-metadata=false does resolve the issue. Upon googling, I see that is documented here: https://docs.spring.io/spring-cloud-consul/docs/current/reference/html/index.html#official-consul-metadata

Thanks pointing me in the right direction.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Cloud Consul
Spring Cloud Consul uses Consul tags to approximate metadata until Consul officially supports metadata. Tags with the form key=value will be split and...
Read more >
How to IgnoredPatterns in spring cloud gateway as zuul?
Then I used the label as a condition in the include-expression from the locator ... spring.cloud.kubernetes.discovery.metadata.labels-prefix.
Read more >
Part XVIII. Appendix: Compendium of Configuration Properties
Part XVIII. Appendix: Compendium of Configuration Properties ; spring.cloud.consul.discovery.management-tags. Tags to use when registering management service.
Read more >
微服务可配置属性一览大全Spring Cloud configuration properties
Enable tag override for the registered management service. spring.cloud.consul.discovery.management-metadata. `` Metadata to use when ...
Read more >
Part XIX. Appendix: Compendium of Configuration Properties
Spring Cloud provides tools for developers to quickly build some of the common ... spring.cloud.consul.discovery.default-zone-metadata-name.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found