From 46324f085d52a34b28717c1178248feb5a3561d6 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Sun, 24 Aug 2025 14:30:35 +0200 Subject: [PATCH] fix: disable telemetry in test profile (#10931) * Tests: disable telemetry in tests by default Disable the plugin in cli tests and sharness by default. Enable only in telemetry tests. There are cases when tests get stuck or get killed and leave daemons hanging around. We don't want to be getting telemetry from those. * sharness: attempt to fix * sharness: add missing --bool flag * fix(ci): add omitempty to Plugin.Config field The sharness problem is that when the telemetry plugin is configured initially with 'ipfs config --bool', it creates a structure without the 'Config: null' field, but when the config is copied and replaced, it expects the structure to be preserved. Adding omitempty ensures the Config field is omitted from JSON when nil, making the config structure consistent between initial creation and replacement operations. --------- Co-authored-by: Marcin Rataj (cherry picked from commit 15f723a15e7c79f12857f52e652ffecb6d043e4d) --- config/plugins.go | 2 +- test/cli/harness/node.go | 8 ++++++++ test/cli/telemetry_test.go | 5 +++++ test/sharness/lib/test-lib.sh | 8 ++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/config/plugins.go b/config/plugins.go index 08a1acb34..0c438cbd7 100644 --- a/config/plugins.go +++ b/config/plugins.go @@ -7,5 +7,5 @@ type Plugins struct { type Plugin struct { Disabled bool - Config interface{} + Config interface{} `json:",omitempty"` } diff --git a/test/cli/harness/node.go b/test/cli/harness/node.go index 6403a2f1a..0315e81df 100644 --- a/test/cli/harness/node.go +++ b/test/cli/harness/node.go @@ -245,6 +245,14 @@ func (n *Node) Init(ipfsArgs ...string) *Node { cfg.Swarm.DisableNatPortMap = true cfg.Discovery.MDNS.Enabled = n.EnableMDNS cfg.Routing.LoopbackAddressesOnLanDHT = config.True + // Telemetry disabled by default in tests. + cfg.Plugins = config.Plugins{ + Plugins: map[string]config.Plugin{ + "telemetry": config.Plugin{ + Disabled: true, + }, + }, + } }) return n } diff --git a/test/cli/telemetry_test.go b/test/cli/telemetry_test.go index 455ea7df1..69b87e80d 100644 --- a/test/cli/telemetry_test.go +++ b/test/cli/telemetry_test.go @@ -25,6 +25,7 @@ func TestTelemetry(t *testing.T) { // Create a new node node := harness.NewT(t).NewNode().Init() + node.SetIPFSConfig("Plugins.Plugins.telemetry.Disabled", false) // Set the opt-out environment variable node.Runner.Env["IPFS_TELEMETRY"] = "off" @@ -64,6 +65,7 @@ func TestTelemetry(t *testing.T) { // Create a new node node := harness.NewT(t).NewNode().Init() + node.SetIPFSConfig("Plugins.Plugins.telemetry.Disabled", false) // Set opt-out via config node.IPFS("config", "Plugins.Plugins.telemetry.Config.Mode", "off") @@ -106,6 +108,7 @@ func TestTelemetry(t *testing.T) { // Create a new node node := harness.NewT(t).NewNode().Init() + node.SetIPFSConfig("Plugins.Plugins.telemetry.Disabled", false) // Create a UUID file manually to simulate previous telemetry run uuidPath := filepath.Join(node.Dir, "telemetry_uuid") @@ -154,6 +157,7 @@ func TestTelemetry(t *testing.T) { // Create a new node node := harness.NewT(t).NewNode().Init() + node.SetIPFSConfig("Plugins.Plugins.telemetry.Disabled", false) // Capture daemon output stdout := &harness.Buffer{} @@ -255,6 +259,7 @@ func TestTelemetry(t *testing.T) { // Create a new node node := harness.NewT(t).NewNode().Init() + node.SetIPFSConfig("Plugins.Plugins.telemetry.Disabled", false) // Configure telemetry with a very short delay for testing node.IPFS("config", "Plugins.Plugins.telemetry.Config.Delay", "100ms") diff --git a/test/sharness/lib/test-lib.sh b/test/sharness/lib/test-lib.sh index e8030dcc4..413d0e92f 100644 --- a/test/sharness/lib/test-lib.sh +++ b/test/sharness/lib/test-lib.sh @@ -205,6 +205,10 @@ test_init_ipfs() { ipfs init "${args[@]}" --profile=test > /dev/null ' + test_expect_success "disable telemetry" ' + test_config_set --bool Plugins.Plugins.telemetry.Disabled "true" + ' + test_expect_success "prepare config -- mounting" ' mkdir mountdir ipfs ipns mfs && test_config_set Mounts.IPFS "$(pwd)/ipfs" && @@ -227,6 +231,10 @@ test_init_ipfs_measure() { ipfs init "${args[@]}" --profile=test,flatfs-measure > /dev/null ' + test_expect_success "disable telemetry" ' + test_config_set --bool Plugins.Plugins.telemetry.Disabled "true" + ' + test_expect_success "prepare config -- mounting" ' mkdir mountdir ipfs ipns && test_config_set Mounts.IPFS "$(pwd)/ipfs" &&