Skip to content

[Q2-P2] Add synthetic monitoring with continuous SDK health checks #28

Description

@karlwaldman

Problem

We only test SDK when:

  • Someone runs tests manually
  • CI runs on commits
  • Customers use it in production

Gap: No continuous validation that SDK works in production

Solution

Add synthetic monitoring that runs realistic SDK queries continuously:

# monitoring/synthetic/sdk_health_check.py

import schedule
import time
from oilpriceapi import OilPriceAPI

def health_check():
    """Run realistic SDK queries."""
    client = OilPriceAPI(api_key=MONITOR_KEY)

    checks = [
        ('current_price', lambda: client.prices.get('WTI_USD')),
        ('1_week_historical', lambda: client.historical.get(
            'WTI_USD',
            (datetime.now() - timedelta(days=7)).date(),
            datetime.now().date()
        )),
        ('1_month_historical', lambda: client.historical.get(
            'WTI_USD',
            (datetime.now() - timedelta(days=30)).date(),
            datetime.now().date()
        )),
    ]

    for name, check in checks:
        try:
            start = time.time()
            result = check()
            duration = time.time() - start

            send_metric(f'synthetic.{name}.success', 1)
            send_metric(f'synthetic.{name}.duration', duration)
        except Exception as e:
            send_metric(f'synthetic.{name}.failure', 1)
            send_alert(f'Synthetic check failed: {name}: {e}')

# Run every 5 minutes
schedule.every(5).minutes.do(health_check)

Deploy

# Deploy as cron job or lambda
apiVersion: batch/v1
kind: CronJob
metadata:
  name: sdk-synthetic-monitoring
spec:
  schedule: "*/5 * * * *"  # Every 5 minutes
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: health-check
            image: oilpriceapi/sdk-monitor:latest
            env:
            - name: MONITOR_API_KEY
              valueFrom:
                secretKeyRef:
                  name: monitoring-secrets
                  key: api-key

Alerts

ALERT: Synthetic check failure rate >10% over 15min
ALERT: Synthetic check duration >2x baseline
ALERT: Synthetic check not running (missing data)

Acceptance Criteria

  • Synthetic monitoring script created
  • Deployed and running every 5 minutes
  • Alerts configured
  • Dashboard shows synthetic check results
  • Runbook for responding to failures

Estimated Effort

Time: 4 hours

Activity

  1. coderabbitai commented on Dec 17, 2025

    @coderabbitai

    📝 CodeRabbit Plan Mode

    Generate an implementation plan and prompts that you can use with your favorite coding agent.

    • Create Plan
    Examples
    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    🔗 Similar Issues

    Related Issues

    👤 Suggested Assignees


    🧪 Issue enrichment is currently in open beta.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord or schedule a call!

  2. karlwaldman commented on Jul 25, 2026

    @karlwaldman
    MemberAuthor

    Completion receipt for PR #74 / c2f6a882b1aa483815b9191e8c83a1a25a7c224f:

    • replaced the perpetually failing full integration/stress schedule with an hourly, bounded latest-price + five-record history synthetic
    • missing monitor credentials now fail loudly instead of silently skipping
    • receipts contain structural assertions and durations but no keys, response values, URLs, bodies, or exception messages
    • removed the undeployed/broken Docker-Prometheus example that referenced missing configs and printed part of the key
    • local: 401 non-integration tests, 4 synthetic unit tests, keyless production contract, authenticated synthetic, package build, and docs build passed
    • main CI: Python 3.8–3.12, Ruff, mypy, storefront validation, unit tests, live API tests, and Pages are green
    • first real manual run: https://github.com/OilpriceAPI/python-sdk/actions/runs/30169188492 — completed in 21s; latest 0.462s, history 0.417s, both pass
    • 30-day artifact sdk-health-30169188492 exists and expires 2026-08-24
    • runbook is live at https://oilpriceapi.github.io/python-sdk/SYNTHETIC_MONITORING/

    The schedule is hourly rather than every five minutes: this keeps detection bounded while avoiding roughly 8,640 CI starts/month and unnecessary API quota. Push/PR live checks cover changes between scheduled runs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: mediumShould be fixed eventuallyquadrant: q2Important, Not Urgent (Schedule)type: monitoringMonitoring, observability, and alerting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions