限制timestamp不能大于当前时间5分钟 (#872)
This commit is contained in:
parent
8664c3df37
commit
01f1f50880
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue