Skip to content

Commit

Permalink
Prep for v0.30.2 (#2723)
Browse files Browse the repository at this point in the history
* prometheus.relabel: clone labels before relabeling (#2701)

This commit clones the label set before applying relabels. Not
cloning does two things:

1. It forces the computed ID of the incoming series to change (as its
   labels changed)

2. It can cause obscure bugs with relabel rules being applied, such as
   a `keep` action which doesn't work after modifying the original
   slice.

* component/common/loki: drop unqueued logs after 5 seconds on shutdown (#2721)

Fix an issue where being unable to send logs to `loki.write` due to the
client being permanently backlogged would deadlock the Flow controller.

The `loki.write` client may be permanently backlogged when:

* Limits are reached when sending logs to Loki, leading to endless
  request retries.
* Loki has an extended outage.

When an EntryHandler is stopped, it will wait for 5 seconds before
forcibly stopping the goroutine which queues log entries. If this
timeout is reached, any unqueued log entries are permanently lost, as
the positions file will likely be updated past the point where the entry
was read.

While losing logs is not ideal, it's unacceptable for any Flow component
to be able to block the controller. This is a short-term solution to
allow the Flow controller to continue working properly. A long term
solution would be to use a Write-Ahead Log (WAL) for log entries. See
grafana/loki#7993.

Fixes #2716.
Related to grafana/loki#2361.

* prepare for v0.30.2 release

* address review feedback

* operator: Use enableHttp2 field as boolean in libsonnet templates (#2724)

Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>

Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
Co-authored-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com>
  • Loading branch information
rfratto and tpaschalis authored Jan 11, 2023
1 parent 583819d commit 59144c6
Show file tree
Hide file tree
Showing 22 changed files with 94 additions and 31 deletions.
18 changes: 16 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,22 @@ This document contains a historical list of changes between releases. Only
changes that impact end-user behavior are listed; changes to documentation or
internal API changes are not present.

Main (unreleased)
-----------------
v0.30.2 (2023-01-11)
--------------------

### Bugfixes

- Flow: `prometheus.relabel` will no longer modify the labels of the original
metrics, which could lead to the incorrect application of relabel rules on
subsequent relabels. (@rfratto)

- Flow: `loki.source.file` will no longer deadlock other components if log
lines cannot be sent to Loki. `loki.source.file` will wait for 5 seconds per
file to finish flushing read logs to the client, after which it will drop
them, resulting in lost logs. (@rfratto)

- Operator: Fix the handling of the enableHttp2 field as a boolean in
`pod_monitor` and `service_monitor` templates. (@tpaschalis)

v0.30.1 (2022-12-23)
--------------------
Expand Down
54 changes: 50 additions & 4 deletions component/common/loki/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@ package loki
// to relabeling, stages and finally batched in a client to be written to Loki.

import (
"context"
"sync"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"

"github.com/grafana/loki/pkg/logproto"
)

// finalEntryTimeout is how long NewEntryMutatorHandler will wait before giving
// up on sending the final log entry. If this timeout is reached, the final log
// entry is permanently lost.
//
// This timeout can only be reached if the loki.write client is backlogged due
// to an outage or erroring (such as limits being hit).
const finalEntryTimeout = 5 * time.Second

// LogsReceiver is an alias for chan Entry which will be used for component
// communication
type LogsReceiver chan Entry
Expand Down Expand Up @@ -77,17 +87,53 @@ func NewEntryHandler(entries chan<- Entry, stop func()) EntryHandler {

// NewEntryMutatorHandler creates a EntryHandler that mutates incoming entries from another EntryHandler.
func NewEntryMutatorHandler(next EntryHandler, f EntryMutatorFunc) EntryHandler {
in, wg, once := make(chan Entry), sync.WaitGroup{}, sync.Once{}
nextChan := next.Chan()
var (
ctx, cancel = context.WithCancel(context.Background())

in = make(chan Entry)
nextChan = next.Chan()
)

var wg sync.WaitGroup
wg.Add(1)

go func() {
defer wg.Done()
defer cancel()

for e := range in {
nextChan <- f(e)
select {
case <-ctx.Done():
// This is a hard stop to the reading goroutine. Anything not forwarded
// to nextChan at this point will probably be permanently lost, since
// the positions file has likely already updated to a byte offset past
// the read entry.
//
// TODO(rfratto): revisit whether this logic is necessary after we have
// a WAL for logs.
return
case nextChan <- f(e):
// no-op; log entry has been queued for sending.
}
}
}()

var closeOnce sync.Once
return NewEntryHandler(in, func() {
once.Do(func() { close(in) })
closeOnce.Do(func() {
close(in)

select {
case <-ctx.Done():
// The goroutine above exited on its own so we don't have to wait for
// the timeout.
case <-time.After(finalEntryTimeout):
// We reached the timeout for sending the final entry to nextChan;
// request a hard stop from the reading goroutine.
cancel()
}
})

wg.Wait()
})
}
Expand Down
4 changes: 3 additions & 1 deletion component/prometheus/relabel/relabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ func (c *Component) relabel(val float64, lbls labels.Labels) labels.Labels {
relabelled = newLbls.labels
}
} else {
relabelled = relabel.Process(lbls, c.mrc...)
// Relabel against a copy of the labels to prevent modifying the original
// slice.
relabelled = relabel.Process(lbls.Copy(), c.mrc...)
c.cacheMisses.Inc()
c.cacheSize.Inc()
c.addToCache(globalRef, relabelled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ docker run \
-v "/proc:/host/proc:ro,rslave" \
-v /tmp/agent:/etc/agent \
-v /path/to/config.yaml:/etc/agent-config/agent.yaml \
grafana/agent:v0.30.1 \
grafana/agent:v0.30.2 \
--config.file=/etc/agent-config/agent.yaml
```

Expand Down Expand Up @@ -67,7 +67,7 @@ metadata:
name: agent
spec:
containers:
- image: grafana/agent:v0.30.0
- image: grafana/agent:v0.30.2
name: agent
args:
- --config.file=/etc/agent-config/agent.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ docker run \
-v "/proc:/proc:ro" \
-v /tmp/agent:/etc/agent \
-v /path/to/config.yaml:/etc/agent-config/agent.yaml \
grafana/agent:v0.30.1 \
grafana/agent:v0.30.2 \
--config.file=/etc/agent-config/agent.yaml
```

Expand All @@ -37,7 +37,7 @@ metadata:
name: agent
spec:
containers:
- image: grafana/agent:v0.30.1
- image: grafana/agent:v0.30.2
name: agent
args:
- --config.file=/etc/agent-config/agent.yaml
Expand Down
2 changes: 1 addition & 1 deletion docs/sources/operator/custom-resource-quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ metadata:
labels:
app: grafana-agent
spec:
image: grafana/agent:v0.30.1
image: grafana/agent:v0.30.2
logLevel: info
serviceAccountName: grafana-agent
metrics:
Expand Down
2 changes: 1 addition & 1 deletion docs/sources/operator/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ spec:
serviceAccountName: grafana-agent-operator
containers:
- name: operator
image: grafana/agent-operator:v0.30.1
image: grafana/agent-operator:v0.30.2
args:
- --kubelet-service=default/kubelet
---
Expand Down
2 changes: 1 addition & 1 deletion docs/sources/set-up/install-agent-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Install Grafana Agent and get it up and running on Docker.
docker run \
-v /tmp/agent:/etc/agent/data \
-v /path/to/config.yaml:/etc/agent/agent.yaml \
grafana/agent:v0.30.1
grafana/agent:v0.30.2
```

2. Replace `/tmp/agent` with the folder you want to store WAL data in.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function(
proxy_url: optionals.string(endpoint.ProxyURL),
params: optionals.object(endpoint.Params),
scheme: optionals.string(endpoint.Scheme),
enable_http2: optionals.string(endpoint.EnableHttp2),
enable_http2: optionals.bool(endpoint.EnableHttp2),

// NOTE(rfratto): unlike ServiceMonitor, pod monitors explicitly use
// SafeTLSConfig.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function(
proxy_url: optionals.string(endpoint.ProxyURL),
params: optionals.object(endpoint.Params),
scheme: optionals.string(endpoint.Scheme),
enable_http2: optionals.string(endpoint.EnableHttp2),
enable_http2: optionals.bool(endpoint.EnableHttp2),

tls_config:
if endpoint.TLSConfig != null then new_tls_config(meta.Namespace, endpoint.TLSConfig),
Expand Down
1 change: 1 addition & 0 deletions pkg/operator/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (
"v0.29.0",
"v0.30.0",
"v0.30.1",
"v0.30.2",
// NOTE(rfratto): when performing an upgrade, add the newest version above instead of changing the existing reference.
}

Expand Down
2 changes: 1 addition & 1 deletion production/grafanacloud-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ PACKAGE_SYSTEM=${PACKAGE_SYSTEM:=}
#
# Global constants.
#
RELEASE_VERSION="v0.30.1"
RELEASE_VERSION="v0.30.2"

# The DEB and RPM urls don't include the `v` version prefix in the file names,
# so we trim it out using ${RELEASE_VERSION#v} below.
Expand Down
2 changes: 1 addition & 1 deletion production/kubernetes/agent-bare.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
image: grafana/agent:v0.30.1
image: grafana/agent:v0.30.2
imagePullPolicy: IfNotPresent
name: grafana-agent
ports:
Expand Down
2 changes: 1 addition & 1 deletion production/kubernetes/agent-loki.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
image: grafana/agent:v0.30.1
image: grafana/agent:v0.30.2
imagePullPolicy: IfNotPresent
name: grafana-agent-logs
ports:
Expand Down
2 changes: 1 addition & 1 deletion production/kubernetes/agent-traces.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
image: grafana/agent:v0.30.1
image: grafana/agent:v0.30.2
imagePullPolicy: IfNotPresent
name: grafana-agent-traces
ports:
Expand Down
2 changes: 1 addition & 1 deletion production/kubernetes/build/lib/version.libsonnet
Original file line number Diff line number Diff line change
@@ -1 +1 @@
'grafana/agent:v0.30.1'
'grafana/agent:v0.30.2'
4 changes: 2 additions & 2 deletions production/kubernetes/build/templates/operator/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ local ksm = import 'kube-state-metrics/kube-state-metrics.libsonnet';
local this = self,

_images:: {
agent: 'grafana/agent:v0.30.1',
agent_operator: 'grafana/agent-operator:v0.30.1',
agent: 'grafana/agent:v0.30.2',
agent_operator: 'grafana/agent-operator:v0.30.2',
ksm: 'registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.5.0',
},

Expand Down
2 changes: 1 addition & 1 deletion production/kubernetes/install-bare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ check_installed() {
check_installed curl
check_installed envsubst

MANIFEST_BRANCH=v0.30.1
MANIFEST_BRANCH=v0.30.2
MANIFEST_URL=${MANIFEST_URL:-https://raw.githubusercontent.com/grafana/agent/${MANIFEST_BRANCH}/production/kubernetes/agent-bare.yaml}
NAMESPACE=${NAMESPACE:-default}

Expand Down
4 changes: 2 additions & 2 deletions production/operator/templates/agent-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ spec:
containers:
- args:
- --kubelet-service=default/kubelet
image: grafana/agent-operator:v0.30.1
image: grafana/agent-operator:v0.30.2
imagePullPolicy: IfNotPresent
name: grafana-agent-operator
serviceAccount: grafana-agent-operator
Expand Down Expand Up @@ -436,7 +436,7 @@ metadata:
name: grafana-agent
namespace: ${NAMESPACE}
spec:
image: grafana/agent:v0.30.1
image: grafana/agent:v0.30.2
integrations:
selector:
matchLabels:
Expand Down
4 changes: 2 additions & 2 deletions production/tanka/grafana-agent/v1/main.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ local service = k.core.v1.service;
(import './lib/traces.libsonnet') +
{
_images:: {
agent: 'grafana/agent:v0.30.1',
agentctl: 'grafana/agentctl:v0.30.1',
agent: 'grafana/agent:v0.30.2',
agentctl: 'grafana/agentctl:v0.30.2',
},

// new creates a new DaemonSet deployment of the grafana-agent. By default,
Expand Down
4 changes: 2 additions & 2 deletions production/tanka/grafana-agent/v2/internal/base.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ function(name='grafana-agent', namespace='') {
local this = self,

_images:: {
agent: 'grafana/agent:v0.30.1',
agentctl: 'grafana/agentctl:v0.30.1',
agent: 'grafana/agent:v0.30.2',
agentctl: 'grafana/agentctl:v0.30.2',
},
_config:: {
name: name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function(
) {
local _config = {
api: error 'api must be set',
image: 'grafana/agentctl:v0.30.1',
image: 'grafana/agentctl:v0.30.2',
schedule: '*/5 * * * *',
configs: [],
} + config,
Expand Down

0 comments on commit 59144c6

Please sign in to comment.