| 1 | # Exporter Helper |
| 2 | |
| 3 | This package provides reusable implementations of common capabilities for exporters. |
| 4 | Currently, this includes queuing, batching, timeouts, and retries. |
| 5 | |
| 6 | ## Configuration |
| 7 | |
| 8 | The following configuration options can be modified: |
| 9 | |
| 10 | ### Retry on Failure |
| 11 | |
| 12 | - `retry_on_failure` |
| 13 | - `enabled` (default = true) |
| 14 | - `initial_interval` (default = 5s): Time to wait after the first failure before retrying; ignored if `enabled` is `false` |
| 15 | - `max_interval` (default = 30s): Is the upper bound on backoff; ignored if `enabled` is `false` |
| 16 | - `max_elapsed_time` (default = 300s): Is the maximum amount of time spent trying to send a batch; ignored if `enabled` is `false`. If set to 0, the retries are never stopped. |
| 17 | - `multiplier` (default = 1.5): Factor by which the retry interval is multiplied on each attempt; ignored if `enabled` is `false` |
| 18 | |
| 19 | ### Sending Queue |
| 20 | |
| 21 | - `sending_queue` |
| 22 | - `enabled` (default = true) |
| 23 | - `num_consumers` (default = 10): Number of consumers that dequeue batches; ignored if `enabled` is `false` |
| 24 | - `wait_for_result` (default = false): determines if incoming requests are blocked until the request is processed or not. |
| 25 | - `block_on_overflow` (default = false): If true, blocks the request until the queue has space otherwise rejects the data immediately; ignored if `enabled` is `false` |
| 26 | - `sizer` (default = requests): How the queue and batching is measured. Available options: |
| 27 | - `requests`: number of incoming batches of metrics, logs, traces (the most performant option); |
| 28 | - `items`: number of the smallest parts of each signal (spans, metric data points, log records); |
| 29 | - `bytes`: the size of serialized data in bytes (the least performant option). |
| 30 | - `queue_size` (default = 1000): Maximum size the queue can accept. Measured in units defined by `sizer` |
| 31 | - `batch`: see below. |
| 32 | |
| 33 | #### Sending queue batch settings |
| 34 | |
| 35 | Batch settings are available in the sending queue. Batching is disabled, by default. To enable default |
| 36 | batch settings, use `batch: {}`. When `batch` is defined, the settings are: |
| 37 | |
| 38 | - `flush_timeout` (default = 200 ms): time after which a batch will be sent regardless of its size. Must be a non-zero value; |
| 39 | - `min_size` (default = 8192): the minimum size of a batch; should be less than or equal to the `sending_queue::queue_size` if `sending_queue::batch::sizer` matches `sending_queue::sizer`. |
| 40 | - `max_size` (default = 0): the maximum size of a batch, enables batch splitting. The maximum size of a batch should be greater than or equal to the minimum size of a batch. If set to zero, there is no maximum size; |
| 41 | - `sizer`: see below. |
| 42 | |
| 43 | The `batch::sizer` field is given special treatment because the queue itself also defines a `sizer`. This field supports using different size limits for the queue and batch-related logic. |
| 44 | |
| 45 | If the `batch::sizer` field is not set, it takes its value from the parent structure. |
| 46 | |
| 47 | If `sending_queue::sizer` is not set, `batch::sizer` defaults to `items`. |
| 48 | |
| 49 | Available `batch::sizer` options: |
| 50 | |
| 51 | - `items`: number of the smallest parts of each signal (spans, metric data points, log records); |
| 52 | - `bytes`: the size of serialized data in bytes (the least performant option). |
| 53 | ### Timeout |
| 54 | |
| 55 | - `timeout` (default = 5s): Time to wait per individual attempt to send data to a backend |
| 56 | |
| 57 | The `initial_interval`, `max_interval`, `max_elapsed_time`, and `timeout` options accept |
| 58 | [duration strings](https://pkg.go.dev/time#ParseDuration), |
| 59 | valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". |
| 60 | |
| 61 | ### Persistent Queue |
| 62 | |
| 63 | To use the persistent queue, the following setting needs to be set: |
| 64 | |
| 65 | - `sending_queue` |
| 66 | - `storage` (default = none): When set, enables persistence and uses the component specified as a storage extension for the persistent queue. |
| 67 | There is no in-memory queue when set. |
| 68 | |
| 69 | The maximum number of batches stored to disk can be controlled using `sending_queue.queue_size` parameter (which, |
| 70 | similarly as for in-memory buffering, defaults to 1000 batches). |
| 71 | |
| 72 | When persistent queue is enabled, the batches are being buffered using the provided storage extension - [filestorage] is a popular and safe choice. If the collector instance is killed while having some items in the persistent queue, on restart the items will be picked and the exporting is continued. |
| 73 | |
| 74 | **Context Propagation**: Request context (including client metadata and span context) is preserved when using persistent queues. However, context set by Auth extensions is **not** propagated through the persistent queue. Auth extension context is ignored when data is persisted to disk, which means authentication/authorization information will not be available when the persisted data is processed. |
| 75 | |
| 76 | ``` |
| 77 | ┌─Consumer #1─┐ |
| 78 | │ ┌───┐ │ |
| 79 | ──────Deleted────── ┌───►│ │ 1 │ ├───► Success |
| 80 | Waiting in channel x x x │ │ └───┘ │ |
| 81 | for consumer ───┐ x x x │ │ │ |
| 82 | │ x x x │ └─────────────┘ |
| 83 | ▼ x x x │ |
| 84 | ┌─────────────────────────────────────────x─────x───┐ │ ┌─Consumer #2─┐ |
| 85 | │ x x x │ │ │ ┌───┐ │ |
| 86 | │ ┌───┐ ┌───┐ ┌───┐ ┌─x─┐ ┌───┐ ┌─x─┐ ┌─x─┐ │ │ │ │ 2 │ ├───► Permanent -> X |
| 87 | │ n+1 │ n │ ... │ 6 │ │ 5 │ │ 4 │ │ 3 │ │ 2 │ │ 1 │ ├────┼───►│ └───┘ │ failure |
| 88 | │ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ │ │ │ │ |
| 89 | │ │ │ └─────────────┘ |
| 90 | └───────────────────────────────────────────────────┘ │ |
| 91 | ▲ ▲ ▲ ▲ │ ┌─Consumer #3─┐ |
| 92 | │ │ │ │ │ │ ┌───┐ │ |
| 93 | │ │ │ │ │ │ │ 3 │ ├───► (in progress) |
| 94 | write read └─────┬─────┘ ├───►│ └───┘ │ |
| 95 | index index │ │ │ │ |
| 96 | │ │ └─────────────┘ |
| 97 | │ │ |
| 98 | currently │ ┌─Consumer #4─┐ |
| 99 | dispatched │ │ ┌───┐ │ Temporary |
| 100 | └───►│ │ 4 │ ├───► failure |
| 101 | │ └───┘ │ │ |
| 102 | │ │ │ |
| 103 | └─────────────┘ │ |
| 104 | ▲ │ |
| 105 | └── Retry ───────┤ |
| 106 | │ |
| 107 | │ |
| 108 | X ◄────── Retry limit exceeded ───┘ |
| 109 | ``` |
| 110 | |
| 111 | Example: |
| 112 | |
| 113 | ``` |
| 114 | receivers: |
| 115 | otlp: |
| 116 | protocols: |
| 117 | grpc: |
| 118 | exporters: |
| 119 | otlp: |
| 120 | endpoint: <ENDPOINT> |
| 121 | sending_queue: |
| 122 | storage: file_storage/otc |
| 123 | extensions: |
| 124 | file_storage/otc: |
| 125 | directory: /var/lib/storage/otc |
| 126 | timeout: 10s |
| 127 | service: |
| 128 | extensions: [file_storage] |
| 129 | pipelines: |
| 130 | metrics: |
| 131 | receivers: [otlp] |
| 132 | exporters: [otlp] |
| 133 | logs: |
| 134 | receivers: [otlp] |
| 135 | exporters: [otlp] |
| 136 | traces: |
| 137 | receivers: [otlp] |
| 138 | exporters: [otlp] |
| 139 | |
| 140 | ``` |
| 141 | |
| 142 | [filestorage]: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/extension/storage/filestorage |