Skip to content

Commit

Permalink
feat(config): add new config for ping_timeout and connect_timeout
Browse files Browse the repository at this point in the history
Signed-off-by: Rory Z <16801068+Rory-Z@users.noreply.github.com>
  • Loading branch information
Rory-Z committed Dec 21, 2024
1 parent 9f8ab82 commit a16ef9a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ type Probe struct {
QoS byte `yaml:"qos,omitempty"`
// KeepAlive is the keep alive period in seconds. Defaults to 30 seconds.
KeepAlive int64 `yaml:"keep_alive,omitempty"`
// PingTimeout is the timeout in seconds for the MQTT ping request. Defaults to 10 seconds.
PingTimeout int64 `yaml:"ping_timeout,omitempty"`
// ConnectTimeout is the timeout in seconds for the MQTT connect request. Defaults to 30 seconds.
ConnectTimeout int64 `yaml:"connect_timeout,omitempty"`
// TLSClientConfig is the TLS configuration to use when probing.
TLSClientConfig *TLSClientConfig `yaml:"tls_config,omitempty"`
}
Expand Down Expand Up @@ -183,6 +187,13 @@ func (sc *SafeConfig) ReloadConfig(confFile string) (err error) {
if probe.KeepAlive == 0 {
probe.KeepAlive = 30
}
if probe.PingTimeout == 0 {
probe.PingTimeout = 10
}
if probe.ConnectTimeout == 0 {
probe.ConnectTimeout = 30
}

c.Probes[index] = probe
}

Expand Down
2 changes: 2 additions & 0 deletions prober/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func newMQTTProbe(probe config.Probe, logger log.Logger) *MQTTProbe {
opt.SetUsername(probe.Username)
opt.SetPassword(probe.Password)
opt.SetKeepAlive(time.Duration(probe.KeepAlive) * time.Second)
opt.SetPingTimeout(time.Duration(probe.PingTimeout) * time.Second)
opt.SetConnectTimeout(time.Duration(probe.ConnectTimeout) * time.Second)
if probe.TLSClientConfig != nil {
opt.SetTLSConfig(probe.TLSClientConfig.ToTLSConfig())
}
Expand Down

0 comments on commit a16ef9a

Please # to comment.