Skip to content

Commit

Permalink
Prepare release v0.40.1 (#6569)
Browse files Browse the repository at this point in the history
* ignore errors when the logging node empties the log buffer (#6558)

(cherry picked from commit b691a44)

* Fix wiring of custom component nodes (#6563)

* fix wiring of custom component nodes by checking import before local declares

* update changelog

* add comment in loader to explain why the imports should be checked before the local declare

(cherry picked from commit 0dde507)

* flow/logging: check for nil values when writing logs (#6561)

There may be situations where the flow mode logger receivers a nil
value, potentially due to misconfiguration or a component which exports
its values only after being ran.

Fixes #6557.

(cherry picked from commit bcc9b0a)

* changelog: cut 0.40.1 (#6568)

(cherry picked from commit 9154af3)

---------

Co-authored-by: William Dumont <william.dumont@grafana.com>
  • Loading branch information
rfratto and wildum committed Feb 29, 2024
1 parent 9be9693 commit f222e2e
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 10 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ internal API changes are not present.



v0.40.1 (2024-02-27)
--------------------

### Bugfixes

- Fix an issues where the logging config block would trigger an error when trying to send logs to components that were not running. (@wildum)

- Fix an issue where a custom component might be wired to a local declare instead of an import declare when they have the same label. (@wildum)

- Fix an issue where flow mode panics if the `logging` config block is given a `null` Loki receiver to write log entries to. (@rfratto)

v0.40.0 (2024-02-27)
--------------------

Expand Down
2 changes: 1 addition & 1 deletion docs/sources/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: Grafana Agent
description: Grafana Agent is a flexible, performant, vendor-neutral, telemetry collector
weight: 350
cascade:
AGENT_RELEASE: v0.40.0
AGENT_RELEASE: v0.40.1
OTEL_VERSION: v0.87.0
---

Expand Down
10 changes: 6 additions & 4 deletions pkg/flow/internal/controller/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,15 +589,17 @@ func (l *Loader) wireGraphEdges(g *dag.Graph) diag.Diagnostics {

// wireCustomComponentNode wires a custom component to the import/declare nodes that it depends on.
func (l *Loader) wireCustomComponentNode(g *dag.Graph, cc *CustomComponentNode) {
if declare, ok := l.declareNodes[cc.customComponentName]; ok {
// It's important to check first if the importNamespace matches an import node because there might be a
// local node that has the same label as an imported declare.
if importNode, ok := l.importConfigNodes[cc.importNamespace]; ok {
// add an edge between the custom component and the corresponding import node.
g.AddEdge(dag.Edge{From: cc, To: importNode})
} else if declare, ok := l.declareNodes[cc.customComponentName]; ok {
refs := l.findCustomComponentReferences(declare.Block())
for ref := range refs {
// add edges between the custom component and declare/import nodes.
g.AddEdge(dag.Edge{From: cc, To: ref})
}
} else if importNode, ok := l.importConfigNodes[cc.importNamespace]; ok {
// add an edge between the custom component and the corresponding import node.
g.AddEdge(dag.Edge{From: cc, To: importNode})
}
}

Expand Down
15 changes: 12 additions & 3 deletions pkg/flow/logging/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ func (l *Logger) Update(o Options) error {

// Print out the buffered logs since we determined the log format already
for _, bufferedLogChunk := range l.buffer {
if err := slogadapter.GoKit(l.handler).Log(bufferedLogChunk...); err != nil {
return err
}
// the buffered logs are currently only sent to the standard output
// because the components with the receivers are not running yet
slogadapter.GoKit(l.handler).Log(bufferedLogChunk...)
}
l.buffer = nil

Expand Down Expand Up @@ -164,6 +164,15 @@ type lokiWriter struct {

func (fw *lokiWriter) Write(p []byte) (int, error) {
for _, receiver := range fw.f {
// We may have been given a nil value in rare circumstances due to
// misconfiguration or a component which generates exports after
// construction.
//
// Ignore nil values so we don't panic.
if receiver == nil {
continue
}

select {
case receiver.Chan() <- loki.Entry{
Labels: model.LabelSet{"component": "agent"},
Expand Down
20 changes: 20 additions & 0 deletions pkg/flow/logging/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/go-kit/log"
gokitlevel "github.com/go-kit/log/level"
"github.com/grafana/agent/component/common/loki"
"github.com/grafana/agent/pkg/flow/logging"
flowlevel "github.com/grafana/agent/pkg/flow/logging/level"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -165,6 +166,25 @@ func TestLevels(t *testing.T) {
}
}

// Test_lokiWriter_nil ensures that writing to a lokiWriter doesn't panic when
// given a nil receiver.
func Test_lokiWriter_nil(t *testing.T) {
logger, err := logging.New(io.Discard, debugLevel())
require.NoError(t, err)

err = logger.Update(logging.Options{
Level: logging.LevelDebug,
Format: logging.FormatLogfmt,

WriteTo: []loki.LogsReceiver{nil},
})
require.NoError(t, err)

require.NotPanics(t, func() {
_ = logger.Log("msg", "test message")
})
}

func BenchmarkLogging_NoLevel_Prints(b *testing.B) {
logger, err := logging.New(io.Discard, infoLevel())
require.NoError(b, err)
Expand Down
36 changes: 36 additions & 0 deletions pkg/flow/testdata/import_file/import_file_16.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Imported declare and local declare have the same label.

-- main.river --
testcomponents.count "inc" {
frequency = "10ms"
max = 10
}

import.file "certmanager" {
filename = "module.river"
}

certmanager.config "this" {
input = testcomponents.count.inc.count
}

declare "config" {
}

testcomponents.summation "sum" {
input = certmanager.config.this.output
}

-- module.river --
declare "config" {
argument "input" {}

testcomponents.passthrough "pt" {
input = argument.input.value
lag = "1ms"
}

export "output" {
value = testcomponents.passthrough.pt.output
}
}
2 changes: 1 addition & 1 deletion pkg/operator/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package operator

// Supported versions of the Grafana Agent.
var (
DefaultAgentVersion = "v0.40.0"
DefaultAgentVersion = "v0.40.1"
DefaultAgentBaseImage = "grafana/agent"
DefaultAgentImage = DefaultAgentBaseImage + ":" + DefaultAgentVersion
)
Expand Down
2 changes: 1 addition & 1 deletion tools/gen-versioned-files/agent-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.40.0
v0.40.1

0 comments on commit f222e2e

Please sign in to comment.