-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Provide scraper for Azure Monitor Autoscale (#1624)
* Serialization Signed-off-by: Tom Kerkhove <[email protected]> * Provide scraping Signed-off-by: Tom Kerkhove <[email protected]> * Docs Signed-off-by: Tom Kerkhove <[email protected]>
- Loading branch information
1 parent
c8ddeed
commit fd9807c
Showing
22 changed files
with
423 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
layout: default | ||
title: Azure Monitor Autoscale Declaration | ||
--- | ||
|
||
## Azure Monitor Autoscale | ||
|
||
![Availability Badge](https://img.shields.io/badge/Available%20Starting-v2.3-green.svg)![Resource Discovery Support Badge](https://img.shields.io/badge/Support%20for%20Resource%20Discovery-Yes-green.svg) | ||
|
||
You can declare to scrape an Azure Monitor Autoscale via the `MonitorAutoscale` | ||
resource type. | ||
|
||
When using declared resources, the following fields need to be provided: | ||
|
||
- `autoscaleSettingsName` - The name of the Azure Monitor Autoscale settings | ||
|
||
All supported metrics are documented in the official [Azure Monitor documentation](https://docs.microsoft.com/en-us/azure/azure-monitor/essentials/metrics-supported#microsoftinsightsautoscalesettings). | ||
|
||
Example: | ||
|
||
```yaml | ||
- name: promitor_demo_appplan_autoscale_observed_capacity | ||
description: "Average amount of current instances for an Azure App Plan with Azure Monitor Autoscale" | ||
resourceType: MonitorAutoscale | ||
labels: | ||
app: promitor | ||
azureMetricConfiguration: | ||
metricName: ObservedCapacity | ||
aggregation: | ||
type: Average | ||
resources: # Optional, required when no resource discovery is configured | ||
- autoscaleSettingsName: app-service-autoscaling-rules | ||
resourceDiscoveryGroups: # Optional, requires Promitor Resource Discovery agent (https://promitor.io/concepts/how-it-works#using-resource-discovery) | ||
- name: autoscaling-rules | ||
``` | ||
<!-- markdownlint-disable MD033 --> | ||
[← back to metrics declarations](/configuration/v2.x/metrics)<br /> | ||
[← back to introduction](/) | ||
<!-- markdownlint-enable --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Promitor.Agents.ResourceDiscovery/Graph/ResourceTypes/MonitorAutoscaleDiscoveryQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using GuardNet; | ||
using Newtonsoft.Json.Linq; | ||
using Promitor.Core.Contracts; | ||
using Promitor.Core.Contracts.ResourceTypes; | ||
|
||
namespace Promitor.Agents.ResourceDiscovery.Graph.ResourceTypes | ||
{ | ||
public class MonitorAutoscaleDiscoveryQuery : ResourceDiscoveryQuery | ||
{ | ||
public override string[] ResourceTypes => new[] { "microsoft.insights/autoscalesettings" }; | ||
public override string[] ProjectedFieldNames => new[] { "subscriptionId", "resourceGroup", "type", "name" }; | ||
|
||
public override AzureResourceDefinition ParseResults(JToken resultRowEntry) | ||
{ | ||
Guard.NotNull(resultRowEntry, nameof(resultRowEntry)); | ||
|
||
var autoscaleSettingsName = resultRowEntry[3]?.ToString(); | ||
|
||
var resource = new MonitorAutoscaleResourceDefinition(resultRowEntry[0]?.ToString(), resultRowEntry[1]?.ToString(), autoscaleSettingsName); | ||
return resource; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...nts.Scraper/Validation/MetricDefinitions/ResourceTypes/MonitorAutoscaleMetricValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using GuardNet; | ||
using Promitor.Core.Scraping.Configuration.Model.Metrics; | ||
using Promitor.Agents.Scraper.Validation.MetricDefinitions.Interfaces; | ||
using Promitor.Core.Contracts.ResourceTypes; | ||
|
||
namespace Promitor.Agents.Scraper.Validation.MetricDefinitions.ResourceTypes | ||
{ | ||
internal class MonitorAutoscaleMetricValidator : IMetricValidator | ||
{ | ||
public IEnumerable<string> Validate(MetricDefinition metricDefinition) | ||
{ | ||
Guard.NotNull(metricDefinition, nameof(metricDefinition)); | ||
|
||
foreach (var resourceDefinition in metricDefinition.Resources.Cast<MonitorAutoscaleResourceDefinition>()) | ||
{ | ||
if (string.IsNullOrWhiteSpace(resourceDefinition.AutoscaleSettingsName)) | ||
{ | ||
yield return "No Azure Monitor Autoscale settings name is configured"; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/Promitor.Core.Contracts/ResourceTypes/MonitorAutoscaleResourceDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Promitor.Core.Contracts.ResourceTypes | ||
{ | ||
public class MonitorAutoscaleResourceDefinition : AzureResourceDefinition | ||
{ | ||
public MonitorAutoscaleResourceDefinition(string subscriptionId, string resourceGroupName, string autoscaleSettingsName) | ||
: base(ResourceType.MonitorAutoscale, subscriptionId, resourceGroupName, autoscaleSettingsName) | ||
{ | ||
AutoscaleSettingsName = autoscaleSettingsName; | ||
} | ||
|
||
public string AutoscaleSettingsName { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...Scraping/Configuration/Serialization/v1/Model/ResourceTypes/MonitorAutoscaleResourceV1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes | ||
{ | ||
/// <summary> | ||
/// Contains the configuration required to scrape an Azure Monitor Autoscale settings. | ||
/// </summary> | ||
public class MonitorAutoscaleResourceV1 : AzureResourceDefinitionV1 | ||
{ | ||
/// <summary> | ||
/// The name of the Azure Monitor Autoscale settings to get metrics for. | ||
/// </summary> | ||
public string AutoscaleSettingsName { get; set; } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...or.Core.Scraping/Configuration/Serialization/v1/Providers/MonitorAutoscaleDeserializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes; | ||
|
||
namespace Promitor.Core.Scraping.Configuration.Serialization.v1.Providers | ||
{ | ||
public class MonitorAutoscaleDeserializer : ResourceDeserializer<MonitorAutoscaleResourceV1> | ||
{ | ||
public MonitorAutoscaleDeserializer(ILogger<MonitorAutoscaleDeserializer> logger) : base(logger) | ||
{ | ||
Map(resource => resource.AutoscaleSettingsName) | ||
.IsRequired(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/Promitor.Core.Scraping/ResourceTypes/MonitorAutoscaleScraper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Promitor.Core.Contracts; | ||
using Promitor.Core.Contracts.ResourceTypes; | ||
using Promitor.Core.Scraping.Configuration.Model.Metrics; | ||
|
||
namespace Promitor.Core.Scraping.ResourceTypes | ||
{ | ||
internal class MonitorAutoscaleScraper : AzureMonitorScraper<MonitorAutoscaleResourceDefinition> | ||
{ | ||
private const string ResourceUriTemplate = "subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Insights/autoscalesettings/{2}"; | ||
|
||
public MonitorAutoscaleScraper(ScraperConfiguration scraperConfiguration) | ||
: base(scraperConfiguration) | ||
{ | ||
} | ||
|
||
protected override string BuildResourceUri(string subscriptionId, ScrapeDefinition<IAzureResourceDefinition> scrapeDefinition, MonitorAutoscaleResourceDefinition resource) | ||
{ | ||
return string.Format(ResourceUriTemplate, subscriptionId, scrapeDefinition.ResourceGroupName, resource.AutoscaleSettingsName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/Promitor.Tests.Unit/Serialization/v1/Providers/MonitorAutoscaleDeserializerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.ComponentModel; | ||
using Promitor.Core.Scraping.Configuration.Serialization; | ||
using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; | ||
using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes; | ||
using Promitor.Core.Scraping.Configuration.Serialization.v1.Providers; | ||
using Xunit; | ||
|
||
namespace Promitor.Tests.Unit.Serialization.v1.Providers | ||
{ | ||
[Category("Unit")] | ||
public class MonitorAutoscaleDeserializerTests : ResourceDeserializerTest<MonitorAutoscaleDeserializer> | ||
{ | ||
private readonly MonitorAutoscaleDeserializer _deserializer; | ||
|
||
public MonitorAutoscaleDeserializerTests() | ||
{ | ||
_deserializer = new MonitorAutoscaleDeserializer(Logger); | ||
} | ||
|
||
[Fact] | ||
public void Deserialize_AutoscaleSettingsNameSupplied_SetsName() | ||
{ | ||
YamlAssert.PropertySet<MonitorAutoscaleResourceV1, AzureResourceDefinitionV1, string>( | ||
_deserializer, | ||
"autoscaleSettingsName: promitor-application-gateway", | ||
"promitor-application-gateway", | ||
r => r.AutoscaleSettingsName); | ||
} | ||
|
||
[Fact] | ||
public void Deserialize_AutoscaleSettingsNameNotSupplied_Null() | ||
{ | ||
YamlAssert.PropertyNull<MonitorAutoscaleResourceV1, AzureResourceDefinitionV1>( | ||
_deserializer, | ||
"resourceGroupName: promitor-group", | ||
r => r.AutoscaleSettingsName); | ||
} | ||
|
||
[Fact] | ||
public void Deserialize_AutoscaleSettingsNameNotSupplied_ReportsError() | ||
{ | ||
// Arrange | ||
var node = YamlUtils.CreateYamlNode("resourceGroupName: promitor-group"); | ||
|
||
// Act / Assert | ||
YamlAssert.ReportsErrorForProperty( | ||
_deserializer, | ||
node, | ||
"autoscaleSettingsName"); | ||
} | ||
|
||
protected override IDeserializer<AzureResourceDefinitionV1> CreateDeserializer() | ||
{ | ||
return new MonitorAutoscaleDeserializer(Logger); | ||
} | ||
} | ||
} |
Oops, something went wrong.