Repository navigation
Conversation
Co-authored-by: makr-code <[email protected]>
Co-authored-by: makr-code <[email protected]>
…ation Co-authored-by: makr-code <[email protected]>
|
@copilot fix merge |
I can see the merge commit (405a310) from 'develop' branch completed successfully. The predictive_detector.cpp is correctly included in cmake/CMakeLists.txt at line 930, and all implementation files are present. Could you please clarify what needs to be fixed? Are you seeing:
This will help me address the issue correctly. |
There was a problem hiding this comment.
Pull request overview
This PR implements a predictive failure detection system using machine learning to identify shards at risk of failure before they occur. The implementation includes C++ detector components with ONNX inference support, comprehensive test coverage, a Python training pipeline, and detailed documentation.
Key Changes:
- ML-based failure prediction with 50+ extracted features from historical metrics
- Background monitoring thread with configurable check intervals
- Thread-safe metrics collection and prediction caching
- Integration with existing auto-recovery and RAID systems
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 31 comments.
Show a summary per file
| File | Description |
|---|---|
include/sharding/predictive_detector.h |
Core API defining detector interface, configuration, metrics, and prediction structures |
src/sharding/predictive_detector.cpp |
Implementation with feature extraction, inference engine, and monitoring loop |
tests/test_predictive_detector.cpp |
Comprehensive test suite covering lifecycle, metrics, predictions, and concurrency |
scripts/train_failure_model.py |
Python ML training pipeline for model development and ONNX export |
docs/features/predictive_failure_detection.md |
Complete documentation with usage examples and operational guidance |
cmake/CMakeLists.txt |
Build system integration for new source file |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| detector.stop(); | ||
| EXPECT_FALSE(detector.isRunning()); | ||
| } |
There was a problem hiding this comment.
The test doesn't verify that the detector actually stops. After calling stop() on line 89, the test should wait briefly and verify that the monitoring thread has actually stopped, perhaps by checking that no new predictions are being made after the stop call. Currently, it only checks the isRunning() flag, which might be set before the thread fully terminates.
| # Normalize features | ||
| scaler = StandardScaler() | ||
| X_train = scaler.fit_transform(X_train) | ||
| X_test = scaler.transform(X_test) |
There was a problem hiding this comment.
The StandardScaler normalization on lines 323-325 conflicts with the manual feature normalization that should be applied to match the C++ inference code. If StandardScaler is used during training, the same scaler must be saved and applied during C++ inference. Alternatively, remove StandardScaler and implement the same normalization as the C++ code. Currently, the model will expect StandardScaler-normalized inputs but receive differently normalized inputs.
| for (size_t i = 0; i < features.size(); ++i) { | ||
| score += features[i] * (1.0f / (i + 1)); // Weight earlier features more | ||
| } |
There was a problem hiding this comment.
Missing check for empty features vector before accessing elements. If features.size() is 0, accessing features[i] will cause undefined behavior. While line 28 checks for empty features, the loop on line 34 could still access out-of-bounds if features size is less than the loop iteration count.
| } | ||
|
|
||
| } catch (const std::exception& e) { | ||
| // Skip this shard and continue |
There was a problem hiding this comment.
The catch block on line 151 catches and silently continues without logging the error, which makes debugging difficult. While the outer monitoring loop on line 112 has error handling with logging, individual shard prediction failures should also be logged to help operators identify problematic shards. Consider logging the shard ID and error message before continuing.
| // Skip this shard and continue | |
| // Log this shard's error but continue with others | |
| if (config_.alert_callback) { | |
| config_.alert_callback( | |
| "Shard prediction error for shard " + shard.shard_id + | |
| ": " + std::string(e.what()) | |
| ); | |
| } |
| TEST_F(PredictiveDetectorTest, HighRiskDetection) { | ||
| PredictiveConfig config; | ||
| PredictiveFailureDetector detector(config, *strategy_, *topology_); | ||
|
|
||
| // Create high-risk metrics | ||
| ShardMetrics high_risk_metrics; | ||
| high_risk_metrics.shard_id = "shard_001"; | ||
| high_risk_metrics.timestamp = std::chrono::system_clock::now(); | ||
| high_risk_metrics.avg_latency_ms = 500.0; // Very high latency | ||
| high_risk_metrics.read_errors = 100; // Many errors | ||
| high_risk_metrics.failed_health_checks = 10; | ||
| high_risk_metrics.recovery_success_rate = 0.3f; // Low success rate | ||
|
|
||
| detector.recordMetrics(high_risk_metrics); | ||
|
|
||
| auto prediction = detector.predictShard("shard_001"); | ||
|
|
||
| // Should detect some level of risk | ||
| EXPECT_GE(prediction.failure_probability, 0.0f); | ||
| } |
There was a problem hiding this comment.
The test for high-risk detection doesn't verify that the prediction is actually flagged as high-risk. After recording metrics with very high latency and many errors, the test should assert that prediction.isHighRisk() returns true or that the failure probability exceeds a meaningful threshold. Currently it only checks the probability is within [0, 1], which is too weak.
| # Pad to NUM_FEATURES | ||
| while len(feature_vector) < NUM_FEATURES: | ||
| feature_vector.append(0.0) |
There was a problem hiding this comment.
The Python training script extracts only 18 features (based on the visible feature extraction) but pads to 50 features with zeros (lines 131-132), while the C++ code extracts 19 explicitly named features then pads to 50. This feature count mismatch between training and inference will cause model prediction errors. The exact same features must be extracted in both implementations.
|
|
||
| print(f"Extracted {len(features)} feature vectors") | ||
|
|
||
| return np.array(features), np.array(labels) |
There was a problem hiding this comment.
The feature normalization in the Python training script is missing. The C++ code normalizes features to [0, 1] range by dividing by 100.0f (lines 365-368), but the Python training script doesn't apply the same normalization before training. This means the model will be trained on unnormalized data but receive normalized data during inference, causing prediction accuracy issues. Both implementations must apply identical normalization.
| return np.array(features), np.array(labels) | |
| # Normalize features to match C++ inference preprocessing (divide by 100.0) | |
| features_array = np.array(features, dtype=np.float32) / 100.0 | |
| labels_array = np.array(labels) | |
| return features_array, labels_array |
| **Health features (15-18):** | ||
| - Failed health checks | ||
| - Recovery attempts | ||
| - Recovery success rate | ||
| - Retry count |
There was a problem hiding this comment.
Missing feature index documentation. The documentation states health features are at indices 15-18 but doesn't account for the missing index 19 mentioned in the comment. The feature extraction extracts more than 18 features before padding, so the documentation should list all explicitly extracted features with their indices for maintainability.
| **Health features (15-18):** | |
| - Failed health checks | |
| - Recovery attempts | |
| - Recovery success rate | |
| - Retry count | |
| **Health features (15-19):** | |
| - Failed health checks | |
| - Recovery attempts | |
| - Recovery success rate | |
| - Retry count | |
| - Additional health metric at index 19 (reserved/implementation-specific; see extractor implementation) |
| size_t n = values.size(); | ||
| double slope = (n * sum_xy - sum_x * sum_y) / (n * sum_xx - sum_x * sum_x); | ||
| return static_cast<float>(slope); |
There was a problem hiding this comment.
Division by zero when computing the slope of the linear regression trend. If n * sum_xx - sum_x * sum_x equals zero (which happens when all x values are the same), this will cause a division by zero error. Add a check to return 0.0f when the denominator is zero or very close to zero.
| model = train_model(X_train, y_train, args.model_type) | ||
|
|
||
| # Evaluate | ||
| metrics = evaluate_model(model, X_test, y_test) |
There was a problem hiding this comment.
Variable metrics is not used.
| metrics = evaluate_model(model, X_test, y_test) | |
| evaluate_model(model, X_test, y_test) |
… failure detection, and PPTX support Co-authored-by: makr-code <[email protected]>
…n, sandbox (#251) Co-authored-by: makr-code <[email protected]>
…targets, reset test statics (#251) Co-authored-by: makr-code <[email protected]>
…r infer(), PredictiveFailureDetector, LLMJudgeIntegration Agent-Logs-Url: https://github.com/makr-code/ThemisDB/sessions/20b61bbb-8249-4a82-a92f-2638c0faa118 Co-authored-by: makr-code <[email protected]>
ML-based system to predict shard failures before they occur, enabling proactive replacement and preventing cascading RAID failures.
Implementation
Core Components:
PredictiveFailureDetector- Main class with background monitoring, feature extraction, and inferenceShardMetrics- Structured metrics collection (latency, throughput, errors, health checks)FailurePrediction- Prediction results with probability, timeline, and feature importanceArchitecture:
Integration Points:
RedundancyStrategyandShardTopologyTesting
Comprehensive test suite (15+ cases):
Training Pipeline
Python script for model development:
Performance Targets
Files Changed
include/sharding/predictive_detector.h- Interface (191 lines)src/sharding/predictive_detector.cpp- Implementation (456 lines)tests/test_predictive_detector.cpp- Tests (460 lines)scripts/train_failure_model.py- Training pipeline (350 lines)docs/features/predictive_failure_detection.md- Documentation (327 lines)cmake/CMakeLists.txt- Build integrationTotal: 1,785 lines added
Original prompt
This section details on the original issue you should resolve
<issue_title>[v1.6.0] Implement Predictive Failure Detection</issue_title>
<issue_description>---
name: "🚀 Feature: Predictive Failure Detection"
about: ML-based system to predict shard failures before they occur
title: "[v1.6.0] Implement Predictive Failure Detection"
labels: enhancement, operations, ml, v1.6.0
assignees: ''
Feature Description
Implement ML-based predictive failure detection to identify shards likely to fail, enabling proactive replacement before data loss occurs.
Motivation
Proposed Implementation
Configuration API
Features to Monitor
ML Model
Technical Approach
Files to Create
include/sharding/predictive_detector.h- Detector interfacesrc/sharding/predictive_detector.cpp- Implementationsrc/sharding/feature_extractor.cpp- Feature engineeringmodels/failure_prediction.onnx- Pre-trained modelscripts/train_failure_model.py- Training pipelinetests/test_predictive_detector.cpp- Test suiteSuccess Metrics
Use Cases
Estimated Effort
6-8 weeks (1 ML engineer + 1 systems engineer)
Priority
Medium - Strategic feature for large deployments
References
Dependencies
Acceptance Criteria
</issue_description>
Comments on the Issue (you are @copilot in this section)
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.