-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[chore][graph] Remodel node id as attribute sets #11344
Draft
djaglowski
wants to merge
2
commits into
open-telemetry:main
Choose a base branch
from
djaglowski:graph-attributes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+235
−56
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package attribute // import "go.opentelemetry.io/collector/service/internal/graph/attribute" | ||
|
||
import ( | ||
"fmt" | ||
"hash/fnv" | ||
|
||
"go.opentelemetry.io/otel/attribute" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/pipeline" | ||
) | ||
|
||
const ( | ||
componentKindKey = "otelcol.component.kind" | ||
componentIDKey = "otelcol.component.id" | ||
pipelineIDKey = "otelcol.pipeline.id" | ||
signalKey = "otelcol.signal" | ||
signalOutputKey = "otelcol.signal.output" | ||
|
||
receiverKind = "receiver" | ||
processorKind = "processor" | ||
exporterKind = "exporter" | ||
connectorKind = "connector" | ||
capabiltiesKind = "capabilities" | ||
fanoutKind = "fanout" | ||
) | ||
|
||
type Attributes struct { | ||
set attribute.Set | ||
id int64 | ||
} | ||
|
||
func newAttributes(attrs ...attribute.KeyValue) *Attributes { | ||
h := fnv.New64a() | ||
for _, kv := range attrs { | ||
h.Write([]byte("(" + string(kv.Key) + "|" + kv.Value.AsString() + ")")) | ||
} | ||
return &Attributes{ | ||
set: attribute.NewSet(attrs...), | ||
id: int64(h.Sum64()), // #nosec G115 | ||
} | ||
} | ||
|
||
func (a Attributes) Attributes() *attribute.Set { | ||
return &a.set | ||
} | ||
|
||
func (a Attributes) ID() int64 { | ||
return a.id | ||
} | ||
|
||
func Receiver(pipelineType pipeline.Signal, id component.ID) *Attributes { | ||
return newAttributes( | ||
attribute.String(componentKindKey, receiverKind), | ||
attribute.String(signalKey, pipelineType.String()), | ||
attribute.String(componentIDKey, id.String()), | ||
) | ||
} | ||
|
||
func Processor(pipelineID pipeline.ID, id component.ID) *Attributes { | ||
return newAttributes( | ||
attribute.String(componentKindKey, processorKind), | ||
attribute.String(signalKey, pipelineID.Signal().String()), | ||
attribute.String(pipelineIDKey, pipelineID.String()), | ||
attribute.String(componentIDKey, id.String()), | ||
) | ||
} | ||
|
||
func Exporter(pipelineType pipeline.Signal, id component.ID) *Attributes { | ||
return newAttributes( | ||
attribute.String(componentKindKey, exporterKind), | ||
attribute.String(signalKey, pipelineType.String()), | ||
attribute.String(componentIDKey, id.String()), | ||
) | ||
} | ||
|
||
func Connector(exprPipelineType, rcvrPipelineType pipeline.Signal, id component.ID) *Attributes { | ||
return newAttributes( | ||
attribute.String(componentKindKey, connectorKind), | ||
attribute.String(signalKey, fmt.Sprintf("%s_to_%s", exprPipelineType.String(), rcvrPipelineType.String())), | ||
attribute.String(componentIDKey, id.String()), | ||
) | ||
} | ||
|
||
func Capabilities(pipelineID pipeline.ID) *Attributes { | ||
return newAttributes( | ||
attribute.String(componentKindKey, capabiltiesKind), | ||
attribute.String(pipelineIDKey, pipelineID.String()), | ||
) | ||
} | ||
|
||
func Fanout(pipelineID pipeline.ID) *Attributes { | ||
return newAttributes( | ||
attribute.String(componentKindKey, fanoutKind), | ||
attribute.String(pipelineIDKey, pipelineID.String()), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package attribute | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/pipeline" | ||
"go.opentelemetry.io/collector/pipeline/pipelineprofiles" | ||
) | ||
|
||
var ( | ||
signals = []pipeline.Signal{ | ||
pipeline.SignalTraces, | ||
pipeline.SignalMetrics, | ||
pipeline.SignalLogs, | ||
pipelineprofiles.SignalProfiles, | ||
} | ||
|
||
cIDs = []component.ID{ | ||
component.MustNewID("foo"), | ||
component.MustNewID("foo2"), | ||
component.MustNewID("bar"), | ||
} | ||
|
||
pIDs = []pipeline.ID{ | ||
pipeline.MustNewID("traces"), | ||
pipeline.MustNewIDWithName("traces", "2"), | ||
pipeline.MustNewID("metrics"), | ||
pipeline.MustNewIDWithName("metrics", "2"), | ||
pipeline.MustNewID("logs"), | ||
pipeline.MustNewIDWithName("logs", "2"), | ||
pipeline.MustNewID("profiles"), | ||
pipeline.MustNewIDWithName("profiles", "2"), | ||
} | ||
) | ||
|
||
func TestAttributes(t *testing.T) { | ||
// The sets are created independently but should be exactly equivalent. | ||
// We will ensure that corresponding elements are equal and that | ||
// non-corresponding elements are not equal. | ||
setI, setJ := createExampleSets(), createExampleSets() | ||
for i, ei := range setI { | ||
for j, ej := range setJ { | ||
if i == j { | ||
require.Equal(t, ei.ID(), ej.ID()) | ||
require.True(t, ei.Attributes().Equals(ej.Attributes())) | ||
} else { | ||
require.NotEqual(t, ei.ID(), ej.ID()) | ||
require.False(t, ei.Attributes().Equals(ej.Attributes())) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func createExampleSets() []*Attributes { | ||
sets := []*Attributes{} | ||
|
||
// Receiver examples. | ||
for _, sig := range signals { | ||
for _, id := range cIDs { | ||
sets = append(sets, Receiver(sig, id)) | ||
} | ||
} | ||
|
||
// Processor examples. | ||
for _, pID := range pIDs { | ||
for _, cID := range cIDs { | ||
sets = append(sets, Processor(pID, cID)) | ||
} | ||
} | ||
|
||
// Exporter examples. | ||
for _, sig := range signals { | ||
for _, id := range cIDs { | ||
sets = append(sets, Exporter(sig, id)) | ||
} | ||
} | ||
|
||
// Connector examples. | ||
for _, exprSig := range signals { | ||
for _, rcvrSig := range signals { | ||
for _, id := range cIDs { | ||
sets = append(sets, Connector(exprSig, rcvrSig, id)) | ||
} | ||
} | ||
} | ||
|
||
// Capabilities examples. | ||
for _, pID := range pIDs { | ||
sets = append(sets, Capabilities(pID)) | ||
} | ||
|
||
// Fanout examples. | ||
for _, pID := range pIDs { | ||
sets = append(sets, Fanout(pID)) | ||
} | ||
|
||
return sets | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change in test here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's really just a change in where the start of the cycle is reported, but it still reports the same cycle deterministically.
What it comes down to is that this PR changes the way node IDs are generated. Previously, we built a particualr string for each kind of component. Now we build the ID from the attribute set. Both methods are deterministic, but the graph presumably contains some logic where the node ids are considered in an order that is sensitive to their values (e.g. sort the ids, then for each one, follow the edges, etc). The logical graph that is produced is the same, but when a cycle is encountered, the order in which it is reported is affected by the order in which nodes were considered.