• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 14358372723

09 Apr 2025 01:26PM UTC coverage: 56.696% (-12.3%) from 69.037%
14358372723

Pull #9696

github

web-flow
Merge e2837e400 into 867d27d68
Pull Request #9696: Add `development_guidelines.md` for both human and machine

107055 of 188823 relevant lines covered (56.7%)

22721.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lncfg/healthcheck.go
1
package lncfg
2

3
import (
4
        "errors"
5
        "fmt"
6
        "time"
7
)
8

9
var (
10
        // MinHealthCheckInterval is the minimum interval we allow between
11
        // health checks.
12
        MinHealthCheckInterval = time.Minute
13

14
        // MinHealthCheckTimeout is the minimum timeout we allow for health
15
        // check calls.
16
        MinHealthCheckTimeout = time.Second
17

18
        // MinHealthCheckBackoff is the minimum back off we allow between health
19
        // check retries.
20
        MinHealthCheckBackoff = time.Second
21
)
22

23
// HealthCheckConfig contains the configuration for the different health checks
24
// the lnd runs.
25
//
26
//nolint:ll
27
type HealthCheckConfig struct {
28
        ChainCheck *CheckConfig `group:"chainbackend" namespace:"chainbackend"`
29

30
        DiskCheck *DiskCheckConfig `group:"diskspace" namespace:"diskspace"`
31

32
        TLSCheck *CheckConfig `group:"tls" namespace:"tls"`
33

34
        TorConnection *CheckConfig `group:"torconnection" namespace:"torconnection"`
35

36
        RemoteSigner *CheckConfig `group:"remotesigner" namespace:"remotesigner"`
37

38
        LeaderCheck *CheckConfig `group:"leader" namespace:"leader"`
39
}
40

41
// Validate checks the values configured for our health checks.
42
func (h *HealthCheckConfig) Validate() error {
×
43
        if err := h.ChainCheck.validate("chain backend"); err != nil {
×
44
                return err
×
45
        }
×
46

47
        if err := h.DiskCheck.validate("disk space"); err != nil {
×
48
                return err
×
49
        }
×
50

51
        if err := h.TLSCheck.validate("tls"); err != nil {
×
52
                return err
×
53
        }
×
54

55
        if h.DiskCheck.RequiredRemaining < 0 ||
×
56
                h.DiskCheck.RequiredRemaining >= 1 {
×
57

×
58
                return errors.New("disk required ratio must be in [0:1)")
×
59
        }
×
60

61
        if err := h.TorConnection.validate("tor connection"); err != nil {
×
62
                return err
×
63
        }
×
64

65
        return nil
×
66
}
67

68
type CheckConfig struct {
69
        Interval time.Duration `long:"interval" description:"How often to run a health check."`
70

71
        Attempts int `long:"attempts" description:"The number of calls we will make for the check before failing. Set this value to 0 to disable a check."`
72

73
        Timeout time.Duration `long:"timeout" description:"The amount of time we allow the health check to take before failing due to timeout."`
74

75
        Backoff time.Duration `long:"backoff" description:"The amount of time to back-off between failed health checks."`
76
}
77

78
// validate checks the values in a health check config entry if it is enabled.
79
func (c *CheckConfig) validate(name string) error {
×
80
        if c.Attempts == 0 {
×
81
                return nil
×
82
        }
×
83

84
        if c.Backoff < MinHealthCheckBackoff {
×
85
                return fmt.Errorf("%v backoff: %v below minimum: %v", name,
×
86
                        c.Backoff, MinHealthCheckBackoff)
×
87
        }
×
88

89
        if c.Timeout < MinHealthCheckTimeout {
×
90
                return fmt.Errorf("%v timeout: %v below minimum: %v", name,
×
91
                        c.Timeout, MinHealthCheckTimeout)
×
92
        }
×
93

94
        if c.Interval < MinHealthCheckInterval {
×
95
                return fmt.Errorf("%v interval: %v below minimum: %v", name,
×
96
                        c.Interval, MinHealthCheckInterval)
×
97
        }
×
98

99
        return nil
×
100
}
101

102
// DiskCheckConfig contains configuration for ensuring that our node has
103
// sufficient disk space.
104
type DiskCheckConfig struct {
105
        RequiredRemaining float64 `long:"diskrequired" description:"The minimum ratio of free disk space to total capacity that we allow before shutting lnd down safely."`
106

107
        *CheckConfig
108
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc