> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sawmills.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# KEDA External Scaler

> Understand the Sawmills KEDA External Scaler architecture that bridges OpenTelemetry metrics with Kubernetes event-driven autoscaling for dynamic workloads.

## KEDA External Scaler

The Sawmills implementation provides a powerful bridge between OpenTelemetry (OTel) and KEDA, enabling dynamic scaling based on OTel metrics. This implementation offers a flexible and efficient way to scale your applications based on custom metrics collected through OpenTelemetry.

## Architecture Overview

The implementation consists of three main components:

1. **Receiver**: Implements the OTLP Receiver specification, running a gRPC server (default port 4317) that receives and processes incoming metrics.

2. **In-Memory Metric Storage**: A high-performance in-memory storage system that maintains recent metric measurements for each metric vector. Key features include:
   * Automatic cleanup of stale measurements
   * Label-based querying support
   * Optimized for real-time metric processing

3. **External Scaler**: Implements the KEDA External Scaler contract, running a gRPC server (default port 4318) that queries the metric storage and communicates with the KEDA operator.

## Installation

### Prerequisites

* Kubernetes cluster
* KEDA installed
* Helm 3.x

### Step 1: Install KEDA

```bash theme={null}
helm repo add kedacore https://kedacore.github.io/charts
helm repo update
helm upgrade -i keda kedacore/keda --namespace keda --create-namespace
```

### Step 2: Configure Sawmills Collector with KEDA Scaler

Create a `values.yaml` file with the following configuration to enable KEDA scaler and external scaling:

```yaml theme={null}
managedChartsValues:
  sawmills-collector:
    # Enable KEDA-based autoscaling
    keda:
      enabled: true
      minReplicas: 1
      maxReplicas: 10
      pollingInterval: 30
      cooldownPeriod: 300
      scaling:
        external:
          enabled: true
          metricType: Value
          metadata:
            query: "histogram_quantile(0.95, sum(rate(http_server_duration_bucket[2m])) by (le))"
            targetValue: "2000"

    # Enable KEDA scaler component
    kedaScaler:
      enabled: true
```

> **Note:** The chart derives the KEDA scaler service address from the rendered scaler service name and the Helm release namespace. Avoid hardcoding a namespace in `scalerAddress`, especially when deploying through an umbrella chart or using `resourceBaseName`.
