These are chat archives for spring-cloud/spring-cloud

29th
Nov 2017
Dmitry
@dementiev
Nov 29 2017 14:47
Hello everybody, i have a question posted on SO https://stackoverflow.com/questions/47531708/grails-2-4-application-as-spring-cloud-microservice Please, propose your ideas
Marcin Grzejszczak
@marcingrzejszczak
Nov 29 2017 14:51
you can use Spring Cloud Netflix to register your app in Eureka. I don't understand your problem.
if you can't use Spring Cloud then you can use Netflix Eureka client directly
Dmitry
@dementiev
Nov 29 2017 14:52
problem that it is grails app, it is not clear for me how to register grails 2.4 app in eureka
Marcin Grzejszczak
@marcingrzejszczak
Nov 29 2017 14:55
have you tried looking at the Netflix wiki? https://github.com/Netflix/eureka/wiki/Eureka-2.0-Client-Configuration-And-Use (I don't know if that's the proper page, but I guess you need to google yourself a little bit)
Dmitry
@dementiev
Nov 29 2017 15:00
thanks, will try to do it like this
Markus Plangg
@mksplg
Nov 29 2017 15:02
Hi, could you point me to some documentation on sending Spring Cloud Spectator monitoring data to CloudWatch
mohanrao
@mohanrao
Nov 29 2017 17:46
I need help in the spring cloud zuul routing
@mohanrao
I have a route to forward like /services/fooservice to downstream service to endpoint /
I have used to routing as path as zuul.routes.foo.path=/services/fooservice
it's not stripping the prefix
'code' protected Route getRoute(ZuulRoute route, String path) {
if (route == null) {
return null;
}
if (log.isDebugEnabled()) {
log.debug("route matched=" + route);
}
String targetPath = path;
String prefix = this.properties.getPrefix();
if (path.startsWith(prefix) && this.properties.isStripPrefix()) {
targetPath = path.substring(prefix.length());
}
if (route.isStripPrefix()) {
int index = route.getPath().indexOf("*") - 1;
if (index > 0) {
String routePrefix = route.getPath().substring(0, index);
targetPath = targetPath.replaceFirst(routePrefix, "");
prefix = prefix + routePrefix;
}
}
Boolean retryable = this.properties.getRetryable();
if (route.getRetryable() != null) {
retryable = route.getRetryable();
}
return new Route(route.getId(), targetPath, route.getLocation(), prefix,
retryable,
route.isCustomSensitiveHeaders() ? route.getSensitiveHeaders() : null);
}
'code'
Marcin Grzejszczak
@marcingrzejszczak
Nov 29 2017 17:49
please use 3 x ` instead of code
mohanrao
@mohanrao
Nov 29 2017 17:49
seems the targetpath identification logic has the issue
protected Route getRoute(ZuulRoute route, String path) { if (route == null) { return null; } if (log.isDebugEnabled()) { log.debug("route matched=" + route); } String targetPath = path; String prefix = this.properties.getPrefix(); if (path.startsWith(prefix) && this.properties.isStripPrefix()) { targetPath = path.substring(prefix.length()); } if (route.isStripPrefix()) { int index = route.getPath().indexOf("*") - 1; if (index > 0) { String routePrefix = route.getPath().substring(0, index); targetPath = targetPath.replaceFirst(routePrefix, ""); prefix = prefix + routePrefix; } } Boolean retryable = this.properties.getRetryable(); if (route.getRetryable() != null) { retryable = route.getRetryable(); } return new Route(route.getId(), targetPath, route.getLocation(), prefix, retryable, route.isCustomSensitiveHeaders() ? route.getSensitiveHeaders() : null); }
protected Route getRoute(ZuulRoute route, String path) { if (route == null) { return null; } if (log.isDebugEnabled()) { log.debug("route matched=" + route); } String targetPath = path; String prefix = this.properties.getPrefix(); if (path.startsWith(prefix) && this.properties.isStripPrefix()) { targetPath = path.substring(prefix.length()); } if (route.isStripPrefix()) { int index = route.getPath().indexOf("*") - 1; if (index > 0) { String routePrefix = route.getPath().substring(0, index); targetPath = targetPath.replaceFirst(routePrefix, ""); prefix = prefix + routePrefix; } } Boolean retryable = this.properties.getRetryable(); if (route.getRetryable() != null) { retryable = route.getRetryable(); } return new Route(route.getId(), targetPath, route.getLocation(), prefix, retryable, route.isCustomSensitiveHeaders() ? route.getSensitiveHeaders() : null); }
mohanrao
@mohanrao
Nov 29 2017 17:51
protected Route getRoute(ZuulRoute route, String path) {
        if (route == null) {
            return null;
        }
        if (log.isDebugEnabled()) {
            log.debug("route matched=" + route);
        }
        String targetPath = path;
        String prefix = this.properties.getPrefix();
        if (path.startsWith(prefix) && this.properties.isStripPrefix()) {
            targetPath = path.substring(prefix.length());
        }
        if (route.isStripPrefix()) {
            int index = route.getPath().indexOf("*") - 1;
            if (index > 0) {
                String routePrefix = route.getPath().substring(0, index);
                targetPath = targetPath.replaceFirst(routePrefix, "");
                prefix = prefix + routePrefix;
            }
        }
        Boolean retryable = this.properties.getRetryable();
        if (route.getRetryable() != null) {
            retryable = route.getRetryable();
        }
        return new Route(route.getId(), targetPath, route.getLocation(), prefix,
                retryable,
                route.isCustomSensitiveHeaders() ? route.getSensitiveHeaders() : null);
    }
In the above code target path generation is causing problem
it is looking for star presence and causing the target path to be the same path
@marcingrzejszczak Thank you for markdown help!
Marcin Grzejszczak
@marcingrzejszczak
Nov 29 2017 17:57
n
p
mohanrao
@mohanrao
Nov 29 2017 18:24
I am trying to understand how the stripPrefix property works
Ryan Baxter
@ryanjbaxter
Nov 29 2017 18:26
Zuul should strip the prefix unless disabled
mohanrao
@mohanrao
Nov 29 2017 18:27
I am using the out of box configuration nothing disabled/enabled
On every route isStripPrefix is enabled by default
Ryan Baxter
@ryanjbaxter
Nov 29 2017 18:29
and Zuul is still including the prefix in the request downstream? how do u know?
mohanrao
@mohanrao
Nov 29 2017 18:30
Because if we see the above to find the target path it looking for * character to present in the route path
if not target path will be the same path of the original request
And I am seeing this behavior
Ryan Baxter
@ryanjbaxter
Nov 29 2017 18:31
can you show me your configuration?
mohanrao
@mohanrao
Nov 29 2017 18:33
Sure. below is the configuration
zuul.routes.fooservice.path=/services/fooservice
zuul.routes.fooservice.serviceId=ServiceOne
to the zuul server the request is coming as /services/fooservice and request is getting forward as /services/fooservice instead of /
Ryan Baxter
@ryanjbaxter
Nov 29 2017 18:39
If you change the path to /services/fooservice/** does it work as expected?
mohanrao
@mohanrao
Nov 29 2017 18:40
Nope.. it doesn't It fails at the ant matching it self
to find ZuulRoute
Ryan Baxter
@ryanjbaxter
Nov 29 2017 18:41
you mean a request to /services/fooservice does not match /services/fooservice/**?
mohanrao
@mohanrao
Nov 29 2017 18:41
yes
sorry
let me check
yes it worked
Ryan Baxter
@ryanjbaxter
Nov 29 2017 18:47
ok
sounds like we just need to clarify the documentation then
mohanrao
@mohanrao
Nov 29 2017 18:47
yep..
one more quick question
Ryan Baxter
@ryanjbaxter
Nov 29 2017 18:48
would u mind creating an issue in Spring Cloud Netflix to clarify the documentation
mohanrao
@mohanrao
Nov 29 2017 18:48
what if /services/fooservice or /services/fooservices/ to forward ServiceOne endpoint path of /
@ryanjbaxter yes
Ryan Baxter
@ryanjbaxter
Nov 29 2017 18:48
sorry I dont understand your last question
mohanrao
@mohanrao
Nov 29 2017 18:49
What if /services/fooservice/newendpoint should get forward to forward to ServiceTwo endpoint path of /
/services/fooservice/** is going to match all after fooservice
what if /services/fooservice or /services/fooservices/ to forward ServiceOne endpoint path of /
and /services/fooservice/newendpoint should get forward to forward to ServiceTwo endpoint path of /
Ryan Baxter
@ryanjbaxter
Nov 29 2017 18:50
ah i see
mohanrao
@mohanrao
Nov 29 2017 18:50
Will that work ?
I mean how to do that
Ryan Baxter
@ryanjbaxter
Nov 29 2017 18:56
yes that will work but only if you use a YAML file to maintain the order

If you need your routes to have their order preserved you need to use a YAML file as the ordering will be lost using a properties file. For example:
application.yml.

 zuul:
  routes:
    users:
      path: /myusers/**
    legacy:
      path: /**

If you were to use a properties file, the legacy path may end up in front of the users path rendering the users path unreachable.

mohanrao
@mohanrao
Nov 29 2017 19:05
@ryanjbaxter Thanks good to know if we use YAML then the ordering is guaranteed
Also is there way you can change the target path
for example if i am getting request for /myusers/account/ to downstream as /oldusers/account
Ryan Baxter
@ryanjbaxter
Nov 29 2017 19:09
not without implementing your own Zuul filter
mohanrao
@mohanrao
Nov 29 2017 19:10
okay.. A moment back untill i know the trick I was extending the SimpleRouteLocator and able to achieve by overriding the getRoute method
Ryan Baxter
@ryanjbaxter
Nov 29 2017 19:11
yeah that is essentially what i am recommending
mohanrao
@mohanrao
Nov 29 2017 19:11
Not sure.. extending the filter is a right approach or extending the simpleroutelocator
okay
Got it!
Thank you very much. It was very helpful!
Ryan Baxter
@ryanjbaxter
Nov 29 2017 19:12
yeah you need to change the route somehow you might just look at implementing your own ZuulFilter rather than extending one of our classes to protect your self a little bit
mohanrao
@mohanrao
Nov 29 2017 19:18
yes. That works