Skip to content

Commit

Permalink
Split pdata package by telemetry signal type
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryax committed Mar 29, 2022
1 parent a73610a commit 4b2a570
Show file tree
Hide file tree
Showing 31 changed files with 880 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
instance for consistency with other OneOf field accessors (#5034)
- Update OTLP to v0.15.0 (#5064)
- Adding support for transition from older versions of OTLP to OTLP v0.15.0 (#5085)
- Split pdata package separated by telemetry signal type (#5087)

### 🧰 Bug fixes 🧰

Expand Down
28 changes: 24 additions & 4 deletions model/internal/cmd/pdatagen/internal/base_slices.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ func fillTest${structName}(tv ${structName}) {
}`

const commonSliceAliasTemplate = `// ${structName} is an alias for pdata.${structName} struct.
type ${structName} = pdata.${structName}
${extraStructComment}type ${structName} = pdata.${structName}
// New${structName} is an alias for a function to create ${structName}.
var New${structName} = pdata.New${structName}`
${extraNewComment}var New${structName} = pdata.New${structName}`

const slicePtrTemplate = `// ${structName} logically represents a slice of ${elementName}.
//
Expand Down Expand Up @@ -477,11 +477,21 @@ func (ss *sliceOfPtrs) templateFields() func(name string) string {
}
}

func (ss *sliceOfPtrs) generateAlias(sb *strings.Builder) {
func (ss *sliceOfPtrs) generateAlias(sb *strings.Builder, deprecatedInFavor string) {
sb.WriteString(os.Expand(commonSliceAliasTemplate, func(name string) string {
switch name {
case "structName":
return ss.structName
case "extraStructComment":
if deprecatedInFavor != "" {
return "// Deprecated: [v0.49.0] Use " + deprecatedInFavor + "." + ss.structName + " instead.\n"
}
return ""
case "extraNewComment":
if deprecatedInFavor != "" {
return "// Deprecated: [v0.49.0] Use " + deprecatedInFavor + ".New" + ss.structName + " instead.\n"
}
return ""
default:
panic(name)
}
Expand Down Expand Up @@ -530,11 +540,21 @@ func (ss *sliceOfValues) templateFields() func(name string) string {
}
}

func (ss *sliceOfValues) generateAlias(sb *strings.Builder) {
func (ss *sliceOfValues) generateAlias(sb *strings.Builder, deprecatedInFavor string) {
sb.WriteString(os.Expand(commonSliceAliasTemplate, func(name string) string {
switch name {
case "structName":
return ss.structName
case "extraStructComment":
if deprecatedInFavor != "" {
return "// Deprecated: [v0.49.0] Use " + deprecatedInFavor + "." + ss.structName + " instead.\n"
}
return ""
case "extraNewComment":
if deprecatedInFavor != "" {
return "// Deprecated: [v0.49.0] Use " + deprecatedInFavor + ".New" + ss.structName + " instead.\n"
}
return ""
default:
panic(name)
}
Expand Down
18 changes: 14 additions & 4 deletions model/internal/cmd/pdatagen/internal/base_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ const messageValueFillTestHeaderTemplate = `func fillTest${structName}(tv ${stru
const messageValueFillTestFooterTemplate = `}`

const messageValueAliasTemplate = `// ${structName} is an alias for pdata.${structName} struct.
type ${structName} = pdata.${structName}
${extraStructComment}type ${structName} = pdata.${structName}
// New${structName} is an alias for a function to create a new empty ${structName}.
var New${structName} = pdata.New${structName}`
${extraNewComment}var New${structName} = pdata.New${structName}`

const newLine = "\n"

Expand All @@ -97,7 +97,7 @@ type baseStruct interface {
}

type aliasGenerator interface {
generateAlias(sb *strings.Builder)
generateAlias(sb *strings.Builder, deprecatedInFavor string)
}

type messageValueStruct struct {
Expand Down Expand Up @@ -196,11 +196,21 @@ func (ms *messageValueStruct) generateTestValueHelpers(sb *strings.Builder) {
}))
}

func (ms *messageValueStruct) generateAlias(sb *strings.Builder) {
func (ms *messageValueStruct) generateAlias(sb *strings.Builder, deprecatedInFavor string) {
sb.WriteString(os.Expand(messageValueAliasTemplate, func(name string) string {
switch name {
case "structName":
return ms.structName
case "extraStructComment":
if deprecatedInFavor != "" {
return "// Deprecated: [v0.49.0] Use " + deprecatedInFavor + "." + ms.structName + " instead.\n"
}
return ""
case "extraNewComment":
if deprecatedInFavor != "" {
return "// Deprecated: [v0.49.0] Use " + deprecatedInFavor + ".New" + ms.structName + " instead.\n"
}
return ""
default:
panic(name)
}
Expand Down
33 changes: 19 additions & 14 deletions model/internal/cmd/pdatagen/internal/files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion model/internal/cmd/pdatagen/internal/log_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package internal // import "go.opentelemetry.io/collector/model/internal/cmd/pdatagen/internal"

var logFile = &File{
Name: "log",
Name: "plog",
imports: []string{
`"sort"`,
``,
Expand Down
2 changes: 1 addition & 1 deletion model/internal/cmd/pdatagen/internal/metrics_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package internal // import "go.opentelemetry.io/collector/model/internal/cmd/pdatagen/internal"

var metricsFile = &File{
Name: "metrics",
Name: "pmetric",
imports: []string{
`"sort"`,
``,
Expand Down
2 changes: 1 addition & 1 deletion model/internal/cmd/pdatagen/internal/trace_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package internal // import "go.opentelemetry.io/collector/model/internal/cmd/pdatagen/internal"

var traceFile = &File{
Name: "trace",
Name: "ptrace",
imports: []string{
`"sort"`,
``,
Expand Down
14 changes: 13 additions & 1 deletion model/internal/cmd/pdatagen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main

import (
"os"
"path/filepath"

"go.opentelemetry.io/collector/model/internal/cmd/pdatagen/internal"
)
Expand All @@ -40,7 +41,18 @@ func main() {
check(f.Close())
f, err = os.Create("./model/pdata/generated_" + fp.Name + "_alias.go")
check(err)
_, err = f.WriteString(fp.GenerateAliasFile())
fileName := "generated_alias.go"
packageName := fp.Name
if fp.IsCommon() {
fileName = "generated_" + fp.Name + "_alias.go"
packageName = "pcommon"
}
_, err = f.WriteString(fp.GenerateAliasFile("pdata", packageName))
check(err)
check(f.Close())
f, err = os.Create(filepath.Clean("./model/" + packageName + "/" + fileName))
check(err)
_, err = f.WriteString(fp.GenerateAliasFile(packageName, ""))
check(err)
check(f.Close())
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
68 changes: 68 additions & 0 deletions model/pcommon/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package pcommon // import "go.opentelemetry.io/collector/model/pcommon"

// This file contains aliases to data structures that are common for all
// signal types, such as timestamps, attributes, etc.

import "go.opentelemetry.io/collector/model/internal/pdata"

// ValueType is an alias for pdata.ValueType type.
type ValueType = pdata.ValueType

// AttributeValueType is an alias for pdata.ValueType type.
// Deprecated: [v0.48.0] Use ValueType instead.
type AttributeValueType = pdata.ValueType

const (
ValueTypeEmpty = pdata.ValueTypeEmpty
ValueTypeString = pdata.ValueTypeString
ValueTypeInt = pdata.ValueTypeInt
ValueTypeDouble = pdata.ValueTypeDouble
ValueTypeBool = pdata.ValueTypeBool
ValueTypeMap = pdata.ValueTypeMap
ValueTypeSlice = pdata.ValueTypeSlice
ValueTypeBytes = pdata.ValueTypeBytes
)

// Value is an alias for pdata.Value struct.
type Value = pdata.Value

// Deprecated: [v0.48.0] Use Value instead.
type AttributeValue = pdata.Value

// Aliases for functions to create pdata.Value.
var (
NewValueEmpty = pdata.NewValueEmpty
NewValueString = pdata.NewValueString
NewValueInt = pdata.NewValueInt
NewValueDouble = pdata.NewValueDouble
NewValueBool = pdata.NewValueBool
NewValueMap = pdata.NewValueMap
NewValueSlice = pdata.NewValueSlice
NewValueBytes = pdata.NewValueBytes
)

// Map is an alias for pdata.Map struct.
type Map = pdata.Map

// Deprecated: [v0.48.0] Use Map instead.
type AttributeMap = pdata.Map

// Aliases for functions to create pdata.Map.
var (
NewMap = pdata.NewMap
NewMapFromRaw = pdata.NewMapFromRaw
)
32 changes: 32 additions & 0 deletions model/pcommon/generated_common_alias.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions model/pcommon/generated_resource_alias.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions model/pcommon/spanid_alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package pcommon // import "go.opentelemetry.io/collector/model/pcommon"

import "go.opentelemetry.io/collector/model/internal/pdata"

// SpanID is an alias for pdata.SpanID struct.
type SpanID = pdata.SpanID

// InvalidSpanID is an alias for pdata.InvalidSpanID function.
var InvalidSpanID = pdata.InvalidSpanID

// NewSpanID is an alias for a function to create new SpanID.
var NewSpanID = pdata.NewSpanID
Loading

0 comments on commit 4b2a570

Please sign in to comment.