Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hkfgo committed Sep 26, 2024
1 parent a853c26 commit 430c725
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private async Task ScrapeMetrics(IEnumerable<ScrapeDefinition<IAzureResourceDefi
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: {ResoureceID}, ResourceGroup: {ResourceGroup}, Prometheus metric name: {MetricName}, Batch Key: {BatchKey}", definition.Resource.ResourceName, definition.ResourceGroupName, definition.PrometheusMetricDefinition.Name, definition.BuildPropertiesForBatch().BuildBatchHashKey());
Logger.LogInformation("ResourceID: {ResoureceID}, 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class AzureResourceDefinitionBatching
/// </summary>
public static List<BatchScrapeDefinition<IAzureResourceDefinition>> GroupScrapeDefinitions(IEnumerable<ScrapeDefinition<IAzureResourceDefinition>> allScrapeDefinitions, int maxBatchSize, CancellationToken cancellationToken)
{
return allScrapeDefinitions.GroupBy(def => def.BuildPropertiesForBatch())
return allScrapeDefinitions.GroupBy(def => def.BuildScrapingBatchInfo())
.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, cancellationToken)) // split to right-sized batches
.SelectMany(group => group.Value.Select(batch => new BatchScrapeDefinition<IAzureResourceDefinition>(group.Key, batch)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public class BatchScrapeDefinition<TResourceDefinition> where TResourceDefinitio
/// <param name="groupedScrapeDefinitions">Scape definitions in the batch</param>
public BatchScrapeDefinition(ScrapeDefinitionBatchProperties scrapeDefinitionBatchProperties, List<ScrapeDefinition<TResourceDefinition>> groupedScrapeDefinitions)
{
Guard.NotNull(groupedScrapeDefinitions, nameof(scrapeDefinitionBatchProperties));
Guard.NotNull(groupedScrapeDefinitions, nameof(groupedScrapeDefinitions));
Guard.NotLessThan(groupedScrapeDefinitions.Count, 1, nameof(groupedScrapeDefinitions));
Guard.NotNull(scrapeDefinitionBatchProperties, nameof(scrapeDefinitionBatchProperties));

ScrapeDefinitionBatchProperties = scrapeDefinitionBatchProperties;
ScrapeDefinitions = groupedScrapeDefinitions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public ScrapeDefinition(
return AzureMetricConfiguration?.Aggregation?.Interval;
}

public ScrapeDefinitionBatchProperties BuildPropertiesForBatch() {
public ScrapeDefinitionBatchProperties BuildScrapingBatchInfo() {
return new ScrapeDefinitionBatchProperties(
this.AzureMetricConfiguration,
this.LogAnalyticsConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Promitor.Integrations.AzureMonitor.Configuration
{
public class AzureMonitorMetricBatchScrapeConfig
{
public bool Enabled { get; set; }
public bool Enabled { get; set; } = false;
public int MaxBatchSize { get; set; }
public string AzureRegion { get; set; } = "eastus"; // Batch scrape endpoints are deployed by region
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System.Text.RegularExpressions;
using Azure.Monitor.Query.Models;

namespace Promitor.Integrations.AzureMonitor.Extensions
{
public static class MetricResultExtension
{
// hacky to to get resource ID since it's not available directly through the SDK model
/// <summary>
/// hacky to to get resource ID since it's not available directly through the SDK model, because the MetricResult model does not have the ResourceID attribute that comes with Response JSON
/// </summary>
public static string ParseResourceIdFromResultId(this MetricResult metricResult)
{
return ExtractResourceId(metricResult.Id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
using Microsoft.Extensions.Logging;

namespace Promitor.Integrations.AzureMonitor.HttpPipelinePolicies{
/// <summary>
/// Work around to make sure range queries work properly. <see cref="https://github.com/Azure/azure-sdk-for-net/issues/40047">
/// </summary>
public class ModifyOutgoingAzureMonitorRequestsPolicy : HttpPipelinePolicy
{
private readonly ILogger _logger;
Expand Down

0 comments on commit 430c725

Please sign in to comment.