-
Notifications
You must be signed in to change notification settings - Fork 13
/
statusconfig.go
85 lines (72 loc) · 2.8 KB
/
statusconfig.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package config
import (
"time"
"github.com/Axway/agent-sdk/pkg/cmd/properties"
)
// StatusConfig - Interface for status config
type StatusConfig interface {
GetPort() int
GetHealthCheckPeriod() time.Duration
GetHealthCheckInterval() time.Duration
ValidateCfg() error
}
// StatusConfiguration -
type StatusConfiguration struct {
StatusConfig
Port int `config:"port"`
HealthCheckPeriod time.Duration `config:"healthCheckPeriod"`
HealthCheckInterval time.Duration `config:"healthCheckInterval"` // this for binary agents only
}
// NewStatusConfig - create a new status config
func NewStatusConfig() StatusConfig {
return &StatusConfiguration{
Port: 8989,
HealthCheckPeriod: 3 * time.Minute,
HealthCheckInterval: 30 * time.Second,
}
}
// GetPort - Returns the status port
func (a *StatusConfiguration) GetPort() int {
return a.Port
}
// GetHealthCheckPeriod - Returns the timeout before exiting discovery agent
func (a *StatusConfiguration) GetHealthCheckPeriod() time.Duration {
return a.HealthCheckPeriod
}
// GetHealthCheckInterval - Returns the interval between running periodic health checks (binary agents only)
func (a *StatusConfiguration) GetHealthCheckInterval() time.Duration {
return a.HealthCheckInterval
}
const (
pathPort = "status.port"
pathHealthcheckPeriod = "status.healthCheckPeriod"
pathHealthcheckInterval = "status.healthCheckInterval"
)
// AddStatusConfigProperties - Adds the command properties needed for Status Config
func AddStatusConfigProperties(props properties.Properties) {
props.AddIntProperty(pathPort, 8989, "The port that will serve the status endpoints")
props.AddDurationProperty(pathHealthcheckPeriod, 3*time.Minute, "Time in minutes allotted for services to be ready before exiting discovery agent")
props.AddDurationProperty(pathHealthcheckInterval, 30*time.Second, "Time between running periodic health checker. Can be between 30 seconds and 5 minutes (binary agents only)")
props.AddBoolFlag("status", "Get the status of all the Health Checks")
}
// ParseStatusConfig - Parses the Status Config values form teh command line
func ParseStatusConfig(props properties.Properties) (StatusConfig, error) {
cfg := &StatusConfiguration{
Port: props.IntPropertyValue(pathPort),
HealthCheckPeriod: props.DurationPropertyValue(pathHealthcheckPeriod),
HealthCheckInterval: props.DurationPropertyValue(pathHealthcheckInterval),
}
return cfg, nil
}
// ValidateCfg - Validates the config, implementing IConfigInterface
func (a *StatusConfiguration) ValidateCfg() error {
mins := a.GetHealthCheckPeriod().Minutes()
if mins < 1 || mins > 5 {
return ErrStatusHealthCheckPeriod
}
secs := a.GetHealthCheckInterval().Seconds()
if secs < 30 || secs > 300 {
return ErrStatusHealthCheckInterval
}
return nil
}