Skip to content

Commit 9f042c5

Browse files
removes tracing and redundant code
Signed-off-by: Elena Kolevska <[email protected]>
1 parent f3c54fe commit 9f042c5

File tree

9 files changed

+16
-197
lines changed

9 files changed

+16
-197
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ OTEL_SERVICE_VERSION=1.0.0
5656
OTEL_EXPORTER_OTLP_ENDPOINT=
5757
OTEL_EXPORTER_OTLP_HEADERS=
5858
OTEL_EXPORTER_OTLP_TIMEOUT=10
59-
OTEL_EXPORTER_JAEGER_ENDPOINT=
59+
6060
OTEL_RESOURCE_ATTRIBUTES=service.name=redis-py-test-app,service.version=1.0.0
6161

6262
# Multi-App Identification

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ python main.py run --workload-profile basic_rw # unlimited test run
3131
**Access your dashboards:**
3232
- **📊 Grafana**: http://localhost:3000 (admin/admin) - **Redis Test Dashboard**
3333
- **📈 Prometheus**: http://localhost:9090 - Raw metrics
34-
- **🔍 Jaeger**: http://localhost:16686 - Distributed tracing
3534

3635
### 🐳 Full Docker Environment
3736

@@ -44,7 +43,7 @@ python main.py run --workload-profile basic_rw # unlimited test run
4443
This single command will:
4544
- Build the Redis test application
4645
- Start Redis database
47-
- Launch complete monitoring stack (Prometheus, Grafana, Jaeger)
46+
- Launch complete monitoring stack (Prometheus, Grafana)
4847
- Begin running performance tests
4948

5049
**Management commands:**
@@ -71,7 +70,7 @@ make dev-start
7170
```
7271

7372
This will:
74-
- Start metrics stack (Redis, Prometheus, Grafana, Jaeger) in Docker
73+
- Start metrics stack (Redis, Prometheus, Grafana) in Docker
7574
- Install Python dependencies in virtual environment
7675
- Configure local environment (.env file)
7776
- Test the connection
@@ -88,7 +87,6 @@ make dev-start-metrics-stack
8887
### Access Services
8988
- **📊 Grafana**: http://localhost:3000 (admin/admin) - **Redis Test Dashboard**
9089
- **📈 Prometheus**: http://localhost:9090 - Raw metrics and queries
91-
- **🔍 Jaeger**: http://localhost:16686 - Distributed tracing
9290
- **📡 Redis**: localhost:6379 - Database connection
9391

9492
### Development Workflow
@@ -474,7 +472,6 @@ make deploy-prod # Production environment
474472
### **Monitoring Stack:**
475473
- **Prometheus** - Metrics collection
476474
- **Grafana** - Dashboards and visualization
477-
- **Jaeger** - Distributed tracing
478475
- **OpenTelemetry** - Observability framework
479476

480477
**📋 TODO Items:**

cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def test_connection():
213213
client = RedisClientManager(redis_config)
214214

215215
# Test basic operations
216-
client.execute_command('ping')
216+
client.ping()
217217
info = client.get_info()
218218

219219
click.echo("✓ Redis connection successful!")

diagrams/class-diagram.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ classDiagram
128128
+publish(channel: str, message: str) int
129129
+pubsub() PubSub
130130
+pipeline() Pipeline
131-
+execute_command(command: str, *args) Any
131+
132132
+ping() bool
133133
+close() void
134134
}
@@ -272,7 +272,7 @@ classDiagram
272272
+record_connection_attempt(success: bool) void
273273
+record_reconnection(duration: float) void
274274
+update_active_connections(count: int) void
275-
+update_calculated_metrics() void
275+
276276
+get_stats() Dict[str,Any]
277277
+get_detailed_stats() Dict[str,Any]
278278
+reset_stats() void

docker-compose.metrics.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ services:
3030
- "4317:4317" # OTLP gRPC receiver
3131
- "4318:4318" # OTLP HTTP receiver
3232
- "8889:8889" # Prometheus metrics endpoint
33-
- "14250:14250" # Jaeger gRPC
33+
3434
depends_on:
3535
- prometheus
36-
- jaeger
3736
networks:
3837
- redis-test-network
3938

@@ -74,17 +73,7 @@ services:
7473
networks:
7574
- redis-test-network
7675

77-
# Jaeger
78-
jaeger:
79-
image: jaegertracing/all-in-one:latest
80-
container_name: jaeger
81-
environment:
82-
- COLLECTOR_OTLP_ENABLED=true
83-
ports:
84-
- "16686:16686" # Jaeger UI
85-
- "14268:14268" # Jaeger collector HTTP
86-
networks:
87-
- redis-test-network
76+
8877

8978
networks:
9079
redis-test-network:

docker-compose.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,8 @@ services:
122122
- "4317:4317" # OTLP gRPC receiver
123123
- "4318:4318" # OTLP HTTP receiver
124124
- "8889:8889" # Prometheus metrics
125-
- "14250:14250" # Jaeger gRPC
125+
126126
depends_on:
127-
- jaeger
128127
- prometheus
129128
networks:
130129
- redis-test-network
@@ -166,17 +165,7 @@ services:
166165
networks:
167166
- redis-test-network
168167

169-
# Jaeger
170-
jaeger:
171-
image: jaegertracing/all-in-one:latest
172-
container_name: jaeger
173-
ports:
174-
- "16686:16686" # Jaeger UI
175-
- "14268:14268" # Jaeger HTTP
176-
environment:
177-
- COLLECTOR_OTLP_ENABLED=true
178-
networks:
179-
- redis-test-network
168+
180169

181170
volumes:
182171
redis_data:

metrics.py

Lines changed: 4 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,15 @@
1212
import uuid
1313

1414
# Prometheus imports (for backward compatibility)
15-
from prometheus_client import Counter, Histogram, Gauge, start_http_server
15+
from prometheus_client import Counter, Histogram, Gauge
1616

1717
# OpenTelemetry imports
1818
from opentelemetry import metrics as otel_metrics
19-
from opentelemetry import trace as otel_trace
2019
from opentelemetry.sdk.metrics import MeterProvider
21-
from opentelemetry.sdk.trace import TracerProvider
2220
from opentelemetry.sdk.resources import Resource
2321
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter
24-
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
2522
from opentelemetry.exporter.prometheus import PrometheusMetricReader
2623
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
27-
from opentelemetry.sdk.trace.export import BatchSpanProcessor
2824
# Note: RedisInstrumentor import removed to prevent automatic instrumentation
2925

3026
from logger import get_logger
@@ -136,18 +132,7 @@ def _setup_opentelemetry(self):
136132
unit="1"
137133
)
138134

139-
# Setup tracing
140-
if self.otel_endpoint:
141-
trace_exporter = OTLPSpanExporter(
142-
endpoint=self.otel_endpoint,
143-
insecure=True
144-
)
145-
trace_provider = TracerProvider(resource=resource)
146-
trace_provider.add_span_processor(
147-
BatchSpanProcessor(trace_exporter)
148-
)
149-
otel_trace.set_tracer_provider(trace_provider)
150-
self.tracer = otel_trace.get_tracer(self.service_name, self.service_version)
135+
151136

152137
# Note: Using manual instrumentation instead of automatic Redis instrumentation
153138
# to have full control over operation labeling and avoid "BATCH" aggregation
@@ -214,14 +199,7 @@ def _setup_prometheus_metrics(self):
214199
['operation'] + base_labels
215200
)
216201

217-
def _start_prometheus_server(self):
218-
"""Start Prometheus metrics server."""
219-
try:
220-
start_http_server(self.prometheus_port)
221-
self.logger.info(f"Prometheus metrics server started on port {self.prometheus_port}")
222-
except Exception as e:
223-
self.logger.error(f"Failed to start Prometheus server: {e}")
224-
self.enable_prometheus = False
202+
225203

226204
def record_operation(self, operation: str, duration: float, success: bool, error_type: str = None):
227205
"""Record metrics for a Redis operation."""
@@ -318,50 +296,9 @@ def update_active_connections(self, count: int):
318296

319297
# Active connections tracked via OpenTelemetry only
320298

321-
def update_calculated_metrics(self):
322-
"""Update calculated metrics like throughput, error rate, and average latency."""
323-
if not self.enable_otel:
324-
return
325299

326-
with self._lock:
327-
# Calculate overall throughput and error rate
328-
total_ops = sum(m.total_count for m in self._metrics.values())
329-
total_errors = sum(m.error_count for m in self._metrics.values())
330300

331-
if total_ops > 0:
332-
# Calculate current throughput (ops in last interval)
333-
current_time = time.time()
334-
if hasattr(self, '_last_metrics_update'):
335-
time_diff = current_time - self._last_metrics_update
336-
if time_diff > 0:
337-
ops_diff = total_ops - getattr(self, '_last_total_ops', 0)
338-
current_throughput = ops_diff / time_diff
339-
# Calculated metrics are now handled by the OpenTelemetry Collector
340-
# which exposes them via its Prometheus endpoint
341-
342-
# Error rate and average latency calculations
343-
error_rate = (total_errors / total_ops) * 100
344-
# These calculated metrics are available via the collector's Prometheus endpoint
345-
346-
# Store for next calculation
347-
self._last_metrics_update = current_time
348-
self._last_total_ops = total_ops
349-
350-
def create_span(self, operation_name: str, **attributes):
351-
"""Create an OpenTelemetry span for tracing Redis operations."""
352-
if self.enable_otel and hasattr(self, 'tracer'):
353-
return self.tracer.start_span(
354-
name=f"redis.{operation_name}",
355-
attributes={
356-
"db.system": "redis",
357-
"db.operation": operation_name,
358-
**attributes
359-
}
360-
)
361-
else:
362-
# Return a no-op context manager if OpenTelemetry is not enabled
363-
from contextlib import nullcontext
364-
return nullcontext()
301+
365302

366303
def get_operation_stats(self, operation: str) -> Dict:
367304
"""Get statistics for a specific operation."""

observability/otel-collector-config.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,15 @@ exporters:
2222
endpoint: "0.0.0.0:8889"
2323
# Remove const_labels to avoid duplication
2424

25-
# OTLP exporter for Jaeger (using internal Docker network)
26-
otlp/jaeger:
27-
endpoint: jaeger:4317
28-
tls:
29-
insecure: true
25+
3026

3127
# Debug exporter for debugging (replaces deprecated logging exporter)
3228
debug:
3329
verbosity: normal
3430

3531
service:
3632
pipelines:
37-
traces:
38-
receivers: [otlp]
39-
processors: [batch]
40-
exporters: [otlp/jaeger, debug]
33+
4134

4235
metrics:
4336
receivers: [otlp]

redis_client.py

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -183,93 +183,7 @@ def _reconnect(self) -> bool:
183183
self.logger.error(f"Failed to reconnect after {self.config.retry_attempts} attempts")
184184
return False
185185

186-
def execute_command(self, command: str, *args, **kwargs) -> Any:
187-
"""Execute a Redis command with automatic retry and error handling."""
188-
if not self._ensure_connection():
189-
raise ConnectionError("No Redis connection available")
190-
191-
start_time = time.time()
192-
last_exception = None
193-
194-
# Create OpenTelemetry span for tracing
195-
with self.metrics.create_span(
196-
command,
197-
db_statement=f"{command} {' '.join(str(arg) for arg in args[:2])}", # Limit args for privacy
198-
db_redis_database_index=self.config.database
199-
) as span:
200-
for attempt in range(self.config.retry_attempts):
201-
try:
202-
# Execute the command
203-
result = getattr(self._client, command.lower())(*args, **kwargs)
204-
205-
# Record successful operation
206-
duration = time.time() - start_time
207-
self.metrics.record_operation(command, duration, True)
208-
209-
# Update span with success
210-
if span and hasattr(span, 'set_status'):
211-
from opentelemetry.trace import Status, StatusCode
212-
span.set_status(Status(StatusCode.OK))
213-
span.set_attribute("db.operation.success", True)
214-
215-
return result
216-
217-
except (ConnectionError, TimeoutError, ClusterDownError) as e:
218-
last_exception = e
219-
self.logger.warning(f"Connection error during {command}: {e}")
220-
221-
# Update span with error
222-
if span and hasattr(span, 'record_exception'):
223-
span.record_exception(e)
224-
span.set_attribute("db.operation.success", False)
225-
span.set_attribute("error.type", type(e).__name__)
226-
227-
# Try to reconnect
228-
if not self._reconnect():
229-
break
230-
231-
except (ResponseError, RedisError) as e:
232-
# Redis-level errors (don't retry)
233-
duration = time.time() - start_time
234-
error_type = type(e).__name__
235-
self.metrics.record_operation(command, duration, False, error_type)
236-
237-
# Update span with error
238-
if span and hasattr(span, 'record_exception'):
239-
span.record_exception(e)
240-
span.set_attribute("db.operation.success", False)
241-
span.set_attribute("error.type", error_type)
242-
243-
raise e
244-
245-
except Exception as e:
246-
# Unexpected errors
247-
duration = time.time() - start_time
248-
error_type = type(e).__name__
249-
self.metrics.record_operation(command, duration, False, error_type)
250-
log_error_with_traceback(f"Unexpected error during {command}", e)
251-
252-
# Update span with error
253-
if span and hasattr(span, 'record_exception'):
254-
span.record_exception(e)
255-
span.set_attribute("db.operation.success", False)
256-
span.set_attribute("error.type", error_type)
257-
258-
raise e
259-
260-
# All retry attempts failed
261-
duration = time.time() - start_time
262-
error_type = type(last_exception).__name__ if last_exception else "ConnectionError"
263-
self.metrics.record_operation(command, duration, False, error_type)
264-
265-
# Update span with final error
266-
if span and hasattr(span, 'record_exception') and last_exception:
267-
span.record_exception(last_exception)
268-
span.set_attribute("db.operation.success", False)
269-
span.set_attribute("error.type", error_type)
270-
span.set_attribute("retry.attempts", self.config.retry_attempts)
271186

272-
raise last_exception or ConnectionError("Failed to execute command after retries")
273187

274188
def pipeline(self, transaction: bool = True):
275189
"""Create a pipeline for batch operations."""

0 commit comments

Comments
 (0)