-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chore][graph] Remodel node id as attribute sets
- Loading branch information
1 parent
403f1df
commit f3779d2
Showing
11 changed files
with
233 additions
and
55 deletions.
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,98 @@ | ||
// 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 ( | ||
signalKey = "otel.signal" | ||
componentIDKey = "otel.component.id" | ||
pipelineIDKey = "otel.pipeline.id" | ||
componentKindKey = "otel.component.kind" | ||
|
||
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()), | ||
} | ||
} | ||
|
||
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/component/componentprofiles" | ||
"go.opentelemetry.io/collector/pipeline" | ||
) | ||
|
||
var ( | ||
signals = []pipeline.Signal{ | ||
pipeline.SignalTraces, | ||
pipeline.SignalMetrics, | ||
pipeline.SignalLogs, | ||
componentprofiles.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.