Skip to content

Commit

Permalink
fix: fix parsing timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
huskar-t committed May 9, 2024
1 parent 24a49a9 commit 76174b8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions controller/rest/restful.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ func (ctl *Restful) sql(c *gin.Context) {
timeBuffer = timeBuffer[:0]
switch precision {
case common.PrecisionMilliSecond: // milli-second
timeBuffer = time.Unix(0, ts*1e6).In(location).AppendFormat(timeBuffer, layout.LayoutMillSecond)
timeBuffer = time.Unix(ts/1e3, (ts%1e3)*1e6).In(location).AppendFormat(timeBuffer, layout.LayoutMillSecond)
case common.PrecisionMicroSecond: // micro-second
timeBuffer = time.Unix(0, ts*1e3).In(location).AppendFormat(timeBuffer, layout.LayoutMicroSecond)
timeBuffer = time.Unix(ts/1e6, (ts%1e6)*1e3).In(location).AppendFormat(timeBuffer, layout.LayoutMicroSecond)
case common.PrecisionNanoSecond: // nano-second
timeBuffer = time.Unix(0, ts).In(location).AppendFormat(timeBuffer, layout.LayoutNanoSecond)
default:
Expand Down
4 changes: 2 additions & 2 deletions plugin/prometheus/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func generateWriteSql(timeseries []prompbWrite.TimeSeries, sql *bytes.Buffer, tt
for _, sample := range timeseries[i].Samples {
sql.WriteString("('")
timeBuffer.Reset()
timeBuffer.B = time.Unix(0, sample.Timestamp*1e6).UTC().AppendFormat(timeBuffer.B, time.RFC3339Nano)
timeBuffer.B = time.Unix(sample.Timestamp/1e3, (sample.Timestamp%1e3)*1e6).UTC().AppendFormat(timeBuffer.B, time.RFC3339Nano)
sql.WriteString(bytesutil.ToUnsafeString(timeBuffer.B))
sql.WriteString("',")
if math.IsNaN(sample.Value) {
Expand Down Expand Up @@ -262,7 +262,7 @@ func generateReadSql(query *prompb.Query) (string, error) {
}

func ms2Time(ts int64) string {
return time.Unix(0, ts*1e6).UTC().Format(time.RFC3339Nano)
return time.Unix(ts/1e3, (ts%1e3)*1e6).UTC().Format(time.RFC3339Nano)
}

func escapeString(s string) string {
Expand Down

0 comments on commit 76174b8

Please sign in to comment.