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 <lidel@lidel.org>
(cherry picked from commit 15f723a15e)
This commit is contained in:
Hector Sanjuan 2025-08-24 14:30:35 +02:00 committed by Marcin Rataj
parent fae08d6633
commit 46324f085d
4 changed files with 22 additions and 1 deletions

View File

@ -7,5 +7,5 @@ type Plugins struct {
type Plugin struct {
Disabled bool
Config interface{}
Config interface{} `json:",omitempty"`
}

View File

@ -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
}

View File

@ -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")

View File

@ -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" &&