diff --git a/CHANGELOG.md b/CHANGELOG.md index ed031a135650..05de3c37ffc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ Main (unreleased) - Fix a memory leak which would occur any time `loki.process` had its configuration reloaded. (@ptodev) +- Fix a bug where custom components would not shadow the stdlib. If you have a module whose name conflicts with an stdlib function + and if you use this exact function in your config, then you will need to rename your module. (@wildum) + ### Other changes - Change the Docker base image for Linux containers to `ubuntu:noble`. (@amontalban) diff --git a/internal/flow/declare_test.go b/internal/flow/declare_test.go index d66505c8fb11..ca2849d68d5e 100644 --- a/internal/flow/declare_test.go +++ b/internal/flow/declare_test.go @@ -261,6 +261,38 @@ func TestDeclare(t *testing.T) { `, expected: -10, }, + { + name: "ShadowStdlib", + config: ` + declare "constants" { + argument "input" { + optional = false + } + + testcomponents.passthrough "pt" { + input = argument.input.value + lag = "1ms" + } + + export "output" { + value = testcomponents.passthrough.pt.output + } + } + testcomponents.count "inc" { + frequency = "10ms" + max = 10 + } + + constants "myModule" { + input = testcomponents.count.inc.count + } + + testcomponents.summation "sum" { + input = constants.myModule.output + } + `, + expected: 10, + }, } for _, tc := range tt { diff --git a/internal/flow/internal/controller/component_references.go b/internal/flow/internal/controller/component_references.go index c046895dda4f..13c850628885 100644 --- a/internal/flow/internal/controller/component_references.go +++ b/internal/flow/internal/controller/component_references.go @@ -42,19 +42,17 @@ func ComponentReferences(cn dag.Node, g *dag.Graph) ([]Reference, diag.Diagnosti refs := make([]Reference, 0, len(traversals)) for _, t := range traversals { - // We use an empty scope to determine if a reference refers to something in - // the stdlib, since vm.Scope.Lookup will search the scope tree + the - // stdlib. - // - // Any call to an stdlib function is ignored. - var emptyScope vm.Scope - if _, ok := emptyScope.Lookup(t[0].Name); ok { - continue - } - ref, resolveDiags := resolveTraversal(t, g) - diags = append(diags, resolveDiags...) if resolveDiags.HasErrors() { + // We use an empty scope to determine if a reference refers to something in + // the stdlib, since vm.Scope.Lookup will search the scope tree + the + // stdlib. + // + // Any call to an stdlib function is ignored. + var emptyScope vm.Scope + if _, exist := emptyScope.Lookup(t[0].Name); !exist { + diags = append(diags, resolveDiags...) + } continue } refs = append(refs, ref)