Skip to content

Commit

Permalink
Cleanup usage of TimestampUnixNanos and its API
Browse files Browse the repository at this point in the history
Updates #2488

Important Changes:

* Rename pdata.TimestampUnixNanos to pdata.Timestamp
* Remove pdata.TimestampUnixNanos and helpers, move them of the pdata.Timestamp type.
* Fix bug around IsZero, this function should return true if the time is January 1, year 1, 00:00:00 UTC not epoch.

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Feb 25, 2021
1 parent 7d7ae2e commit e9a4c2a
Show file tree
Hide file tree
Showing 70 changed files with 336 additions and 374 deletions.
2 changes: 1 addition & 1 deletion cmd/pdatagen/internal/base_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (pf *primitiveField) generateCopyToValue(sb *strings.Builder) {

var _ baseField = (*primitiveField)(nil)

// Types that has defined a custom type (e.g. "type TimestampUnixNano uint64")
// Types that has defined a custom type (e.g. "type Timestamp uint64")
type primitiveTypedField struct {
fieldName string
originFieldName string
Expand Down
18 changes: 9 additions & 9 deletions cmd/pdatagen/internal/common_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,28 @@ var instrumentationLibraryField = &messageValueField{
var startTimeField = &primitiveTypedField{
fieldName: "StartTime",
originFieldName: "StartTimeUnixNano",
returnType: "TimestampUnixNano",
returnType: "Timestamp",
rawType: "uint64",
defaultVal: "TimestampUnixNano(0)",
testVal: "TimestampUnixNano(1234567890)",
defaultVal: "Timestamp(0)",
testVal: "Timestamp(1234567890)",
}

var timeField = &primitiveTypedField{
fieldName: "Timestamp",
originFieldName: "TimeUnixNano",
returnType: "TimestampUnixNano",
returnType: "Timestamp",
rawType: "uint64",
defaultVal: "TimestampUnixNano(0)",
testVal: "TimestampUnixNano(1234567890)",
defaultVal: "Timestamp(0)",
testVal: "Timestamp(1234567890)",
}

var endTimeField = &primitiveTypedField{
fieldName: "EndTime",
originFieldName: "EndTimeUnixNano",
returnType: "TimestampUnixNano",
returnType: "Timestamp",
rawType: "uint64",
defaultVal: "TimestampUnixNano(0)",
testVal: "TimestampUnixNano(1234567890)",
defaultVal: "Timestamp(0)",
testVal: "Timestamp(1234567890)",
}

var attributes = &sliceField{
Expand Down
6 changes: 3 additions & 3 deletions cmd/pdatagen/internal/log_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ var logRecord = &messageValueStruct{
&primitiveTypedField{
fieldName: "Timestamp",
originFieldName: "TimeUnixNano",
returnType: "TimestampUnixNano",
returnType: "Timestamp",
rawType: "uint64",
defaultVal: "TimestampUnixNano(0)",
testVal: "TimestampUnixNano(1234567890)",
defaultVal: "Timestamp(0)",
testVal: "Timestamp(1234567890)",
},
traceIDField,
spanIDField,
Expand Down
9 changes: 0 additions & 9 deletions consumer/pdata/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,10 @@ package pdata

import (
"sort"
"time"

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

// TimestampUnixNano is a time specified as UNIX Epoch time in nanoseconds since
// 00:00:00 UTC on 1 January 1970.
type TimestampUnixNano uint64

func (ts TimestampUnixNano) String() string {
return time.Unix(0, int64(ts)).String()
}

// AttributeValueType specifies the type of AttributeValue.
type AttributeValueType int

Expand Down
6 changes: 3 additions & 3 deletions consumer/pdata/generated_log.go

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

6 changes: 3 additions & 3 deletions consumer/pdata/generated_log_test.go

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

72 changes: 36 additions & 36 deletions consumer/pdata/generated_metrics.go

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

Loading

0 comments on commit e9a4c2a

Please sign in to comment.