From 00adb8bc2275d84ab0c1b8672614bc904fa0bd0b Mon Sep 17 00:00:00 2001 From: Romain LE JEUNE Date: Fri, 21 Apr 2023 11:26:36 +0200 Subject: [PATCH] feat(GODT-2552): Fix review comment + use only string for Heartbeat Dimension. --- internal/bridge/heartbeat.go | 10 ++++------ internal/telemetry/heartbeat.go | 3 ++- internal/telemetry/heartbeat_test.go | 2 +- internal/telemetry/types_heartbeat.go | 2 +- tests/features/bridge/heartbeat.feature | 7 +++---- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/internal/bridge/heartbeat.go b/internal/bridge/heartbeat.go index 508a237b..1a8e0399 100644 --- a/internal/bridge/heartbeat.go +++ b/internal/bridge/heartbeat.go @@ -59,12 +59,10 @@ func (bridge *Bridge) SendHeartbeat(heartbeat *telemetry.HeartbeatData) bool { var sent = false safe.RLock(func() { - if len(bridge.users) > 0 { - for _, user := range bridge.users { - if err := user.SendTelemetry(context.Background(), data); err == nil { - sent = true - break - } + for _, user := range bridge.users { + if err := user.SendTelemetry(context.Background(), data); err == nil { + sent = true + break } } }, bridge.usersLock) diff --git a/internal/telemetry/heartbeat.go b/internal/telemetry/heartbeat.go index c2a7b888..3852a78d 100644 --- a/internal/telemetry/heartbeat.go +++ b/internal/telemetry/heartbeat.go @@ -18,6 +18,7 @@ package telemetry import ( + "strconv" "time" "github.com/ProtonMail/proton-bridge/v3/internal/updater" @@ -41,7 +42,7 @@ func NewHeartbeat(manager HeartbeatManager, imapPort, smtpPort int, cacheDir, ke } func (heartbeat *Heartbeat) SetRollout(val float64) { - heartbeat.metrics.Dimensions.Rollout = int(val * 100) + heartbeat.metrics.Dimensions.Rollout = strconv.Itoa(int(val * 100)) } func (heartbeat *Heartbeat) SetNbAccount(val int) { diff --git a/internal/telemetry/heartbeat_test.go b/internal/telemetry/heartbeat_test.go index 7c8b4fb1..046b0d18 100644 --- a/internal/telemetry/heartbeat_test.go +++ b/internal/telemetry/heartbeat_test.go @@ -48,7 +48,7 @@ func TestHeartbeat_default_heartbeat(t *testing.T) { CacheLocation: "default", KeychainPref: "default", PrevVersion: "1.2.3", - Rollout: 10, + Rollout: "10", }, } diff --git a/internal/telemetry/types_heartbeat.go b/internal/telemetry/types_heartbeat.go index e41a9c2d..a10f42b1 100644 --- a/internal/telemetry/types_heartbeat.go +++ b/internal/telemetry/types_heartbeat.go @@ -57,7 +57,7 @@ type HeartbeatDimensions struct { CacheLocation string `json:"cache_location"` KeychainPref string `json:"keychain_pref"` PrevVersion string `json:"prev_version"` - Rollout int `json:"rollout"` + Rollout string `json:"rollout"` } type HeartbeatData struct { diff --git a/tests/features/bridge/heartbeat.feature b/tests/features/bridge/heartbeat.feature index 3675cd38..9584f800 100644 --- a/tests/features/bridge/heartbeat.feature +++ b/tests/features/bridge/heartbeat.feature @@ -31,7 +31,7 @@ Feature: Send Telemetry Heartbeat "cache_location": "default", "keychain_pref": "default", "prev_version": "0.0.0", - "rollout": 42 + "rollout": "42" } } """ @@ -75,7 +75,7 @@ Feature: Send Telemetry Heartbeat "cache_location": "custom", "keychain_pref": "custom", "prev_version": "0.0.0", - "rollout": 42 + "rollout": "42" } } """ @@ -113,7 +113,7 @@ Feature: Send Telemetry Heartbeat "cache_location": "default", "keychain_pref": "default", "prev_version": "0.0.0", - "rollout": 42 + "rollout": "42" } } """ @@ -127,4 +127,3 @@ Feature: Send Telemetry Heartbeat When the user logs in with username "[user:user1]" and password "password" And user "[user:user1]" finishes syncing Then bridge needs to send heartbeat -