From 01f1f50880b8ac232c951790f6abb3cb1c668c50 Mon Sep 17 00:00:00 2001 From: zheng Date: Fri, 18 Feb 2022 19:17:28 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=90=E5=88=B6timestamp=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E5=A4=A7=E4=BA=8E=E5=BD=93=E5=89=8D=E6=97=B6=E9=97=B45?= =?UTF-8?q?=E5=88=86=E9=92=9F=20(#872)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/router/router_openfalcon.go | 9 +++++++-- src/server/router/router_opentsdb.go | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/server/router/router_openfalcon.go b/src/server/router/router_openfalcon.go index 76402463..54ea9a0e 100644 --- a/src/server/router/router_openfalcon.go +++ b/src/server/router/router_openfalcon.go @@ -28,7 +28,7 @@ type FalconMetric struct { Tags string `json:"tags"` } -func (m *FalconMetric) Clean() error { +func (m *FalconMetric) Clean(ts int64) error { if m.Metric == "" { return fmt.Errorf("metric is blank") } @@ -57,6 +57,11 @@ func (m *FalconMetric) Clean() error { m.Timestamp /= 1000 } + // If the timestamp is greater than 5 minutes, the current time shall prevail + diff := m.Timestamp - ts + if diff > 300 { + m.Timestamp = ts + } return nil } @@ -180,7 +185,7 @@ func falconPush(c *gin.Context) { ) for i := 0; i < len(arr); i++ { - if err := arr[i].Clean(); err != nil { + if err := arr[i].Clean(ts); err != nil { fail++ continue } diff --git a/src/server/router/router_opentsdb.go b/src/server/router/router_opentsdb.go index 1d3ca949..83263d82 100644 --- a/src/server/router/router_opentsdb.go +++ b/src/server/router/router_opentsdb.go @@ -28,7 +28,7 @@ type HTTPMetric struct { Tags map[string]string `json:"tags"` } -func (m *HTTPMetric) Clean() error { +func (m *HTTPMetric) Clean(ts int64) error { if m.Metric == "" { return fmt.Errorf("metric is blank") } @@ -57,6 +57,11 @@ func (m *HTTPMetric) Clean() error { m.Timestamp /= 1000 } + // If the timestamp is greater than 5 minutes, the current time shall prevail + diff := m.Timestamp - ts + if diff > 300 { + m.Timestamp = ts + } return nil } @@ -163,7 +168,7 @@ func handleOpenTSDB(c *gin.Context) { ) for i := 0; i < len(arr); i++ { - if err := arr[i].Clean(); err != nil { + if err := arr[i].Clean(ts); err != nil { fail++ continue }