diff --git a/src/Promitor.Core.Scraping/Configuration/Model/Metrics/ScrapeDefinition.cs b/src/Promitor.Core.Scraping/Configuration/Model/Metrics/ScrapeDefinition.cs index 2e4ddb1c1..375ef43ac 100644 --- a/src/Promitor.Core.Scraping/Configuration/Model/Metrics/ScrapeDefinition.cs +++ b/src/Promitor.Core.Scraping/Configuration/Model/Metrics/ScrapeDefinition.cs @@ -98,6 +98,7 @@ public ScrapeDefinition( public ScrapeDefinitionBatchProperties buildPropertiesForBatch() { return new ScrapeDefinitionBatchProperties( this.AzureMetricConfiguration, + this.LogAnalyticsConfiguration, this.PrometheusMetricDefinition, this.Resource.ResourceType, this.Scraping, diff --git a/src/Promitor.Core.Scraping/Configuration/Model/Metrics/ScrapeDefinitionBatch.cs b/src/Promitor.Core.Scraping/Configuration/Model/Metrics/ScrapeDefinitionBatch.cs index 74281800b..9d3209459 100644 --- a/src/Promitor.Core.Scraping/Configuration/Model/Metrics/ScrapeDefinitionBatch.cs +++ b/src/Promitor.Core.Scraping/Configuration/Model/Metrics/ScrapeDefinitionBatch.cs @@ -21,6 +21,7 @@ public class ScrapeDefinitionBatchProperties : IEquatable public ScrapeDefinitionBatchProperties( AzureMetricConfiguration azureMetricConfiguration, + LogAnalyticsConfiguration logAnalyticsConfiguration, PrometheusMetricDefinition prometheusMetricDefinition, ResourceType resourceType, Scraping scraping, @@ -32,6 +33,7 @@ public ScrapeDefinitionBatchProperties( Guard.NotNull(subscriptionId, nameof(subscriptionId)); AzureMetricConfiguration = azureMetricConfiguration; + LogAnalyticsConfiguration = logAnalyticsConfiguration; PrometheusMetricDefinition = prometheusMetricDefinition; Scraping = scraping; SubscriptionId = subscriptionId; @@ -43,6 +45,11 @@ public ScrapeDefinitionBatchProperties( /// public AzureMetricConfiguration AzureMetricConfiguration { get; } + /// + /// Configuration about the Azure Monitor log analytics resource to scrape + /// + public LogAnalyticsConfiguration LogAnalyticsConfiguration { get; } + /// /// The details of the prometheus metric that will be created. /// @@ -67,6 +74,10 @@ public ScrapeDefinitionBatchProperties( public TimeSpan? GetAggregationInterval() { + if (ResourceType == ResourceType.LogAnalytics) + { + return LogAnalyticsConfiguration?.Aggregation?.Interval; + } return AzureMetricConfiguration?.Aggregation?.Interval; } diff --git a/src/Promitor.Tests.Unit/Core/Metrics/ScrapeDefinitionBatchPropertiesTest.cs b/src/Promitor.Tests.Unit/Core/Metrics/ScrapeDefinitionBatchPropertiesTest.cs index bac524edb..38312041e 100644 --- a/src/Promitor.Tests.Unit/Core/Metrics/ScrapeDefinitionBatchPropertiesTest.cs +++ b/src/Promitor.Tests.Unit/Core/Metrics/ScrapeDefinitionBatchPropertiesTest.cs @@ -31,6 +31,14 @@ public class ScrapeDefinitionBatchPropertiesTest Type = PromitorMetricAggregationType.Average }, }; + private readonly static LogAnalyticsConfigurationV1 _logAnalyticsConfigurationBase = new LogAnalyticsConfigurationV1 + { + Query = "A eq B", + Aggregation = new AggregationV1 + { + Interval = TimeSpan.FromMinutes(60) + }, + }; private readonly static ScrapingV1 _scrapingBase = new ScrapingV1 { Schedule = "5 4 3 2 1" @@ -46,9 +54,11 @@ public ScrapeDefinitionBatchPropertiesTest() public void BuildBatchHashKeySameResultNoDimensions() { var azureMetricConfiguration = _mapper.Map(_azureMetricConfigurationBase); + var logAnalyticsConfiguration = _mapper.Map(_logAnalyticsConfigurationBase); + var scraping = _mapper.Map(_scrapingBase); - var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); - var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); + var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); + var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); var hashCode1 = batchProperties.GetHashCode(); var hashCode2 = batchProperties2.GetHashCode(); @@ -60,11 +70,12 @@ public void BuildBatchHashKeySameResultIdenticalDimensions() { var azureMetricConfiguration = _mapper.Map(_azureMetricConfigurationBase); azureMetricConfiguration.Dimensions = [new MetricDimension{Name = "Dimension1"}, new MetricDimension{Name = "Dimension2"}]; + var logAnalyticsConfiguration = _mapper.Map(_logAnalyticsConfigurationBase); var scraping = _mapper.Map(_scrapingBase); - var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); - var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); + var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); + var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); var hashCode1 = batchProperties.GetHashCode(); var hashCode2 = batchProperties2.GetHashCode(); @@ -78,11 +89,12 @@ public void BuildBatchHashKeyDifferentResultDifferentDimensions() azureMetricConfiguration1.Dimensions = [new MetricDimension{Name = "Dimension1"}, new MetricDimension{Name = "Dimension2"}]; var azureMetricConfiguration2 = _mapper.Map(_azureMetricConfigurationBase); azureMetricConfiguration2.Dimensions = [new MetricDimension{Name = "DiffDimension1"}, new MetricDimension{Name = "DiffDimension2"}]; + var logAnalyticsConfiguration = _mapper.Map(_logAnalyticsConfigurationBase); var scraping = _mapper.Map(_scrapingBase); - var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration1, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); - var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration2, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); + var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration1, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); + var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration2, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); var hashCode1 = batchProperties.GetHashCode(); var hashCode2 = batchProperties2.GetHashCode(); @@ -92,16 +104,17 @@ public void BuildBatchHashKeyDifferentResultDifferentDimensions() [Fact] public void BuildBatchHashKeyDifferentResultDifferentMetricName() { - var azureMetricConfiguration1 = _mapper.Map(_azureMetricConfigurationBase); + var azureMetricConfiguration1 = _mapper.Map(_azureMetricConfigurationBase); azureMetricConfiguration1.Dimensions = [new MetricDimension{Name = "Dimension1"}, new MetricDimension{Name = "Dimension2"}]; var azureMetricConfiguration2 = _mapper.Map(_azureMetricConfigurationBase); azureMetricConfiguration2.Dimensions = [new MetricDimension{Name = "Dimension1"}, new MetricDimension{Name = "Dimension2"}]; azureMetricConfiguration2.MetricName = "diffName"; + var logAnalyticsConfiguration = _mapper.Map(_logAnalyticsConfigurationBase); var scraping = _mapper.Map(_scrapingBase); - var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration1, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); - var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration2, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); + var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration1, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); + var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration2, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); var hashCode1 = batchProperties.GetHashCode(); var hashCode2 = batchProperties2.GetHashCode(); @@ -113,9 +126,11 @@ public void BuildBatchHashKeyDifferentResultDifferentSubscription() { var azureMetricConfiguration = _mapper.Map(_azureMetricConfigurationBase); var scraping = _mapper.Map(_scrapingBase); + var logAnalyticsConfiguration = _mapper.Map(_logAnalyticsConfigurationBase); - var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); - var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: "subscription2"); + + var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); + var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: "subscription2"); var hashCode1 = batchProperties.GetHashCode(); var hashCode2 = batchProperties2.GetHashCode(); @@ -127,9 +142,10 @@ public void BuildBatchHashKeyDifferentResultDifferentResourceType() { var azureMetricConfiguration = _mapper.Map(_azureMetricConfigurationBase); var scraping = _mapper.Map(_scrapingBase); + var logAnalyticsConfiguration = _mapper.Map(_logAnalyticsConfigurationBase); - var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); - var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.LoadBalancer, scraping: scraping, subscriptionId: "subscription2"); + var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: _subscriptionId); + var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.LoadBalancer, scraping: scraping, subscriptionId: "subscription2"); var hashCode1 = batchProperties.GetHashCode(); var hashCode2 = batchProperties2.GetHashCode(); @@ -143,9 +159,11 @@ public void BuildBatchHashKeyDifferentResultDifferentSchedule() var scraping1 = _mapper.Map(_scrapingBase); var scraping2 = _mapper.Map(_scrapingBase); scraping2.Schedule = "6 4 3 2 1"; + var logAnalyticsConfiguration = _mapper.Map(_logAnalyticsConfigurationBase); + - var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping1, subscriptionId: _subscriptionId); - var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping2, subscriptionId: "subscription2"); + var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping1, subscriptionId: _subscriptionId); + var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping2, subscriptionId: "subscription2"); var hashCode1 = batchProperties.GetHashCode(); var hashCode2 = batchProperties2.GetHashCode(); diff --git a/src/Promitor.Tests.Unit/Core/Scraping/Batching/AzureResourceDefinitionBatchingTests.cs b/src/Promitor.Tests.Unit/Core/Scraping/Batching/AzureResourceDefinitionBatchingTests.cs index 0fa11d051..f552f26f6 100644 --- a/src/Promitor.Tests.Unit/Core/Scraping/Batching/AzureResourceDefinitionBatchingTests.cs +++ b/src/Promitor.Tests.Unit/Core/Scraping/Batching/AzureResourceDefinitionBatchingTests.cs @@ -30,6 +30,14 @@ public class AzureResourceDefinitionBatchingTests Type = PromitorMetricAggregationType.Average }, }; + private readonly static LogAnalyticsConfigurationV1 _logAnalyticsConfigurationBase = new LogAnalyticsConfigurationV1 + { + Query = "A eq B", + Aggregation = new AggregationV1 + { + Interval = TimeSpan.FromMinutes(60) + }, + }; private readonly static ScrapingV1 _scrapingBase = new ScrapingV1 { Schedule = "5 4 3 2 1" @@ -48,7 +56,7 @@ public void IdenticalBatchPropertiesShouldBatchTogether() { var azureMetricConfiguration = _mapper.Map(_azureMetricConfigurationBase); var scraping = _mapper.Map(_scrapingBase); - var logAnalyticsConfiguration = new LogAnalyticsConfiguration(); + var logAnalyticsConfiguration = _mapper.Map(_logAnalyticsConfigurationBase); var scrapeDefinitions = BuildScrapeDefinitionBatch( azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, scraping: scraping, resourceType: ResourceType.StorageAccount, subscriptionId: _subscriptionId, resourceGroupName: _resourceGroupName, 10 @@ -63,8 +71,9 @@ public void IdenticalBatchPropertiesShouldBatchTogether() public void BatchShouldSplitAccordingToConfiguredBatchSize() { var azureMetricConfiguration = _mapper.Map(_azureMetricConfigurationBase); + var logAnalyticsConfiguration = _mapper.Map(_logAnalyticsConfigurationBase); + var scraping = _mapper.Map(_scrapingBase); - var logAnalyticsConfiguration = new LogAnalyticsConfiguration(); var scrapeDefinitions = BuildScrapeDefinitionBatch( azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, scraping: scraping, resourceType: ResourceType.StorageAccount, subscriptionId: _subscriptionId, resourceGroupName: _resourceGroupName, 130 @@ -80,7 +89,7 @@ public void DifferentBatchPropertiesShouldBatchSeparately() { var azureMetricConfiguration = _mapper.Map(_azureMetricConfigurationBase); var scraping = _mapper.Map(_scrapingBase); - var logAnalyticsConfiguration = new LogAnalyticsConfiguration(); + var logAnalyticsConfiguration = _mapper.Map(_logAnalyticsConfigurationBase); var scrapeDefinitions = BuildScrapeDefinitionBatch( azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, scraping: scraping, resourceType: ResourceType.StorageAccount, subscriptionId: _subscriptionId, resourceGroupName: _resourceGroupName, 10 @@ -103,8 +112,8 @@ public void DifferentAggregationIntervalsShouldBatchSeparately() azureMetricConfiguration5mInterval.Aggregation.Interval = TimeSpan.FromMinutes(5); var azureMetricConfiguration2mInterval = _mapper.Map(_azureMetricConfigurationBase); azureMetricConfiguration5mInterval.Aggregation.Interval = TimeSpan.FromMinutes(2); + var logAnalyticsConfiguration = _mapper.Map(_logAnalyticsConfigurationBase); var scraping = _mapper.Map(_scrapingBase); - var logAnalyticsConfiguration = new LogAnalyticsConfiguration(); var scrapeDefinitions5m = BuildScrapeDefinitionBatch( azureMetricConfiguration: azureMetricConfiguration5mInterval, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: _prometheusMetricDefinition, scraping: scraping, resourceType: ResourceType.StorageAccount, subscriptionId: _subscriptionId, resourceGroupName: _resourceGroupName, 10