Add GoVPP integration and GetVPPInfo gRPC call
VPP client (internal/vpp/) - New package managing connections to both VPP API and stats sockets, treated as a unit: if either drops, both are torn down and re-established together. - Run() loop: connect, fetch version via vpe.ShowVersion, read /sys/boottime from the stats segment, log vpp-connect, then monitor with control_ping every 10s. On failure, disconnect both, retry after 5s. - Registers as client name "vpp-maglev" (visible in VPP's "show api clients"). - Flags: --vpp-api-addr (default /run/vpp/api.sock) and --vpp-stats-addr (default /run/vpp/stats.sock). Empty api addr disables VPP integration entirely. gRPC / proto - Add GetVPPInfo RPC returning VPPInfo: version, build_date, build_directory, pid, boottime_ns, connecttime_ns. Both times are unix timestamps in nanoseconds — the client computes durations locally for display. - Returns codes.Unavailable if VPP is disabled or not connected. maglevc - Add 'show vpp info' command displaying version, build-date, build-dir, vpp-pid, vpp-boottime (with duration), and connected time (with duration).
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"git.ipng.ch/ipng/vpp-maglev/internal/config"
|
||||
"git.ipng.ch/ipng/vpp-maglev/internal/grpcapi"
|
||||
"git.ipng.ch/ipng/vpp-maglev/internal/metrics"
|
||||
"git.ipng.ch/ipng/vpp-maglev/internal/vpp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -40,6 +41,8 @@ func run() error {
|
||||
configPath := stringFlag("config", "/etc/vpp-maglev/maglev.yaml", "MAGLEV_CONFIG", "path to maglev.yaml")
|
||||
grpcAddr := stringFlag("grpc-addr", ":9090", "MAGLEV_GRPC_ADDR", "gRPC listen address")
|
||||
metricsAddr := stringFlag("metrics-addr", ":9091", "MAGLEV_METRICS_ADDR", "Prometheus /metrics listen address (empty to disable)")
|
||||
vppAPIAddr := stringFlag("vpp-api-addr", "/run/vpp/api.sock", "MAGLEV_VPP_API_ADDR", "VPP binary API socket path (empty to disable)")
|
||||
vppStatsAddr := stringFlag("vpp-stats-addr", "/run/vpp/stats.sock", "MAGLEV_VPP_STATS_ADDR", "VPP stats socket path")
|
||||
logLevel := stringFlag("log-level", "info", "MAGLEV_LOG_LEVEL", "log level (debug|info|warn|error)")
|
||||
flag.Parse()
|
||||
|
||||
@@ -92,13 +95,20 @@ func run() error {
|
||||
}
|
||||
}()
|
||||
|
||||
// ---- VPP connection -----------------------------------------------------
|
||||
var vppClient *vpp.Client
|
||||
if *vppAPIAddr != "" {
|
||||
vppClient = vpp.New(*vppAPIAddr, *vppStatsAddr)
|
||||
go vppClient.Run(ctx)
|
||||
}
|
||||
|
||||
// ---- gRPC server --------------------------------------------------------
|
||||
lis, err := net.Listen("tcp", *grpcAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("listen %s: %w", *grpcAddr, err)
|
||||
}
|
||||
srv := grpc.NewServer()
|
||||
maglevServer := grpcapi.NewServer(ctx, chkr, logBroadcaster, *configPath)
|
||||
maglevServer := grpcapi.NewServer(ctx, chkr, logBroadcaster, *configPath, vppClient)
|
||||
grpcapi.RegisterMaglevServer(srv, maglevServer)
|
||||
if *enableReflection {
|
||||
reflection.Register(srv)
|
||||
|
||||
Reference in New Issue
Block a user