Skip to content

Commit 5c962a8

Browse files
committed
Remove unused metrics, health check, and unit test files
Deleted obsolete `metrics.py`, `health.py`, and their related unit test files. These files are no longer relevant to the project, reducing unnecessary code and improving project maintainability.
1 parent d733b09 commit 5c962a8

File tree

15 files changed

+457
-2059
lines changed

15 files changed

+457
-2059
lines changed

main.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
os.environ.setdefault("MQ_FILE_PATH", os.path.join(os.getcwd(), "mq_files/windows"))
55
import signal
6-
import anyio
76
from src.bindings.bindings import Bindings
87
from src.common.log import get_logger
98
from src.api.app import APIServer
@@ -35,19 +34,19 @@ async def main():
3534
logger.info("Starting KubeMQ - IBM MQ bindings")
3635
bindings = Bindings(config_path)
3736
bindings.init()
38-
37+
3938
# Initialize and start the API server
4039
api_port = int(os.environ.get("API_PORT", "9000"))
4140
api_host = os.environ.get("API_HOST", "0.0.0.0")
4241
logger.info(f"Initializing API server on {api_host}:{api_port}")
4342
api_server = APIServer(bindings, host=api_host, port=api_port)
44-
43+
4544
# Start bindings and API server
4645
await bindings.start()
4746
await api_server.start()
48-
47+
4948
logger.info("KubeMQ - IBM MQ bindings and API server started successfully")
50-
49+
5150
# Wait for shutdown signal instead of infinite loop
5251
await shutdown_event.wait()
5352

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dependencies = [
88
"aiodebug>=2.3.0",
99
"anyio>=4.7.0",
1010
"asyncer>=0.0.8",
11-
"kubemq>=3.4.2",
11+
"kubemq>=3.5.3",
1212
"loguru>=0.7.3",
1313
"pydantic>=2.10.4",
1414
"pymqi>=1.12.10",

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ setuptools>=70.0.0
22
aiodebug>=2.3.0
33
anyio>=4.7.0
44
asyncer>=0.0.8
5-
kubemq>=3.4.2
5+
kubemq>=3.5.3
66
pydantic>=2.10.4
77
pymqi>=1.12.10
88
python-dotenv>=1.0.1

src/bindings/binding.py

Lines changed: 46 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from src.kubemq.client import KubeMQClient
99
from src.kubemq.config import Config as KubeMQConfig
1010
from src.ibm_mq.config import Config as IBMMQConfig
11-
from src.bindings.metrics import BindingMetricsCollector
1211

1312

1413
class Binding:
@@ -17,7 +16,6 @@ def __init__(self, config: BindingConfig):
1716
self.source: Connection | None = None
1817
self.target: Connection | None = None
1918
self.logger = get_logger(f"binding.{self.config.name}")
20-
self.metrics_collector: BindingMetricsCollector | None = None
2119

2220
def init(self):
2321
"""
@@ -71,14 +69,6 @@ def init(self):
7169
msg = f"Error {target_err} initialization: {str(e)}"
7270
self.logger.error(msg)
7371
raise BindingConfigError(msg)
74-
75-
# Initialize binding metrics collector
76-
if self.source and self.target:
77-
self.metrics_collector = BindingMetricsCollector(
78-
self.config.name,
79-
self.source.metrics,
80-
self.target.metrics
81-
)
8272

8373
async def start(self):
8474
await self.target.start()
@@ -88,66 +78,55 @@ async def start(self):
8878
async def stop(self):
8979
await self.source.stop()
9080
await self.target.stop()
91-
92-
def get_metrics(self) -> Dict[str, Any]:
93-
"""Get metrics from both source and target connections and aggregate them.
94-
95-
Returns:
96-
Dict containing aggregated metrics from source and target connections
97-
"""
98-
if self.metrics_collector:
99-
return self.metrics_collector.get_metrics()
100-
101-
# Fallback if metrics collector is not initialized
102-
metrics = {
103-
"binding_name": self.config.name,
104-
"binding_type": self.config.type.value,
105-
"source": None,
106-
"target": None
107-
}
108-
109-
if self.source:
110-
metrics["source"] = self.source.get_metrics()
111-
112-
if self.target:
113-
metrics["target"] = self.target.get_metrics()
114-
115-
return metrics
116-
117-
async def check_health(self) -> Dict[str, Any]:
118-
"""Check health of both source and target connections.
119-
81+
82+
async def is_healthy(self) -> bool:
83+
"""Check if the binding is healthy.
84+
12085
Returns:
121-
Dict containing health information for the binding
86+
bool: True if both source and target are healthy, False otherwise
12287
"""
123-
health = {
124-
"binding_name": self.config.name,
125-
"binding_type": self.config.type.value,
126-
"status": "healthy",
127-
"source": None,
128-
"target": None
129-
}
130-
13188
try:
132-
if self.source:
133-
source_health = await self.source.check_health()
134-
health["source"] = source_health
135-
if source_health["status"] != "healthy":
136-
health["status"] = "unhealthy"
89+
source_healthy = await self.source.is_healthy() if self.source else False
90+
target_healthy = await self.target.is_healthy() if self.target else False
91+
92+
return source_healthy and target_healthy
13793
except Exception as e:
138-
self.logger.error(f"Error checking source health: {str(e)}")
139-
health["status"] = "unhealthy"
140-
health["source"] = {"status": "unhealthy", "error": str(e)}
141-
94+
self.logger.error(f"Error checking binding health: {str(e)}")
95+
return False
96+
97+
async def get_detailed_health(self) -> Dict[str, Any]:
98+
"""Get detailed health status including source and target.
99+
100+
Returns:
101+
Dict containing health information for the binding and its components
102+
"""
142103
try:
143-
if self.target:
144-
target_health = await self.target.check_health()
145-
health["target"] = target_health
146-
if target_health["status"] != "healthy":
147-
health["status"] = "unhealthy"
104+
# Check source health
105+
source_healthy = await self.source.is_healthy() if self.source else False
106+
107+
# Check target health
108+
target_healthy = await self.target.is_healthy() if self.target else False
109+
110+
# Determine binding health
111+
binding_healthy = source_healthy and target_healthy
112+
113+
# Create health response
114+
health = {
115+
"binding_name": self.config.name,
116+
"binding_type": self.config.type.value,
117+
"is_healthy": binding_healthy,
118+
"source": {"is_healthy": source_healthy},
119+
"target": {"is_healthy": target_healthy},
120+
}
121+
122+
return health
148123
except Exception as e:
149-
self.logger.error(f"Error checking target health: {str(e)}")
150-
health["status"] = "unhealthy"
151-
health["target"] = {"status": "unhealthy", "error": str(e)}
152-
153-
return health
124+
self.logger.error(f"Error getting detailed health: {str(e)}")
125+
return {
126+
"binding_name": self.config.name,
127+
"binding_type": self.config.type.value,
128+
"is_healthy": False,
129+
"error": str(e),
130+
"source": {"is_healthy": False},
131+
"target": {"is_healthy": False},
132+
}

src/bindings/bindings.py

Lines changed: 38 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
from src.bindings.binding import Binding
55
from src.bindings.config import BindingsConfig
66
from src.common.log import get_logger
7-
from src.bindings.metrics import SystemMetricsCollector
87

98

109
class Bindings:
1110
def __init__(self, config_path: str):
1211
self.logger = get_logger("binding_manager")
1312
self.config = BindingsConfig.load(config_path)
1413
self.bindings: List[Binding] = []
15-
self.system_metrics = SystemMetricsCollector()
1614

1715
def init(self):
1816
try:
@@ -21,10 +19,6 @@ def init(self):
2119
new_binding = Binding(binding)
2220
new_binding.init()
2321
self.bindings.append(new_binding)
24-
25-
# Add binding to system metrics if it has a metrics collector
26-
if new_binding.metrics_collector:
27-
self.system_metrics.add_binding(new_binding.config.name, new_binding.metrics_collector)
2822
except Exception as e:
2923
raise Exception(f"Error initializing bindings: {str(e)}")
3024

@@ -41,78 +35,55 @@ async def stop(self):
4135
tasks.append(binding.stop())
4236

4337
await asyncio.gather(*tasks)
44-
45-
def get_all_metrics(self) -> Dict[str, Any]:
46-
"""Get aggregated metrics from all bindings.
47-
38+
39+
async def is_healthy(self) -> bool:
40+
"""Check if all bindings are healthy.
41+
4842
Returns:
49-
Dict containing system-level metrics and metrics from all bindings
43+
bool: True if all bindings are healthy, False otherwise
5044
"""
51-
# Use system metrics collector for aggregated metrics
52-
return self.system_metrics.get_metrics()
53-
54-
async def check_all_health(self) -> Dict[str, Any]:
55-
"""Check health of all bindings.
56-
45+
for binding in self.bindings:
46+
try:
47+
if not await binding.is_healthy():
48+
return False
49+
except Exception as e:
50+
self.logger.error(
51+
f"Error checking health for binding {binding.config.name}: {str(e)}"
52+
)
53+
return False
54+
55+
return True
56+
57+
async def get_detailed_health_status(self) -> Dict[str, Any]:
58+
"""Get detailed health status for all bindings.
59+
5760
Returns:
58-
Dict containing health information for all bindings
61+
Dict containing detailed health information for all bindings
5962
"""
63+
# Get overall system health
64+
system_healthy = await self.is_healthy()
65+
6066
health = {
6167
"bindings_count": len(self.bindings),
62-
"overall_status": "healthy",
63-
"bindings": {}
68+
"is_healthy": system_healthy,
69+
"bindings": {},
6470
}
65-
71+
72+
# Get health for each binding
6673
for binding in self.bindings:
6774
try:
68-
binding_health = await binding.check_health()
75+
binding_health = await binding.get_detailed_health()
6976
health["bindings"][binding.config.name] = binding_health
70-
71-
# Update overall status based on binding status
72-
if binding_health["status"] == "unhealthy":
73-
health["overall_status"] = "unhealthy"
7477
except Exception as e:
75-
self.logger.error(f"Error checking health for binding {binding.config.name}: {str(e)}")
78+
self.logger.error(
79+
f"Error checking health for binding {binding.config.name}: {str(e)}"
80+
)
7681
health["bindings"][binding.config.name] = {
77-
"status": "unhealthy",
78-
"error": str(e)
82+
"binding_name": binding.config.name,
83+
"is_healthy": False,
84+
"error": str(e),
85+
"source": {"is_healthy": False},
86+
"target": {"is_healthy": False},
7987
}
80-
health["overall_status"] = "unhealthy"
81-
88+
8289
return health
83-
84-
async def get_binding_metrics(self, binding_name: str) -> Dict[str, Any]:
85-
"""Get metrics for a specific binding.
86-
87-
Args:
88-
binding_name: Name of the binding to get metrics for
89-
90-
Returns:
91-
Dict containing metrics for the specified binding or error if not found
92-
93-
Raises:
94-
ValueError: If binding with the specified name is not found
95-
"""
96-
for binding in self.bindings:
97-
if binding.config.name == binding_name:
98-
return binding.get_metrics()
99-
100-
raise ValueError(f"Binding with name '{binding_name}' not found")
101-
102-
async def get_binding_health(self, binding_name: str) -> Dict[str, Any]:
103-
"""Check health for a specific binding.
104-
105-
Args:
106-
binding_name: Name of the binding to check health for
107-
108-
Returns:
109-
Dict containing health information for the specified binding
110-
111-
Raises:
112-
ValueError: If binding with the specified name is not found
113-
"""
114-
for binding in self.bindings:
115-
if binding.config.name == binding_name:
116-
return await binding.check_health()
117-
118-
raise ValueError(f"Binding with name '{binding_name}' not found")

src/bindings/connection.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from abc import ABC, abstractmethod
2-
from typing import Dict, Any
32

43

54
class Connection(ABC):
@@ -20,19 +19,10 @@ async def send_message(self, message: bytes):
2019
pass
2120

2221
@abstractmethod
23-
async def check_health(self) -> Dict[str, Any]:
24-
"""Check the health of the connection.
25-
26-
Returns:
27-
Dict containing health status information
28-
"""
29-
pass
22+
async def is_healthy(self) -> bool:
23+
"""Check if the connection is healthy.
3024
31-
@abstractmethod
32-
def get_metrics(self) -> Dict[str, Any]:
33-
"""Get all metrics for this connection.
34-
3525
Returns:
36-
Dict containing all metrics data
26+
bool: True if healthy, False otherwise
3727
"""
3828
pass

0 commit comments

Comments
 (0)