Skip to content

Commit

Permalink
fix: visualize object attributes (#185)
Browse files Browse the repository at this point in the history
This fixes an issue in which references inside object parameters were not
considered for visualization
  • Loading branch information
theSuess authored Jan 25, 2024
1 parent 4e8eaa9 commit 05f199a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/lib/river.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ describe("collecting references", () => {
),
).toEqual(["otelcol.exporter.prometheus.to_prometheus.input"]);
});
test("collect object arg references", () => {
expect(
collectReferences(
new Block("otelcol.processor.probabilistic_sampler", "default", [
new Attribute("output", {
traces: {
"-reference": "otelcol.exporter.prometheus.to_prometheus.input",
},
}),
]),
),
).toEqual(["otelcol.exporter.prometheus.to_prometheus.input"]);
});
});

describe("marshall/unmarshal", () => {
Expand Down
5 changes: 4 additions & 1 deletion src/lib/river.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ export function toBlock(
function extractRefs(...v: any[]): string[] {
const out: string[] = [];
for (const e of v) {
if (typeof e === "object" && e["-reference"]) out.push(e["-reference"]);
if (typeof e === "object") {
if (e["-reference"]) out.push(e["-reference"]);
else out.push(...extractRefs(...Object.values(e)));
}
}
return out;
}
Expand Down

0 comments on commit 05f199a

Please sign in to comment.