Skip to content

Commit

Permalink
Add WithPipelines method to InstanceID
Browse files Browse the repository at this point in the history
  • Loading branch information
mwear committed Jul 8, 2024
1 parent 16d047d commit e9004ae
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
36 changes: 18 additions & 18 deletions component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion component/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
8 changes: 3 additions & 5 deletions service/internal/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit e9004ae

Please sign in to comment.