fix: Decouple cloud sync from telemetry (#343)

This commit is contained in:
Abhisek Datta
2026-06-17 16:03:26 +05:30
committed by GitHub
parent baf637be97
commit 55f3f2a252
5 changed files with 10 additions and 31 deletions
-6
View File
@@ -8,7 +8,6 @@ import (
"github.com/safedep/dry/usefulerror"
"github.com/safedep/pmg/config"
"github.com/safedep/pmg/errcodes"
"github.com/safedep/pmg/internal/analytics"
"github.com/safedep/pmg/internal/audit"
"github.com/safedep/pmg/internal/ui"
"github.com/spf13/cobra"
@@ -37,11 +36,6 @@ func newSyncCommand() *cobra.Command {
func runSync(cmd *cobra.Command, args []string) error {
cfg := config.Get()
if analytics.IsDisabled() {
ui.Infof("Cloud sync is disabled because telemetry is disabled (disable_telemetry or PMG_DISABLE_TELEMETRY)")
return nil
}
if !cfg.Config.Cloud.Enabled {
ui.ErrorExit(usefulerror.NewUsefulError().
WithCode(errcodes.Lifecycle).
-6
View File
@@ -5,7 +5,6 @@ import (
"github.com/safedep/dry/log"
"github.com/safedep/pmg/config"
"github.com/safedep/pmg/internal/analytics"
"github.com/safedep/pmg/internal/audit"
"github.com/spf13/cobra"
)
@@ -30,11 +29,6 @@ func runSyncBackground(cmd *cobra.Command, args []string) error {
cfg := config.Get()
if analytics.IsDisabled() {
log.Debugf("Auto-sync: telemetry disabled; exiting")
return nil
}
if !cfg.Config.Cloud.Enabled || !cfg.Config.Cloud.AutoSync.Enabled {
log.Debugf("Auto-sync: cloud or auto_sync disabled; exiting")
return nil
+1 -6
View File
@@ -8,7 +8,6 @@ import (
packagev1 "buf.build/gen/go/safedep/api/protocolbuffers/go/safedep/messages/package/v1"
"github.com/safedep/dry/log"
"github.com/safedep/pmg/config"
"github.com/safedep/pmg/internal/analytics"
)
var global *auditor
@@ -27,7 +26,7 @@ func Initialize(cfg *config.RuntimeConfig) error {
var sinks []Sink
sinks = append(sinks, newEventlogSink())
if cfg.Config.Cloud.Enabled && !analytics.IsDisabled() {
if cfg.Config.Cloud.Enabled {
cs, err := newCloudSink(cfg, newCloudSinkCIResolver())
if err != nil {
log.Warnf("Cloud sync initialization failed: %v", err)
@@ -36,10 +35,6 @@ func Initialize(cfg *config.RuntimeConfig) error {
}
}
if cfg.Config.Cloud.Enabled && analytics.IsDisabled() {
log.Warnf("Cloud sync is disabled because telemetry is disabled")
}
setGlobal(newAuditor(sinks...))
return nil
}
-4
View File
@@ -6,7 +6,6 @@ import (
"github.com/safedep/dry/log"
"github.com/safedep/pmg/config"
"github.com/safedep/pmg/internal/analytics"
)
// SyncBackgroundSubcommand is the cobra `Use` of the hidden child command
@@ -48,9 +47,6 @@ func MaybeSpawnBackgroundSync(cfg *config.RuntimeConfig) {
if !cfg.Config.Cloud.Enabled || !cfg.Config.Cloud.AutoSync.Enabled {
return
}
if analytics.IsDisabled() {
return
}
if !SyncCooldownElapsed(cfg.CloudSyncLastRunPath(), cfg.Config.Cloud.AutoSync.MinInterval) {
log.Debugf("Auto-sync cooldown not elapsed; skipping spawn")
+9 -9
View File
@@ -83,6 +83,15 @@ func TestMaybeSpawnBackgroundSyncSpawnsByDefault(t *testing.T) {
assert.NotEmpty(t, rec.calls[0].name, "spawned name should be a resolved binary path")
}
func TestMaybeSpawnBackgroundSyncIgnoresTelemetryDisabled(t *testing.T) {
rec := withMockSpawner(t)
cfg := newAutoSyncConfig(t)
cfg.Config.DisableTelemetry = true
MaybeSpawnBackgroundSync(cfg)
assert.Equal(t, 1, rec.callCount())
}
func TestMaybeSpawnBackgroundSyncShortCircuits(t *testing.T) {
t.Run("nil config", func(t *testing.T) {
rec := withMockSpawner(t)
@@ -108,15 +117,6 @@ func TestMaybeSpawnBackgroundSyncShortCircuits(t *testing.T) {
assert.Equal(t, 0, rec.callCount())
})
t.Run("telemetry disabled via config", func(t *testing.T) {
rec := withMockSpawner(t)
cfg := newAutoSyncConfig(t)
cfg.Config.DisableTelemetry = true
MaybeSpawnBackgroundSync(cfg)
assert.Equal(t, 0, rec.callCount())
})
t.Run("we are the sync-background child", func(t *testing.T) {
rec := withMockSpawner(t)
cfg := newAutoSyncConfig(t)