# Retention and Downsampling

## Retention Rules
Retention rules define how long metrics data is stored. By default, **data is retained indefinitely**.

The Thanos [Compactor](https://thanos.io/tip/components/compact.md/#enforcing-retention-of-data) manages retention through a single parameter: `compactor.retention.days`. This setting applies uniformly to all data resolutions:
- Raw metrics
- 5-minute downsampled data
- 1-hour downsampled data

### Configure Retention via API
> [!NOTE] 
> Retention configuration is currently only available via the REST API. The Exoscale Portal does not support this feature.


Use the [Update Thanos Service API]({{< ref "reference/api/dbaas/dbaas-thanos/" >}}) to set the `compactor.retention.days` parameter:

```bash
curl -X PUT "https://api-{zone}.exoscale.com/v2/dbaas-thanos/{service-name}" \
  -H "Content-Type: application/json" \
  -d '{
    "thanos-settings": {
      "compactor.retention.days": 90
    }
  }'
```

### Retention Considerations
- **Cost**: Longer retention periods increase storage costs
- **Compliance**: Some regulations require specific retention periods
- **Query performance**: Downsampled data (5-min and 1-hour intervals) improves query performance for older data

---

## Downsampling
Thanos automatically [downsamples](https://thanos.io/tip/components/compact.md/#downsampling) metrics data to optimize query performance over large time ranges. The Compactor creates downsampled blocks based on the age of the data:

- Raw metrics older than **40 hours** are downsampled to **5-minute** resolution
- Metrics older than **10 days** are downsampled to **1-hour** resolution

| Resolution | Description | Created After | Use Case |
|---|---|---|---|
| Raw | Original metric resolution | — | Recent data, detailed analysis |
| 5-minute | Aggregated every 5 minutes | 40 hours | Medium-term queries |
| 1-hour | Aggregated every hour | 10 days | Long-term trends, dashboards |

Downsampling preserves essential aggregations (min, max, sum, count) to enable fast queries across months or years of data.


> [!NOTE] 
> Downsampled blocks are stored alongside raw data, not in place of it. Reducing storage requires configuring [retention rules](#retention-rules). See the [official Thanos documentation](https://thanos.io/tip/components/compact.md/#-downsampling-note-about-resolution-and-retention-) for details on how retention interacts with downsampling.

