Skip to content

Commit 15f723a

Browse files
hsanjuanlidel
andauthored
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 <[email protected]>
1 parent ae068a8 commit 15f723a

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

config/plugins.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ type Plugins struct {
77

88
type Plugin struct {
99
Disabled bool
10-
Config interface{}
10+
Config interface{} `json:",omitempty"`
1111
}

test/cli/harness/node.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,14 @@ func (n *Node) Init(ipfsArgs ...string) *Node {
245245
cfg.Swarm.DisableNatPortMap = true
246246
cfg.Discovery.MDNS.Enabled = n.EnableMDNS
247247
cfg.Routing.LoopbackAddressesOnLanDHT = config.True
248+
// Telemetry disabled by default in tests.
249+
cfg.Plugins = config.Plugins{
250+
Plugins: map[string]config.Plugin{
251+
"telemetry": config.Plugin{
252+
Disabled: true,
253+
},
254+
},
255+
}
248256
})
249257
return n
250258
}

test/cli/telemetry_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func TestTelemetry(t *testing.T) {
2525

2626
// Create a new node
2727
node := harness.NewT(t).NewNode().Init()
28+
node.SetIPFSConfig("Plugins.Plugins.telemetry.Disabled", false)
2829

2930
// Set the opt-out environment variable
3031
node.Runner.Env["IPFS_TELEMETRY"] = "off"
@@ -64,6 +65,7 @@ func TestTelemetry(t *testing.T) {
6465

6566
// Create a new node
6667
node := harness.NewT(t).NewNode().Init()
68+
node.SetIPFSConfig("Plugins.Plugins.telemetry.Disabled", false)
6769

6870
// Set opt-out via config
6971
node.IPFS("config", "Plugins.Plugins.telemetry.Config.Mode", "off")
@@ -106,6 +108,7 @@ func TestTelemetry(t *testing.T) {
106108

107109
// Create a new node
108110
node := harness.NewT(t).NewNode().Init()
111+
node.SetIPFSConfig("Plugins.Plugins.telemetry.Disabled", false)
109112

110113
// Create a UUID file manually to simulate previous telemetry run
111114
uuidPath := filepath.Join(node.Dir, "telemetry_uuid")
@@ -154,6 +157,7 @@ func TestTelemetry(t *testing.T) {
154157

155158
// Create a new node
156159
node := harness.NewT(t).NewNode().Init()
160+
node.SetIPFSConfig("Plugins.Plugins.telemetry.Disabled", false)
157161

158162
// Capture daemon output
159163
stdout := &harness.Buffer{}
@@ -255,6 +259,7 @@ func TestTelemetry(t *testing.T) {
255259

256260
// Create a new node
257261
node := harness.NewT(t).NewNode().Init()
262+
node.SetIPFSConfig("Plugins.Plugins.telemetry.Disabled", false)
258263

259264
// Configure telemetry with a very short delay for testing
260265
node.IPFS("config", "Plugins.Plugins.telemetry.Config.Delay", "100ms")

test/sharness/lib/test-lib.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ test_init_ipfs() {
205205
ipfs init "${args[@]}" --profile=test > /dev/null
206206
'
207207

208+
test_expect_success "disable telemetry" '
209+
test_config_set --bool Plugins.Plugins.telemetry.Disabled "true"
210+
'
211+
208212
test_expect_success "prepare config -- mounting" '
209213
mkdir mountdir ipfs ipns mfs &&
210214
test_config_set Mounts.IPFS "$(pwd)/ipfs" &&
@@ -227,6 +231,10 @@ test_init_ipfs_measure() {
227231
ipfs init "${args[@]}" --profile=test,flatfs-measure > /dev/null
228232
'
229233

234+
test_expect_success "disable telemetry" '
235+
test_config_set --bool Plugins.Plugins.telemetry.Disabled "true"
236+
'
237+
230238
test_expect_success "prepare config -- mounting" '
231239
mkdir mountdir ipfs ipns &&
232240
test_config_set Mounts.IPFS "$(pwd)/ipfs" &&

0 commit comments

Comments
 (0)