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

Redis provider is not working #6210

Closed
leshik opened this issue Jan 21, 2020 · 3 comments · Fixed by #6291
Closed

Redis provider is not working #6210

leshik opened this issue Jan 21, 2020 · 3 comments · Fixed by #6291
Assignees
Projects
Milestone

Comments

@leshik
Copy link

leshik commented Jan 21, 2020

What did you do?

Set up Redis, populated a simple dynamic configuration, then started traefik.

traefik/http/routers/toSite1/rule			Host(`site1.local`)
traefik/http/routers/toSite1/service			Site1
traefik/http/routers/toSite2/rule			Host(`site2.local`)
traefik/http/routers/toSite2/service			Site2
traefik/http/services/Site1/loadBalancer/servers/0/url	http://site1
traefik/http/services/Site2/loadBalancer/servers/1/url	http://site2

This config works ok if using etcd instead of Redis.

What did you expect to see?

Traefik working with the config from Redis.

What did you see instead?

No matter what I do traefik is unable to get any config from Redis. It either complains that it can't build the config because the key wasn't found (if the key starts with just traefik), or throws parsing errors (if it starts with /traefik). I also described the issue here: https://community.containo.us/t/struggle-with-redis-in-current-master/4028

Output of traefik version: (What version of Traefik are you using?)

Version:      e378cb410c4ce1f0d25be64f1e963d42e1c7c004
Codename:     cheddar
Go version:   go1.13.6
Built:        2020-01-17_04:57:08PM
OS/Arch:      linux/amd64

What is your environment & configuration (arguments, toml, provider, platform, ...)?

Redis latest version (v5.0.7).

--providers.redis --providers.redis.endpoints=127.0.0.1:6379

If applicable, please paste the log output in DEBUG level (--log.level=DEBUG switch)

No slash in front of the key:

time="2020-01-21T03:03:35Z" level=info msg="Starting provider *redis.Provider {\"rootKey\":\"traefik\",\"endpoints\":[\"127.0.0.1:6379\"]}"
time="2020-01-21T03:03:35Z" level=error msg="Cannot build the configuration: Key not found in store" providerName=redis

With slash in front of the key:

time="2020-01-21T03:07:26Z" level=error msg="Cannot build the configuration: json: cannot unmarshal bool into Go value of type store.KVPair" providerName=redis

or

time="2020-01-21T03:09:39Z" level=error msg="Cannot build the configuration: invalid character 'o' in literal false (expecting 'a')" providerName=redis

Obviously it tries to parse keys when the prefix starts with the slash, but this is inconsistent with etcd provider behavior.

@ldez
Copy link
Member

ldez commented Jan 21, 2020

Hello,

I take the configuration you provided, and it's working with the latest Redis:

Screenshot_2020-01-21 Traefik

Could give more precise information?

FYI, if you want to use /traefik as root key: --providers.etcd.rootkey=/traefik. But you don't need to do that.

@ldez ldez added area/provider/redis contributor/waiting-for-feedback kind/bug/possible a possible bug that needs analysis before it is confirmed or fixed. and removed status/0-needs-triage labels Jan 21, 2020
@ldez ldez added this to issues in v2 via automation Jan 21, 2020
@leshik
Copy link
Author

leshik commented Jan 21, 2020

@ldez Here is the docker-compose file I use:

version: "3.7"

services:
  site1:
    image: nginx
    volumes:
      - ./site1:/usr/share/nginx/html

  site2:
    image: nginx
    volumes:
      - ./site2:/usr/share/nginx/html

  storage:
    sysctls:
      net.core.somaxconn: 1024
    image: redis
    command: --appendonly yes --save 60 1
    ports:
      - 6379:6379
    volumes:
      - ./storage:/data

  router:
    depends_on:
      - storage
    image: containous/traefik:experimental-master
    command: --api.insecure=true --providers.redis --providers.redis.endpoints=storage:6379 --log --log.level=INFO
    ports:
      - 80:80
      - 8080:8080

Then I start Redis first:

$ docker-compose up -d storage
Creating network "traefik_default" with the default driver
Creating traefik_storage_1 ... done

Then I create the config:

$ redis-cli
127.0.0.1:6379> set traefik/http/routers/toSite1/rule Host(`site1.local`)
OK
127.0.0.1:6379> set traefik/http/routers/toSite1/service Site1
OK
127.0.0.1:6379> set traefik/http/routers/toSite2/rule Host(`site2.local`)
OK
127.0.0.1:6379> set traefik/http/routers/toSite2/service Site2
OK
127.0.0.1:6379> set traefik/http/services/Site1/loadBalancer/servers/0/url http://site1
OK
127.0.0.1:6379> set traefik/http/services/Site2/loadBalancer/servers/1/url http://site2
OK
127.0.0.1:6379> get traefik/http/routers/toSite1/rule
"Host(`site1.local`)"
127.0.0.1:6379> get traefik/http/routers/toSite1/service
"Site1"
127.0.0.1:6379> get traefik/http/routers/toSite2/rule
"Host(`site2.local`)"
127.0.0.1:6379> get traefik/http/routers/toSite2/service
"Site2"
127.0.0.1:6379> get traefik/http/services/Site1/loadBalancer/servers/0/url
"http://site1"
127.0.0.1:6379> get traefik/http/services/Site2/loadBalancer/servers/1/url
"http://site2"
127.0.0.1:6379>

Starting the rest of the services and streaming logs:

$ docker-compose up
traefik_storage_1 is up-to-date
Creating traefik_site1_1  ... done
Creating traefik_router_1 ... done
Creating traefik_site2_1  ... done
Attaching to traefik_storage_1, traefik_site1_1, traefik_site2_1, traefik_router_1
storage_1  | 1:C 21 Jan 2020 11:28:06.175 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
storage_1  | 1:C 21 Jan 2020 11:28:06.175 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=1, just started
storage_1  | 1:C 21 Jan 2020 11:28:06.176 # Configuration loaded
storage_1  | 1:M 21 Jan 2020 11:28:06.181 * Running mode=standalone, port=6379.
storage_1  | 1:M 21 Jan 2020 11:28:06.182 # Server initialized
storage_1  | 1:M 21 Jan 2020 11:28:06.185 * Ready to accept connections
storage_1  | 1:M 21 Jan 2020 11:29:51.506 * 1 changes in 60 seconds. Saving...
storage_1  | 1:M 21 Jan 2020 11:29:51.507 * Background saving started by pid 17
storage_1  | 17:C 21 Jan 2020 11:29:51.514 * DB saved on disk
storage_1  | 17:C 21 Jan 2020 11:29:51.515 * RDB: 0 MB of memory used by copy-on-write
storage_1  | 1:M 21 Jan 2020 11:29:51.610 * Background saving terminated with success
storage_1  | 1:M 21 Jan 2020 11:30:52.004 * 1 changes in 60 seconds. Saving...
storage_1  | 1:M 21 Jan 2020 11:30:52.004 * Background saving started by pid 18
storage_1  | 18:C 21 Jan 2020 11:30:52.012 * DB saved on disk
storage_1  | 18:C 21 Jan 2020 11:30:52.013 * RDB: 0 MB of memory used by copy-on-write
storage_1  | 1:M 21 Jan 2020 11:30:52.105 * Background saving terminated with success
router_1   | time="2020-01-21T11:31:45Z" level=info msg="Configuration loaded from flags."
router_1   | time="2020-01-21T11:31:45Z" level=info msg="Traefik version e378cb410c4ce1f0d25be64f1e963d42e1c7c004 built on 2020-01-17_04:57:08PM"
router_1   | time="2020-01-21T11:31:45Z" level=info msg="\nStats collection is disabled.\nHelp us improve Traefik by turning this feature on :)\nMore details on: https://docs.traefik.io/v2.0/contributing/data-collection/\n"
router_1   | time="2020-01-21T11:31:45Z" level=info msg="Starting provider aggregator.ProviderAggregator {}"
router_1   | time="2020-01-21T11:31:45Z" level=info msg="Starting provider *traefik.Provider {}"
router_1   | time="2020-01-21T11:31:45Z" level=info msg="Starting provider *redis.Provider {\"rootKey\":\"traefik\",\"endpoints\":[\"storage:6379\"]}"
router_1   | time="2020-01-21T11:31:45Z" level=error msg="Cannot build the configuration: Key not found in store" providerName=redis
router_1   | 2020/01/21 11:31:45 redis.go:310: watchLoop in WatchTree err:Key not found in store
storage_1  | 1:M 21 Jan 2020 11:31:53.072 * 1 changes in 60 seconds. Saving...
storage_1  | 1:M 21 Jan 2020 11:31:53.073 * Background saving started by pid 19
storage_1  | 19:C 21 Jan 2020 11:31:53.084 * DB saved on disk
storage_1  | 19:C 21 Jan 2020 11:31:53.085 * RDB: 0 MB of memory used by copy-on-write
storage_1  | 1:M 21 Jan 2020 11:31:53.174 * Background saving terminated with success

image

What am I doing wrong?

@ldez ldez added kind/bug/confirmed a confirmed bug (reproducible). and removed contributor/waiting-for-feedback kind/bug/possible a possible bug that needs analysis before it is confirmed or fixed. labels Jan 21, 2020
@ldez
Copy link
Member

ldez commented Jan 21, 2020

I reproduce if I use the redis-cli to set values in the KV.

The current value format is:

{"Key":"traefik/http/routers/Router1/rule","Value":"Zm9vYmFy","LastIndex":318341026}

instead of:

foobar

It's related to the the lib we use to manage KV: https://github.com/abronan/valkeyrie

So I will try to fix this lib.

kvtools/valkeyrie#34

v2 automation moved this from issues to Done Feb 10, 2020
@traefiker traefiker added this to the next milestone Feb 10, 2020
@traefik traefik locked and limited conversation to collaborators Mar 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
v2
Done
Development

Successfully merging a pull request may close this issue.

3 participants