Skip to content

Commit

Permalink
Remove heartbeat service from node (filecoin-project#4163)
Browse files Browse the repository at this point in the history
* Remove heartbeat service from node

* Tests passing

Co-authored-by: ZenGround0 <[email protected]>
  • Loading branch information
ZenGround0 and ZenGround0 authored May 28, 2020
1 parent efe9c3c commit 46ed000
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 122 deletions.
47 changes: 0 additions & 47 deletions cmd/go-filecoin/inspector_integration_test.go

This file was deleted.

1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ github.com/filecoin-project/sector-storage v0.0.0-20200508203401-a74812ba12f3/go
github.com/filecoin-project/specs-actors v0.0.0-20200210130641-2d1fbd8672cf/go.mod h1:xtDZUB6pe4Pksa/bAJbJ693OilaC5Wbot9jMhLm3cZA=
github.com/filecoin-project/specs-actors v0.0.0-20200409043918-e569f4a2f504/go.mod h1:mdJraXq5vMy0+/FqVQIrnNlpQ/Em6zeu06G/ltQ0/lA=
github.com/filecoin-project/specs-actors v0.3.0/go.mod h1:nQYnFbQ7Y0bHZyq6HDEuVlCPR+U3z5Q3wMOQ+2aiV+Y=
github.com/filecoin-project/specs-actors v0.4.1-0.20200509020627-3c96f54f3d7d/go.mod h1:UW3ft23q6VS8wQoNqLWjENsu9gu1uh6lxOd+H8cwhT8=
github.com/filecoin-project/specs-actors v0.5.2/go.mod h1:r5btrNzZD0oBkEz1pohv80gSCXQnqGrD0kYwOTiExyE=
github.com/filecoin-project/specs-actors v0.5.3 h1:fdq8Gx0izhnUKl6sYEtI4SUEjT2U6W2w06HeqLz5vmw=
github.com/filecoin-project/specs-actors v0.5.3/go.mod h1:r5btrNzZD0oBkEz1pohv80gSCXQnqGrD0kYwOTiExyE=
Expand Down
38 changes: 0 additions & 38 deletions internal/app/go-filecoin/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package node
import (
"context"
"fmt"
"os"
"reflect"
"runtime"

Expand All @@ -23,7 +22,6 @@ import (
"github.com/filecoin-project/go-filecoin/internal/pkg/cborutil"
"github.com/filecoin-project/go-filecoin/internal/pkg/chain"
"github.com/filecoin-project/go-filecoin/internal/pkg/clock"
"github.com/filecoin-project/go-filecoin/internal/pkg/config"
"github.com/filecoin-project/go-filecoin/internal/pkg/consensus"
"github.com/filecoin-project/go-filecoin/internal/pkg/message"
"github.com/filecoin-project/go-filecoin/internal/pkg/metrics"
Expand Down Expand Up @@ -156,10 +154,6 @@ func (node *Node) Start(ctx context.Context) error {
return err
}

if err := node.setupHeartbeatServices(ctx); err != nil {
return errors.Wrap(err, "failed to start heartbeat services")
}

// Start node discovery
if err := node.Discovery.Start(node); err != nil {
return err
Expand All @@ -186,38 +180,6 @@ func (node *Node) pubsubscribe(ctx context.Context, topic *pubsub.Topic, handler
return sub, nil
}

func (node *Node) setupHeartbeatServices(ctx context.Context) error {
mag := func() address.Address {
addr, err := node.MiningAddress()
// the only error MiningAddress() returns is ErrNoMinerAddress.
// if there is no configured miner address, simply send a zero
// address across the wire.
if err != nil {
return address.Undef
}
return addr
}

// start the primary heartbeat service
if len(node.Repo.Config().Heartbeat.BeatTarget) > 0 {
hbs := metrics.NewHeartbeatService(node.Host(), node.chain.ChainReader.GenesisCid(), node.Repo.Config().Heartbeat, node.PorcelainAPI.ChainHead, metrics.WithMinerAddressGetter(mag))
go hbs.Start(ctx)
}

// check if we want to connect to an alert service. An alerting service is a heartbeat
// service that can trigger alerts based on the contents of heatbeats.
if alertTarget := os.Getenv("FIL_HEARTBEAT_ALERTS"); len(alertTarget) > 0 {
ahbs := metrics.NewHeartbeatService(node.Host(), node.chain.ChainReader.GenesisCid(), &config.HeartbeatConfig{
BeatTarget: alertTarget,
BeatPeriod: "10s",
ReconnectPeriod: "10s",
Nickname: node.Repo.Config().Heartbeat.Nickname,
}, node.PorcelainAPI.ChainHead, metrics.WithMinerAddressGetter(mag))
go ahbs.Start(ctx)
}
return nil
}

func (node *Node) setIsMining(isMining bool) {
node.BlockMining.Mining.Lock()
defer node.BlockMining.Mining.Unlock()
Expand Down
12 changes: 0 additions & 12 deletions internal/app/go-filecoin/plumbing/cfg/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ func TestConfigSet(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, testSwarmAddr, cfg.Swarm.Address)

err = cfgAPI.Set("heartbeat.nickname", "Nickleless")
require.NoError(t, err)
assert.Equal(t, "Nickleless", cfg.Heartbeat.Nickname)

err = cfgAPI.Set("datastore.path", "/dev/null")
require.NoError(t, err)
assert.Equal(t, "/dev/null", cfg.Datastore.Path)
Expand Down Expand Up @@ -122,12 +118,4 @@ func TestConfigSet(t *testing.T) {
assert.EqualError(t, err, address.ErrUnknownProtocol.Error())
})

t.Run("validates the node nickname", func(t *testing.T) {
repo := repo.NewInMemoryRepo()
cfgAPI := NewConfig(repo)

err := cfgAPI.Set("heartbeat.nickname", "Bad Nickname")

assert.EqualError(t, err, `"heartbeat.nickname" must only contain letters`)
})
}
11 changes: 0 additions & 11 deletions internal/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type Config struct {
Bootstrap *BootstrapConfig `json:"bootstrap"`
Datastore *DatastoreConfig `json:"datastore"`
Drand *DrandConfig `json:"drand"`
Heartbeat *HeartbeatConfig `json:"heartbeat"`
Mining *MiningConfig `json:"mining"`
Mpool *MessagePoolConfig `json:"mpool"`
NetworkParams *NetworkParamsConfig `json:"parameters"`
Expand Down Expand Up @@ -172,15 +171,6 @@ type HeartbeatConfig struct {
Nickname string `json:"nickname"`
}

func newDefaultHeartbeatConfig() *HeartbeatConfig {
return &HeartbeatConfig{
BeatTarget: "",
BeatPeriod: "3s",
ReconnectPeriod: "10s",
Nickname: "",
}
}

// ObservabilityConfig is a container for configuration related to observables.
type ObservabilityConfig struct {
Metrics *MetricsConfig `json:"metrics"`
Expand Down Expand Up @@ -291,7 +281,6 @@ func NewDefaultConfig() *Config {
Bootstrap: newDefaultBootstrapConfig(),
Datastore: newDefaultDatastoreConfig(),
Drand: newDefaultDrandConfig(),
Heartbeat: newDefaultHeartbeatConfig(),
Mining: newDefaultMiningConfig(),
Mpool: newDefaultMessagePoolConfig(),
NetworkParams: newDefaultNetworkParamsConfig(),
Expand Down
14 changes: 0 additions & 14 deletions internal/pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,6 @@ func TestWriteFile(t *testing.T) {
assert.NoError(t, os.Remove(filepath.Join(dir, "config.json")))
}

func TestSetRejectsInvalidNicks(t *testing.T) {
tf.UnitTest(t)

cfg := NewDefaultConfig()

// sic: json includes the quotes in the value
err := cfg.Set("heartbeat.nickname", "\"goodnick\"")
assert.NoError(t, err)
err = cfg.Set("heartbeat.nickname", "bad nick<p>")
assert.Error(t, err)
err = cfg.Set("heartbeat", `{"heartbeat": "bad nick"}`)
assert.Error(t, err)
}

func TestConfigRoundtrip(t *testing.T) {
tf.UnitTest(t)

Expand Down

0 comments on commit 46ed000

Please sign in to comment.