6969_INSTANTIATED_FACTORIES_LOCK = threading .RLock ()
7070_MIN_DEFAULT_DATA_SAMPLING_ALLOWED = 0.1 # 10%
7171_MAX_RETRY_SYNC_ALL = 3
72+ _FLAG_SETS_LOCK = threading .RLock ()
73+ _TOTAL_FLAG_SETS = 0
74+ _INVALID_FLAG_SETS = 0
7275
7376
7477class Status (Enum ):
@@ -417,6 +420,9 @@ def _build_in_memory_factory(api_key, cfg, sdk_url=None, events_url=None, # pyl
417420 )
418421
419422 telemetry_init_producer .record_config (cfg , extra_cfg )
423+ total_flag_sets , invalid_flag_sets = _get_total_and_invalid_flag_sets ()
424+ telemetry_init_producer .record_flag_sets (total_flag_sets )
425+ telemetry_init_producer .record_invalid_flag_sets (invalid_flag_sets )
420426
421427 if preforked_initialization :
422428 synchronizer .sync_all (max_retry_attempts = _MAX_RETRY_SYNC_ALL )
@@ -508,7 +514,10 @@ def _build_redis_factory(api_key, cfg):
508514 telemetry_init_producer = telemetry_init_producer
509515 )
510516 redundant_factory_count , active_factory_count = _get_active_and_redundant_count ()
517+ total_flag_sets , invalid_flag_sets = _get_total_and_invalid_flag_sets ()
511518 storages ['telemetry' ].record_active_and_redundant_factories (active_factory_count , redundant_factory_count )
519+ storages ['telemetry' ].record_flag_sets (total_flag_sets )
520+ storages ['telemetry' ].record_invalid_flag_sets (invalid_flag_sets )
512521 telemetry_submitter .synchronize_config ()
513522
514523 return split_factory
@@ -586,7 +595,10 @@ def _build_pluggable_factory(api_key, cfg):
586595 telemetry_init_producer = telemetry_init_producer
587596 )
588597 redundant_factory_count , active_factory_count = _get_active_and_redundant_count ()
598+ total_flag_sets , invalid_flag_sets = _get_total_and_invalid_flag_sets ()
589599 storages ['telemetry' ].record_active_and_redundant_factories (active_factory_count , redundant_factory_count )
600+ storages ['telemetry' ].record_flag_sets (total_flag_sets )
601+ storages ['telemetry' ].record_invalid_flag_sets (invalid_flag_sets )
590602 telemetry_submitter .synchronize_config ()
591603
592604 return split_factory
@@ -684,7 +696,16 @@ def get_factory(api_key, **kwargs):
684696 _INSTANTIATED_FACTORIES .update ([api_key ])
685697 _INSTANTIATED_FACTORIES_LOCK .release ()
686698
687- config = sanitize_config (api_key , kwargs .get ('config' , {}))
699+ config_raw = kwargs .get ('config' , {})
700+ if config_raw .get ('flagSetsFilter' ) is not None and isinstance (config_raw .get ('flagSetsFilter' ), list ):
701+ global _TOTAL_FLAG_SETS
702+ global _INVALID_FLAG_SETS
703+ _FLAG_SETS_LOCK .acquire ()
704+ _TOTAL_FLAG_SETS = len (config_raw .get ('flagSetsFilter' ))
705+ _INVALID_FLAG_SETS = _TOTAL_FLAG_SETS - len (input_validator .validate_flag_sets (config_raw .get ('flagSetsFilter' ), 'Telemetry Init' ))
706+ _FLAG_SETS_LOCK .release ()
707+
708+ config = sanitize_config (api_key , config_raw )
688709
689710 if config ['operationMode' ] == 'localhost' :
690711 split_factory = _build_localhost_factory (config )
@@ -712,4 +733,13 @@ def _get_active_and_redundant_count():
712733 redundant_factory_count += _INSTANTIATED_FACTORIES [item ] - 1
713734 active_factory_count += _INSTANTIATED_FACTORIES [item ]
714735 _INSTANTIATED_FACTORIES_LOCK .release ()
715- return redundant_factory_count , active_factory_count
736+ return redundant_factory_count , active_factory_count
737+
738+ def _get_total_and_invalid_flag_sets ():
739+ total_flag_sets = 0
740+ invalid_flag_sets = 0
741+ _FLAG_SETS_LOCK .acquire ()
742+ total_flag_sets = _TOTAL_FLAG_SETS
743+ invalid_flag_sets = _INVALID_FLAG_SETS
744+ _FLAG_SETS_LOCK .release ()
745+ return total_flag_sets , invalid_flag_sets
0 commit comments