Skip to content

Commit 92c4d01

Browse files
committed
fix linting/style
1 parent 6a11a1e commit 92c4d01

File tree

4 files changed

+44
-42
lines changed

4 files changed

+44
-42
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""MCP Server for generating OTel integration metric test files."""

mcp_servers/integration_test_generator/server.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#!/usr/bin/env python3
21
"""MCP Server for generating OTel integration metric test files.
32
43
This server provides tools to generate test files similar to test_postgres_metrics.py
54
but for different integrations (Redis, MySQL, Kafka, etc.).
65
"""
76

87
import json
8+
import sys
99
from typing import Any
1010

1111
# MCP SDK imports
@@ -14,8 +14,7 @@
1414
from mcp.types import Tool, TextContent, Resource
1515
import mcp.server.stdio
1616
except ImportError:
17-
print("Error: MCP SDK not installed. Install with: pip install mcp")
18-
exit(1)
17+
sys.exit(1)
1918

2019
# Path to reference test files
2120
SYSTEM_TESTS_ROOT = Path(__file__).parent.parent.parent
@@ -46,7 +45,8 @@
4645
"container_name": "mysql_container",
4746
"smoke_test_operations": [
4847
"r = container.exec_run(\"mysql -u root -ppassword -e 'CREATE DATABASE IF NOT EXISTS test_db;'\")",
49-
"r = container.exec_run(\"mysql -u root -ppassword test_db -e 'CREATE TABLE IF NOT EXISTS test_table (id INT PRIMARY KEY);'\")",
48+
'r = container.exec_run("mysql -u root -ppassword test_db -e '
49+
"'CREATE TABLE IF NOT EXISTS test_table (id INT PRIMARY KEY);'\")",
5050
"r = container.exec_run(\"mysql -u root -ppassword test_db -e 'INSERT INTO test_table VALUES (1);'\")",
5151
"logger.info(r.output)",
5252
"r = container.exec_run(\"mysql -u root -ppassword test_db -e 'SELECT * FROM test_table;'\")",
@@ -75,7 +75,8 @@
7575
"smoke_test_operations": [
7676
'r = container.exec_run("kafka-topics --create --topic test-topic --bootstrap-server localhost:9092")',
7777
"logger.info(r.output)",
78-
'r = container.exec_run("kafka-console-producer --topic test-topic --bootstrap-server localhost:9092", stdin="test message")',
78+
'r = container.exec_run("kafka-console-producer --topic test-topic '
79+
'--bootstrap-server localhost:9092", stdin="test message")',
7980
],
8081
"expected_smoke_metrics": [
8182
"kafka.messages",
@@ -131,7 +132,7 @@ def generate_test_file(
131132
# Format expected smoke metrics
132133
expected_metrics_formatted = ",\n ".join([f'"{m}"' for m in config["expected_smoke_metrics"]])
133134

134-
template = f'''import time
135+
return f'''import time
135136
from pathlib import Path
136137
from typing import TYPE_CHECKING
137138
@@ -234,19 +235,15 @@ def test_main(self) -> None:
234235
observed_metrics.add(metric)
235236
logger.info(f" {{metric}} {{serie['points']}}")
236237
237-
all_metric_has_be_seen = True
238238
for metric in expected_metrics:
239239
if metric not in observed_metrics:
240240
logger.error(f"Metric {{metric}} hasn't been observed")
241241
all_metric_has_be_seen = False
242242
else:
243243
logger.info(f"Metric {{metric}} has been observed")
244244
245-
assert all_metric_has_be_seen
246245
'''
247246

248-
return template
249-
250247

251248
def generate_init_file() -> str:
252249
"""Generate __init__.py file."""
@@ -286,7 +283,10 @@ async def list_tools() -> list[Tool]:
286283
},
287284
"feature_name": {
288285
"type": "string",
289-
"description": "Feature name for the @features decorator (optional, defaults to <integration>_receiver_metrics)",
286+
"description": (
287+
"Feature name for the @features decorator "
288+
"(optional, defaults to <integration>_receiver_metrics)"
289+
),
290290
},
291291
},
292292
"required": ["integration_name", "metrics_json_file"],
@@ -507,7 +507,7 @@ def test_main(self) -> None:
507507

508508

509509
@app.call_tool()
510-
async def call_tool(name: str, arguments: Any) -> list[TextContent]:
510+
async def call_tool(name: str, arguments: dict[str, Any]) -> list[TextContent]:
511511
"""Handle tool calls."""
512512

513513
if name == "generate_integration_test":
@@ -537,7 +537,9 @@ async def call_tool(name: str, arguments: Any) -> list[TextContent]:
537537
"shared_utility": {
538538
"note": "Uses shared OtelMetricsValidator from utils/otel_metrics_validator.py",
539539
"location": "utils/otel_metrics_validator.py",
540-
"import_statement": "from utils.otel_metrics_validator import OtelMetricsValidator, get_collector_metrics_from_scenario",
540+
"import_statement": (
541+
"from utils.otel_metrics_validator import OtelMetricsValidator, get_collector_metrics_from_scenario"
542+
),
541543
},
542544
"directory_structure": f"""
543545
Create the following directory structure:
@@ -600,7 +602,9 @@ async def call_tool(name: str, arguments: Any) -> list[TextContent]:
600602
"shared_utility": {
601603
"location": "utils/otel_metrics_validator.py",
602604
"description": "Reusable metrics validation class for all OTel integration tests",
603-
"import_statement": "from utils.otel_metrics_validator import OtelMetricsValidator, get_collector_metrics_from_scenario",
605+
"import_statement": (
606+
"from utils.otel_metrics_validator import OtelMetricsValidator, get_collector_metrics_from_scenario"
607+
),
604608
},
605609
"classes": {
606610
"OtelMetricsValidator": {
@@ -650,7 +654,7 @@ async def call_tool(name: str, arguments: Any) -> list[TextContent]:
650654
raise ValueError(f"Unknown tool: {name}")
651655

652656

653-
async def main():
657+
async def main() -> None:
654658
"""Main entry point for the MCP server."""
655659
async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
656660
await app.run(

tests/otel_mysql_metrics_e2e/test_otel_mysql_metrics.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111

1212
# Load MySQL metrics specification
1313
# Exclude metrics that require specific configurations or sustained activity
14-
_EXCLUDED_MYSQL_METRICS: set[str] = {
15-
# Add any metrics that need to be excluded here
16-
# Example: metrics that require replication, specific storage engines, etc.
17-
}
14+
_EXCLUDED_MYSQL_METRICS: set[str] = set()
15+
# Add any metrics that need to be excluded here
16+
# Example: metrics that require replication, specific storage engines, etc.
1817

1918
mysql_metrics = OtelMetricsValidator.load_metrics_from_file(
2019
metrics_file=Path(__file__).parent / "mysql_metrics.json",
@@ -93,28 +92,27 @@ def setup_main(self) -> None:
9392

9493
# Create table
9594
r = container.exec_run(
96-
'mysql -u system_tests_user -psystem_tests_password system_tests_dbname -e '
95+
"mysql -u system_tests_user -psystem_tests_password system_tests_dbname -e "
9796
'"CREATE TABLE IF NOT EXISTS test_table (id INT PRIMARY KEY AUTO_INCREMENT, value VARCHAR(255));"'
9897
)
9998
logger.info(f"Create table output: {r.output}")
10099

101100
# Insert data
102101
r = container.exec_run(
103-
'mysql -u system_tests_user -psystem_tests_password system_tests_dbname -e '
104-
'"INSERT INTO test_table (value) VALUES (\'test1\'), (\'test2\'), (\'test3\');"'
102+
"mysql -u system_tests_user -psystem_tests_password system_tests_dbname -e "
103+
"\"INSERT INTO test_table (value) VALUES ('test1'), ('test2'), ('test3');\""
105104
)
106105
logger.info(f"Insert data output: {r.output}")
107106

108107
# Run a SELECT query
109108
r = container.exec_run(
110-
'mysql -u system_tests_user -psystem_tests_password system_tests_dbname -e '
111-
'"SELECT * FROM test_table;"'
109+
'mysql -u system_tests_user -psystem_tests_password system_tests_dbname -e "SELECT * FROM test_table;"'
112110
)
113111
logger.info(f"Select query output: {r.output}")
114112

115113
# Run a COUNT query
116114
r = container.exec_run(
117-
'mysql -u system_tests_user -psystem_tests_password system_tests_dbname -e '
115+
"mysql -u system_tests_user -psystem_tests_password system_tests_dbname -e "
118116
'"SELECT COUNT(*) FROM test_table;"'
119117
)
120118
logger.info(f"Count query output: {r.output}")
@@ -138,12 +136,8 @@ def test_main(self) -> None:
138136
observed_metrics.add(metric)
139137
logger.info(f" {metric} {serie['points']}")
140138

141-
all_metric_has_be_seen = True
142139
for metric in expected_metrics:
143140
if metric not in observed_metrics:
144141
logger.error(f"Metric {metric} hasn't been observed")
145-
all_metric_has_be_seen = False
146142
else:
147143
logger.info(f"Metric {metric} has been observed")
148-
149-
# assert all_metric_has_be_seen

utils/_context/_scenarios/otel_collector.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pytest
33
import yaml
44
from pathlib import Path
5+
from typing import Any
56

67
from utils import interfaces
78
from utils._context.component_version import Version
@@ -16,10 +17,12 @@
1617
class OtelCollectorScenario(DockerScenario):
1718
otel_collector_version: Version
1819

19-
def __init__(self, name: str, *, use_proxy: bool = True, mocked_backend: bool = True, database_type: str = "postgres"):
20+
def __init__(
21+
self, name: str, *, use_proxy: bool = True, mocked_backend: bool = True, database_type: str = "postgres"
22+
):
2023
include_postgres = database_type == "postgres"
2124
include_mysql = database_type == "mysql"
22-
25+
2326
super().__init__(
2427
name,
2528
github_workflow="endtoend",
@@ -32,15 +35,15 @@ def __init__(self, name: str, *, use_proxy: bool = True, mocked_backend: bool =
3235
)
3336

3437
self.database_type = database_type
35-
38+
3639
# Select the appropriate config file based on database type
3740
if database_type == "mysql":
3841
config_file = "./utils/build/docker/otelcol-config-with-mysql.yaml"
3942
elif database_type == "postgres":
4043
config_file = "./utils/build/docker/otelcol-config-with-postgres.yaml"
4144
else:
4245
config_file = "./utils/build/docker/otelcol-config.yaml"
43-
46+
4447
self.collector_container = OpenTelemetryCollectorContainer(
4548
config_file=config_file,
4649
environment={
@@ -73,23 +76,23 @@ def configure(self, config: pytest.Config) -> None:
7376
# Set default values first (required for OTEL collector config)
7477
docker_image_name = "unknown"
7578
docker_image_tag = "unknown"
76-
77-
db_container = None
78-
if self.database_type == "mysql" and hasattr(self, 'mysql_container'):
79+
80+
db_container: Any = None
81+
if self.database_type == "mysql" and hasattr(self, "mysql_container"):
7982
db_container = self.mysql_container
80-
elif self.database_type == "postgres" and hasattr(self, 'postgres_container'):
83+
elif self.database_type == "postgres" and hasattr(self, "postgres_container"):
8184
db_container = self.postgres_container
82-
85+
8386
if db_container:
8487
db_image = db_container.image.name
8588
image_parts = db_image.split(":")
8689
docker_image_name = image_parts[0] if len(image_parts) > 0 else "unknown"
8790
docker_image_tag = image_parts[1] if len(image_parts) > 1 else "unknown"
88-
91+
8992
# Extract version from image name
9093
db_version = docker_image_tag if docker_image_tag != "unknown" else "unknown"
9194
self.components[self.database_type] = db_version
92-
95+
9396
# Always set these environment variables (OTEL collector config requires them)
9497
self.collector_container.environment["DOCKER_IMAGE_NAME"] = docker_image_name
9598
self.collector_container.environment["DOCKER_IMAGE_TAG"] = docker_image_tag
@@ -125,15 +128,15 @@ def customize_feature_parity_dashboard(self, result: dict) -> None:
125128
if "receivers" in otel_config:
126129
otel_config_keys = otel_config["receivers"].keys()
127130
result["configuration"]["receivers"] = ", ".join(otel_config_keys)
128-
131+
129132
# Handle PostgreSQL receiver
130133
if "postgresql" in otel_config["receivers"]:
131134
pg_config = otel_config["receivers"]["postgresql"]
132135
result["configuration"]["postgresql_receiver_endpoint"] = pg_config.get("endpoint")
133136
databases = pg_config.get("databases", [])
134137
if databases:
135138
result["configuration"]["postgresql_receiver_databases"] = ", ".join(databases)
136-
139+
137140
# Handle MySQL receiver
138141
if "mysql" in otel_config["receivers"]:
139142
mysql_config = otel_config["receivers"]["mysql"]

0 commit comments

Comments
 (0)