Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions cns/logger/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,31 @@ const (

var codeRegex = regexp.MustCompile(`Code:(\w*)`)

func SendHeartBeat(heartbeatIntervalInMins int, stopheartbeat chan bool) {
heartbeat := time.NewTicker(time.Minute * time.Duration(heartbeatIntervalInMins)).C
metric := aitelemetry.Metric{
Name: HeartBeatMetricStr,
// This signifies 1 heartbeat is sent. Sum of this metric will give us number of heartbeats received
Value: 1.0,
CustomDimensions: make(map[string]string),
}
for {
select {
case <-heartbeat:
SendMetric(metric)
case <-stopheartbeat:
return
}
}
}

// SendCnsTelemetry - handles cns telemetry reports
func SendCnsTelemetry(reports chan interface{}, heartbeatIntervalInMins int, telemetryStopProcessing chan bool) {
func SendToTelemetryService(reports chan interface{}, telemetryStopProcessing chan bool) {

CONNECT:
tb := telemetry.NewTelemetryBuffer("")
tb.ConnectToTelemetryService(telemetryNumRetries, telemetryWaitTimeInMilliseconds)
if tb.Connected {
heartbeat := time.NewTicker(time.Minute * time.Duration(heartbeatIntervalInMins)).C
metric := aitelemetry.Metric{
Name: HeartBeatMetricStr,
// This signifies 1 heartbeat is sent. Sum of this metric will give us number of heartbeats received
Value: 1.0,
CustomDimensions: make(map[string]string),
}

reportMgr := telemetry.ReportManager{
ContentType: telemetry.ContentType,
Expand All @@ -52,8 +63,6 @@ CONNECT:

for {
select {
case <-heartbeat:
SendMetric(metric)
case msg := <-reports:
codeStr := codeRegex.FindString(msg.(string))
if len(codeStr) > errorcodePrefix {
Expand Down
6 changes: 4 additions & 2 deletions cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var version string
// Reports channel
var reports = make(chan interface{})
var telemetryStopProcessing = make(chan bool)
var stopheartbeat = make(chan bool)

// Command line arguments for CNS.
var args = acn.ArgumentList{
Expand Down Expand Up @@ -308,8 +309,8 @@ func main() {
}

if !disableTelemetry {
go logger.SendCnsTelemetry(reports, cnsconfig.TelemetrySettings.HeartBeatIntervalInMins,
telemetryStopProcessing)
go logger.SendToTelemetryService(reports, telemetryStopProcessing)
go logger.SendHeartBeat(cnsconfig.TelemetrySettings.HeartBeatIntervalInMins, stopheartbeat)
}

var netPlugin network.NetPlugin
Expand Down Expand Up @@ -384,6 +385,7 @@ func main() {

if !disableTelemetry {
telemetryStopProcessing <- true
stopheartbeat <- true
}

// Cleanup.
Expand Down