Skip to content

Commit

Permalink
get rid of excessive logging
Browse files Browse the repository at this point in the history
  • Loading branch information
hkfgo committed Sep 26, 2024
1 parent 943e437 commit 88f43cc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,14 @@ private async Task ScrapeMetrics(IEnumerable<ScrapeDefinition<IAzureResourceDefi
var batchScrapingEnabled = this._azureMonitorIntegrationConfiguration.Value.MetricsBatching?.Enabled ?? false;
if (batchScrapingEnabled) {
Logger.LogInformation("Promitor Scraper with operate in batch scraping mode, with max batch size {BatchSize}", this._azureMonitorIntegrationConfiguration.Value.MetricsBatching.MaxBatchSize);
Logger.LogWarning("");
Logger.LogWarning("Batch scraping is an experimental feature. See Promitor.io for its limitations and cost considerations");

var batchScrapeDefinitions = AzureResourceDefinitionBatching.GroupScrapeDefinitions(scrapeDefinitions, this._azureMonitorIntegrationConfiguration.Value.MetricsBatching.MaxBatchSize);

foreach(var batchScrapeDefinition in batchScrapeDefinitions) {
var azureMetricName = batchScrapeDefinition.ScrapeDefinitionBatchProperties.AzureMetricConfiguration.MetricName;
var resourceType = batchScrapeDefinition.ScrapeDefinitionBatchProperties.ResourceType;
Logger.LogInformation("Executing batch scrape job of size {BatchSize} for Azure Metric {AzureMetricName} for resource type {ResourceType}.", batchScrapeDefinition.ScrapeDefinitions.Count, azureMetricName, resourceType);
Logger.LogInformation("Logging individual definitions batch: Azure Metric {AzureMetricName} and resource type {ResourceType}.", azureMetricName, resourceType);
foreach (ScrapeDefinition<IAzureResourceDefinition> 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 {
Expand Down
8 changes: 0 additions & 8 deletions src/Promitor.Core.Scraping/AzureMonitorScraper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ protected override async Task<List<ScrapeResult>> 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<IAzureResourceDefinition, TResourceDefinition>(resourceDefinitionToCache, (TResourceDefinition)scrapeDefinition.Resource), (newTuple, oldTuple) => oldTuple);
}

Expand All @@ -116,12 +115,7 @@ protected override async Task<List<ScrapeResult>> 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)
{
Expand All @@ -144,9 +138,7 @@ protected override async Task<List<ScrapeResult>> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;

Check warning on line 1 in src/Promitor.Tests.Unit/Core/Extensions/MeasureMetricExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / Code Quality (R#)

"[RedundantUsingDirective] Using directive is not required by the code and can be safely removed" on /home/runner/work/promitor/promitor/src/Promitor.Tests.Unit/Core/Extensions/MeasureMetricExtensionsTests.cs
using System.ComponentModel;
using Azure.Monitor.Query.Models;

Check warning on line 3 in src/Promitor.Tests.Unit/Core/Extensions/MeasureMetricExtensionsTests.cs

View workflow job for this annotation

GitHub Actions / Code Quality (R#)

"[RedundantUsingDirective] Using directive is not required by the code and can be safely removed" on /home/runner/work/promitor/promitor/src/Promitor.Tests.Unit/Core/Extensions/MeasureMetricExtensionsTests.cs(3,63)
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);
}
}
}

0 comments on commit 88f43cc

Please sign in to comment.