Skip to content

Commit c6c5d68

Browse files
arikalon1claude
andauthored
Add feature flags to disable discovery, findings, and resource watch (#2020)
* Add env vars to disable findings persistence, discovery, and resource watch writes DISABLE_FINDINGS_PERSISTENCE - skip writing findings to Issues/Evidence tables DISABLE_DISCOVERY - skip the periodic resource discovery loop (keeps cluster status) DISABLE_RESOURCE_WATCH_PERSISTENCE - skip real-time K8s watch event DB writes https://claude.ai/code/session_015jBvu6MGAga8iFmnWmiA2g * handle no resource on pod investigator --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c5ed072 commit c6c5d68

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

playbooks/robusta_playbooks/pod_investigator_enricher.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ def pod_issue_investigator(event: KubernetesResourceEvent):
4141
The only supported resources for investigation are "Deployment", "DaemonSet", "ReplicaSet", "Pod", "StatefulSet", "Job"
4242
"""
4343
resource = event.get_resource()
44+
if not resource:
45+
logging.warning("Cannot run pod issue investigator with no resource")
46+
return
47+
4448
if resource.kind not in supported_resources:
4549
raise ActionException(
4650
ErrorCodes.RESOURCE_NOT_SUPPORTED, f"Pod investigator is not supported for resource {resource.kind}"

src/robusta/core/model/env_vars.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ def load_bool(env_var, default: bool):
9999
DISCOVERY_POD_OWNED_PODS = load_bool("DISCOVERY_POD_OWNED_PODS", False)
100100

101101
DISABLE_HELM_MONITORING = load_bool("DISABLE_HELM_MONITORING", False)
102+
DISABLE_FINDINGS_PERSISTENCE = load_bool("DISABLE_FINDINGS_PERSISTENCE", False)
103+
DISABLE_DISCOVERY = load_bool("DISABLE_DISCOVERY", False)
104+
DISABLE_RESOURCE_WATCH_PERSISTENCE = load_bool("DISABLE_RESOURCE_WATCH_PERSISTENCE", False)
102105

103106
PROMETHEUS_ERROR_LOG_PERIOD_SEC = int(os.environ.get("DISCOVERY_MAX_BATCHES", 14400))
104107

src/robusta/core/sinks/robusta/robusta_sink.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
from robusta.core.model.cluster_status import ActivityStats, ClusterStats, ClusterStatus
1818
from 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

Comments
 (0)