Skip to content
Merged
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
98 changes: 51 additions & 47 deletions source/plugins/ruby/podinventory_to_mdm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,67 +93,71 @@ def initialize(custom_metrics_azure_regions)
end

def get_pod_inventory_mdm_records(batch_time)
records = []
begin
# generate all possible values of non_phase_dim_values X pod Phases and zero-fill the ones that are not already present
@no_phase_dim_values_hash.each { |key, value|
@@pod_phase_values.each { |phase|
pod_key = [key, phase].join("~~")
if !@pod_count_hash.key?(pod_key)
@pod_count_hash[pod_key] = 0
else
if @process_incoming_stream
# generate all possible values of non_phase_dim_values X pod Phases and zero-fill the ones that are not already present
@no_phase_dim_values_hash.each { |key, value|
@@pod_phase_values.each { |phase|
pod_key = [key, phase].join("~~")
if !@pod_count_hash.key?(pod_key)
@pod_count_hash[pod_key] = 0
else
next
end
}
}
@pod_count_hash.each { |key, value|
key_elements = key.split("~~")
if key_elements.length != 4
next
end
}
}
records = []
@pod_count_hash.each { |key, value|
key_elements = key.split("~~")
if key_elements.length != 4
next
end

# get dimension values by key
podNodeDimValue = key_elements[0]
podNamespaceDimValue = key_elements[1]
podControllerNameDimValue = key_elements[2]
podPhaseDimValue = key_elements[3]
# get dimension values by key
Copy link
Contributor

@ganga1980 ganga1980 Aug 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bunch of whitespaces and i think, we need to get rid off these to have cleaner code. I use this setting in vscode "files.trimTrailingWhitespace": true to avoid getting these whitespaces.

Can you add this settings "files.trimTrailingWhitespace": true to your vs code, File->Preferences->settings and push the update so these will get resolved automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is coming from formatter. I have ruby formatter that is formatting the code

podNodeDimValue = key_elements[0]
podNamespaceDimValue = key_elements[1]
podControllerNameDimValue = key_elements[2]
podPhaseDimValue = key_elements[3]

record = @@pod_inventory_custom_metrics_template % {
timestamp: batch_time,
metricName: @@pod_count_metric_name,
phaseDimValue: podPhaseDimValue,
namespaceDimValue: podNamespaceDimValue,
nodeDimValue: podNodeDimValue,
controllerNameDimValue: podControllerNameDimValue,
podCountMetricValue: value,
record = @@pod_inventory_custom_metrics_template % {
timestamp: batch_time,
metricName: @@pod_count_metric_name,
phaseDimValue: podPhaseDimValue,
namespaceDimValue: podNamespaceDimValue,
nodeDimValue: podNodeDimValue,
controllerNameDimValue: podControllerNameDimValue,
podCountMetricValue: value,
}
records.push(JSON.parse(record))
}
records.push(JSON.parse(record))
}

#Add pod metric records
records = MdmMetricsGenerator.appendAllPodMetrics(records, batch_time)
#Add pod metric records
records = MdmMetricsGenerator.appendAllPodMetrics(records, batch_time)

#Send telemetry for pod metrics
timeDifference = (DateTime.now.to_time.to_i - @@metricTelemetryTimeTracker).abs
timeDifferenceInMinutes = timeDifference / 60
if (timeDifferenceInMinutes >= Constants::TELEMETRY_FLUSH_INTERVAL_IN_MINUTES)
MdmMetricsGenerator.flushPodMdmMetricTelemetry
@@metricTelemetryTimeTracker = DateTime.now.to_time.to_i
end
#Send telemetry for pod metrics
timeDifference = (DateTime.now.to_time.to_i - @@metricTelemetryTimeTracker).abs
timeDifferenceInMinutes = timeDifference / 60
if (timeDifferenceInMinutes >= Constants::TELEMETRY_FLUSH_INTERVAL_IN_MINUTES)
MdmMetricsGenerator.flushPodMdmMetricTelemetry
@@metricTelemetryTimeTracker = DateTime.now.to_time.to_i
end

# Clearing out all hashes after telemetry is flushed
MdmMetricsGenerator.clearPodHashes
# Clearing out all hashes after telemetry is flushed
MdmMetricsGenerator.clearPodHashes
end
rescue Exception => e
@log.info "Error processing pod inventory record Exception: #{e.class} Message: #{e.message}"
ApplicationInsightsUtility.sendExceptionTelemetry(e.backtrace)
return []
end
@log.info "Pod Count To Phase #{@pod_count_by_phase} "
@log.info "resetting convertor state "
@pod_count_hash = {}
@no_phase_dim_values_hash = {}
@pod_count_by_phase = {}
@pod_uids = {}
if @process_incoming_stream
@log.info "Pod Count To Phase #{@pod_count_by_phase} "
@log.info "resetting convertor state "
@pod_count_hash = {}
@no_phase_dim_values_hash = {}
@pod_count_by_phase = {}
@pod_uids = {}
end
return records
end

Expand Down