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.

Add a possibility to change service name dynamically because of Consul tags

See original GitHub issue

Hello,

At the moment service name is chosen based on first segment in the path. I would like to be able to map one (or multiple) path segments to service name in Consul.

Few examples: authorization => would mapped to authorization.service.web authorization/api => would be mapped to authorization.service.api

Reason for this, that my routes are defined in Consul tags and I would like to use them as a key when selecting service name in Consul. At the moment to achieve this I have to replace whole DownstreamRouteCreator class, while I would be keen to keep custom part as small as possible.

Would you mind if I make a PR for this?

So something like:

    public interface IServiceNameProvider
    {
        string GetServiceName(string upstreamUrlPath);
    }

    public class ServiceNameProvider: IServiceNameProvider
    {
        public string GetServiceName(string upstreamUrlPath)
        {
            if (upstreamUrlPath.IndexOf('/', 1) == -1)
            {
                return upstreamUrlPath
                    .Substring(1);
            }

            return upstreamUrlPath
                .Substring(1, upstreamUrlPath.IndexOf('/', 1))
                .TrimEnd('/');
        }
    }

and use this such provider in CustomDownstreamRouteCreator class.

with best regards

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
mantasaudickascommented, Aug 1, 2023

Will you push some commit soon?

Sorry, no chance…

But you can do it on your own… just IDownstreamServiceFinder should have this signature:

string GetServiceName(HttpRequest request)
1reaction
mantasaudickascommented, Jul 28, 2023

In the example above authorization is like a DNS name, right?

Not really. Path is just a key to configuration item. That item has all necessary information about downstream service.

To be honest - now I would do this PR a bit differently. Finder should take HttpRequest as parameter and then you can have various logics in routing where service instance can be identified by:

  • path prefix
  • query parameter
  • host name
  • request header
  • even port

In microservices world where services are created and registered kind of dynamically such kind of flexibility is necessary. In our infrastructure there are hundreds of microservices running and routing rules might vary quite a lot thus in application gateway a lot of flexibility is required 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamically set service tags tags
I have a scenario where I've got a database cluster running, and would like the clients to use a Consul DNS address (e.g. ......
Read more >
Dynamic tags applied like health checks. #1048
I would like to have master.mongodb.service.consul resolve to the one IP of the master ... Set up my service definition with dynamic tags....
Read more >
Remotely update service tags on client node - Consul
I want to update tag value in client node config files. I do it manually by SSHing the node and updating the tag...
Read more >
Dynamic traffic tagging with Consul - luisico
This exercise is a way to show built-in service discovery, tagging and k/v capabilities in Consul. It's not production ready configuration, so ...
Read more >
Consul nodes and service are not getting created/updated ...
Because the service objects are connected to the node objects by name, the Consul provider can't tell that nodes are being replaced when ......
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