configure logging

This commit is contained in:
Fran Bull committed 2025-02-24 11:41:53 -08:00
1 parent f0223a9dba
commit 0b971dffd3
2 files changed
+23 -10

No files matched your search

+9 -2
View File
@@ -36,6 +36,7 @@ import (
"net/netip"
"time"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/raft"
"tailscale.com/ipn/ipnstate"
"tailscale.com/tsnet"
@@ -223,14 +224,20 @@ func startRaft(ts *tsnet.Server, fsm *raft.FSM, self selfRaftNode, auth *authori
return nil, err
}
transport := raft.NewNetworkTransport(StreamLayer{
logger := hclog.New(&hclog.LoggerOptions{
Name: "raft-net",
Output: cfg.Raft.LogOutput,
Level: hclog.LevelFromString(cfg.Raft.LogLevel),
})
transport := raft.NewNetworkTransportWithLogger(StreamLayer{
s: ts,
Listener: ln,
auth: auth,
},
cfg.MaxConnPool,
cfg.ConnTimeout,
nil) // TODO pass in proper logging
logger)
return raft.NewRaft(config, *fsm, logStore, stableStore, snapshots, transport)
}
+14 -8
View File
@@ -182,6 +182,12 @@ func tagNodes(t *testing.T, control *testcontrol.Server, nodeKeys []key.NodePubl
}
}
func warnLogConfig() Config {
c := DefaultConfig()
c.Raft.LogLevel = "WARN"
return c
}
func TestStart(t *testing.T) {
nettest.SkipIfNoNetwork(t)
control, controlURL := startControl(t)
@@ -195,7 +201,7 @@ func TestStart(t *testing.T) {
waitForNodesToBeTaggedInStatus(t, ctx, one, []key.NodePublic{k}, clusterTag)
sm := &fsm{}
r, err := Start(ctx, one, (*fsm)(sm), clusterTag, DefaultConfig())
r, err := Start(ctx, one, (*fsm)(sm), clusterTag, warnLogConfig())
if err != nil {
t.Fatal(err)
}
@@ -303,7 +309,7 @@ func TestApply(t *testing.T) {
defer cancel()
clusterTag := "tag:whatever"
ps, _, _ := startNodesAndWaitForPeerStatus(t, ctx, clusterTag, 2)
cfg := DefaultConfig()
cfg := warnLogConfig()
createConsensusCluster(t, ctx, clusterTag, ps, cfg)
fut := ps[0].c.raft.Apply([]byte("woo"), 2*time.Second)
@@ -353,7 +359,7 @@ func TestConfig(t *testing.T) {
defer cancel()
clusterTag := "tag:whatever"
ps, _, _ := startNodesAndWaitForPeerStatus(t, ctx, clusterTag, 3)
cfg := DefaultConfig()
cfg := warnLogConfig()
// test all is well with non default ports
cfg.CommandPort = 12347
cfg.RaftPort = 11882
@@ -389,7 +395,7 @@ func TestFollowerFailover(t *testing.T) {
defer cancel()
clusterTag := "tag:whatever"
ps, _, _ := startNodesAndWaitForPeerStatus(t, ctx, clusterTag, 3)
cfg := DefaultConfig()
cfg := warnLogConfig()
createConsensusCluster(t, ctx, clusterTag, ps, cfg)
smThree := ps[2].sm
@@ -431,7 +437,7 @@ func TestFollowerFailover(t *testing.T) {
// follower comes back
smThreeAgain := &fsm{}
rThreeAgain, err := Start(ctx, ps[2].ts, (*fsm)(smThreeAgain), clusterTag, DefaultConfig())
rThreeAgain, err := Start(ctx, ps[2].ts, (*fsm)(smThreeAgain), clusterTag, warnLogConfig())
if err != nil {
t.Fatal(err)
}
@@ -451,7 +457,7 @@ func TestRejoin(t *testing.T) {
defer cancel()
clusterTag := "tag:whatever"
ps, control, controlURL := startNodesAndWaitForPeerStatus(t, ctx, clusterTag, 3)
cfg := DefaultConfig()
cfg := warnLogConfig()
createConsensusCluster(t, ctx, clusterTag, ps, cfg)
for _, p := range ps {
defer p.c.Stop(ctx)
@@ -487,7 +493,7 @@ func TestOnlyTaggedPeersCanDialRaftPort(t *testing.T) {
defer cancel()
clusterTag := "tag:whatever"
ps, control, controlURL := startNodesAndWaitForPeerStatus(t, ctx, clusterTag, 3)
cfg := DefaultConfig()
cfg := warnLogConfig()
createConsensusCluster(t, ctx, clusterTag, ps, cfg)
for _, p := range ps {
defer p.c.Stop(ctx)
@@ -617,7 +623,7 @@ func TestOnlyTaggedPeersCanJoin(t *testing.T) {
defer cancel()
clusterTag := "tag:whatever"
ps, _, controlURL := startNodesAndWaitForPeerStatus(t, ctx, clusterTag, 3)
cfg := DefaultConfig()
cfg := warnLogConfig()
createConsensusCluster(t, ctx, clusterTag, ps, cfg)
for _, p := range ps {
defer p.c.Stop(ctx)