Skip to content

Commit 7570d65

Browse files
kalleepthampiotr
andauthored
feat: Add sharding for loki.write (#4882)
Co-authored-by: Piotr <17101802+thampiotr@users.noreply.github.com>
1 parent 22e4991 commit 7570d65

File tree

16 files changed

+1509
-1406
lines changed

16 files changed

+1509
-1406
lines changed

docs/sources/reference/components/loki/loki.write.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ You can use the following blocks with `loki.write`:
4646
| `endpoint` > [`basic_auth`][basic_auth] | Configure `basic_auth` for authenticating to the endpoint. | no |
4747
| `endpoint` > [`oauth2`][oauth2] | Configure OAuth 2.0 for authenticating to the endpoint. | no |
4848
| `endpoint` > `oauth2` > [`tls_config`][tls_config] | Configure TLS settings for connecting to the endpoint. | no |
49-
| `endpoint` > [`queue_config`][queue_config] | When WAL is enabled, configures the queue client. | no |
49+
| `endpoint` > [`queue_config`][queue_config] | Configure the queue used for the endpoint. | no |
5050
| `endpoint` > [`tls_config`][tls_config] | Configure TLS settings for connecting to the endpoint. | no |
5151
| [`wal`][wal] | Write-ahead log configuration. | no |
5252

@@ -104,8 +104,9 @@ The following arguments are supported:
104104
If no `tenant_id` is provided, the component assumes that the Loki instance at `endpoint` is running in single-tenant mode and no X-Scope-OrgID header is sent.
105105

106106
When multiple `endpoint` blocks are provided, the `loki.write` component creates a client for each.
107-
Received log entries are fanned-out to these clients in succession.
108-
That means that if one client is bottlenecked, it may impact the rest.
107+
Received log entries are fanned-out to these endpoints in succession. That means that if one endpoint is bottlenecked, it may impact the rest.
108+
109+
Each endpoint has a _queue_ of batches to be sent. The `queue_config` block can be used to customize the behavior of this queue.
109110

110111
Endpoints can be named for easier identification in debug metrics by using the `name` argument. If the `name` argument isn't provided, a name is generated based on a hash of the endpoint settings.
111112

@@ -129,15 +130,21 @@ When `retry_on_http_429` is enabled, the retry mechanism is governed by the back
129130

130131
{{< docs/shared lookup="stability/experimental_feature.md" source="alloy" version="<ALLOY_VERSION>" >}}
131132

132-
The optional `queue_config` block configures, when WAL is enabled, how the underlying client queues batches of logs sent to Loki.
133-
Refer to [Write-Ahead block](#wal) for more information.
133+
The optional `queue_config` block configures how the endpoint queues batches of logs sent to Loki.
134134

135135
The following arguments are supported:
136136

137137
| Name | Type | Description | Default | Required |
138138
| --------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -------- |
139139
| `capacity` | `string` | Controls the size of the underlying send queue buffer. This setting should be considered a worst-case scenario of memory consumption, in which all enqueued batches are full. | `10MiB` | no |
140140
| `drain_timeout` | `duration` | Configures the maximum time the client can take to drain the send queue upon shutdown. During that time, it enqueues pending batches and drains the send queue sending each. | `"1m"` | no |
141+
| `min_shards` | `number` | Minimum number of concurrent shards sending samples to the endpoint. | `1` | no |
142+
143+
Each endpoint is divided into a number of concurrent _shards_ which are responsible for sending a fraction of batches. The number of shards is controlled with `min_shards` argument.
144+
Each shard has a queue of batches it keeps in memory, controlled with the `capacity` argument.
145+
146+
Queue size is calculated using `batch_size` and `capacity` for each shard. So if `batch_size` is 1MiB and `capacity` is 10MiB each shard would be able to queue up 10 batches.
147+
The maximum amount of memory required for all configured shards can be calculated using `capacity` * `min_shards`.
141148

142149
### `tls_config`
143150

internal/component/common/loki/client/config.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ type Config struct {
3333
// prevent HOL blocking in multitenant deployments.
3434
DropRateLimitedBatches bool
3535

36-
// Queue controls configuration parameters specific to the queue client
37-
Queue QueueConfig
36+
// QueueConfig controls how shards and queues are configured for endpoint.
37+
QueueConfig QueueConfig
3838
}
3939

40-
// QueueConfig holds configurations for the queue-based remote-write client.
40+
// QueueConfig controls how shards and queues are configured for endpoints.
4141
type QueueConfig struct {
4242
// Capacity is the worst case size in bytes desired for the send queue. This value is used to calculate the size of
4343
// the buffered channel used underneath. The worst case scenario assumed is that every batch buffered in full, hence
@@ -47,6 +47,9 @@ type QueueConfig struct {
4747
// is the 1 MiB default, and a capacity of 100 MiB, the underlying buffered channel would buffer up to 100 batches.
4848
Capacity int
4949

50-
// DrainTimeout controls the maximum time that draining the send queue can take.
50+
// MinShards is the minimum number of concurrent shards sending batches to the endpoint.
51+
MinShards int
52+
53+
// DrainTimeout controls the maximum time that draining the queue can take.
5154
DrainTimeout time.Duration
5255
}

0 commit comments

Comments
 (0)