1717from robusta .core .model .cluster_status import ActivityStats , ClusterStats , ClusterStatus
1818from robusta .core .model .env_vars import (
1919 CLUSTER_STATUS_PERIOD_SEC ,
20+ DISABLE_DISCOVERY ,
21+ DISABLE_FINDINGS_PERSISTENCE ,
22+ DISABLE_RESOURCE_WATCH_PERSISTENCE ,
2023 DISCOVERY_CHECK_THRESHOLD_SEC ,
2124 DISCOVERY_PERIOD_SEC ,
2225 DISCOVERY_WATCHDOG_CHECK_SEC ,
@@ -87,6 +90,13 @@ def __init__(self, sink_config: RobustaSinkConfigWrapper, registry):
8790 self .signing_key ,
8891 )
8992
93+ if DISABLE_FINDINGS_PERSISTENCE :
94+ logging .info ("DISABLE_FINDINGS_PERSISTENCE is set - findings will not be persisted to the platform database" )
95+ if DISABLE_DISCOVERY :
96+ logging .info ("DISABLE_DISCOVERY is set - resource discovery will not run" )
97+ if DISABLE_RESOURCE_WATCH_PERSISTENCE :
98+ logging .info ("DISABLE_RESOURCE_WATCH_PERSISTENCE is set - real-time resource watch writes are disabled" )
99+
90100 self .first_prometheus_alert_time = 0
91101 self .last_send_time = 0
92102 self .__discovery_period_sec = DISCOVERY_PERIOD_SEC
@@ -228,6 +238,8 @@ def handle_service_diff(
228238 new_resource : Union [Deployment , DaemonSet , StatefulSet , ReplicaSet , Pod , Node ],
229239 operation : K8sOperationType ,
230240 ):
241+ if DISABLE_RESOURCE_WATCH_PERSISTENCE :
242+ return
231243 try :
232244 if isinstance (new_resource , (Deployment , DaemonSet , StatefulSet , ReplicaSet , Pod )):
233245 self .__publish_single_service (Discovery .create_service_info_from_hikaru (new_resource ), operation )
@@ -244,6 +256,8 @@ def handle_service_diff(
244256 )
245257
246258 def write_finding (self , finding : Finding , platform_enabled : bool ):
259+ if DISABLE_FINDINGS_PERSISTENCE :
260+ return
247261 self .dal .persist_finding (finding )
248262
249263 def __publish_single_service (self , new_service : ServiceInfo , operation : K8sOperationType ):
@@ -626,18 +640,21 @@ def __discovery_watchdog(self):
626640
627641 def __discover_cluster (self ):
628642 logging .info ("Cluster discovery initialized" )
629- get_history = self .__should_run_history ()
643+ get_history = self .__should_run_history () if not DISABLE_DISCOVERY else False
630644 self .last_namespace_discovery = 0
631645 while self .__active :
632646 start_t = time .time ()
633647 self .__periodic_cluster_status ()
634- discovery_results = self .__discover_resources ()
635648
636- if get_history :
637- self .__get_events_history ()
638- get_history = False
639- if discovery_results and discovery_results .helm_releases :
640- self .__send_helm_release_events (release_data = discovery_results .helm_releases )
649+ if not DISABLE_DISCOVERY :
650+ discovery_results = self .__discover_resources ()
651+
652+ if get_history :
653+ self .__get_events_history ()
654+ get_history = False
655+ if discovery_results and discovery_results .helm_releases :
656+ self .__send_helm_release_events (release_data = discovery_results .helm_releases )
657+
641658 duration = round (time .time () - start_t )
642659 sleep_dur = min (max (self .__discovery_period_sec , 3 * duration ), 300 )
643660
0 commit comments