Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: send k8s details over opamp if env vars are set #36

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions opamp/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
# Setup the logger
opamp_logger = logging.getLogger('odigos')


env_var_mappings = {
"ODIGOS_WORKLOAD_NAMESPACE": ResourceAttributes.K8S_NAMESPACE_NAME,
"ODIGOS_CONTAINER_NAME": ResourceAttributes.CONTAINER_NAME,
"ODIGOS_POD_NAME": ResourceAttributes.K8S_POD_NAME
}

class OpAMPHTTPClient:
def __init__(self, event, condition: threading.Condition):
self.server_host = os.getenv('ODIGOS_OPAMP_SERVER_HOST')
Expand Down Expand Up @@ -182,6 +189,17 @@ def get_agent_description(self) -> opamp_pb2.AgentDescription: # type: ignore
)
]

# Add additional attributes from environment variables
for env_var, attribute_key in env_var_mappings.items():
value = os.environ.get(env_var)
if value:
identifying_attributes.append(
anyvalue_pb2.KeyValue(
key=attribute_key,
value=anyvalue_pb2.AnyValue(string_value=value)
)
)

return opamp_pb2.AgentDescription(
identifying_attributes=identifying_attributes,
non_identifying_attributes=[]
Expand Down
Loading