@@ -550,28 +550,18 @@ def push_data_to_redistimeseries(rts, time_series_dict: dict, expire_msecs=0):
550550
551551def exporter_create_ts (rts , time_series , timeseries_name ):
552552 try :
553- logging .debug (
554- "Creating timeseries named {} with labels {}" .format (
555- timeseries_name , time_series ["labels" ]
556- )
557- )
558- rts .create (timeseries_name , labels = time_series ["labels" ], chunk_size = 128 )
559- except redis .exceptions .ResponseError as e :
560- if "already exists" in e .__str__ ():
553+ if rts .redis .exists (timeseries_name ) is False :
561554 logging .debug (
562- "Timeseries named {} already exists. Checking that the labels match. " .format (
563- timeseries_name
555+ "Creating timeseries named {} with labels {} " .format (
556+ timeseries_name , time_series [ "labels" ]
564557 )
565558 )
566- set1 = set (time_series ["labels" ].items ())
567- set2 = set (rts .info (timeseries_name ).labels .items ())
568- if len (set1 - set2 ) > 0 or len (set2 - set1 ) > 0 :
569- logging .info (
570- "Given the labels don't match using TS.ALTER on {} to update labels to {}" .format (
571- timeseries_name , time_series ["labels" ]
572- )
573- )
574- rts .alter (timeseries_name , labels = time_series ["labels" ])
559+ rts .create (timeseries_name , labels = time_series ["labels" ], chunk_size = 128 )
560+ else :
561+ check_rts_labels (rts , time_series , timeseries_name )
562+ except redis .exceptions .ResponseError as e :
563+ if "already exists" in e .__str__ ():
564+ check_rts_labels (rts , time_series , timeseries_name )
575565 pass
576566 else :
577567 logging .error (
@@ -582,6 +572,23 @@ def exporter_create_ts(rts, time_series, timeseries_name):
582572 raise
583573
584574
575+ def check_rts_labels (rts , time_series , timeseries_name ):
576+ logging .debug (
577+ "Timeseries named {} already exists. Checking that the labels match." .format (
578+ timeseries_name
579+ )
580+ )
581+ set1 = set (time_series ["labels" ].items ())
582+ set2 = set (rts .info (timeseries_name ).labels .items ())
583+ if len (set1 - set2 ) > 0 or len (set2 - set1 ) > 0 :
584+ logging .info (
585+ "Given the labels don't match using TS.ALTER on {} to update labels to {}" .format (
586+ timeseries_name , time_series ["labels" ]
587+ )
588+ )
589+ rts .alter (timeseries_name , labels = time_series ["labels" ])
590+
591+
585592def extract_redisgraph_version_from_resultdict (results_dict : dict ):
586593 version = None
587594 if "DBSpecificConfigs" in results_dict :
0 commit comments