Skip to content
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

Remove the proto dependency in goldendataset for traces #3322

Merged
merged 16 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
## 💡 Enhancements 💡

- Add `doc.go` files to the consumer package and its subpackages (#3270)
- Remove the proto dependency in `goldendataset` for traces (#TBD)

## v0.27.0 Beta

Expand Down
4 changes: 4 additions & 0 deletions consumer/pdata/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ func NewAttributeMap() AttributeMap {
return AttributeMap{&orig}
}

func NewAttributeMapFromKeyValues(orig *[]otlpcommon.KeyValue) AttributeMap {
return newAttributeMap(orig)
}
IrisTuntun marked this conversation as resolved.
Show resolved Hide resolved

func newAttributeMap(orig *[]otlpcommon.KeyValue) AttributeMap {
return AttributeMap{orig}
}
Expand Down
10 changes: 5 additions & 5 deletions internal/goldendataset/generator_commons.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/spf13/cast"

"go.opentelemetry.io/collector/internal/data"
"go.opentelemetry.io/collector/consumer/pdata"
otlpcommon "go.opentelemetry.io/collector/internal/data/protogen/common/v1"
)

Expand Down Expand Up @@ -94,20 +94,20 @@ func loadPictOutputFile(fileName string) ([][]string, error) {
return reader.ReadAll()
}

func generateTraceID(random io.Reader) data.TraceID {
func generatePDataTraceID(random io.Reader) pdata.TraceID {
var r [16]byte
_, err := random.Read(r[:])
if err != nil {
panic(err)
}
return data.NewTraceID(r)
return pdata.NewTraceID(r)
}

func generateSpanID(random io.Reader) data.SpanID {
func generatePDataSpanID(random io.Reader) pdata.SpanID {
var r [8]byte
_, err := random.Read(r[:])
if err != nil {
panic(err)
}
return data.NewSpanID(r)
return pdata.NewSpanID(r)
}
31 changes: 31 additions & 0 deletions internal/goldendataset/resource_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package goldendataset

import (
"go.opentelemetry.io/collector/consumer/pdata"
otlpcommon "go.opentelemetry.io/collector/internal/data/protogen/common/v1"
otlpresource "go.opentelemetry.io/collector/internal/data/protogen/resource/v1"
"go.opentelemetry.io/collector/translator/conventions"
Expand Down Expand Up @@ -56,6 +57,36 @@ func GenerateResource(rscID PICTInputResource) otlpresource.Resource {
}
}

// generatePDataResource generates a PData Resource object with representative attributes for the
// underlying resource type specified by the rscID input parameter.
func generatePDataResource(rscID PICTInputResource) pdata.Resource {
var attrs map[string]interface{}
switch rscID {
case ResourceNil:
attrs = generateNilAttributes()
case ResourceEmpty:
attrs = generateEmptyAttributes()
case ResourceVMOnPrem:
attrs = generateOnpremVMAttributes()
case ResourceVMCloud:
attrs = generateCloudVMAttributes()
case ResourceK8sOnPrem:
attrs = generateOnpremK8sAttributes()
case ResourceK8sCloud:
attrs = generateCloudK8sAttributes()
case ResourceFaas:
attrs = generateFassAttributes()
case ResourceExec:
attrs = generateExecAttributes()
default:
attrs = generateEmptyAttributes()
}
resource := pdata.NewResource()
attrMap := convertMapToAttributeKeyValues(attrs)
pdata.NewAttributeMapFromKeyValues(&attrMap).CopyTo(resource.Attributes())
return resource
}

func generateNilAttributes() map[string]interface{} {
return nil
}
Expand Down
Loading