ACOR Documentation

Monitoring

Monitor ACOR performance with built-in observability support.

Overview

ACOR provides three pillars of observability:

graph LR
    A[ACOR] --> B[Metrics]
    A --> C[Logs]
    A --> D[Traces]

    B --> E[Prometheus]
    C --> F[Log Aggregator]
    D --> G[Jaeger/Zipkin]

Metrics

Import the metrics package:

import "github.com/skyoo2003/acor/pkg/metrics"

Available Metrics

MetricTypeDescription
acor_http_requests_totalCounterTotal HTTP requests by method, path, status
acor_http_request_duration_secondsHistogramHTTP request latency
acor_grpc_requests_totalCounterTotal gRPC requests by method, status
acor_grpc_request_duration_secondsHistogramgRPC request latency
acor_redis_operations_totalCounterTotal Redis operations by type, status
acor_redis_operation_duration_secondsHistogramRedis operation latency
acor_keywords_totalGaugeNumber of registered keywords
acor_trie_nodes_totalGaugeNumber of trie nodes

Exposing Metrics

import (
    "net/http"

    "github.com/prometheus/client_golang/prometheus/promhttp"
    "github.com/skyoo2003/acor/pkg/metrics"
)

func main() {
    // nil registerer defaults to prometheus.DefaultRegisterer,
    // which is what promhttp.Handler() serves
    _ = metrics.NewRegistry(nil)

    http.Handle("/metrics", promhttp.Handler())
    http.ListenAndServe(":8080", nil)
}

Logging

Import the logging package:

import "github.com/skyoo2003/acor/pkg/logging"

Structured Logging

logger := logging.NewLogger(logging.Config{
    Level:  "info",
    Format: "json",
})

logger.Info("operation completed",
    "operation", "Find",
    "duration_ms", 12,
    "matches", 5,
)

Log Levels

Tracing

Import the tracing package:

import "github.com/skyoo2003/acor/pkg/tracing"

OpenTelemetry Setup

tracer, err := tracing.NewTracer(&tracing.Config{
    Enabled:     true,
    ServiceName: "my-service",
    Endpoint:    "localhost:4317",
    SampleRatio: 1.0,
})
if err != nil {
    // handle error
}
defer tracer.Shutdown()

Spans

ACOR automatically creates spans for:

Dashboards

Key Metrics to Monitor

  1. Operation Latency: P50, P95, P99
  2. Error Rate: Operations failing
  3. Keyword Count: Collection size
  4. Redis Connections: Pool utilization

Grafana Dashboard

Create a Grafana dashboard using the metrics above. Key panels to include:

  1. Operation Latency: P50/P95/P99 of acor_redis_operation_duration_seconds
  2. Error Rate: Rate of acor_redis_operations_total{status="error"}
  3. Keyword Count: Gauge acor_keywords_total
  4. Trie Nodes: Gauge acor_trie_nodes_total

Alerting Rules

groups:
  - name: acor
    rules:
      - alert: HighLatency
        expr: histogram_quantile(0.95, rate(acor_redis_operation_duration_seconds_bucket[5m])) > 0.1
        for: 5m
        annotations:
          summary: "ACOR operations are slow"

      - alert: HighRedisErrorRate
        expr: rate(acor_redis_operations_total{status="error"}[5m]) > 0.1
        for: 5m
        annotations:
          summary: "High Redis error rate"