GoogleCloudPlatform / GoogleCloudPlatform/k8s-stackdriver
Event timestamp truncated to seconds precision when exporting to StackDriver
- Dominant language
- Go
- Stars
- 409
- Forks
- 236
- Avg merge
- 2h 34m
- Merged PRs (30d)
- 9
Description
Hello!
It looks like the StackDriver sink of *event-exporter* truncates timestamps to the second, although both the internal [`metav1.Time` values][2] and the [StackDriver `Timestamp` object][1] allow nanosecond precision.
The reason for this seems to be the [`MarshalJSON()` method in the vendorized package `k8s.io/apimachinery/pkg/apis/meta/v1`][3] which uses the [`time.RFC3339` format instead of `RFC3339Nano`][4]:
```go
// MarshalJSON implements the json.Marshaler interface.
func (t Time) MarshalJSON() ([]byte, error) {
...
buf = t.UTC().AppendFormat(buf, time.RFC3339)
buf = append(buf, '"')
return buf, nil
}
```
Is there a reason for this truncation?
[1]: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.timestamp:~:text=string%20(Timestamp%20format),-Optional
[2]: https://golang.org/pkg/time/#Time
[3]: https://github.com/GoogleCloudPlatform/k8s-stackdriver/blob/master/event-exporter/vendor/k8s.io/apimachinery/pkg/apis/meta/v1/time.go#L151
[4]: https://golang.org/src/time/format.go#L82
Contributor guide
Assessment
This issue has not been assessed yet.