Skip to content

Commit 6a1c5ef

Browse files
committed
fix valkey docker tests
1 parent ea73a0e commit 6a1c5ef

File tree

5 files changed

+23
-81
lines changed

5 files changed

+23
-81
lines changed

tests/opentelemetry-docker-tests/tests/check_availability.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import psycopg2
2020
import pymongo
2121
import pyodbc
22+
import redis
2223
import valkey
2324

2425
MONGODB_COLLECTION_NAME = "test"
@@ -37,6 +38,8 @@
3738
POSTGRES_USER = os.getenv("POSTGRESQL_USER", "testuser")
3839
REDIS_HOST = os.getenv("REDIS_HOST", "localhost")
3940
REDIS_PORT = int(os.getenv("REDIS_PORT ", "6379"))
41+
VALKEY_HOST = os.getenv("VALKEY_HOST", "localhost")
42+
VALKEY_PORT = int(os.getenv("VALKEY_PORT ", "16379"))
4043
MSSQL_DB_NAME = os.getenv("MSSQL_DB_NAME", "opentelemetry-tests")
4144
MSSQL_HOST = os.getenv("MSSQL_HOST", "localhost")
4245
MSSQL_PORT = int(os.getenv("MSSQL_PORT", "1433"))
@@ -106,7 +109,12 @@ def check_postgres_connection():
106109

107110
@retryable
108111
def check_redis_connection():
109-
connection = valkey.Redis(host=REDIS_HOST, port=REDIS_PORT)
112+
connection = redis.Redis(host=REDIS_HOST, port=REDIS_PORT)
113+
connection.hgetall("*")
114+
115+
@retryable
116+
def check_valkey_connection():
117+
connection = valkey.Valkey(host=VALKEY_HOST, port=VALKEY_PORT)
110118
connection.hgetall("*")
111119

112120

@@ -139,6 +147,7 @@ def check_docker_services_availability():
139147
check_mysql_connection()
140148
check_postgres_connection()
141149
check_redis_connection()
150+
check_valkey_connection()
142151
check_mssql_connection()
143152
setup_mssql_db()
144153

tests/opentelemetry-docker-tests/tests/docker-compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ services:
3838
- "127.0.0.1:7003:7003"
3939
- "127.0.0.1:7004:7004"
4040
- "127.0.0.1:7005:7005"
41+
otvalkey:
42+
image: valkey/valkey:8.1.1
43+
ports:
44+
- "127.0.0.1:16379:6379"
45+
4146
otjaeger:
4247
image: jaegertracing/all-in-one:1.8
4348
environment:

tests/opentelemetry-docker-tests/tests/test-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ tomli==2.0.1
6868
typing_extensions==4.12.2
6969
tzdata==2024.1
7070
urllib3==1.26.19
71+
valkey[libvalkey]==6.1.0
7172
vine==5.1.0
7273
wcwidth==0.2.13
7374
websocket-client==0.59.0

tests/opentelemetry-docker-tests/tests/valkey/test_valkey_functional.py

Lines changed: 6 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717

1818
import valkey
1919
import valkey.asyncio
20-
from valkey.commands.search.field import (
21-
TextField,
22-
VectorField,
23-
)
2420
from valkey.commands.search.indexDefinition import IndexDefinition, IndexType
2521
from valkey.commands.search.query import Query
2622
from valkey.exceptions import ResponseError
@@ -34,7 +30,7 @@
3430
class TestValkeyInstrument(TestBase):
3531
def setUp(self):
3632
super().setUp()
37-
self.valkey_client = valkey.Valkey(port=6379)
33+
self.valkey_client = valkey.Valkey(port=16379)
3834
self.valkey_client.flushall()
3935
ValkeyInstrumentor().instrument(tracer_provider=self.tracer_provider)
4036

@@ -51,7 +47,7 @@ def _check_span(self, span, name):
5147
self.assertEqual(
5248
span.attributes[SpanAttributes.NET_PEER_NAME], "localhost"
5349
)
54-
self.assertEqual(span.attributes[SpanAttributes.NET_PEER_PORT], 6379)
50+
self.assertEqual(span.attributes[SpanAttributes.NET_PEER_PORT], 16379)
5551

5652
def test_long_command_sanitized(self):
5753
ValkeyInstrumentor().uninstrument()
@@ -280,7 +276,7 @@ def async_call(coro):
280276
class TestAsyncValkeyInstrument(TestBase):
281277
def setUp(self):
282278
super().setUp()
283-
self.valkey_client = valkey.asyncio.Valkey(port=6379)
279+
self.valkey_client = valkey.asyncio.Valkey(port=16379)
284280
async_call(self.valkey_client.flushall())
285281
ValkeyInstrumentor().instrument(tracer_provider=self.tracer_provider)
286282

@@ -297,7 +293,7 @@ def _check_span(self, span, name):
297293
self.assertEqual(
298294
span.attributes[SpanAttributes.NET_PEER_NAME], "localhost"
299295
)
300-
self.assertEqual(span.attributes[SpanAttributes.NET_PEER_PORT], 6379)
296+
self.assertEqual(span.attributes[SpanAttributes.NET_PEER_PORT], 16379)
301297

302298
def test_long_command(self):
303299
async_call(self.valkey_client.mget(*range(1000)))
@@ -593,7 +589,7 @@ def test_parent(self):
593589
class TestValkeyDBIndexInstrument(TestBase):
594590
def setUp(self):
595591
super().setUp()
596-
self.valkey_client = valkey.Valkey(port=6379, db=10)
592+
self.valkey_client = valkey.Valkey(port=16379, db=10)
597593
self.valkey_client.flushall()
598594
ValkeyInstrumentor().instrument(tracer_provider=self.tracer_provider)
599595

@@ -607,7 +603,7 @@ def _check_span(self, span, name):
607603
self.assertEqual(
608604
span.attributes[SpanAttributes.NET_PEER_NAME], "localhost"
609605
)
610-
self.assertEqual(span.attributes[SpanAttributes.NET_PEER_PORT], 6379)
606+
self.assertEqual(span.attributes[SpanAttributes.NET_PEER_PORT], 16379)
611607
self.assertEqual(
612608
span.attributes["db.valkey.database_index"], 10
613609
)
@@ -621,73 +617,3 @@ def test_get(self):
621617
self.assertEqual(
622618
span.attributes.get(SpanAttributes.DB_STATEMENT), "GET ?"
623619
)
624-
625-
626-
class TestValkeyearchInstrument(TestBase):
627-
def setUp(self):
628-
super().setUp()
629-
self.valkey_client = valkey.Valkey(port=6379)
630-
self.valkey_client.flushall()
631-
self.embedding_dim = 256
632-
ValkeyInstrumentor().instrument(tracer_provider=self.tracer_provider)
633-
self.prepare_data()
634-
self.create_index()
635-
636-
def tearDown(self):
637-
ValkeyInstrumentor().uninstrument()
638-
super().tearDown()
639-
640-
def prepare_data(self):
641-
try:
642-
self.valkey_client.ft("idx:test_vss").dropindex(True)
643-
except ResponseError:
644-
print("No such index")
645-
item = {
646-
"name": "test",
647-
"value": "test_value",
648-
"embeddings": [0.1] * 256,
649-
}
650-
pipeline = self.valkey_client.pipeline()
651-
pipeline.json().set("test:001", "$", item)
652-
res = pipeline.execute()
653-
assert False not in res
654-
655-
def create_index(self):
656-
schema = (
657-
TextField("$.name", no_stem=True, as_name="name"),
658-
TextField("$.value", no_stem=True, as_name="value"),
659-
VectorField(
660-
"$.embeddings",
661-
"FLAT",
662-
{
663-
"TYPE": "FLOAT32",
664-
"DIM": self.embedding_dim,
665-
"DISTANCE_METRIC": "COSINE",
666-
},
667-
as_name="vector",
668-
),
669-
)
670-
definition = IndexDefinition(
671-
prefix=["test:"], index_type=IndexType.JSON
672-
)
673-
res = self.valkey_client.ft("idx:test_vss").create_index(
674-
fields=schema, definition=definition
675-
)
676-
assert "OK" in str(res)
677-
678-
def test_valkey_create_index(self):
679-
spans = self.memory_exporter.get_finished_spans()
680-
span = next(
681-
span for span in spans if span.name == "valkey.create_index"
682-
)
683-
assert "valkey.create_index.fields" in span.attributes
684-
685-
def test_valkey_query(self):
686-
query = "@name:test"
687-
self.valkey_client.ft("idx:test_vss").search(Query(query))
688-
689-
spans = self.memory_exporter.get_finished_spans()
690-
span = next(span for span in spans if span.name == "valkey.search")
691-
692-
assert span.attributes.get("valkey.search.query") == query
693-
assert span.attributes.get("valkey.search.total") == 1

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,7 @@ deps =
993993
-e {toxinidir}/instrumentation/opentelemetry-instrumentation-sqlalchemy
994994
-e {toxinidir}/instrumentation/opentelemetry-instrumentation-aiopg
995995
-e {toxinidir}/instrumentation/opentelemetry-instrumentation-redis
996+
-e {toxinidir}/instrumentation/opentelemetry-instrumentation-valkey
996997
-e {toxinidir}/instrumentation/opentelemetry-instrumentation-remoulade
997998
opentelemetry-exporter-opencensus@{env:CORE_REPO}\#egg=opentelemetry-exporter-opencensus&subdirectory=exporter/opentelemetry-exporter-opencensus
998999

0 commit comments

Comments
 (0)