Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telemetry optimization: Sending mdsd error traces as metrics #1147

Merged
merged 3 commits into from
Jan 12, 2024
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
1 change: 1 addition & 0 deletions source/plugins/go/src/out_oms.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func FLBPluginInit(ctx unsafe.Pointer) int {
if strings.Compare(strings.ToLower(enableTelemetry), "true") == 0 {
telemetryPushInterval := output.FLBPluginConfigKey(ctx, "TelemetryPushIntervalSeconds")
go SendContainerLogPluginMetrics(telemetryPushInterval)
go SendMdsdTracesAsMetrics(telemetryPushInterval)
} else {
Log("Telemetry is not enabled for the plugin %s \n", output.FLBPluginConfigKey(ctx, "Name"))
return output.FLB_OK
Expand Down
49 changes: 49 additions & 0 deletions source/plugins/go/src/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"strconv"
"strings"
"sync"
"time"

"github.com/fluent/fluent-bit-go/output"
Expand Down Expand Up @@ -75,6 +76,12 @@ var (
"daemonset": "DS",
"replicaset": "RS",
}
//Metrics map for the mdsd traces
MdsdErrorMetrics = map[string]float64{}
//Time ticker for sending mdsd errors as metrics
MdsdErrorMetricsTicker *time.Ticker
//Mutex for mdsd error metrics
MdsdErrorMetricsMutex = &sync.Mutex{}
)

const (
Expand Down Expand Up @@ -309,6 +316,26 @@ func SendContainerLogPluginMetrics(telemetryPushIntervalProperty string) {
}
}

// SendMdsdTracesAsMetrics is a go-routine that flushes the mdsd traces as metrics periodically (every 5 mins to App Insights)
func SendMdsdTracesAsMetrics(telemetryPushIntervalProperty string) {
telemetryPushInterval, err := strconv.Atoi(telemetryPushIntervalProperty)
if err != nil {
Log("Error Converting telemetryPushIntervalProperty %s. Using Default Interval... %d \n", telemetryPushIntervalProperty, defaultTelemetryPushIntervalSeconds)
telemetryPushInterval = defaultTelemetryPushIntervalSeconds
}

MdsdErrorMetricsTicker = time.NewTicker(time.Second * time.Duration(telemetryPushInterval))

for ; true; <-MdsdErrorMetricsTicker.C {
MdsdErrorMetricsMutex.Lock()
for metricName, metricValue := range MdsdErrorMetrics {
TelemetryClient.Track(appinsights.NewMetricTelemetry(metricName, metricValue))
}
MdsdErrorMetrics = map[string]float64{}
MdsdErrorMetricsMutex.Unlock()
}
}

// SendEvent sends an event to App Insights
func SendEvent(eventName string, dimensions map[string]string) {
Log("Sending Event : %s\n", eventName)
Expand Down Expand Up @@ -490,6 +517,16 @@ func InitializeTelemetryClient(agentVersion string) (int, error) {
return 0, nil
}

func UpdateMdsdErrorMetrics(key string) {
MdsdErrorMetricsMutex.Lock()
if _, ok := MdsdErrorMetrics[key]; ok {
MdsdErrorMetrics[key]++
} else {
MdsdErrorMetrics[key] = 1
}
MdsdErrorMetricsMutex.Unlock()
}

// PushToAppInsightsTraces sends the log lines as trace messages to the configured App Insights Instance
func PushToAppInsightsTraces(records []map[interface{}]interface{}, severityLevel contracts.SeverityLevel, tag string) int {
var logLines []string
Expand All @@ -500,6 +537,18 @@ func PushToAppInsightsTraces(records []map[interface{}]interface{}, severityLeve
populateKubeMonAgentEventHash(record, ConfigError)
} else if strings.Contains(logEntry, "E! [inputs.prometheus]") {
populateKubeMonAgentEventHash(record, PromScrapingError)
} else if strings.Contains(logEntry, "Lifetime validation failed. The token is expired.") {
jatakiajanvi12 marked this conversation as resolved.
Show resolved Hide resolved
UpdateMdsdErrorMetrics("MdsdTokenExpired")
} else if strings.Contains(logEntry, "Failed to upload to ODS: Error resolving address") {
UpdateMdsdErrorMetrics("MdsdODSUploadErrorResolvingAddress")
} else if strings.Contains(logEntry, "Data collection endpoint must be used to access configuration over private link") {
UpdateMdsdErrorMetrics("MdsdPrivateLinkNoDCE")
} else if strings.Contains(logEntry, "Failed to register certificate with OMS Homing Service:Error resolving address") {
UpdateMdsdErrorMetrics("MdsdOMSHomingServiceError")
} else if strings.Contains(logEntry, "Could not obtain configuration from") {
UpdateMdsdErrorMetrics("MdsdGetConfigError")
} else if strings.Contains(logEntry, " Failed to upload to ODS: 403") {
UpdateMdsdErrorMetrics("MdsdODSUploadError403")
} else {
logLines = append(logLines, logEntry)
}
Expand Down
Loading