From 88f43cc8febceaed7f4a95abd3b76fb7fc502a3a Mon Sep 17 00:00:00 2001 From: xchen Date: Thu, 26 Sep 2024 00:37:22 -0700 Subject: [PATCH] get rid of excessive logging --- .../Scheduling/ResourcesScrapingJob.cs | 7 +----- .../AzureMonitorScraper.cs | 8 ------- .../MeasureMetricExtensionsTests.cs | 22 +++++++++++++++++++ 3 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 src/Promitor.Tests.Unit/Core/Extensions/MeasureMetricExtensionsTests.cs diff --git a/src/Promitor.Agents.Scraper/Scheduling/ResourcesScrapingJob.cs b/src/Promitor.Agents.Scraper/Scheduling/ResourcesScrapingJob.cs index f01c2b2cf..59c3e7abc 100644 --- a/src/Promitor.Agents.Scraper/Scheduling/ResourcesScrapingJob.cs +++ b/src/Promitor.Agents.Scraper/Scheduling/ResourcesScrapingJob.cs @@ -256,7 +256,7 @@ private async Task ScrapeMetrics(IEnumerable definition in batchScrapeDefinition.ScrapeDefinitions) - { - Logger.LogInformation("ResourceID: {ResourceID}, ResourceGroup: {ResourceGroup}, Prometheus metric name: {MetricName}, Batch Key: {BatchKey}", definition.Resource.ResourceName, definition.ResourceGroupName, definition.PrometheusMetricDefinition.Name, definition.BuildScrapingBatchInfo().BuildBatchHashKey()); - } await ScheduleLimitedConcurrencyAsyncTask(tasks, () => ScrapeMetricBatched(batchScrapeDefinition), cancellationToken); } } else { diff --git a/src/Promitor.Core.Scraping/AzureMonitorScraper.cs b/src/Promitor.Core.Scraping/AzureMonitorScraper.cs index 53c6c632e..c9d2ce9d2 100644 --- a/src/Promitor.Core.Scraping/AzureMonitorScraper.cs +++ b/src/Promitor.Core.Scraping/AzureMonitorScraper.cs @@ -105,7 +105,6 @@ protected override async Task> BatchScrapeResourceAsync(strin subscriptionId: scrapeDefinition.SubscriptionId, resourceName: scrapeDefinition.Resource.ResourceName ); - Logger.LogWarning("Caching resource group {Group}, resource name {ResourceName}, subscription ID {SubscriptionID}, for {ResourceId}, of resource type {ResourceType}", resourceDefinitionToCache.ResourceGroupName, resourceDefinitionToCache.ResourceName, resourceDefinitionToCache.SubscriptionId, resourceUri, resourceDefinitionToCache.ResourceType); _resourceDefinitions.AddOrUpdate(resourceUri, new Tuple(resourceDefinitionToCache, (TResourceDefinition)scrapeDefinition.Resource), (newTuple, oldTuple) => oldTuple); } @@ -116,12 +115,7 @@ protected override async Task> BatchScrapeResourceAsync(strin try { // Query Azure Monitor for metrics - Logger.LogWarning("Querying Azure Monitor for metric {MetricName} with batch size {BatchSize}", metricName, resourceUriList.Count); resourceIdTaggedMeasuredMetrics = await AzureMonitorClient.BatchQueryMetricAsync(metricName, dimensionNames, aggregationType, aggregationInterval, resourceUriList, null, metricLimit); - foreach (var resourceMetric in resourceIdTaggedMeasuredMetrics) - { - Logger.LogWarning("Discovered value {Value} for metric {Metric} and resource ID {ResourceID}", resourceMetric.Value, metricName, resourceMetric.ResourceId); - } } catch (MetricInformationNotFoundException metricsNotFoundException) { @@ -144,9 +138,7 @@ protected override async Task> BatchScrapeResourceAsync(strin var resourceDefinition = resourceDefinitionTuple.Item1; var metricLabels = DetermineMetricLabels(resourceDefinitionTuple.Item2); var finalMetricValues = EnrichMeasuredMetrics(resourceDefinitionTuple.Item2, dimensionNames, resourceMetricsGroup.ToImmutableList()); - Logger.LogWarning("Processing {MetricsCount} measured metrics for resourceID {ResourceId} of resource group {ResourceGroup}", finalMetricValues.Count, resourceId, resourceDefinition.ResourceGroupName); scrapeResults.Add(new ScrapeResult(subscriptionId, resourceDefinition.ResourceGroupName, resourceDefinition.ResourceName, resourceId, finalMetricValues, metricLabels)); - Logger.LogWarning("Processed {MetricsCount} measured metrics for Metric {MetricName} and resource {ResourceName}", finalMetricValues.Count, metricName, resourceId); } } diff --git a/src/Promitor.Tests.Unit/Core/Extensions/MeasureMetricExtensionsTests.cs b/src/Promitor.Tests.Unit/Core/Extensions/MeasureMetricExtensionsTests.cs new file mode 100644 index 000000000..604d0fd1e --- /dev/null +++ b/src/Promitor.Tests.Unit/Core/Extensions/MeasureMetricExtensionsTests.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using System.ComponentModel; +using Azure.Monitor.Query.Models; +using Promitor.Core.Extensions; +using Promitor.Core.Metrics; +using Xunit; + +namespace Promitor.Tests.Unit.Core.Extensions +{ + [Category("Unit")] + public class MeasureMetricExtensionsTests + { + [Fact] + public void AssociateWithResourceId() + { + var measuredMetricUnassociated = MeasuredMetric.CreateWithoutDimensions(1); + var resourceId = "/subscriptions/abc/providers/def/test"; + var measuredMetricAssociated = measuredMetricUnassociated.WithResourceIdAssociation(resourceId); + Assert.Equal(resourceId, measuredMetricAssociated.ResourceId); + } + } +} \ No newline at end of file