acde3f16d0
Given that every pin and block/put writes something to IPFS and thus increases the repo size, a while ago we added a check to let the IPFS connector directly trigger the sending of metrics every 10 of such requests. This was meant to update the metrics more often so that balancing happened more granularly (particularly the freespace one). In practice, on a cluster that receives several hundreds of pin/adds operations in a few seconds, this is just bad. So: * We disable by default the whole thing. * We add a new InformerTriggerInterval configuration option to enable the thing. * Fix a bug that made this always call the first informer, which may not have been the freespace one).
81 lines
1.4 KiB
Go
81 lines
1.4 KiB
Go
package ipfshttp
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
var cfgJSON = []byte(`
|
|
{
|
|
"node_multiaddress": "/ip4/127.0.0.1/tcp/5001",
|
|
"connect_swarms_delay": "7s",
|
|
"ipfs_request_timeout": "5m0s",
|
|
"pin_timeout": "2m",
|
|
"unpin_timeout": "3h",
|
|
"repogc_timeout": "24h",
|
|
"informer_trigger_interval": 10
|
|
}
|
|
`)
|
|
|
|
func TestLoadJSON(t *testing.T) {
|
|
cfg := &Config{}
|
|
err := cfg.LoadJSON(cfgJSON)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
j := &jsonConfig{}
|
|
json.Unmarshal(cfgJSON, j)
|
|
|
|
if cfg.InformerTriggerInterval != 10 {
|
|
t.Error("missing value")
|
|
}
|
|
|
|
j.NodeMultiaddress = "abc"
|
|
tst, _ := json.Marshal(j)
|
|
err = cfg.LoadJSON(tst)
|
|
if err == nil {
|
|
t.Error("expected error in node_multiaddress")
|
|
}
|
|
}
|
|
|
|
func TestToJSON(t *testing.T) {
|
|
cfg := &Config{}
|
|
cfg.LoadJSON(cfgJSON)
|
|
newjson, err := cfg.ToJSON()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cfg = &Config{}
|
|
err = cfg.LoadJSON(newjson)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestDefault(t *testing.T) {
|
|
cfg := &Config{}
|
|
cfg.Default()
|
|
if cfg.Validate() != nil {
|
|
t.Fatal("error validating")
|
|
}
|
|
|
|
cfg.NodeAddr = nil
|
|
if cfg.Validate() == nil {
|
|
t.Fatal("expected error validating")
|
|
}
|
|
}
|
|
|
|
func TestApplyEnvVar(t *testing.T) {
|
|
os.Setenv("CLUSTER_IPFSHTTP_PINTIMEOUT", "22m")
|
|
cfg := &Config{}
|
|
cfg.Default()
|
|
cfg.ApplyEnvVars()
|
|
|
|
if cfg.PinTimeout != 22*time.Minute {
|
|
t.Fatal("failed to override pin_timeout with env var")
|
|
}
|
|
}
|