Consul service routing does not work
- Dominant language
- Go
- Stars
- 30.1k
- Forks
- 4.6k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 39
Description
I am a newbie to consul, this might caused by my configuration problem.
#### Overview of the Issue
I have run 2 services in my local dev datacenter, one (weather-forecast) is to provide information weather info, and the other (weather-client) is to query weather info from weather forecast service.
Weather forecast service has 2 running instances, each listens to port 5001 and 5002. And weather client is listening to port 5005, it will call weather forecast service through proxy upstream port 5008. We can get the weather forecasts information through following URL.
http://localhost:5005/WeatherClient?location={location}
An example of response message is shown as below:
``
{
"forecasts": [
{
"date": "2020-01-04T15:34:55.49344+08:00",
"temperatureC": 30,
"temperatureF": 85,
"summary": "Bracing"
},
{
"date": "2020-01-05T15:34:55.493447+08:00",
"temperatureC": 1,
"temperatureF": 33,
"summary": "Chilly"
},
{
"date": "2020-01-06T15:34:55.493447+08:00",
"temperatureC": 10,
"temperatureF": 49,
"summary": "Hot"
},
{
"date": "2020-01-07T15:34:55.493447+08:00",
"temperatureC": 8,
"temperatureF": 46,
"summary": "Chilly"
},
{
"date": "2020-01-08T15:34:55.493447+08:00",
"temperatureC": 38,
"temperatureF": 100,
"summary": "Cool"
}
],
"received": "weather-5001"
}
``
**I would like to route the request for location is "Singapore" to instance 5001, and route location is "GuangZhou" to instance 5002, but it doest not works. Followings are the consul service definition files and L7 configuration files:**
If the routing works properly, the service instance that received request should be "weather-5001" if the location in query parameter is set to "Singapore", as above sample response shown.
- **weather client** (weatherClient.json)
``
{
"service": {
"id": "weather-client",
"name": "weather-client",
"port": 5005,
"connect": {
"sidecar_service": {
"proxy": {
"upstreams": [
{
"destination_name": "weather",
"local_bind_port": 5008
}
]
}
}
}
}
}
``
- **weather forecast service 1** (weather1.json)
``
{
"service": {
"id": "weather-5001",
"name": "weather",
"port": 5001,
"meta": {
"alias": "weather5001"
},
"connect": {
"sidecar_service": {
}
}
}
}
``
- **weather forecast service 2** (weather2.json)
``
{
"service": {
"id": "weather-5002",
"name": "weather",
"port": 5002,
"meta": {
"alias": "weather5002"
},
"connect": {
"sidecar_service": {
}
}
}
}
``
- **weather service defaults** (weather-service-defaults.json)
``
{
"kind": "service-defaults",
"name": "weather",
"protocol": "http"
}
``
- **weather service resolver** (weather-service-resolver.json)
``
{
"kind": "service-resolver",
"name": "weather",
"subsets": {
"5001": {
"filter": "Service.Meta.alias == weather5001"
},
"5002": {
"filter": "Service.Meta.alias == weather5002"
}
}
}
``
- **weather service router** (weather-service-router.json)
``
{
"kind": "service-router",
"name": "weather",
"routes": [
{
"match": {
"http": {
"query_param": {
"name": "location",
"exact": "Singapore"
}
}
},
"destination": {
"service": "weather",
"service_subset": "5001"
}
},
{
"match": {
"http": {
"query_param": {
"name": "location",
"exact": "GuangZhou"
}
}
},
"destination": {
"service": "weather",
"service_subset": "5002"
}
}
]
}
``
#### Reproduction Steps
Steps to reproduce this issue:
1. Initialise a consul server by command (consul agent -dev -ui -config-dir=./weather) and load the service definition, folder "weather" contains service definition files.
2. Run command (consul connect proxy -sidecar-for weather-5001) to initialise the sidecar proxy for all above 3 instances.
3. Run command (consul config write weather-service-defaults.json) to apply configuration to service weather-forcast.
4. Run command (consul config write weather-service-resolver.json) to apply the service resolver to service weather-forcast.
5. Run command (consul config write weather-service-router.json) to apply the service router to service weather-forcast.
And the service router does not work, the request is not dispatched base on the location. I used consul monitor to above command, there was no error being detected.
Contributor guide
Research direction
Reproduce the setup with weatherClient.json, weather1.json, weather2.json, weather-service-defaults.json, weather-service-resolver.json, and weather-service-router.json, using the listed agent, proxy, and config-write commands. Compare requests for Singapore and GuangZhou with the returned instance names; done means each query parameter consistently reaches its configured service subset.
Written by the indexing model from the issue text.
Assessment
- Domain
- infrastructure, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100