From f0d8a144c2e38943514612495f33856e70746b12 Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Wed, 14 Aug 2019 23:10:46 -0700 Subject: [PATCH 1/3] enable ai telemetry for Mooncake --- source/code/go/src/plugins/telemetry.go | 5 ++++- source/code/plugin/ApplicationInsightsUtility.rb | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/source/code/go/src/plugins/telemetry.go b/source/code/go/src/plugins/telemetry.go index 5fc0fa843..066c3c522 100644 --- a/source/code/go/src/plugins/telemetry.go +++ b/source/code/go/src/plugins/telemetry.go @@ -42,6 +42,7 @@ const ( envAKSResourceID = "AKS_RESOURCE_ID" envACSResourceName = "ACS_RESOURCE_NAME" envAppInsightsAuth = "APPLICATIONINSIGHTS_AUTH" + envAppInsightsEndpoint = "APPLICATIONINSIGHTS_ENDPOINT" metricNameAvgFlushRate = "ContainerLogAvgRecordsFlushedPerSec" metricNameAvgLogGenerationRate = "ContainerLogsGeneratedPerSec" metricNameLogSize = "ContainerLogsSize" @@ -141,7 +142,9 @@ func InitializeTelemetryClient(agentVersion string) (int, error) { return -1, err } - TelemetryClient = appinsights.NewTelemetryClient(string(decIkey)) + telemetryClientConfig := appinsights.NewTelemetryConfiguration(string(decIkey)) + telemetryClientConfig.EndpointUrl = envAppInsightsEndpoint + TelemetryClient = appinsights.NewTelemetryClientFromConfig(telemetryClientConfig) telemetryOffSwitch := os.Getenv("DISABLE_TELEMETRY") if strings.Compare(strings.ToLower(telemetryOffSwitch), "true") == 0 { Log("Appinsights telemetry is disabled \n") diff --git a/source/code/plugin/ApplicationInsightsUtility.rb b/source/code/plugin/ApplicationInsightsUtility.rb index 5dc2bfab8..a27601700 100644 --- a/source/code/plugin/ApplicationInsightsUtility.rb +++ b/source/code/plugin/ApplicationInsightsUtility.rb @@ -18,6 +18,7 @@ class ApplicationInsightsUtility @@EnvAksRegion = "AKS_REGION" @@EnvAgentVersion = "AGENT_VERSION" @@EnvApplicationInsightsKey = "APPLICATIONINSIGHTS_AUTH" + @@EnvApplicationInsightsEndpoint = "APPLICATIONINSIGHTS_ENDPOINT" @@EnvControllerType = "CONTROLLER_TYPE" @@CustomProperties = {} @@ -62,6 +63,7 @@ def initializeUtility() @@CustomProperties["AgentVersion"] = ENV[@@EnvAgentVersion] @@CustomProperties["ControllerType"] = ENV[@@EnvControllerType] encodedAppInsightsKey = ENV[@@EnvApplicationInsightsKey] + appInsightsEndpoint = ENV[@@EnvApplicationInsightsEndpoint] #Check if telemetry is turned off telemetryOffSwitch = ENV["DISABLE_TELEMETRY"] @@ -70,7 +72,11 @@ def initializeUtility() @@Tc = ApplicationInsights::TelemetryClient.new elsif !encodedAppInsightsKey.nil? decodedAppInsightsKey = Base64.decode64(encodedAppInsightsKey) - @@Tc = ApplicationInsights::TelemetryClient.new decodedAppInsightsKey + telemetryContext = ApplicationInsights::Channel::TelemetryContext.new + telemetrySynchronousSender = ApplicationInsights::Channel::SynchronousSender.new appInsightsEndpoint + telemetrySynchronousQueue = ApplicationInsights::Channel::SynchronousQueue.new telemetrySynchronousSender + telemetryChannel = ApplicationInsights::Channel.TelemetryChannel.new telemetryContext, telemetrySynchronousQueue + @@Tc = ApplicationInsights::TelemetryClient.new decodedAppInsightsKey, telemetryChannel end rescue => errorStr $log.warn("Exception in AppInsightsUtility: initilizeUtility - error: #{errorStr}") From 5e02987076b8e2f021b52f246b83b6357a825ed1 Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Thu, 15 Aug 2019 21:44:20 -0700 Subject: [PATCH 2/3] fix the bug with reference --- source/code/plugin/ApplicationInsightsUtility.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/code/plugin/ApplicationInsightsUtility.rb b/source/code/plugin/ApplicationInsightsUtility.rb index a27601700..389d58c20 100644 --- a/source/code/plugin/ApplicationInsightsUtility.rb +++ b/source/code/plugin/ApplicationInsightsUtility.rb @@ -72,10 +72,9 @@ def initializeUtility() @@Tc = ApplicationInsights::TelemetryClient.new elsif !encodedAppInsightsKey.nil? decodedAppInsightsKey = Base64.decode64(encodedAppInsightsKey) - telemetryContext = ApplicationInsights::Channel::TelemetryContext.new telemetrySynchronousSender = ApplicationInsights::Channel::SynchronousSender.new appInsightsEndpoint - telemetrySynchronousQueue = ApplicationInsights::Channel::SynchronousQueue.new telemetrySynchronousSender - telemetryChannel = ApplicationInsights::Channel.TelemetryChannel.new telemetryContext, telemetrySynchronousQueue + telemetrySynchronousQueue = ApplicationInsights::Channel::SynchronousQueue.new(telemetrySynchronousSender) + telemetryChannel = ApplicationInsights::Channel::TelemetryChannel.new nil, telemetrySynchronousQueue @@Tc = ApplicationInsights::TelemetryClient.new decodedAppInsightsKey, telemetryChannel end rescue => errorStr From 01c5226cb41479b9b4ca8b132032f7da8fc605ec Mon Sep 17 00:00:00 2001 From: Ganga Mahesh Siddem Date: Fri, 16 Aug 2019 16:43:54 -0700 Subject: [PATCH 3/3] use default endpoint if not provided --- source/code/go/src/plugins/telemetry.go | 10 ++++++++-- source/code/plugin/ApplicationInsightsUtility.rb | 14 ++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/source/code/go/src/plugins/telemetry.go b/source/code/go/src/plugins/telemetry.go index 066c3c522..4f22b8c03 100644 --- a/source/code/go/src/plugins/telemetry.go +++ b/source/code/go/src/plugins/telemetry.go @@ -142,9 +142,15 @@ func InitializeTelemetryClient(agentVersion string) (int, error) { return -1, err } - telemetryClientConfig := appinsights.NewTelemetryConfiguration(string(decIkey)) - telemetryClientConfig.EndpointUrl = envAppInsightsEndpoint + appInsightsEndpoint := os.Getenv(envAppInsightsEndpoint) + telemetryClientConfig := appinsights.NewTelemetryConfiguration(string(decIkey)) + // endpoint override required only for sovereign clouds + if appInsightsEndpoint != "" { + Log("Overriding the default AppInsights EndpointUrl with %s", appInsightsEndpoint) + telemetryClientConfig.EndpointUrl = envAppInsightsEndpoint + } TelemetryClient = appinsights.NewTelemetryClientFromConfig(telemetryClientConfig) + telemetryOffSwitch := os.Getenv("DISABLE_TELEMETRY") if strings.Compare(strings.ToLower(telemetryOffSwitch), "true") == 0 { Log("Appinsights telemetry is disabled \n") diff --git a/source/code/plugin/ApplicationInsightsUtility.rb b/source/code/plugin/ApplicationInsightsUtility.rb index 389d58c20..bb4831701 100644 --- a/source/code/plugin/ApplicationInsightsUtility.rb +++ b/source/code/plugin/ApplicationInsightsUtility.rb @@ -72,10 +72,16 @@ def initializeUtility() @@Tc = ApplicationInsights::TelemetryClient.new elsif !encodedAppInsightsKey.nil? decodedAppInsightsKey = Base64.decode64(encodedAppInsightsKey) - telemetrySynchronousSender = ApplicationInsights::Channel::SynchronousSender.new appInsightsEndpoint - telemetrySynchronousQueue = ApplicationInsights::Channel::SynchronousQueue.new(telemetrySynchronousSender) - telemetryChannel = ApplicationInsights::Channel::TelemetryChannel.new nil, telemetrySynchronousQueue - @@Tc = ApplicationInsights::TelemetryClient.new decodedAppInsightsKey, telemetryChannel + #override ai endpoint if its available otherwise use default. + if appInsightsEndpoint && !appInsightsEndpoint.nil? && !appInsightsEndpoint.empty? + $log.info("AppInsightsUtility: Telemetry client uses overrided endpoint url : #{appInsightsEndpoint}") + telemetrySynchronousSender = ApplicationInsights::Channel::SynchronousSender.new appInsightsEndpoint + telemetrySynchronousQueue = ApplicationInsights::Channel::SynchronousQueue.new(telemetrySynchronousSender) + telemetryChannel = ApplicationInsights::Channel::TelemetryChannel.new nil, telemetrySynchronousQueue + @@Tc = ApplicationInsights::TelemetryClient.new decodedAppInsightsKey, telemetryChannel + else + @@Tc = ApplicationInsights::TelemetryClient.new decodedAppInsightsKey + end end rescue => errorStr $log.warn("Exception in AppInsightsUtility: initilizeUtility - error: #{errorStr}")