diff --git a/source/code/go/src/plugins/oms.go b/source/code/go/src/plugins/oms.go index 01aab85b4..5a323d7e0 100644 --- a/source/code/go/src/plugins/oms.go +++ b/source/code/go/src/plugins/oms.go @@ -412,8 +412,6 @@ func flushKubeMonAgentEventRecords() { if skipKubeMonEventsFlush != true { Log("In flushConfigErrorRecords\n") start := time.Now() - var resp *http.Response - var postError error var elapsed time.Duration var laKubeMonAgentEventsRecords []laKubeMonAgentEvents telemetryDimensions := make(map[string]string) @@ -518,10 +516,10 @@ func flushKubeMonAgentEventRecords() { req.Header.Set("x-ms-AzureResourceId", ResourceID) } - resp, postError = HTTPClient.Do(req) + resp, err := HTTPClient.Do(req) elapsed = time.Since(start) - if postError != nil { + if err != nil { message := fmt.Sprintf("Error when sending kubemonagentevent request %s \n", err.Error()) Log(message) Log("Failed to flush %d records after %s", len(laKubeMonAgentEventsRecords), elapsed) @@ -532,7 +530,7 @@ func flushKubeMonAgentEventRecords() { Log("Failed to flush %d records after %s", len(laKubeMonAgentEventsRecords), elapsed) } else { numRecords := len(laKubeMonAgentEventsRecords) - Log("Successfully flushed %d records in %s", numRecords, elapsed) + Log("FlushKubeMonAgentEventRecords::Info::Successfully flushed %d records in %s", numRecords, elapsed) // Send telemetry to AppInsights resource SendEvent(KubeMonAgentEventsFlushedEvent, telemetryDimensions) @@ -822,7 +820,7 @@ func PostDataHelper(tailPluginRecords []map[interface{}]interface{}) int { defer resp.Body.Close() numRecords := len(dataItems) - Log("Successfully flushed %d records in %s", numRecords, elapsed) + Log("PostDataHelper::Info::Successfully flushed %d records in %s", numRecords, elapsed) ContainerLogTelemetryMutex.Lock() FlushedRecordsCount += float64(numRecords) FlushedRecordsTimeTaken += float64(elapsed / time.Millisecond) diff --git a/source/code/plugin/health/health_monitor_state.rb b/source/code/plugin/health/health_monitor_state.rb index 1bbed91f8..8e2294cc9 100644 --- a/source/code/plugin/health/health_monitor_state.rb +++ b/source/code/plugin/health/health_monitor_state.rb @@ -241,10 +241,23 @@ def agg_monitor_details_changed?(is_aggregate_monitor, last_sent_details, latest if !is_aggregate_monitor return false end - if latest_details['details'] != last_sent_details['details'] - log.info "Last Sent Details #{JSON.pretty_generate(last_sent_details)} \n Latest Details: #{JSON.pretty_generate(latest_details)}" - return true - end + + # Do a deep comparison of the keys under details, since a shallow comparison is hit or miss. + # Actual bug was the array inside the keys were in random order and the previous equality comparison was failing + latest_details['details'].keys.each{|k| + if !last_sent_details['details'].key?(k) + return true + end + if latest_details['details'][k].size != last_sent_details['details'][k].size + return true + end + } + # Explanation: a = [1,2] b = [2,1] a & b = [1,2] , c = [2,3] d = [2] c & d = [2] c.size != (c&d).size + latest_details['details'].keys.each{|k| + if !(latest_details['details'][k].size == (last_sent_details['details'][k] & latest_details['details'][k]).size) + return true + end + } return false end end diff --git a/source/code/plugin/health/health_monitor_utils.rb b/source/code/plugin/health/health_monitor_utils.rb index 9b0560202..e21fdc83d 100644 --- a/source/code/plugin/health/health_monitor_utils.rb +++ b/source/code/plugin/health/health_monitor_utils.rb @@ -32,9 +32,9 @@ def compute_percentage_state(value, config) if config.nil? || ( config['WarnIfGreaterThanPercentage'].nil? && config['WarnIfLesserThanPercentage'].nil? ) warn_percentage = nil else - warn_percentage = config['WarnIfGreaterThanPercentage'].to_f || config['WarnIfLesserThanPercentage'].to_f + warn_percentage = !config['WarnIfGreaterThanPercentage'].nil? ? config['WarnIfGreaterThanPercentage'].to_f : config['WarnIfLesserThanPercentage'].to_f end - fail_percentage = config['FailIfGreaterThanPercentage'].to_f || config['FailIfLesserThanPercentage'].to_f # nil.to_f = 0.0, 90 || 0 = 90 + fail_percentage = !config['FailIfGreaterThanPercentage'].nil? ? config['FailIfGreaterThanPercentage'].to_f : config['FailIfLesserThanPercentage'].to_f is_less_than_comparer = config['FailIfGreaterThanPercentage'].nil? ? true : false # Fail percentage config always present for percentage computation monitors if !config.nil? && is_less_than_comparer