Do not interrupt querying readiness probes for plugins (#6975)

* Do not interrupt querying readiness probes for plugins

Signed-off-by: Gleb Kogtev <gleb.kogtev@gmail.com>

* Add monitor param for ready plugin

Signed-off-by: Gleb Kogtev <gleb.kogtev@gmail.com>

* Update ready docs

Signed-off-by: Gleb Kogtev <gleb.kogtev@gmail.com>

* Update ready docs

Signed-off-by: Gleb Kogtev <gleb.kogtev@gmail.com>

---------

Signed-off-by: Gleb Kogtev <gleb.kogtev@gmail.com>
This commit is contained in:
Gleb Kogtev
2025-04-08 16:46:30 +03:00
committed by GitHub
parent ebd1e41976
commit 52b3172b2e
6 changed files with 206 additions and 27 deletions

View File

@@ -11,10 +11,17 @@ import (
func init() { plugin.Register("ready", setup) }
func setup(c *caddy.Controller) error {
addr, err := parse(c)
addr, monType, err := parse(c)
if err != nil {
return plugin.Error("ready", err)
}
if monType == monitorTypeContinuously {
plugins.keepReadiness = true
} else {
plugins.keepReadiness = false
}
rd := &ready{Addr: addr}
uniqAddr.Set(addr, rd.onStartup)
@@ -48,12 +55,25 @@ func setup(c *caddy.Controller) error {
return nil
}
func parse(c *caddy.Controller) (string, error) {
// monitorType represents the type of monitoring behavior for the readiness plugin.
type monitorType string
const (
// monitorTypeUntilReady indicates the monitoring should continue until the system is ready.
monitorTypeUntilReady monitorType = "until-ready"
// monitorTypeContinuously indicates the monitoring should continue indefinitely.
monitorTypeContinuously monitorType = "continuously"
)
func parse(c *caddy.Controller) (string, monitorType, error) {
addr := ":8181"
monType := monitorTypeUntilReady
i := 0
for c.Next() {
if i > 0 {
return "", plugin.ErrOnce
return "", "", plugin.ErrOnce
}
i++
args := c.RemainingArgs()
@@ -63,11 +83,38 @@ func parse(c *caddy.Controller) (string, error) {
case 1:
addr = args[0]
if _, _, e := net.SplitHostPort(addr); e != nil {
return "", e
return "", "", e
}
default:
return "", c.ArgErr()
return "", "", c.ArgErr()
}
for c.NextBlock() {
switch c.Val() {
case "monitor":
args := c.RemainingArgs()
if len(args) != 1 {
return "", "", c.ArgErr()
}
var err error
monType, err = parseMonitorType(c, args[0])
if err != nil {
return "", "", err
}
}
}
}
return addr, nil
return addr, monType, nil
}
func parseMonitorType(c *caddy.Controller, arg string) (monitorType, error) {
switch arg {
case "until-ready":
return monitorTypeUntilReady, nil
case "continuously":
return monitorTypeContinuously, nil
default:
return "", c.Errf("monitor type '%s' not supported", arg)
}
}