From 31f7919a5a864a12f62cca9fc195f5512ee0d06c Mon Sep 17 00:00:00 2001 From: Brad Hjelmar Date: Wed, 23 Sep 2020 22:16:39 -0400 Subject: [PATCH] Reference Issue: 114. Changed dictionary insert to ensure we are not inserting null values or inserting colliding values. See https://github.com/Appdynamics/AppDynamics.DEXTER/issues/114 for detailed discussion. --- ProcessingSteps/Index/IndexAPMMetricsList.cs | 50 ++++++++++++++------ 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/ProcessingSteps/Index/IndexAPMMetricsList.cs b/ProcessingSteps/Index/IndexAPMMetricsList.cs index cacbb0e..b8050f9 100644 --- a/ProcessingSteps/Index/IndexAPMMetricsList.cs +++ b/ProcessingSteps/Index/IndexAPMMetricsList.cs @@ -71,50 +71,70 @@ public override bool Execute(ProgramOptions programOptions, JobConfiguration job #region Preload lists of entities - List tiersList = FileIOHelper.ReadListFromCSVFile(FilePathMap.APMTiersIndexFilePath(jobTarget), new APMTierReportMap()); - List nodesList = FileIOHelper.ReadListFromCSVFile(FilePathMap.APMNodesIndexFilePath(jobTarget), new APMNodeReportMap()); - List businessTransactionsList = FileIOHelper.ReadListFromCSVFile(FilePathMap.APMBusinessTransactionsIndexFilePath(jobTarget), new APMBusinessTransactionReportMap()); - List serviceEndpointsList = FileIOHelper.ReadListFromCSVFile(FilePathMap.APMServiceEndpointsIndexFilePath(jobTarget), new APMServiceEndpointReportMap()); - List errorsList = FileIOHelper.ReadListFromCSVFile(FilePathMap.APMErrorsIndexFilePath(jobTarget), new APMErrorReportMap()); - List backendsList = FileIOHelper.ReadListFromCSVFile(FilePathMap.APMBackendsIndexFilePath(jobTarget), new APMBackendReportMap()); - List informationPointsList = FileIOHelper.ReadListFromCSVFile(FilePathMap.APMInformationPointsIndexFilePath(jobTarget), new APMInformationPointReportMap()); + var tiersList = FileIOHelper.ReadListFromCSVFile(FilePathMap.APMTiersIndexFilePath(jobTarget), new APMTierReportMap()); + var nodesList = FileIOHelper.ReadListFromCSVFile(FilePathMap.APMNodesIndexFilePath(jobTarget), new APMNodeReportMap()); + var businessTransactionsList = FileIOHelper.ReadListFromCSVFile(FilePathMap.APMBusinessTransactionsIndexFilePath(jobTarget), new APMBusinessTransactionReportMap()); + var serviceEndpointsList = FileIOHelper.ReadListFromCSVFile(FilePathMap.APMServiceEndpointsIndexFilePath(jobTarget), new APMServiceEndpointReportMap()); + var errorsList = FileIOHelper.ReadListFromCSVFile(FilePathMap.APMErrorsIndexFilePath(jobTarget), new APMErrorReportMap()); + var backendsList = FileIOHelper.ReadListFromCSVFile(FilePathMap.APMBackendsIndexFilePath(jobTarget), new APMBackendReportMap()); + var informationPointsList = FileIOHelper.ReadListFromCSVFile(FilePathMap.APMInformationPointsIndexFilePath(jobTarget), new APMInformationPointReportMap()); Dictionary tiersDictionary = new Dictionary(); if (tiersList != null) { - tiersDictionary = tiersList.ToDictionary(e => e.TierName, e => e); + tiersDictionary = tiersList + .Where(e => e.TierName != null) + .GroupBy(e => e.TierName, StringComparer.Ordinal) + .ToDictionary(e => e.Key, e => e.First(), StringComparer.Ordinal); } Dictionary nodesDictionary = new Dictionary(); if (nodesList != null) { - nodesDictionary = nodesList.ToDictionary(e => String.Format(@"{0}\{1}", e.TierName, e.NodeName), e => e); + nodesDictionary = nodesList + .Where(e => e.TierName != null && e.NodeName != null) + .GroupBy(e => $@"{e.TierName}\{e.NodeName}", StringComparer.Ordinal) + .ToDictionary(e => e.Key, e => e.First(), StringComparer.Ordinal); } Dictionary businessTransactionsDictionary = new Dictionary(); if (businessTransactionsList != null) { - businessTransactionsDictionary = businessTransactionsList.ToDictionary(e => String.Format(@"{0}\{1}", e.TierName, e.BTName), e => e); + businessTransactionsDictionary = businessTransactionsList + .Where(e => e.TierName != null && e.BTName != null) + .GroupBy(e => $@"{e.TierName}\{e.BTName}", StringComparer.Ordinal) + .ToDictionary(e => e.Key, e => e.First(), StringComparer.Ordinal); } Dictionary serviceEndpointDictionary = new Dictionary(); if (serviceEndpointsList != null) { - serviceEndpointDictionary = serviceEndpointsList.ToDictionary(e => String.Format(@"{0}\{1}", e.TierName, e.SEPName), e => e); + serviceEndpointDictionary = serviceEndpointsList + .Where(e => e.TierName != null && e.SEPName != null) + .GroupBy(e => $@"{e.TierName}\{e.SEPName}", StringComparer.Ordinal) + .ToDictionary(e => e.Key, e => e.First(), StringComparer.Ordinal); } Dictionary errorDictionary = new Dictionary(); if (errorsList != null) { - errorDictionary = errorsList.ToDictionary(e => String.Format(@"{0}\{1}", e.TierName, e.ErrorName), e => e); + errorDictionary = errorsList + .Where(e => e.TierName != null && e.ErrorName != null) + .GroupBy(e => $@"{e.TierName}\{e.ErrorName}", StringComparer.Ordinal) + .ToDictionary(e => e.Key, e => e.First(), StringComparer.Ordinal); } Dictionary backendDictionary = new Dictionary(); if (backendsList != null) { - backendDictionary = backendsList.ToDictionary(e => e.BackendName, e => e); + backendDictionary = backendsList + .Where(e => e.BackendName != null) + .GroupBy(e => e.BackendName, StringComparer.Ordinal) + .ToDictionary(e => e.Key, e => e.First(), StringComparer.Ordinal); } Dictionary informationPointDictionary = new Dictionary(); if (informationPointsList != null) { - informationPointDictionary = informationPointsList.ToDictionary(e => e.IPName, e => e); + informationPointDictionary = informationPointsList + .Where(e => e.IPName != null) + .GroupBy(e => e.IPName, StringComparer.Ordinal) + .ToDictionary(e => e.Key, e => e.First(), StringComparer.Ordinal); } - #endregion #region Parse metrics into lists