Skip to content

Commit

Permalink
remove some more logging + add null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
hkfgo committed Oct 1, 2024
1 parent c72bda1 commit 206e155
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using GuardNet;
using Promitor.Core.Contracts;
using Promitor.Core.Scraping.Configuration.Model.Metrics;

Expand All @@ -17,18 +18,24 @@ public static class AzureResourceDefinitionBatching
/// </summary>
public static List<BatchScrapeDefinition<IAzureResourceDefinition>> GroupScrapeDefinitions(IEnumerable<ScrapeDefinition<IAzureResourceDefinition>> allScrapeDefinitions, int maxBatchSize)
{
Guard.NotNull(allScrapeDefinitions, nameof(allScrapeDefinitions));

Check warning on line 21 in src/Promitor.Core.Scraping/Batching/AzureResourceDefinitionBatching.cs

View workflow job for this annotation

GitHub Actions / Code Quality (R#)

"[PossibleMultipleEnumeration] Possible multiple enumeration" on /home/runner/work/promitor/promitor/src/Promitor.Core.Scraping/Batching/AzureResourceDefinitionBatching.cs(21,1078)
Guard.NotLessThan(allScrapeDefinitions.Count(), 1, nameof(allScrapeDefinitions));

Check warning on line 22 in src/Promitor.Core.Scraping/Batching/AzureResourceDefinitionBatching.cs

View workflow job for this annotation

GitHub Actions / Code Quality (R#)

"[PossibleMultipleEnumeration] Possible multiple enumeration" on /home/runner/work/promitor/promitor/src/Promitor.Core.Scraping/Batching/AzureResourceDefinitionBatching.cs(22,1161)

return allScrapeDefinitions.GroupBy(def => def.BuildScrapingBatchInfo())

Check warning on line 24 in src/Promitor.Core.Scraping/Batching/AzureResourceDefinitionBatching.cs

View workflow job for this annotation

GitHub Actions / Code Quality (R#)

"[PossibleMultipleEnumeration] Possible multiple enumeration" on /home/runner/work/promitor/promitor/src/Promitor.Core.Scraping/Batching/AzureResourceDefinitionBatching.cs(24,1246)
.ToDictionary(group => group.Key, group => group.ToList()) // first pass to build batches that could exceed max
.ToDictionary(group => group.Key, group => SplitScrapeDefinitionBatch(group.Value, maxBatchSize)) // split to right-sized batches
.SelectMany(group => group.Value.Select(batch => new BatchScrapeDefinition<IAzureResourceDefinition>(group.Key, batch)))
.ToList(); // flatten
}

/// <summary>
/// <summary>
/// splits the "raw" batch according to max batch size configured
/// </summary>
private static List<List<ScrapeDefinition<IAzureResourceDefinition>>> SplitScrapeDefinitionBatch(List<ScrapeDefinition<IAzureResourceDefinition>> batchToSplit, int maxBatchSize)
{
Guard.NotNull(batchToSplit, nameof(batchToSplit));
Guard.NotLessThan(batchToSplit.Count(), 1, nameof(batchToSplit));

int numNewGroups = ((batchToSplit.Count - 1) / maxBatchSize) + 1;

return Enumerable.Range(0, numNewGroups)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public async Task<List<ResourceAssociatedMeasuredMetric>> BatchQueryMetricAsync(

// Get the most recent metric
var metricResultsList = await _metricsBatchQueryClient.GetRelevantMetricForResources(resourceIds, metricName, metricNamespace, MetricAggregationTypeConverter.AsMetricAggregationType(aggregationType), closestAggregationInterval, metricFilter, metricDimensions, metricLimit, startQueryingTime, _azureMonitorIntegrationConfiguration, _logger);
_logger.LogWarning("Azure monitor has returned {ResultsCount} results for metric {MetricName}", metricResultsList.Count, metricName);

//TODO: This is potentially a lot of results to process in a single thread. Think of ways to utilize additional parallelism
return metricResultsList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public static async Task<List<MetricResult>> GetRelevantMetricForResources(this

var metricsBatchQueryResponse = await metricsClient.QueryResourcesAsync(resourceIdentifiers, [metricName], metricNamespace, queryOptions);
var metricsQueryResults = metricsBatchQueryResponse.Value;
logger.LogWarning("Got response");
return metricsQueryResults.Values
.Select(result => GetRelevantMetricResultOrThrow(result, metricName))
.ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ private void ModifyDateTimeParam(List<string> paramNames, HttpMessage message)
message.Request.Uri.Query = query.ToString();
} else {
_logger.LogWarning("Failed to modify parameters {Parms}", string.Join("and ", paramNames));
}
_logger.LogWarning("Final url is {URI}", message.Request.Uri.ToString());

}
}
}
}
Expand Down

0 comments on commit 206e155

Please sign in to comment.