Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport controller refs order wiring #6896

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions internal/flow/declare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 9 additions & 11 deletions internal/flow/internal/controller/component_references.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading