GoogleCloudPlatform / k8s-stackdriver

Apache License 2.0
390 stars 211 forks source link

Event timestamp truncated to seconds precision when exporting to StackDriver #395

Open riccardomurri opened 3 years ago

riccardomurri commented 3 years ago

Hello!

It looks like the StackDriver sink of event-exporter truncates timestamps to the second, although both the internal metav1.Time values and the StackDriver Timestamp object allow nanosecond precision.

The reason for this seems to be the MarshalJSON() method in the vendorized package k8s.io/apimachinery/pkg/apis/meta/v1 which uses the time.RFC3339 format instead of RFC3339Nano:

// 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?

serathius commented 3 years ago

/cc @kawych