限制timestamp不能大于当前时间5分钟 (#872)

This commit is contained in:
zheng 2022-02-18 19:17:28 +08:00 committed by GitHub
parent 8664c3df37
commit 01f1f50880
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -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
}

View File

@ -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
}