Skip to content

Commit 2a7130c

Browse files
committed
backport controller refs order wiring
1 parent 2d14260 commit 2a7130c

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ Main (unreleased)
8787
- Fix an issue on Windows where uninstalling Alloy did not remove it from the
8888
Add/Remove programs list. (@rfratto)
8989

90+
- Fix a bug where custom components would not shadow the stdlib. If you have a module whose name conflicts with an stdlib function
91+
and if you use this exact function in your config, then you will need to rename your module. (@wildum)
92+
9093
### Other changes
9194

9295
- Clustering for Grafana Agent in Flow mode has graduated from beta to stable.

internal/flow/declare_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,38 @@ func TestDeclare(t *testing.T) {
261261
`,
262262
expected: -10,
263263
},
264+
{
265+
name: "ShadowStdlib",
266+
config: `
267+
declare "constants" {
268+
argument "input" {
269+
optional = false
270+
}
271+
272+
testcomponents.passthrough "pt" {
273+
input = argument.input.value
274+
lag = "1ms"
275+
}
276+
277+
export "output" {
278+
value = testcomponents.passthrough.pt.output
279+
}
280+
}
281+
testcomponents.count "inc" {
282+
frequency = "10ms"
283+
max = 10
284+
}
285+
286+
constants "myModule" {
287+
input = testcomponents.count.inc.count
288+
}
289+
290+
testcomponents.summation "sum" {
291+
input = constants.myModule.output
292+
}
293+
`,
294+
expected: 10,
295+
},
264296
}
265297

266298
for _, tc := range tt {

internal/flow/internal/controller/component_references.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,17 @@ func ComponentReferences(cn dag.Node, g *dag.Graph) ([]Reference, diag.Diagnosti
4242

4343
refs := make([]Reference, 0, len(traversals))
4444
for _, t := range traversals {
45-
// We use an empty scope to determine if a reference refers to something in
46-
// the stdlib, since vm.Scope.Lookup will search the scope tree + the
47-
// stdlib.
48-
//
49-
// Any call to an stdlib function is ignored.
50-
var emptyScope vm.Scope
51-
if _, ok := emptyScope.Lookup(t[0].Name); ok {
52-
continue
53-
}
54-
5545
ref, resolveDiags := resolveTraversal(t, g)
56-
diags = append(diags, resolveDiags...)
5746
if resolveDiags.HasErrors() {
47+
// We use an empty scope to determine if a reference refers to something in
48+
// the stdlib, since vm.Scope.Lookup will search the scope tree + the
49+
// stdlib.
50+
//
51+
// Any call to an stdlib function is ignored.
52+
var emptyScope vm.Scope
53+
if _, exist := emptyScope.Lookup(t[0].Name); !exist {
54+
diags = append(diags, resolveDiags...)
55+
}
5856
continue
5957
}
6058
refs = append(refs, ref)

0 commit comments

Comments
 (0)