1717
1818import valkey
1919import valkey .asyncio
20- from valkey .commands .search .field import (
21- TextField ,
22- VectorField ,
23- )
2420from valkey .commands .search .indexDefinition import IndexDefinition , IndexType
2521from valkey .commands .search .query import Query
2622from valkey .exceptions import ResponseError
3430class 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):
280276class 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):
593589class 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
0 commit comments