SIENTIAPDE-1325

Refactor OpcManager to emit connection metrics after successful connection establishment

- Moved the metric emission for OPC_CONNECTIONS_TOTAL to occur after a successful connection.
- Removed redundant metric increment logic to streamline the connection process.
This commit is contained in:
vitor-aignosi
2025-11-07 08:58:11 -03:00
parent 1cb687aa37
commit 032be28eb1

View File

@@ -197,15 +197,6 @@ class OpcManager(SientiaMonitoring):
- OPC_CONNECTION_STATUS: Set to 1 on successful connection
"""
await self.emit_metric(
metric_object=metrics.OPC_CONNECTIONS_TOTAL,
method='inc',
value=1,
tags={
'pod_id': self.pod_id,
'server_name': self.name,
},
)
try:
self.client = Client(self.url, timeout=10, watchdog_intervall=3600000)
assert self.client is not None # Informa ao mypy que client não é None
@@ -230,6 +221,13 @@ class OpcManager(SientiaMonitoring):
'server_url': self.url,
},
)
await self.emit_metric(
metric_object=metrics.OPC_CONNECTIONS_TOTAL,
tags={
'pod_id': self.pod_id,
'server_name': self.name,
}
)
self.logger.info(f'Connection to {self.name} successful.')
except Exception:
await self.disconnect()