Skip to content

Commit

Permalink
[NDM][Cisco SD-WAN] Add config for BFD Session metric collection (#25071
Browse files Browse the repository at this point in the history
)

* Add config for BFD Session metric collection

* Add test
  • Loading branch information
TCheruy authored and alexgallotta committed May 9, 2024
1 parent 143963c commit e9acd8d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pkg/collector/corechecks/network-devices/cisco-sdwan/sdwan.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type checkCfg struct {
CAFile string `yaml:"ca_file"`
SendNDMMetadata *bool `yaml:"send_ndm_metadata"`
MinCollectionInterval int `yaml:"min_collection_interval"`
CollectBFDSessionStatus bool `yaml:"collect_bfd_session_status"`
}

// CiscoSdwanCheck contains the field for the CiscoSdwanCheck
Expand Down Expand Up @@ -99,10 +100,6 @@ func (c *CiscoSdwanCheck) Run() error {
if err != nil {
log.Warnf("Error getting OMP peer states from Cisco SD-WAN API: %s", err)
}
bfdSessionsState, err := client.GetBFDSessionsState()
if err != nil {
log.Warnf("Error getting BFD session states from Cisco SD-WAN API: %s", err)
}
deviceCounters, err := client.GetDevicesCounters()
if err != nil {
log.Warnf("Error getting device counters from Cisco SD-WAN API: %s", err)
Expand All @@ -128,10 +125,18 @@ func (c *CiscoSdwanCheck) Run() error {
c.metricsSender.SendAppRouteMetrics(appRouteStats)
c.metricsSender.SendControlConnectionMetrics(controlConnectionsState)
c.metricsSender.SendOMPPeerMetrics(ompPeersState)
c.metricsSender.SendBFDSessionMetrics(bfdSessionsState)
c.metricsSender.SendDeviceCountersMetrics(deviceCounters)
c.metricsSender.SendDeviceStatusMetrics(deviceStatus)

// Configurable metrics
if c.config.CollectBFDSessionStatus {
bfdSessionsState, err := client.GetBFDSessionsState()
if err != nil {
log.Warnf("Error getting BFD session states from Cisco SD-WAN API: %s", err)
}
c.metricsSender.SendBFDSessionMetrics(bfdSessionsState)
}

// Commit
c.metricsSender.Commit()

Expand Down
42 changes: 42 additions & 0 deletions pkg/collector/corechecks/network-devices/cisco-sdwan/sdwan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ password: 'test-password'
use_http: true
namespace: test
min_collection_interval: 180
collect_bfd_session_status: true
`)

// Use ID to ensure the mock sender gets registered
Expand Down Expand Up @@ -217,5 +218,46 @@ min_collection_interval: 180
assert.NoError(t, err)

sender.AssertEventPlatformEvent(t, compactEvent.Bytes(), "network-devices-metadata")
}

func TestBFDMetricConfig(t *testing.T) {
payload.TimeNow = mockTimeNow
report.TimeNow = mockTimeNow

apiMockServer := client.SetupMockAPIServer()
defer apiMockServer.Close()

deps := createDeps(t)
chk := newCheck()
senderManager := deps.Demultiplexer

url := strings.TrimPrefix(apiMockServer.URL, "http://")

// language=yaml
rawInstanceConfig := []byte(`
vmanage_endpoint: ` + url + `
username: admin
password: 'test-password'
use_http: true
namespace: test
`)

// Use ID to ensure the mock sender gets registered
id := checkid.BuildID(CheckName, integration.FakeConfigHash, rawInstanceConfig, []byte(``))
sender := mocksender.NewMockSenderWithSenderManager(id, senderManager)
sender.On("Gauge", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return()
sender.On("MonotonicCount", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return()
sender.On("GaugeWithTimestamp", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return()
sender.On("CountWithTimestamp", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return()
sender.On("EventPlatformEvent", mock.Anything, mock.Anything).Return()

sender.On("Commit").Return()

err := chk.Configure(senderManager, integration.FakeConfigHash, rawInstanceConfig, []byte(``), "test")
require.NoError(t, err)

err = chk.Run()
require.NoError(t, err)

sender.AssertNotCalled(t, "Gauge", "cisco_sdwan.bfd_session.status", mock.Anything, mock.Anything, mock.Anything)
}

0 comments on commit e9acd8d

Please sign in to comment.