Skip to content

Commit 85a91c5

Browse files
committed
feat(BRIDGE-97): added repair button telemetry
1 parent 56d4bfb commit 85a91c5

File tree

4 files changed

+117
-3
lines changed

4 files changed

+117
-3
lines changed

internal/bridge/bridge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ func (bridge *Bridge) Repair() {
573573
wg.Add(1)
574574
go func(userID string) {
575575
defer wg.Done()
576-
if err = bridgeUser.ResyncIMAP(); err != nil {
576+
if err = bridgeUser.TriggerRepair(); err != nil {
577577
logPkg.WithError(err).Error("Failed re-syncing IMAP for userID", userID)
578578
}
579579
}(userID)

internal/telemetry/repair.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) 2024 Proton AG
2+
//
3+
// This file is part of Proton Mail Bridge.
4+
//
5+
// Proton Mail Bridge is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Proton Mail Bridge is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
17+
18+
package telemetry
19+
20+
type RepairData struct {
21+
MeasurementGroup string
22+
Event string
23+
Values map[string]string
24+
Dimensions map[string]string
25+
}
26+
27+
func NewRepairTriggerData() RepairData {
28+
return RepairData{
29+
MeasurementGroup: "bridge.any.repair",
30+
Event: "repair_trigger",
31+
Values: map[string]string{},
32+
Dimensions: map[string]string{},
33+
}
34+
}
35+
36+
func NewRepairDeferredTriggerData() RepairData {
37+
return RepairData{
38+
MeasurementGroup: "bridge.any.repair",
39+
Event: "repair_deferred_trigger",
40+
Values: map[string]string{},
41+
Dimensions: map[string]string{},
42+
}
43+
}

internal/user/repair_telemetry.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) 2024 Proton AG
2+
//
3+
// This file is part of Proton Mail Bridge.
4+
//
5+
// Proton Mail Bridge is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Proton Mail Bridge is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
17+
18+
package user
19+
20+
import (
21+
"context"
22+
"encoding/json"
23+
24+
"github.com/ProtonMail/proton-bridge/v3/internal/telemetry"
25+
)
26+
27+
func (user *User) SendRepairTrigger(ctx context.Context) {
28+
if !user.IsTelemetryEnabled(ctx) {
29+
return
30+
}
31+
32+
triggerData := telemetry.NewRepairTriggerData()
33+
data, err := json.Marshal(triggerData)
34+
if err != nil {
35+
user.log.WithError(err).Error("Failed to parse repair trigger data.")
36+
return
37+
}
38+
39+
if err := user.SendTelemetry(ctx, data); err != nil {
40+
user.log.WithError(err).Error("Failed to send repair trigger event.")
41+
return
42+
}
43+
44+
user.log.Info("Repair trigger event successfully sent.")
45+
}
46+
47+
func (user *User) SendRepairDeferredTrigger(ctx context.Context) {
48+
if !user.IsTelemetryEnabled(ctx) {
49+
return
50+
}
51+
52+
deferredTriggerData := telemetry.NewRepairDeferredTriggerData()
53+
data, err := json.Marshal(deferredTriggerData)
54+
if err != nil {
55+
user.log.WithError(err).Error("Failed to parse deferred repair trigger data.")
56+
return
57+
}
58+
59+
if err := user.SendTelemetry(ctx, data); err != nil {
60+
user.log.WithError(err).Error("Failed to send deferred repair trigger event.")
61+
return
62+
}
63+
64+
user.log.Info("Deferred repair trigger event successfully sent.")
65+
}

internal/user/user.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,12 +727,18 @@ func (user *User) VerifyResyncAndExecute() {
727727
user.log.WithError(err).Error("Failed to disable re-sync flag in user vault. UserID:", user.ID())
728728
}
729729

730-
if err := user.ResyncIMAP(); err != nil {
730+
user.SendRepairDeferredTrigger(context.Background())
731+
if err := user.resyncIMAP(); err != nil {
731732
user.log.WithError(err).Error("Failed re-syncing IMAP for userID", user.ID())
732733
}
733734
}
734735
}
735736

736-
func (user *User) ResyncIMAP() error {
737+
func (user *User) TriggerRepair() error {
738+
user.SendRepairTrigger(context.Background())
739+
return user.resyncIMAP()
740+
}
741+
742+
func (user *User) resyncIMAP() error {
737743
return user.imapService.Resync(context.Background())
738744
}

0 commit comments

Comments
 (0)