Skip to content

Commit

Permalink
[testbed/datasenders] add missing 0 to nanoseconds calculation (#33321)
Browse files Browse the repository at this point in the history
**Description:** <Describe what has changed.>

Fixing a bug - the calculation when converting pdata timestamps to
`time` is off in both the `syslog` and `tcpudp` datasenders.
Seconds are calculated correctly by dividing the timestamp by `10^9`,
but in nanosecond calculation the remainder of `timestamp/10^8` is used,
effectively always setting the first decimal in the resulting timestamp
to `0`.

Discovered this while writing some tests against the syslog receiver and
receiving unexpected data in the log body, after identifying the issue a
quick search revealed that the same thing was happening in the tcp/upd
datasender.

**Example:**

`2024-05-31T11:53:54.612287004+02:00` becomes
`2024-05-31T11:53:54.012287004+02:00`

**Link to tracking Issue:** no issue as it's a fairly minor thing that
only affects tests, but can open if required

**Testing:** 
- manual tests
- existing tests

**Documentation:** no additional documentation added.
  • Loading branch information
pichlermarc authored Jun 3, 2024
1 parent ed0cf90 commit 22c3296
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion testbed/datasenders/syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (f *SyslogWriter) GenConfigYAMLStr() string {
`, f.network, f.GetEndpoint())
}
func (f *SyslogWriter) Send(lr plog.LogRecord) error {
ts := time.Unix(int64(lr.Timestamp()/1000000000), int64(lr.Timestamp()%100000000)).Format(time.RFC3339Nano)
ts := time.Unix(int64(lr.Timestamp()/1_000_000_000), int64(lr.Timestamp()%1_000_000_000)).Format(time.RFC3339Nano)
sdid := strings.Builder{}
sdid.WriteString(fmt.Sprintf("%s=\"%s\" ", "trace_id", lr.TraceID()))
sdid.WriteString(fmt.Sprintf("%s=\"%s\" ", "span_id", lr.SpanID()))
Expand Down
2 changes: 1 addition & 1 deletion testbed/datasenders/tcpudp.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (f *TCPUDPWriter) GenConfigYAMLStr() string {
`, f.network, f.GetEndpoint())
}
func (f *TCPUDPWriter) Send(lr plog.LogRecord) error {
ts := time.Unix(int64(lr.Timestamp()/1000000000), int64(lr.Timestamp()%100000000)).Format(time.RFC3339Nano)
ts := time.Unix(int64(lr.Timestamp()/1_000_000_000), int64(lr.Timestamp()%1_000_000_000)).Format(time.RFC3339Nano)
sdid := strings.Builder{}
sdid.WriteString(fmt.Sprintf("%s=\"%s\" ", "trace_id", traceutil.TraceIDToHexOrEmptyString(lr.TraceID())))
sdid.WriteString(fmt.Sprintf("%s=\"%s\" ", "span_id", traceutil.SpanIDToHexOrEmptyString(lr.SpanID())))
Expand Down

0 comments on commit 22c3296

Please sign in to comment.