Skip to content

Commit

Permalink
backport controller refs order wiring (#6896)
Browse files Browse the repository at this point in the history
  • Loading branch information
wildum authored Sep 2, 2024
1 parent 1e16c74 commit d87f8af
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
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

0 comments on commit d87f8af

Please sign in to comment.