Skip to content

Commit

Permalink
ATO-1520-35x (#12851)
Browse files Browse the repository at this point in the history
* add username to Redis Lock and Tracker Stores

* reformat

* add changelog
  • Loading branch information
vcidst authored Sep 26, 2023
1 parent 543e952 commit 3ea9722
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/continous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ jobs:
name: Run Tests
if: github.ref_type != 'tag'
runs-on: ${{ matrix.os }}
timeout-minutes: 60
needs: [changes]
strategy:
fail-fast: false
Expand Down Expand Up @@ -363,6 +364,7 @@ jobs:
name: Run Flaky Tests
if: github.ref_type != 'tag'
runs-on: ${{ matrix.os }}
timeout-minutes: 60
needs: [changes]
strategy:
fail-fast: false
Expand Down Expand Up @@ -554,6 +556,7 @@ jobs:
name: Run Non-Sequential Integration Tests
if: github.ref_type != 'tag'
runs-on: ubuntu-22.04
timeout-minutes: 60
needs: [changes]
env:
REDIS_HOST: localhost
Expand Down Expand Up @@ -690,6 +693,7 @@ jobs:
name: Run Sequential Integration Tests
if: github.ref_type != 'tag'
runs-on: ubuntu-20.04
timeout-minutes: 60
needs: [changes]
env:
POSTGRES_HOST: localhost
Expand Down
1 change: 1 addition & 0 deletions changelog/12851.improvement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `username` to the connection parameters for `RedisLockStore` and `RedisTrackerStore`
14 changes: 14 additions & 0 deletions data/test_endpoints/example_endpoints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,27 @@ tracker_store:
url: localhost
port: 6379
db: 0
username: username
password: password
key_prefix: conversation
record_exp: 30000
use_ssl: True
ssl_keyfile: "keyfile.key"
ssl_certfile: "certfile.crt"
ssl_ca_certs: "my-bundle.ca-bundle"
# example of redis external lock store config
lock_store:
type: redis
url: localhost
port: 6379
db: 0
username: username
password: password
key_prefix: lock
use_ssl: True
ssl_keyfile: "keyfile.key"
ssl_certfile: "certfile.crt"
ssl_ca_certs: "my-bundle.ca-bundle"
# example of mongoDB external tracker store config
#tracker_store:
#type: mongod
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/lock-stores.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ The `ConcurrentRedisLockStore` recreates the `TicketLock` from the persisted `Ti
- `key_prefix` (default: `None`): The prefix to prepend to lock store keys. Must
be alphanumeric

- `username` (default: `None`): Username used for authentication

- `password` (default: `None`): Password used for authentication
(`None` equals no authentication)

Expand Down
2 changes: 2 additions & 0 deletions docs/docs/tracker-stores.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ To set up Rasa with Redis the following steps are required:
* `key_prefix` (default: `None`): The prefix to prepend to tracker store keys. Must
be alphanumeric

* `username` (default: `None`): Username used for authentication

* `password` (default: `None`): Password used for authentication
(`None` equals no authentication)

Expand Down
4 changes: 4 additions & 0 deletions rasa/core/lock_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def __init__(
host: Text = "localhost",
port: int = 6379,
db: int = 1,
username: Optional[Text] = None,
password: Optional[Text] = None,
use_ssl: bool = False,
ssl_certfile: Optional[Text] = None,
Expand All @@ -215,6 +216,8 @@ def __init__(
port: The port of the redis server.
db: The name of the database within Redis which should be used by Rasa
Open Source.
username: The username which should be used for authentication with the
Redis database.
password: The password which should be used for authentication with the
Redis database.
use_ssl: `True` if SSL should be used for the connection to Redis.
Expand All @@ -232,6 +235,7 @@ def __init__(
host=host,
port=int(port),
db=int(db),
username=username,
password=password,
ssl=use_ssl,
ssl_certfile=ssl_certfile,
Expand Down
2 changes: 2 additions & 0 deletions rasa/core/tracker_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ def __init__(
host: Text = "localhost",
port: int = 6379,
db: int = 0,
username: Optional[Text] = None,
password: Optional[Text] = None,
event_broker: Optional[EventBroker] = None,
record_exp: Optional[float] = None,
Expand All @@ -473,6 +474,7 @@ def __init__(
host=host,
port=port,
db=db,
username=username,
password=password,
ssl=use_ssl,
ssl_keyfile=ssl_keyfile,
Expand Down
33 changes: 25 additions & 8 deletions tests/core/test_lock_store.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
import asyncio
import logging
import sys
import time
from pathlib import Path
from typing import Text
from unittest.mock import Mock, patch

import numpy as np
import pytest
import time

import rasa.core.lock_store
from _pytest.logging import LogCaptureFixture
from _pytest.monkeypatch import MonkeyPatch
from unittest.mock import patch, Mock

from rasa.core.agent import Agent
from rasa.core.channels import UserMessage
from rasa.core.constants import DEFAULT_LOCK_LIFETIME
from rasa.shared.constants import INTENT_MESSAGE_PREFIX
from rasa.core.lock import TicketLock
import rasa.core.lock_store
from rasa.core.lock_store import (
DEFAULT_REDIS_LOCK_STORE_KEY_PREFIX,
InMemoryLockStore,
LockError,
LockStore,
RedisLockStore,
DEFAULT_REDIS_LOCK_STORE_KEY_PREFIX,
)
from rasa.shared.constants import INTENT_MESSAGE_PREFIX
from rasa.shared.exceptions import ConnectionException
from rasa.utils.endpoints import EndpointConfig
from rasa.utils.endpoints import EndpointConfig, read_endpoint_config


class FakeRedisLockStore(RedisLockStore):
Expand Down Expand Up @@ -384,3 +383,21 @@ async def test_redis_lock_store_with_valid_prefix(monkeypatch: MonkeyPatch):
with pytest.raises(LockError):
async with lock_store.lock("some sender"):
pass


def test_create_lock_store_from_endpoint_config(endpoints_path: Text):
store = read_endpoint_config(endpoints_path, endpoint_type="lock_store")
tracker_store = RedisLockStore(
host="localhost",
port=6379,
db=0,
username="username",
password="password",
use_ssl=True,
ssl_keyfile="keyfile.key",
ssl_certfile="certfile.crt",
ssl_ca_certs="my-bundle.ca-bundle",
key_prefix="lock",
)

assert isinstance(tracker_store, type(LockStore.create(store)))
2 changes: 2 additions & 0 deletions tests/core/test_tracker_stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def test_tracker_store_endpoint_config_loading(endpoints_path: Text):
"url": "localhost",
"port": 6379,
"db": 0,
"username": "username",
"password": "password",
"timeout": 30000,
"use_ssl": True,
Expand All @@ -163,6 +164,7 @@ def test_create_tracker_store_from_endpoint_config(
host="localhost",
port=6379,
db=0,
username="username",
password="password",
record_exp=3000,
use_ssl=True,
Expand Down

0 comments on commit 3ea9722

Please sign in to comment.