|
| 1 | +# Badger Extension |
| 2 | + |
| 3 | +The Badger Extension provides persistent storage for OpenTelemetry Collector components using [BadgerDB](https://github.com/dgraph-io/badger), a fast embeddable key-value database written in Go. Each component receives an isolated BadgerDB instance for data isolation and reliability. |
| 4 | + |
| 5 | +## Configuration |
| 6 | + |
| 7 | +| Field | Type | Default | Required | Description | |
| 8 | +| ----------------------------- | -------- | ------- | -------- | ------------------------------------------------------------------------------------------------- | |
| 9 | +| directory.path | string | | `true` | Directory path where BadgerDB files will be stored. Each component gets a subdirectory. | |
| 10 | +| sync_writes | bool | `false` | `false` | Whether to sync writes to disk immediately. `false` survives process crashes via mmap. | |
| 11 | +| memory.table_size | int64 | 67108864 (64MB) | `false` | Size of each memtable in bytes. Larger values improve write performance but use more memory. | |
| 12 | +| memory.block_cache_size | int64 | 268435456 (256MB) | `false` | Size of block cache in bytes. Larger values improve read performance but use more memory. | |
| 13 | +| blob_garbage_collection.interval | duration | 5m | `false` | Interval at which garbage collection runs on value logs. Set to 0 to disable. | |
| 14 | +| blob_garbage_collection.discard_ratio | float | 0.5 | `false` | Fraction of invalid data in a value log file to trigger GC. Must be between 0 and 1. | |
| 15 | + |
| 16 | +## Example Configuration |
| 17 | + |
| 18 | +### Basic Configuration |
| 19 | + |
| 20 | +```yaml |
| 21 | +extensions: |
| 22 | + badger: |
| 23 | + directory: |
| 24 | + path: /var/lib/otelcol/badger |
| 25 | + |
| 26 | +processors: |
| 27 | + batch: |
| 28 | + storage: badger |
| 29 | + |
| 30 | +exporters: |
| 31 | + otlp: |
| 32 | + endpoint: otelcol:4317 |
| 33 | + |
| 34 | +service: |
| 35 | + extensions: [badger] |
| 36 | + pipelines: |
| 37 | + logs: |
| 38 | + receivers: [otlp] |
| 39 | + processors: [batch] |
| 40 | + exporters: [otlp] |
| 41 | +``` |
| 42 | +
|
| 43 | +## Advanced Configuration |
| 44 | +
|
| 45 | +This extension uses BadgerDB's defaults, which are optimized for most production workloads. The defaults provide a balance of performance, memory usage, and durability suitable for telemetry storage. |
| 46 | +
|
| 47 | +For advanced use cases, the following configuration levers are exposed: |
| 48 | +
|
| 49 | +- **memory.table_size** and **memory.block_cache_size**: Control memory allocation. Only adjust if you have specific memory constraints or performance requirements. |
| 50 | +- **blob_garbage_collection**: Controls disk space reclamation. The defaults (5m interval, 0.5 discard ratio) work well for most scenarios. |
| 51 | +- **sync_writes**: Controls write durability. The default (`false`) provides good performance while surviving process crashes via memory-mapped writes. |
| 52 | + |
| 53 | +Refer to the [BadgerDB documentation](https://dgraph.io/docs/badger/) for detailed information about these settings. |
| 54 | + |
| 55 | +Full configuration example: |
| 56 | + |
| 57 | +```yaml |
| 58 | +extensions: |
| 59 | + badger: |
| 60 | + directory: |
| 61 | + path: /var/lib/otelcol/badger |
| 62 | + sync_writes: true |
| 63 | + memory: |
| 64 | + table_size: 134217728 # 128MB |
| 65 | + block_cache_size: 536870912 # 512MB |
| 66 | + blob_garbage_collection: |
| 67 | + interval: 10m |
| 68 | + discard_ratio: 0.6 |
| 69 | +
|
| 70 | +processors: |
| 71 | + batch: |
| 72 | + storage: badger |
| 73 | +
|
| 74 | +exporters: |
| 75 | + otlp: |
| 76 | + endpoint: otelcol:4317 |
| 77 | +
|
| 78 | +service: |
| 79 | + extensions: [badger] |
| 80 | + pipelines: |
| 81 | + logs: |
| 82 | + receivers: [otlp] |
| 83 | + processors: [batch] |
| 84 | + exporters: [otlp] |
| 85 | +
|
| 86 | +``` |
| 87 | + |
| 88 | +## Component Isolation |
| 89 | + |
| 90 | +Each component that uses the badger extension gets an isolated database instance at: |
| 91 | + |
| 92 | +``` |
| 93 | +{directory.path}/{kind}_{type}_{component_name}_{name}/ |
| 94 | +``` |
| 95 | + |
| 96 | +For example, with `directory.path: $OIQ_OTEL_COLLECTOR_STORAGE`: |
| 97 | + |
| 98 | +``` |
| 99 | +$OIQ_OTEL_COLLECTOR_STORAGE/processor_batch_default/ |
| 100 | +$OIQ_OTEL_COLLECTOR_STORAGE/exporter_otlp_backup/ |
| 101 | +``` |
| 102 | + |
| 103 | +This ensures components cannot interfere with each other's data. |
0 commit comments