Skip to content

Commit 8c1919e

Browse files
pinebitKaloyanTanev
authored andcommitted
app: improved loki client (#4389)
Improved loki client: buffered input channel + dropping and counting entries when the buffer is full. category: refactor ticket: none
1 parent 334c09c commit 8c1919e

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

app/log/loki/client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const (
3232
batchWait = 1 * time.Second
3333
batchMax = 5 * 1 << 20 // 5MB
3434
maxLogLineLen = 4 << 10 // 4096B
35+
inputBuffer = 1000 // Buffered channel capacity for log lines
3536
)
3637

3738
// lazyLabelsFunc abstracts lazy loading of labels, logs will only be sent when it returns true.
@@ -59,7 +60,7 @@ func newInternal(endpoint string, serviceLabel string, batchWait time.Duration,
5960
endpoint: endpoint,
6061
done: make(chan struct{}),
6162
quit: make(chan struct{}),
62-
input: make(chan string),
63+
input: make(chan string, inputBuffer),
6364
batchMax: batchMax,
6465
batchWait: batchWait,
6566
maxLogLineLen: maxLogLineLen,
@@ -156,6 +157,8 @@ func (c *Client) Add(line string) {
156157
select {
157158
case c.input <- line:
158159
case <-c.quit:
160+
default:
161+
droppedTotal.Inc()
159162
}
160163
}
161164

app/log/loki/metrics.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright © 2022-2026 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1
2+
3+
package loki
4+
5+
import (
6+
"github.com/prometheus/client_golang/prometheus"
7+
8+
"github.com/obolnetwork/charon/app/promauto"
9+
)
10+
11+
var droppedTotal = promauto.NewCounter(prometheus.CounterOpts{
12+
Namespace: "app",
13+
Subsystem: "log_loki",
14+
Name: "dropped_total",
15+
Help: "Total count of dropped log lines due to full buffer",
16+
})

docs/metrics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ when storing metrics from multiple nodes or clusters in one Prometheus instance.
3333
| `app_health_checks` | Gauge | Application health checks by name and severity. Set to 1 for failing, 0 for ok. | `severity, name` |
3434
| `app_health_metrics_high_cardinality` | Gauge | Metrics with high cardinality by name. | `name` |
3535
| `app_log_error_total` | Counter | Total count of logged errors by topic | `topic` |
36+
| `app_log_loki_dropped_total` | Counter | Total count of dropped log lines due to full buffer | |
3637
| `app_log_warn_total` | Counter | Total count of logged warnings by topic | `topic` |
3738
| `app_monitoring_readyz` | Gauge | Set to 1 if the node is operational and monitoring api `/readyz` endpoint is returning 200s. Else `/readyz` is returning 500s and this metric is either set to 2 if the beacon node is down, or3 if the beacon node is syncing, or4 if quorum peers are not connected. | |
3839
| `app_peer_name` | Gauge | Constant gauge with label set to the name of the cluster peer | `peer_name` |

0 commit comments

Comments
 (0)