Skip to content

Commit

Permalink
Merge pull request #30 from odigos-io/disabling-opamp-by-env-var
Browse files Browse the repository at this point in the history
feat: disable opamp by flag
  • Loading branch information
tamirdavid1 authored Sep 18, 2024
2 parents 8bf8288 + e0e47a2 commit d7cda38
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion initializer/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# This is necessary because the user application's dependencies may be incompatible with those used by the agent.
reorder_python_path()

from opamp.http_client import OpAMPHTTPClient
from opamp.http_client import OpAMPHTTPClient, MockOpAMPClient


MINIMUM_PYTHON_SUPPORTED_VERSION = (3, 8)
Expand Down Expand Up @@ -107,6 +107,10 @@ def initialize_logging_if_enabled(log_exporters, resource):


def start_opamp_client(event):

if os.getenv('DISABLE_OPAMP_CLIENT', 'false').strip().lower() == 'true':
return MockOpAMPClient(event)

condition = threading.Condition(threading.Lock())
client = OpAMPHTTPClient(event, condition)

Expand Down
14 changes: 13 additions & 1 deletion opamp/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,16 @@ def update_remote_config_status(self, server_to_agent: opamp_pb2.ServerToAgent)
self.remote_config_status = remote_config_status
return True

return False
return False


# Mock client class for non-OpAMP installations
# This class simulates the OpAMP client when the OpAMP server is not available.
# To activate it, set the environment variable DISABLE_OPAMP_CLIENT to true.
class MockOpAMPClient:
def __init__(self, event, *args, **kwargs):
self.resource_attributes = {'odigos.opamp': 'disabled'}
event.set()

def shutdown(self, custom_failure_message=None):
pass

0 comments on commit d7cda38

Please sign in to comment.