-
-
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.
Provide support for scraping metrics for Azure SQL Managed Insta… (#811)
* Update docs & changelog Signed-off-by: Tom Kerkhove <[email protected]> * Update new scraper guide Signed-off-by: Tom Kerkhove <[email protected]> * Implement SQL Managed Instance scraper Signed-off-by: Tom Kerkhove <[email protected]>
- Loading branch information
1 parent
6c390c9
commit 66bc1c6
Showing
18 changed files
with
344 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
layout: default | ||
title: Azure SQL Managed Instance Declaration | ||
--- | ||
|
||
## Azure SQL Managed Instance - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.1-green.svg) | ||
|
||
You can scrape an Azure SQL Managed Instance via the `SqlManagedInstance` | ||
resource type. | ||
|
||
The following fields need to be provided: | ||
|
||
- `instanceName` - The name of the SQL Server instance. | ||
|
||
All supported metrics are documented in the official [Azure Monitor documentation](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftsqlmanagedinstances). | ||
|
||
Example: | ||
|
||
```yaml | ||
name: promitor_demo_azuresqlmanagedinstance_nodes | ||
description: "The amount of nodes for an Azure SQL Managed Instance." | ||
resourceType: SqlManagedInstance | ||
azureMetricConfiguration: | ||
metricName: virtual_core_count | ||
aggregation: | ||
type: Average | ||
resources: | ||
- instanceName: promitor-sql-managed-instance | ||
``` | ||
<!-- markdownlint-disable MD033 --> | ||
[← back to metrics declarations](/configuration/v1.x/metrics)<br /> | ||
[← back to introduction](/) | ||
<!-- markdownlint-enable --> |
24 changes: 24 additions & 0 deletions
24
...r.Core.Scraping/Configuration/Model/Metrics/ResourceTypes/SqlManagedInstanceDefinition.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,24 @@ | ||
namespace Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes | ||
{ | ||
/// <summary> | ||
/// Represents an Azure SQL Managed Instance resource. | ||
/// </summary> | ||
public class SqlManagedInstanceDefinition : AzureResourceDefinition | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SqlManagedInstanceDefinition" /> class. | ||
/// </summary> | ||
/// <param name="resourceGroupName">The name of the resource group the server is in.</param> | ||
/// <param name="instanceName">The name of the Azure SQL Managed Instance resource.</param> | ||
public SqlManagedInstanceDefinition(string resourceGroupName, string instanceName) | ||
: base(ResourceType.SqlManagedInstance, resourceGroupName) | ||
{ | ||
InstanceName = instanceName; | ||
} | ||
|
||
/// <summary> | ||
/// The name of the Azure SQL Managed Instance resource. | ||
/// </summary> | ||
public string InstanceName { 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
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
...raping/Configuration/Serialization/v1/Model/ResourceTypes/SqlManagedInstanceResourceV1.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> | ||
/// Represents an Azure SQL Managed Instance to scrape. | ||
/// </summary> | ||
public class SqlManagedInstanceResourceV1 : AzureResourceDefinitionV1 | ||
{ | ||
/// <summary> | ||
/// The name of the Azure SQL Managed Instance resource. | ||
/// </summary> | ||
public string InstanceName { get; set; } | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
....Core.Scraping/Configuration/Serialization/v1/Providers/SqlManagedInstanceDeserializer.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,31 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; | ||
using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTypes; | ||
using YamlDotNet.RepresentationModel; | ||
|
||
namespace Promitor.Core.Scraping.Configuration.Serialization.v1.Providers | ||
{ | ||
/// <summary> | ||
/// Used to deserialize a <see cref="SqlManagedInstanceDeserializer" /> resource. | ||
/// </summary> | ||
public class SqlManagedInstanceDeserializer : ResourceDeserializer | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SqlManagedInstanceDeserializer" /> class. | ||
/// </summary> | ||
/// <param name="logger">The logger.</param> | ||
public SqlManagedInstanceDeserializer(ILogger logger) : base(logger) | ||
{ | ||
} | ||
|
||
protected override AzureResourceDefinitionV1 DeserializeResource(YamlMappingNode node) | ||
{ | ||
var instanceName = node.GetString("instanceName"); | ||
|
||
return new SqlManagedInstanceResourceV1 | ||
{ | ||
InstanceName = instanceName | ||
}; | ||
} | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
src/Promitor.Core.Scraping/ResourceTypes/SqlManagedInstanceScraper.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,36 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Management.Monitor.Fluent.Models; | ||
using Promitor.Core.Scraping.Configuration.Model.Metrics; | ||
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes; | ||
|
||
namespace Promitor.Core.Scraping.ResourceTypes | ||
{ | ||
public class SqlManagedInstanceScraper : Scraper<SqlManagedInstanceDefinition> | ||
{ | ||
private const string ResourceUriTemplate = "subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/managedInstances/{2}"; | ||
|
||
/// <summary> | ||
/// Initializes an instance of the <see cref="SqlManagedInstanceScraper" /> class. | ||
/// </summary> | ||
/// <param name="scraperConfiguration">The scraper configuration</param> | ||
public SqlManagedInstanceScraper(ScraperConfiguration scraperConfiguration) : base(scraperConfiguration) | ||
{ | ||
} | ||
|
||
protected override async Task<ScrapeResult> ScrapeResourceAsync(string subscriptionId, ScrapeDefinition<AzureResourceDefinition> scrapeDefinition, SqlManagedInstanceDefinition resourceDefinition, AggregationType aggregationType, TimeSpan aggregationInterval) | ||
{ | ||
var resourceUri = string.Format( | ||
ResourceUriTemplate, | ||
AzureMetadata.SubscriptionId, | ||
scrapeDefinition.ResourceGroupName, | ||
resourceDefinition.InstanceName); | ||
|
||
var metricName = scrapeDefinition.AzureMetricConfiguration.MetricName; | ||
var dimensionName = scrapeDefinition.AzureMetricConfiguration.Dimension?.Name; | ||
var foundMetricValue = await AzureMonitorClient.QueryMetricAsync(metricName, dimensionName, aggregationType, aggregationInterval, resourceUri); | ||
|
||
return new ScrapeResult(subscriptionId, scrapeDefinition.ResourceGroupName, null, resourceUri, foundMetricValue); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
29 changes: 29 additions & 0 deletions
29
...aper.Host/Validation/MetricDefinitions/ResourceTypes/SqlManagedInstanceMetricValidator.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,29 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using GuardNet; | ||
using Promitor.Core.Scraping.Configuration.Model.Metrics; | ||
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes; | ||
using Promitor.Scraper.Host.Validation.MetricDefinitions.Interfaces; | ||
|
||
namespace Promitor.Scraper.Host.Validation.MetricDefinitions.ResourceTypes | ||
{ | ||
/// <summary> | ||
/// Validates <see cref="SqlManagedInstanceMetricValidator" /> objects. | ||
/// </summary> | ||
public class SqlManagedInstanceMetricValidator : IMetricValidator | ||
{ | ||
/// <inheritdoc /> | ||
public IEnumerable<string> Validate(MetricDefinition metricDefinition) | ||
{ | ||
Guard.NotNull(metricDefinition, nameof(metricDefinition)); | ||
|
||
foreach (var definition in metricDefinition.Resources.Cast<SqlManagedInstanceDefinition>()) | ||
{ | ||
if (string.IsNullOrWhiteSpace(definition.InstanceName)) | ||
{ | ||
yield return "No instance 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
45 changes: 45 additions & 0 deletions
45
...itor.Scraper.Tests.Unit/Serialization/v1/Providers/SqlManagedInstanceDeserializerTests.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,45 @@ | ||
using System.ComponentModel; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
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.Scraper.Tests.Unit.Serialization.v1.Providers | ||
{ | ||
[Category("Unit")] | ||
public class SqlManagedInstanceDeserializerTests : ResourceDeserializerTest<SqlManagedInstanceDeserializer> | ||
{ | ||
private readonly SqlManagedInstanceDeserializer _deserializer; | ||
|
||
public SqlManagedInstanceDeserializerTests() | ||
{ | ||
_deserializer = new SqlManagedInstanceDeserializer(NullLogger.Instance); | ||
} | ||
|
||
[Fact] | ||
public void Deserialize_InstanceNameSupplied_SetsDatabaseName() | ||
{ | ||
YamlAssert.PropertySet<SqlManagedInstanceResourceV1, AzureResourceDefinitionV1, string>( | ||
_deserializer, | ||
"instanceName: promitor-instance", | ||
"promitor-instance", | ||
c => c.InstanceName); | ||
} | ||
|
||
[Fact] | ||
public void Deserialize_InstanceNameNotSupplied_Null() | ||
{ | ||
YamlAssert.PropertyNull<SqlManagedInstanceResourceV1, AzureResourceDefinitionV1>( | ||
_deserializer, | ||
"resourceGroupName: promitor-group", | ||
c => c.InstanceName); | ||
} | ||
|
||
protected override IDeserializer<AzureResourceDefinitionV1> CreateDeserializer() | ||
{ | ||
return new SqlDatabaseDeserializer(NullLogger.Instance); | ||
} | ||
} | ||
} |
Oops, something went wrong.