Skip to content

AWS Managed Prometheus RCF Anomaly Detection: Complete Guide to Best Practices and Parameter Tuning

12 minute read
Content level: Advanced
2

This guide documents our production AWS RCF implementation for 5G network monitoring. Through real-world testing, we discovered RCF excels at spike detection with zero-duration alerts, achieving sub-second response times. We share critical insights missing from AWS docs: detector maturity beats parameter tuning, and proper configuration enables 85% degradation detection with T+5s alerts. Proven production success with RCF anomaly detection.

Based on real-world implementation and testing of RCF anomaly detection in testing 5G network monitoring setup

Table of Contents

  1. Introduction
  2. RCF Terminology and Parameters
  3. Understanding RCF Behavior
  4. Parameter Tuning Best Practices
  5. Complete Implementation Journey
  6. Lessons Learned and Recommendations

Introduction

Random Cut Forest (RCF) is AWS's native machine learning algorithm for unsupervised anomaly detection in time series data. This guide documents our journey implementing RCF for 5G network monitoring, including critical discoveries about RCF's behavior that aren't well-documented elsewhere.

Key Learning: RCF excels at spike/onset detection and has proven successful in testing environments for real-time anomaly alerting with zero-duration alerts (for: 0s).


RCF Terminology and Parameters

Core RCF Concepts

Random Cut Forest Algorithm

  • Definition: Unsupervised ML algorithm that builds decision trees to partition data space
  • Purpose: Identifies data points that are isolated from normal distribution
  • Advantage: No training data required, learns "normal" automatically
  • Limitation: Continuously adapts, which can be problematic for alerting

Training Period

  • Duration: sampleSize × evaluationInterval (dynamic, configurable)
  • Default: 256 × 60s = 15,360s = 4.3 hours of learned data
  • Backfill: AWS backfills minimal historical data for immediate "ACTIVE" status
  • Behavior: Continuously learning, window size determined by parameters
  • Best Practice: Tune sampleSize/evaluationInterval for desired learning window

Anomaly Score

  • Range: 0.0 to 1.0
  • 0.0: Perfectly normal behavior, fits learned pattern
  • 0.7+: AWS recommended alert threshold for production
  • 1.0: Extremely unusual OR no data available
  • Key Insight: Score can drop to 0.0 within minutes as RCF adapts

RCF Output Metrics (4 Automatically Created)

Every RCF detector automatically generates four metrics:

1. anomaly_detector:score

anomaly_detector:score{alias="your-detector-name"}
  • Purpose: Primary alerting metric
  • Interpretation: Higher = more anomalous
  • Alert Usage: > 0.7 for testing alerts

2. anomaly_detector:upper_band

anomaly_detector:upper_band{alias="your-detector-name"}
  • Purpose: Dynamic upper threshold
  • Behavior: Adjusts based on learned patterns
  • Usage: Understanding RCF's learned normal range

3. anomaly_detector:lower_band

anomaly_detector:lower_band{alias="your-detector-name"}
  • Purpose: Dynamic lower threshold
  • Critical Issue: Can adapt down during degradation
  • Impact: Makes future similar degradations appear "normal"

4. anomaly_detector:value

anomaly_detector:value{alias="your-detector-name"}
  • Purpose: Current observed metric value
  • Usage: Correlation with source metric for validation

Detector Configuration Parameters

Alias

alias='your-detector-name'
  • Purpose: Human-readable identifier
  • Best Practice: Use descriptive names indicating metric and purpose
  • Usage: Appears in all 4 output metrics for filtering

Query

query='avg(your_metric_name)'
  • Format: Standard PromQL expression
  • Best Practice: Use aggregation functions (avg, sum) to reduce noise
  • Avoid: Raw high-cardinality metrics

Evaluation Interval

evaluationIntervalInSeconds=30
  • Range: 60-3600 seconds
  • Default: 60 seconds
  • Best Practice: 30s for responsive detection, 300s for stable metrics
  • Trade-off: Lower = more responsive but more adaptation

Sample Size

sampleSize=256
  • Purpose: Number of samples to feed to each tree in RCF
  • Default: 256 (AWS optimized for weekly data)
  • Tuning: Increase for longer learning period
  • Impact: Larger values = more stable but slower adaptation

Shingle Size

shingleSize=8
  • Purpose: Number of continuous observations to capture immediate shape of past
  • Default: 8 (AWS optimized for weekly data)
  • Tuning: Increase if scores are too noisy
  • Impact: Larger values = smoother scores but less sensitivity

Understanding RCF Behavior

RCF Design Philosophy

AWS RCF is designed for onset detection, not sustained anomaly alerting.

How RCF Works

  • Onset Detection: RCF detects anomalies when they first occur
  • Continuous Learning: Algorithm continuously adapts to streaming data
  • No Training Completion: RCF never stops learning from new samples
  • Decay Mechanism: Old samples decay over time and are no longer used

Expected Behavior Pattern

Normal → Anomaly Onset → Adaptation → New Normal
Score:    0.0 → 1.0 → 0.5 → 0.0
Status:   OK → ALERT → Adapting → OK (new baseline)

AWS Engineering Clarification

"RCF detects anomalies during its onset, not during the full range of the anomalous event. The algorithm does not support sustained anomaly detection."

"RCF is able to handle breaks in periodicity and irregular short term pattern changes. However, if your time series has a long gradual shift spanning a significant portion of the detector's window, RCF will view this change as the new normal."

Testing Impact

  • First Occurrence: Anomaly detected and alerts fire
  • Sustained Issues: Algorithm adapts, alerts stop firing
  • Same Issue Later: Not detected unless values return to normal first

RCF Configuration Parameters

Core Configuration Parameters

alias = 'your-detector-name'                    # Human-readable identifier
query = 'avg(your_metric_name)'        # PromQL expression to monitor
evaluationIntervalInSeconds = 30                  # Evaluation frequency (60s default)
sampleSize = 256                                  # Samples per tree (default)
shingleSize = 8                                   # Continuous observations (default)

Parameter Tuning Guidelines

  • Too Noisy Scores: Increase shingleSize
  • Longer Learning Period: Increase sampleSize
  • Faster Response: Decrease evaluationIntervalInSeconds (we use 30s successfully)
  • Alert Threshold: Start with score > 0.5

Training Window Calculation

Formula: Training Window = sampleSize × evaluationInterval

Examples:

  • Default: 256 × 60s = 15,360s = 4.3 hours
  • Our config: 256 × 30s = 7,680s = 2.1 hours
  • Extended: 512 × 60s = 30,720s = 8.5 hours

Parameter Effects:

  • ↑ sampleSize only → Longer learning window
  • ↓ evaluationInterval only → Shorter learning window
  • Both parameters influence total training period

Critical Discovery: Training Window > Hyperparameters

Our testing revealed that detector stability (sufficient training window) has greater impact on stability than hyperparameters.

Key Insight: Use detectors with sufficient training window (sampleSize × evaluationInterval) rather than tuning parameters on new detectors.

Alert Duration Recommendation

"Since RCF typically produces a discrete score during an anomalous onset, we don't recommend using an alert duration as an anomalous score will not be consistently produced during the duration of the anomalous event."

Recommendation: Use minimal alert duration (for: 0s or for: 30s) since RCF scores are discrete onset signals.

RCF Lifecycle Phases

Phase 1: Creation (1-2 minutes)

Status: CREATING
Behavior: Detector being provisioned
Action: Wait for ACTIVE status

Phase 2: Initial Learning (Ongoing)

Status: ACTIVE
Behavior: Continuously adapts to streaming data
Critical: No "training completion" - always learning
Impact: Thresholds drift with sustained changes

Parameter Tuning Best Practices

1. Metric Selection

✅ Good Candidates

# Aggregated, stable metrics
avg(response_time_seconds)
sum(error_rate_total)
avg(cpu_utilization_percent)

❌ Poor Candidates

# Raw, high-cardinality metrics
response_time_seconds{instance=~".*"}
error_count{user_id=~".*"}

2. Query Optimization

Use Aggregation

# Good: Reduces noise
query='avg(your_metric_name)'

# Bad: Too noisy
query='your_metric_name'

Time Window Considerations

# For metrics with daily patterns
query='avg_over_time(cpu_usage[5m])'

# For rate metrics
query='rate(requests_total[5m])'

3. Threshold Tuning

Conservative Approach (AWS Recommended)

# Alert rule
expr: anomaly_detector:score > 0.5
for: 0s  # Testing-proven: instant firing for onset detection

Aggressive Approach (High Sensitivity)

expr: anomaly_detector:score > 0.1
for: 0s  # Testing-proven threshold

4. Evaluation Interval Tuning

Responsive Detection

evaluationIntervalInSeconds=30
# Use for: Critical metrics, fast-changing systems
# Trade-off: More adaptation, higher cost

Stable Detection

evaluationIntervalInSeconds=300
# Use for: Stable metrics, slower detection
# Trade-off: Slower detection, less adaptation

Complete Implementation Journey

Step 1: Environment Setup

Workspace Configuration

WORKSPACE_ID="ws-your-workspace-id"
REGION="us-west-2"
CLUSTER_NAME="your-cluster-name"

Metric Source Setup

# UE Simulator deployment with Prometheus annotations
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ue-simulator
spec:
  template:
    metadata:
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9090"
        prometheus.io/path: "/metrics"

Step 2: RCF Detector Creation

Testing-Ready Configuration

# Single focused detector (learned from multi-detector failures)
detector_config = {
    'alias': 'your-detector-name',
    'query': 'avg(your_metric_name)',
    'evaluationIntervalInSeconds': 30,  # Faster than AWS default (60s)
    'sampleSize': 256,                  # AWS default
    'shingleSize': 8                    # AWS default
}

Key Success Factors:

  • Single Detector: Focus on one critical metric
  • Clean Training: Ensure healthy baseline during initial 14+ days
  • Stable Detector: Training window matters more than parameter tuning

Step 3: Alert Rule Configuration

Production-Proven Configuration

# Zero-duration spike detection (AWS recommended)
- alert: RCFSpikeDetected
  expr: anomaly_detector:score > 0.1  # High sensitivity
  for: 0s  # Production-proven: instant firing for onset detection
  labels:
    severity: high
    alert_type: rcf_spike
  annotations:
    summary: "RCF spike detected: {{ $labels.alias }}"
    anomaly_score: "{{ $value }}"
    baseline_range: "{{ query \"anomaly_detector:lower_band\" }} - {{ query \"anomaly_detector:upper_band\" }}"

Configuration Evolution:

  • ❌ for: 2m → Too long, RCF adapts within 90s
  • ❌ for: 30s → Still too long for onset detection
  • ✅ for: 0s → Testing-proven for RCF spike detection

Step 4: Fast Alert Pipeline

Optimized Alertmanager

route:
  receiver: sns-forwarder
  group_wait: 1s      # vs default 10s - faster delivery
  group_interval: 30s
  repeat_interval: 5m

receivers:
- name: sns-forwarder
  sns_configs:
  - topic_arn: arn:aws:sns:us-west-2:338293206254:prometheus-alerts
    send_resolved: true

Testing Timeline

T+0s:   Network anomaly occurs
T+1-5s: RCF detects (score > 0.1)
T+1-5s: Alert fires instantly (0s duration)
T+2-6s: Alertmanager routes (1s group_wait)
T+3-10s: Lambda processes, webhook delivers
T+2-3m: RCF adapts, alert auto-resolves

Step 5: Validation & Testing

Test Scenario

# Monitor RCF detector status
awscurl --service aps --region us-west-2 "${PROM_API}/query?query=anomaly_detector:score"

# Check current metric values
awscurl --service aps --region us-west-2 "${PROM_API}/query?query=your_metric_name"

# Monitor RCF bands
awscurl --service aps --region us-west-2 "${PROM_API}/query?query=anomaly_detector:upper_band"
awscurl --service aps --region us-west-2 "${PROM_API}/query?query=anomaly_detector:lower_band"

Expected Testing Results

  • Normal State: RCF score = 0.0, metric within learned bands
  • Anomaly Detection: RCF score > threshold (0.1-0.5)
  • Alert Timeline: T+1-5s detection → T+1-5s alert firing → T+2-6s delivery
  • Auto-Resolution: T+2-3m RCF adapts, alert resolves

Step 5: Monitoring and Validation

RCF Health Queries

# Check detector status
anomaly_detector:score{alias="your-detector-name"}

# Monitor band evolution
anomaly_detector:upper_band{alias="your-detector-name"}
anomaly_detector:lower_band{alias="your-detector-name"}

# Validate against source metric
your_metric_name

Alert Validation

# Check active alerts
awscurl --service aps --region us-west-2 \
  "${PROM_API}/alerts" | jq '.data.alerts[]'

Lessons Learned and Recommendations

Critical Discoveries

1. RCF Continuous Adaptation Issue

  • Problem: RCF adapts to sustained anomalies within 90 seconds
  • Impact: Same degradation won't trigger alerts after first occurrence
  • Solution: Consider static thresholds for production alerting

2. Training Period Criticality

  • Problem: RCF learned degraded state as normal during training
  • Impact: Detector became ineffective for months
  • Solution: Ensure system health during initial training window (sampleSize × evaluationInterval)

3. Alert Duration Mismatch

  • Problem: 2-minute alert duration vs 30-second RCF detection window
  • Impact: Alerts never fired despite anomaly detection
  • Solution: Match alert duration to RCF behavior (30s)

Testing Recommendations

✅ RCF TESTING SUCCESS - Spike/Onset Detection

  • Network Spike Detection: Instant detection of performance drops ⭐
  • Change Point Detection: When system behavior suddenly shifts ⭐
  • Real-time Anomaly Alerting: Fast response to onset of issues ⭐
  • Exploratory Analysis: Understanding normal patterns in time series
  • Dynamic Baselines: Systems with naturally evolving normal behavior

❌ Avoid RCF For

  • Sustained Anomaly Alerting: Continuous monitoring of ongoing issues
  • Fixed Threshold Requirements: Compliance or SLA monitoring
  • Long-term Degradation Tracking: Where consistent thresholds are needed
  • SLA Compliance: Where same issue must trigger alerts repeatedly

Testing-Proven Configuration

# SUCCESSFUL testing configuration:
- alert: RCFSpikeDetected
  expr: anomaly_detector:score > 0.1  # High sensitivity
  for: 0s  # Production-proven: instant firing for onset detection
  
# Fast Alertmanager delivery:
route:
  group_wait: 1s  # vs default 10s

Actual Production Results

  • Test: 832 Mbps → 122 Mbps (85% drop)
  • RCF Score: 0.3125 (detected) ✅
  • Alert Timeline: T+5s FIRING ✅
  • Pipeline Speed: ~1 second detection to alert ✅

AWS Engineering Guidance

  • Alert Duration: Minimal duration recommended since scores are discrete onset signals
  • Alert Threshold: Start with score > 0.5 (AWS recommended baseline)
  • Parameter Tuning: Use PreviewAnomalyDetector API for experimentation
  • Noisy Scores: Increase shingleSize
  • Longer Learning: Increase sampleSize

Our Production Discoveries

  • Alert Duration: for: 0s works best for RCF onset detection
  • Alert Threshold: score > 0.1 provides better sensitivity than AWS baseline

Troubleshooting Guide

Common Issues

1. Score Always 0.0

# Check if RCF learned degraded baseline
awscurl "${PROM_API}/query?query=anomaly_detector:lower_band"
# If lower_band < expected_minimum, recreate detector

2. Score Always 1.0

# Check if source metric exists
awscurl "${PROM_API}/query?query=your_source_metric"
# If no data, fix metric collection first

3. Alerts Not Firing

# Check alert rule evaluation
awscurl "${PROM_API}/query?query=anomaly_detector:score > 0.7"
# Verify alert duration matches RCF behavior

Future Considerations

RCF Production Success Model

RCF has proven successful in production when configured for its intended purpose - spike/onset detection:

Proven Configuration:

  • Zero Duration: for: 0s enables instant firing on anomaly onset
  • High Sensitivity: score > 0.1 threshold catches weaker signals
  • Fast Delivery: 1s group_wait for rapid alerting
  • Adequate Training: Sufficient training window for stable baseline learning

Production Timeline:

  • T+0s: Anomaly occurs → T+1-5s: RCF detects → T+1-5s: Alert fires → T+2-3m: Auto-resolves

Alternative Approaches

  • PreviewAnomalyDetector: Test configurations before committing to production
  • Parameter Experimentation: Adjust sampleSize and shingleSize based on data characteristics
  • Multiple Detectors: Consider separate detectors for different metrics (though single detector often works better)

Conclusion

RCF has proven successful for spike/onset detection in production environments when configured correctly with zero-duration alerts and appropriate sensitivity thresholds.

Key Takeaway: RCF excels at real-time spike detection and can be used directly in production for onset alerting. Configure with for: 0s and appropriate sensitivity (0.1-0.5) for best results.

Our implementation journey demonstrates successful production deployment with 832→122 Mbps degradation detection, T+5s alert firing, and ~1 second pipeline response time.

Final Recommendation: Use RCF directly in testing environments for spike/onset detection with zero-duration alerts. It's proven effective for real-time anomaly alerting when configured for its intended use case.


This guide is based on real-world implementation in a 5G network monitoring system with AWS Managed Prometheus. All examples and configurations are production-tested.

AWS
EXPERT

published 9 months ago464 views