From 7ea7a53aa752d18e0da694fa70373d267712435f Mon Sep 17 00:00:00 2001 From: "ming.tang" Date: Wed, 10 Apr 2024 10:43:44 +0800 Subject: [PATCH] fix device mapper data collecting cycle calculation error. Signed-off-by: ming.tang --- docs/proposals/device-crd-v1beta1.md | 4 ++-- .../_template/mapper/data/dbmethod/influxdb2/handler.go | 3 +-- .../_template/mapper/data/dbmethod/redis/handler.go | 2 +- .../_template/mapper/data/dbmethod/tdengine/handler.go | 2 +- .../mapper-framework/_template/mapper/device/device.go | 4 ++-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/docs/proposals/device-crd-v1beta1.md b/docs/proposals/device-crd-v1beta1.md index 84eacf261a6..1a722a3089d 100644 --- a/docs/proposals/device-crd-v1beta1.md +++ b/docs/proposals/device-crd-v1beta1.md @@ -342,8 +342,8 @@ spec: nodeName: worker-node1 properties: - name: temp - collectCycle: 2000 - reportCycle: 2000 + collectCycle: 2000 # 2000 stands for 2000 milliseconds (2 seconds) + reportCycle: 2000 # 2000 stands for 2000 milliseconds (2 seconds) desired: value: "30" reportToCloud: true diff --git a/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/data/dbmethod/influxdb2/handler.go b/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/data/dbmethod/influxdb2/handler.go index 287bb561624..53d950967be 100644 --- a/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/data/dbmethod/influxdb2/handler.go +++ b/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/data/dbmethod/influxdb2/handler.go @@ -21,7 +21,6 @@ import ( "time" "k8s.io/klog/v2" - "github.com/kubeedge/Template/driver" "github.com/kubeedge/mapper-framework/pkg/common" ) @@ -37,7 +36,7 @@ func DataHandler(ctx context.Context, twin *common.Twin, client *driver.Customiz klog.Errorf("init database client err: %v", err) return } - reportCycle := time.Duration(twin.Property.ReportCycle) + reportCycle := time.Millisecond * time.Duration(twin.Property.ReportCycle) if reportCycle == 0 { reportCycle = common.DefaultReportCycle } diff --git a/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/data/dbmethod/redis/handler.go b/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/data/dbmethod/redis/handler.go index 9363f6f0e35..dfec8af784e 100644 --- a/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/data/dbmethod/redis/handler.go +++ b/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/data/dbmethod/redis/handler.go @@ -37,7 +37,7 @@ func DataHandler(ctx context.Context, twin *common.Twin, client *driver.Customiz klog.Errorf("init redis database client err: %v", err) return } - reportCycle := time.Duration(twin.Property.ReportCycle) + reportCycle := time.Millisecond * time.Duration(twin.Property.ReportCycle) if reportCycle == 0 { reportCycle = common.DefaultReportCycle } diff --git a/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/data/dbmethod/tdengine/handler.go b/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/data/dbmethod/tdengine/handler.go index 2840a6ed3c7..ba67326590f 100644 --- a/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/data/dbmethod/tdengine/handler.go +++ b/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/data/dbmethod/tdengine/handler.go @@ -37,7 +37,7 @@ func DataHandler(ctx context.Context, twin *common.Twin, client *driver.Customiz klog.Errorf("init database client err: %v", err) return } - reportCycle := time.Duration(twin.Property.ReportCycle) + reportCycle := time.Millisecond * time.Duration(twin.Property.ReportCycle) if reportCycle == 0 { reportCycle = common.DefaultReportCycle } diff --git a/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/device/device.go b/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/device/device.go index f7afe8d37c9..c8c7fe947e9 100644 --- a/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/device/device.go +++ b/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/device/device.go @@ -145,7 +145,7 @@ func dataHandler(ctx context.Context, dev *driver.CustomizedDev) { ObservedDesired: twin.ObservedDesired, VisitorConfig: &visitorConfig, Topic: fmt.Sprintf(common.TopicTwinUpdate, dev.Instance.ID), - CollectCycle: time.Duration(twin.Property.CollectCycle), + CollectCycle: time.Millisecond * time.Duration(twin.Property.CollectCycle), ReportToCloud: twin.Property.ReportToCloud, } go twinData.Run(ctx) @@ -196,7 +196,7 @@ func pushHandler(ctx context.Context, twin *common.Twin, client *driver.Customiz klog.Errorf("init publish method err: %v", err) return } - reportCycle := time.Duration(twin.Property.ReportCycle) + reportCycle := time.Millisecond * time.Duration(twin.Property.ReportCycle) if reportCycle == 0 { reportCycle = common.DefaultReportCycle }