Skip to content

Commit c04b1a3

Browse files
committed
Probe OvnClient component liveness via control socket
GetProcessInfo used to read the daemon PID from a .pid file and stat /proc/<pid> to derive its user/group. That only works when the daemon runs in the host PID namespace. In containerized deployments (Kolla, and anywhere else the component runs under a separate PID namespace) the PID file contains the container-namespace PID, so reading /proc/<pid> on the host either returns wrong data (unrelated host process at that numeric ID) or fails outright (no such process). Replace the filesystem dance with a control-socket probe using the same JSON-RPC unix socket the exporter already reaches over (ovnnb_db.ctl, ovnsb_db.ctl, ovn-northd.ctl). A successful "version" command means the daemon is alive; no PID or process metadata is needed. The function now returns a zero-value OvsProcess on success since the numeric PID and host user/group are meaningless in a container; callers should treat a nil error as "reachable". Drop the *-monitoring variants and ovs-vswitchd/ovsdb-server cases; they existed only to walk the parent/daemon tree via /proc, which this approach doesn't support. OvsClient.GetProcessInfo is unchanged since ovs_exporter still needs the /proc-based lookup on hosts that run OVS natively.
1 parent d033504 commit c04b1a3

1 file changed

Lines changed: 12 additions & 37 deletions

File tree

process.go

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -104,52 +104,27 @@ func getProcessInfoFromFile(f string) (OvsProcess, error) {
104104
return info, nil
105105
}
106106

107-
// GetProcessInfo returns information about a service or database process.
107+
// GetProcessInfo probes the liveness of an OVN component by querying its
108+
// control socket. It returns a zero-value OvsProcess on success (the value
109+
// is intentionally empty since PID/user/group read from the host /proc
110+
// namespace is meaningless when the daemon runs inside a container).
111+
// Callers should treat a nil error as "component is reachable".
108112
func (cli *OvnClient) GetProcessInfo(name string) (OvsProcess, error) {
109-
var p OvsProcess
110-
var err error
113+
var ctl string
111114
switch name {
112-
case "ovsdb-server":
113-
p, err = getProcessInfoFromFile(cli.Database.Vswitch.File.Pid.Path)
114115
case "ovsdb-server-southbound":
115-
p, err = getProcessInfoFromFile(cli.Database.Southbound.File.Pid.Path)
116-
case "ovsdb-server-southbound-monitoring":
117-
p, err = getProcessInfo(cli.Database.Southbound.Process.Parent.ID)
116+
ctl = cli.Database.Southbound.Socket.Control
118117
case "ovsdb-server-northbound":
119-
p, err = getProcessInfoFromFile(cli.Database.Northbound.File.Pid.Path)
120-
case "ovsdb-server-northbound-monitoring":
121-
p, err = getProcessInfo(cli.Database.Northbound.Process.Parent.ID)
118+
ctl = cli.Database.Northbound.Socket.Control
122119
case "ovn-northd":
123-
p, err = getProcessInfoFromFile(cli.Service.Northd.File.Pid.Path)
124-
case "ovn-northd-monitoring":
125-
p, err = getProcessInfo(cli.Service.Northd.Process.Parent.ID)
126-
case "ovs-vswitchd":
127-
p, err = getProcessInfoFromFile(cli.Service.Vswitchd.File.Pid.Path)
120+
ctl = cli.Service.Northd.Socket.Control
128121
default:
129122
return OvsProcess{}, fmt.Errorf("The '%s' component is unsupported", name)
130123
}
131-
if err != nil {
132-
return OvsProcess{}, err
124+
if _, err := getVersionViaAppctl(ctl, cli.Timeout); err != nil {
125+
return OvsProcess{}, fmt.Errorf("'%s' is not reachable via %s: %s", name, ctl, err)
133126
}
134-
switch name {
135-
case "ovsdb-server":
136-
cli.Database.Vswitch.Process = p
137-
case "ovsdb-server-southbound":
138-
cli.Database.Southbound.Process = p
139-
case "ovsdb-server-southbound-monitoring":
140-
cli.Database.Southbound.Process.Parent.ID = p.ID
141-
case "ovsdb-server-northbound":
142-
cli.Database.Northbound.Process = p
143-
case "ovsdb-server-northbound-monitoring":
144-
cli.Database.Northbound.Process.Parent.ID = p.ID
145-
case "ovn-northd":
146-
cli.Service.Northd.Process = p
147-
case "ovn-northd-monitoring":
148-
cli.Service.Northd.Process.Parent.ID = p.ID
149-
case "ovs-vswitchd":
150-
cli.Service.Vswitchd.Process = p
151-
}
152-
return p, nil
127+
return OvsProcess{}, nil
153128
}
154129

155130
// GetProcessInfo returns information about a service or database process.

0 commit comments

Comments
 (0)