From 18dccc33a940d0c8785b004b8f2ff82e5a833b41 Mon Sep 17 00:00:00 2001 From: Matthew Wear Date: Mon, 8 Jul 2024 11:24:32 -0700 Subject: [PATCH] Add WithPipelines method to InstanceID --- component/component.go | 36 ++++++++++++++++----------------- component/component_test.go | 2 +- service/internal/graph/graph.go | 8 +++----- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/component/component.go b/component/component.go index 8aba8658c2a..6d6aacc0368 100644 --- a/component/component.go +++ b/component/component.go @@ -197,21 +197,6 @@ type InstanceID struct { pipelineIDs map[ID]struct{} } -// ComponentID returns the ComponentID associated with this instance. -func (id InstanceID) ComponentID() ID { - return id.componentID -} - -// Kind returns the component Kind associated with this instance. -func (id InstanceID) Kind() Kind { - return id.kind -} - -// PipelineIDs returns a set of PipelineIDs associated with this instance. -func (id InstanceID) PipelineIDs() map[ID]struct{} { - return id.pipelineIDs -} - // NewInstanceID returns an ID that uniquely identifies a component. func NewInstanceID(componentID ID, kind Kind, pipelineIDs ...ID) *InstanceID { instanceID := InstanceID{ @@ -225,9 +210,24 @@ func NewInstanceID(componentID ID, kind Kind, pipelineIDs ...ID) *InstanceID { return &instanceID } -// InstanceIDWithPipelines derives a new InstanceID from id with additional -// pipelineIDs added to it. -func InstanceIDWithPipelines(id *InstanceID, pipelineIDs ...ID) *InstanceID { +// ComponentID returns the ComponentID associated with this instance. +func (id *InstanceID) ComponentID() ID { + return id.componentID +} + +// Kind returns the component Kind associated with this instance. +func (id *InstanceID) Kind() Kind { + return id.kind +} + +// PipelineIDs returns a set of PipelineIDs associated with this instance. +func (id *InstanceID) PipelineIDs() map[ID]struct{} { + return id.pipelineIDs +} + +// WithPipelines returns a new InstanceID updated to include the given +// pipelineIDs. +func (id *InstanceID) WithPipelines(pipelineIDs ...ID) *InstanceID { instanceID := InstanceID{ componentID: id.ComponentID(), kind: id.Kind(), diff --git a/component/component_test.go b/component/component_test.go index 828357958cb..2db18527587 100644 --- a/component/component_test.go +++ b/component/component_test.go @@ -37,7 +37,7 @@ func TestInstanceID(t *testing.T) { receiver := MustNewID("receiver") id1 := NewInstanceID(receiver, KindReceiver, traces) - id2 := InstanceIDWithPipelines(id1, metrics, logs) + id2 := id1.WithPipelines(metrics, logs) assert.Equal(t, receiver, id1.ComponentID()) assert.Equal(t, KindReceiver, id1.Kind()) diff --git a/service/internal/graph/graph.go b/service/internal/graph/graph.go index 5058486424c..90f44eeb42a 100644 --- a/service/internal/graph/graph.go +++ b/service/internal/graph/graph.go @@ -194,7 +194,7 @@ func (g *Graph) createReceiver(pipelineID, recvID component.ID) *receiverNode { rcvrNode := newReceiverNode(pipelineID.Type(), recvID) if node := g.componentGraph.Node(rcvrNode.ID()); node != nil { instanceID := g.instanceIDs[node.ID()] - g.instanceIDs[node.ID()] = component.InstanceIDWithPipelines(instanceID, pipelineID) + g.instanceIDs[node.ID()] = instanceID.WithPipelines(pipelineID) return node.(*receiverNode) } g.componentGraph.AddNode(rcvrNode) @@ -217,7 +217,7 @@ func (g *Graph) createExporter(pipelineID, exprID component.ID) *exporterNode { expNode := newExporterNode(pipelineID.Type(), exprID) if node := g.componentGraph.Node(expNode.ID()); node != nil { instanceID := g.instanceIDs[expNode.ID()] - g.instanceIDs[expNode.ID()] = component.InstanceIDWithPipelines(instanceID, pipelineID) + g.instanceIDs[expNode.ID()] = instanceID.WithPipelines(pipelineID) return node.(*exporterNode) } g.componentGraph.AddNode(expNode) @@ -231,9 +231,7 @@ func (g *Graph) createConnector(exprPipelineID, rcvrPipelineID, connID component connNode := newConnectorNode(exprPipelineID.Type(), rcvrPipelineID.Type(), connID) if node := g.componentGraph.Node(connNode.ID()); node != nil { instanceID := g.instanceIDs[connNode.ID()] - g.instanceIDs[connNode.ID()] = component.InstanceIDWithPipelines( - instanceID, exprPipelineID, rcvrPipelineID, - ) + g.instanceIDs[connNode.ID()] = instanceID.WithPipelines(exprPipelineID, rcvrPipelineID) return node.(*connectorNode) } g.componentGraph.AddNode(connNode)