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

Incorrect Dapr Redis StateStore Source Used #1302

Closed
JaimeStill opened this issue Mar 28, 2023 · 7 comments
Closed

Incorrect Dapr Redis StateStore Source Used #1302

JaimeStill opened this issue Mar 28, 2023 · 7 comments
Labels
kind/bug Something isn't working stale

Comments

@JaimeStill
Copy link

JaimeStill commented Mar 28, 2023

In what area(s)?

/area runtime

/area operator

/area placement

/area docs

/area test-and-release

What version of Dapr?

1.1.x

Expected Behavior

When initializing Dapr via dapr --init and interfacing with the Redis store component, Dapr should be interfacing with the dapr_redis Docker container.

Actual Behavior

If Redis is already installed and running somewhere else on the machine, Dapr will interface with the previously installed instance of Redis vs. the Docker container initialized by Dapr.

Steps to Reproduce the Problem

On my Windows 11 machine, I already had Redis installed in WSL prior to installing and initializing Dapr. These steps will assume no artifacts of Dapr previously exist

Install Redis in WSL Ubuntu

sudo snap install redis

Install the Dapr CLI

From an Administrative terminal

pwsh -Command "iwr -useb https://raw.githubusercontent.com/dapr/cli/master/install/install.ps1 | iex"

Initialize Dapr and start a Dapr app

From an Administrative terminal

dapr init

dapr run --app-id myapp --dapr-http-port 3500

Store and Retrieve Data in Dapr State Store

# POST data
Invoke-RestMethod -Method Post -ContentType 'application/json' -Body '[{"key": "name", "value": "Bruce Wayne"}]' -Uri 'http://localhost:3500/v1.0/state/statestore'

# GET data
# Output: Bruce Wayne
Invoke-RestMethod -Uri 'http://localhost:3500/v1.0/state/statestore/name'

Connect to dapr_redis Container and Check Data

The following output should print (empty array)
for all executed redis commands

docker exec -it dapr_redis redis-cli

127.0.0.1:6370>keys *
(empty array)

127.0.0.1:6370>hgetall "myapp||name"
(empty array)

Connect to WSL Redis Instance and Check Data

Output

# connect to WSL
wsl

# make sure redis-cli is installed
sudo apt install redis-tools

# connect to redis
~$ redis-cli

# check for keys
127.0.0.1:6379> keys *
1) "myapp||name"

# check value
127.0.0.1:6379> hgetall "myapp||name"
1) "data"
2) "\"Bruce Wayne\""
3) "version"
4) "1"

Remediate Problem

I honestly had forgotten that I installed Redis in WSL at an earlier point and spent a long time trying to figure out what I had done wrong. Nothing about the scenario made sense until I remembered that I had installed it. Data was able to be stored and retrieved via the Dapr REST methods, but I could not find any trace of it in the dapr_redis instance.

Once I understood what was happening, I was able to get everything working after the following steps:

  1. Remove all Redis artifacts from Ubuntu

    # connect to WSL Ubuntu
    wsl
    
    # remove redis-tools
    sudo apt remove redis-tools
    
    # exit WSL
    exit
    
    # restart WSL
    wsl --shutdown Ubuntu
    
    # connect again
    wsl
    
    # remove redis
    sudo snap remove redis --purge
    
    # exit wsl
    exit
  2. Purge / Clean Docker for Desktop and Restart.

  3. From an administrative command prompt:

    # uninstall Dapr
    dapr uninstall
    
    # reinit Dapr
    dapr init
  4. Start the Dapr app

    dapr run --app-id myapp --dapr-http-port 3500
  5. Store and Retrieve State Store Data

    Invoke-RestMethod -Method Post -ContentType 'application/json' -Body '[{"key": "name", "value": "Bruce Wayne"}]' -Uri 'http://localhost:3500/v1.0/state/statestore'
    
    Invoke-RestMethod -Uri 'http://localhost:3500/v1.0/state/statestore/name'

    Output

    Bruce Wayne
    
  6. Connect to dapr_redis and verify data:

    > docker exec -it dapr_redis redis-cli
    
    127.0.0.1:6379> keys *
    1) "myapp||name"
    
    127.0.0.1:6379> hgetall "myapp||name"
    1) "data"
    2) "\"Bruce Wayne\""
    3) "version"
    4) "1"
    

Release Note

RELEASE NOTE:

@JaimeStill JaimeStill added the kind/bug Something isn't working label Mar 28, 2023
@ItalyPaleAle
Copy link
Contributor

Dapr will connect to the Redis instance defined in the ~/.dapr/components/statestore.yaml file (which is created when you run dapr init). The default is localhost:6379.

In your case, it seems more like an issue with the Windows/WSL networking stack, since you had two instances of Redis (listening on the same port)?

@JaimeStill
Copy link
Author

Dapr will connect to the Redis instance defined in the ~/.dapr/components/statestore.yaml file (which is created when you run dapr init). The default is localhost:6379.

Tracking. localhost:6379 is the default port that Redis listens when it is installed. If the intent is for Dapr to connect to the instance running in dapr_redis after running dapr init, perhaps it might be better to have it run on a different port and adjust the default configuration accordingly? This way, you can better project that Dapr is interfacing with the correct instance.

At the very least, it might be helpful to make a note of this in the documentation (maybe in the Initialize Dapr document, as well as this section) as this was pretty difficult for someone new to Dapr to pinpoint on first approach.

@ItalyPaleAle
Copy link
Contributor

I think this may make sense.

@mukundansundar this seems more of a CLI issue, can you transfer the issue please?

@dapr-bot
Copy link
Collaborator

This issue has been automatically marked as stale because it has not had activity in the last 60 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue, help wanted or triaged/resolved) or other activity occurs. Thank you for your contributions.

@dapr-bot dapr-bot added the stale label May 28, 2023
@dapr-bot
Copy link
Collaborator

dapr-bot commented Jun 4, 2023

This issue has been automatically closed because it has not had activity in the last 67 days. If this issue is still valid, please ping a maintainer and ask them to label it as pinned, good first issue, help wanted or triaged/resolved. Thank you for your contributions.

@dapr-bot dapr-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 4, 2023
@yaron2 yaron2 reopened this Jun 4, 2023
@yaron2 yaron2 transferred this issue from dapr/dapr Jun 4, 2023
@dapr-bot dapr-bot removed the stale label Jun 4, 2023
@dapr-bot
Copy link
Collaborator

dapr-bot commented Jul 4, 2023

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue, help wanted or triaged/resolved) or other activity occurs. Thank you for your contributions.

@dapr-bot dapr-bot added the stale label Jul 4, 2023
@dapr-bot
Copy link
Collaborator

This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as pinned, good first issue, help wanted or triaged/resolved. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working stale
Projects
None yet
Development

No branches or pull requests

4 participants