Skip to content

Commit

Permalink
Permit agent to run even when VPP stats are unavailable (#1712)
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrej-fabry committed Aug 27, 2020
1 parent 7707f36 commit 8d5e501
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
5 changes: 3 additions & 2 deletions plugins/govppmux/plugin_impl_govppmux.go
Expand Up @@ -173,9 +173,10 @@ func (p *Plugin) Init() (err error) {
}
err := p.startProxy(NewVppAdapter(address, useShm), NewStatsAdapter(statsSocket))
if err != nil {
return err
p.Log.Warnf("VPP proxy failed to start: %v", err)
} else {
p.Log.Infof("VPP proxy ready")
}
p.Log.Infof("VPP proxy ready")
}

// register REST API handlers
Expand Down
3 changes: 3 additions & 0 deletions plugins/telemetry/stats_poller.go
Expand Up @@ -31,6 +31,9 @@ func (s *statsPollerServer) PollStats(req *configurator.PollStatsRequest, svr co
if req.GetPeriodSec() == 0 && req.GetNumPolls() > 1 {
return status.Error(codes.InvalidArgument, "period must be > 0 if number of polls is > 1")
}
if s.handler == nil {
return status.Errorf(codes.Unavailable, "VPP telemetry handler not available")
}

ctx := svr.Context()

Expand Down
7 changes: 4 additions & 3 deletions plugins/telemetry/telemetry.go
Expand Up @@ -159,10 +159,11 @@ func (p *Plugin) AfterInit() error {
func (p *Plugin) setupStatsPoller() error {
h := vppcalls.CompatibleTelemetryHandler(p.VPP)
if h == nil {
return fmt.Errorf("VPP telemetry handler unavailable")
p.Log.Warnf("VPP telemetry handler unavailable")
} else {
p.statsPollerServer.handler = h
}
p.statsPollerServer.handler = h
p.ifIndex = p.IfPlugin.GetInterfaceIndex()
p.statsPollerServer.ifIndex = p.IfPlugin.GetInterfaceIndex()

if p.GRPC != nil && p.GRPC.GetServer() != nil {
configurator.RegisterStatsPollerServiceServer(p.GRPC.GetServer(), &p.statsPollerServer)
Expand Down
12 changes: 9 additions & 3 deletions plugins/vpp/ifplugin/interface_state.go
Expand Up @@ -210,7 +210,13 @@ func (c *InterfaceStateUpdater) startReadingCounters(ctx context.Context) {
for {
select {
case <-tick.C:
c.doInterfaceStatsRead()
statsClient := c.vppClient.Stats()
if statsClient == nil {
c.log.Warnf("VPP stats client not available")
// TODO: use retry with backoff instead of returning here
return
}
c.doInterfaceStatsRead(statsClient)

case <-ctx.Done():
c.log.Debug("Interface state VPP periodic polling stopped")
Expand Down Expand Up @@ -276,7 +282,7 @@ func (c *InterfaceStateUpdater) doUpdatesIfStateDetails() {
}

// doInterfaceStatsRead dumps statistics using interface filter and processes them
func (c *InterfaceStateUpdater) doInterfaceStatsRead() {
func (c *InterfaceStateUpdater) doInterfaceStatsRead(statsClient govppapi.StatsProvider) {
c.access.Lock()
defer c.access.Unlock()

Expand All @@ -286,7 +292,7 @@ func (c *InterfaceStateUpdater) doInterfaceStatsRead() {
return
}

err := c.vppClient.Stats().GetInterfaceStats(&c.ifStats)
err := statsClient.GetInterfaceStats(&c.ifStats)
if err != nil {
// TODO add some counter to prevent it log forever
c.log.Errorf("failed to read statistics data: %v", err)
Expand Down

0 comments on commit 8d5e501

Please sign in to comment.