Skip to content

Commit

Permalink
Rename 'AzureSqlDatabase' scraper to 'SqlDatabase' (#766)
Browse files Browse the repository at this point in the history
* Rename in docs

* Rename codebase & tests

Signed-off-by: Tom Kerkhove <[email protected]>
  • Loading branch information
tomkerkhove authored Nov 15, 2019
1 parent fe698c5 commit 7c7a2e2
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion docs/configuration/v1.x/metrics/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ We also provide a simplified way to scrape the following Azure resources:
- [Azure Database for PostgreSQL](postgresql)
- [Azure Network Interface](network-interface)
- [Azure Service Bus Queue](service-bus-queue)
- [Azure SQL Database](azure-sql-database)
- [Azure SQL Database](sql-database)
- [Azure Storage Queue](storage-queue)
- [Azure Virtual Machine](virtual-machine)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Azure SQL Database Declaration

## Azure SQL Database - ![Availability Badge](https://img.shields.io/badge/Available%20Starting-v1.1.0-green.svg)

You can scrape an Azure SQL Database via the `AzureSqlDatabase` resource type.
You can scrape an Azure SQL Database via the `SqlDatabase` resource type.

The following fields need to be provided:

Expand All @@ -24,7 +24,7 @@ Example:
```yaml
name: azure_sql_database_dtu_consumption_percent
description: "The DTU consumption percentage used by an Azure SQL Database."
resourceType: AzureSqlDatabase
resourceType: SqlDatabase
azureMetricConfiguration:
metricName: dtu_consumption_percent
aggregation:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ namespace Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes
/// <summary>
/// Represents an Azure SQL Database resource.
/// </summary>
public class AzureSqlDatabaseResourceDefinition : AzureResourceDefinition
public class SqlDatabaseResourceDefinition : AzureResourceDefinition
{
/// <summary>
/// Initializes a new instance of the <see cref="AzureSqlDatabaseResourceDefinition" /> class.
/// Initializes a new instance of the <see cref="SqlDatabaseResourceDefinition" /> class.
/// </summary>
/// <param name="resourceGroupName">The name of the resource group the server is in.</param>
/// <param name="serverName">The name of the Azure SQL Server instance.</param>
/// <param name="databaseName">The name of the Azure SQL database name.</param>
public AzureSqlDatabaseResourceDefinition(string resourceGroupName, string serverName, string databaseName)
: base(ResourceType.AzureSqlDatabase, resourceGroupName)
public SqlDatabaseResourceDefinition(string resourceGroupName, string serverName, string databaseName)
: base(ResourceType.SqlDatabase, resourceGroupName)
{
ServerName = serverName;
DatabaseName = databaseName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public enum ResourceType
CosmosDb = 8,
RedisCache = 9,
PostgreSql = 10,
AzureSqlDatabase = 11
SqlDatabase = 11
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public IDeserializer<AzureResourceDefinitionV1> GetDeserializerFor(ResourceType
return new RedisCacheDeserializer(_logger);
case ResourceType.PostgreSql:
return new PostgreSqlDeserializer(_logger);
case ResourceType.AzureSqlDatabase:
return new AzureSqlDatabaseDeserializer(_logger);
case ResourceType.SqlDatabase:
return new SqlDatabaseDeserializer(_logger);
default:
throw new ArgumentOutOfRangeException($"Resource Type {resourceType} not supported.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public V1MappingProfile()
.ForCtorParam("ns", o => o.MapFrom(s => s.Namespace));
CreateMap<StorageQueueResourceV1, StorageQueueResourceDefinition>();
CreateMap<VirtualMachineResourceV1, VirtualMachineResourceDefinition>();
CreateMap<AzureSqlDatabaseResourceV1, AzureSqlDatabaseResourceDefinition>();
CreateMap<SqlDatabaseResourceV1, SqlDatabaseResourceDefinition>();

CreateMap<MetricDefinitionV1, PrometheusMetricDefinition>();

Expand All @@ -49,7 +49,7 @@ public V1MappingProfile()
.Include<ServiceBusQueueResourceV1, ServiceBusQueueResourceDefinition>()
.Include<StorageQueueResourceV1, StorageQueueResourceDefinition>()
.Include<VirtualMachineResourceV1, VirtualMachineResourceDefinition>()
.Include<AzureSqlDatabaseResourceV1, AzureSqlDatabaseResourceDefinition>();
.Include<SqlDatabaseResourceV1, SqlDatabaseResourceDefinition>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Promitor.Core.Scraping.Configuration.Serialization.v1.Model.ResourceTy
/// <summary>
/// Represents an Azure SQL Database to scrape.
/// </summary>
public class AzureSqlDatabaseResourceV1 : AzureResourceDefinitionV1
public class SqlDatabaseResourceV1 : AzureResourceDefinitionV1
{
/// <summary>
/// The name of the SQL Server instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
namespace Promitor.Core.Scraping.Configuration.Serialization.v1.Providers
{
/// <summary>
/// Used to deserialize a <see cref="AzureSqlDatabaseResourceV1" /> resource.
/// Used to deserialize a <see cref="SqlDatabaseResourceV1" /> resource.
/// </summary>
public class AzureSqlDatabaseDeserializer : ResourceDeserializer
public class SqlDatabaseDeserializer : ResourceDeserializer
{
/// <summary>
/// Initializes a new instance of the <see cref="AzureSqlDatabaseDeserializer" /> class.
/// Initializes a new instance of the <see cref="SqlDatabaseDeserializer" /> class.
/// </summary>
/// <param name="logger">The logger.</param>
public AzureSqlDatabaseDeserializer(ILogger logger) : base(logger)
public SqlDatabaseDeserializer(ILogger logger) : base(logger)
{
}

Expand All @@ -23,7 +23,7 @@ protected override AzureResourceDefinitionV1 DeserializeResource(YamlMappingNode
var serverName = node.GetString("serverName");
var databaseName = node.GetString("databaseName");

return new AzureSqlDatabaseResourceV1
return new SqlDatabaseResourceV1
{
ServerName = serverName,
DatabaseName = databaseName
Expand Down
4 changes: 2 additions & 2 deletions src/Promitor.Core.Scraping/Factories/MetricScraperFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public IScraper<AzureResourceDefinition> CreateScraper(ResourceType metricDefini
return new RedisCacheScraper(scraperConfiguration);
case ResourceType.PostgreSql:
return new PostgreSqlScraper(scraperConfiguration);
case ResourceType.AzureSqlDatabase:
return new AzureSqlDatabaseScraper(scraperConfiguration);
case ResourceType.SqlDatabase:
return new SqlDatabaseScraper(scraperConfiguration);
default:
throw new ArgumentOutOfRangeException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ namespace Promitor.Core.Scraping.ResourceTypes
/// <summary>
/// Scrapes an Azure SQL Database.
/// </summary>
public class AzureSqlDatabaseScraper : Scraper<AzureSqlDatabaseResourceDefinition>
public class SqlDatabaseScraper : Scraper<SqlDatabaseResourceDefinition>
{
private const string ResourceUriTemplate = "subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/servers/{2}/databases/{3}";

/// <summary>
/// Initializes an instance of the <see cref="AzureSqlDatabaseScraper" /> class.
/// Initializes an instance of the <see cref="SqlDatabaseScraper" /> class.
/// </summary>
/// <param name="scraperConfiguration">The scraper configuration</param>
public AzureSqlDatabaseScraper(ScraperConfiguration scraperConfiguration)
public SqlDatabaseScraper(ScraperConfiguration scraperConfiguration)
: base(scraperConfiguration)
{
}

protected override async Task<ScrapeResult> ScrapeResourceAsync(string subscriptionId, ScrapeDefinition<AzureResourceDefinition> scrapeDefinition, AzureSqlDatabaseResourceDefinition resource, AggregationType aggregationType, TimeSpan aggregationInterval)
protected override async Task<ScrapeResult> ScrapeResourceAsync(string subscriptionId, ScrapeDefinition<AzureResourceDefinition> scrapeDefinition, SqlDatabaseResourceDefinition resource, AggregationType aggregationType, TimeSpan aggregationInterval)
{
var resourceUri = string.Format(
ResourceUriTemplate,
Expand Down
6 changes: 3 additions & 3 deletions src/Promitor.Scraper.Host/Docs/Open-Api.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ internal static IMetricValidator GetValidatorFor(ResourceType resourceType)
return new RedisCacheMetricValidator();
case ResourceType.PostgreSql:
return new PostgreSqlMetricValidator();
case ResourceType.AzureSqlDatabase:
return new AzureSqlDatabaseMetricValidator();
case ResourceType.SqlDatabase:
return new SqlDatabaseMetricValidator();
}

throw new ArgumentOutOfRangeException(nameof(resourceType), $"No validation rules are defined for metric type '{resourceType}'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
namespace Promitor.Scraper.Host.Validation.MetricDefinitions.ResourceTypes
{
/// <summary>
/// Validates <see cref="AzureSqlDatabaseResourceDefinition" /> objects.
/// Validates <see cref="SqlDatabaseResourceDefinition" /> objects.
/// </summary>
public class AzureSqlDatabaseMetricValidator : IMetricValidator
public class SqlDatabaseMetricValidator : IMetricValidator
{
/// <inheritdoc />
public IEnumerable<string> Validate(MetricDefinition metricDefinition)
{
Guard.NotNull(metricDefinition, nameof(metricDefinition));

foreach (var definition in metricDefinition.Resources.Cast<AzureSqlDatabaseResourceDefinition>())
foreach (var definition in metricDefinition.Resources.Cast<SqlDatabaseResourceDefinition>())
{
if (string.IsNullOrWhiteSpace(definition.ServerName))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,15 @@ private AzureMetricConfigurationV1 CreateAzureMetricConfiguration(string azureMe
return this;
}

public MetricsDeclarationBuilder WithAzureSqlDatabaseMetric(
public MetricsDeclarationBuilder WithSqlDatabaseMetric(
string metricName = "promitor-sql-db",
string azureMetricName = "cpu_percent",
string serverName = "promitor-sql-server",
string databaseName = "promitor-db",
string metricDescription = "Metric description")
{
var azureMetricConfiguration = CreateAzureMetricConfiguration(azureMetricName);
var resource = new AzureSqlDatabaseResourceV1
var resource = new SqlDatabaseResourceV1
{
ServerName = serverName,
DatabaseName = databaseName
Expand All @@ -330,7 +330,7 @@ public MetricsDeclarationBuilder WithAzureSqlDatabaseMetric(
Description = metricDescription,
AzureMetricConfiguration = azureMetricConfiguration,
Resources = new List<AzureResourceDefinitionV1> {resource},
ResourceType = ResourceType.AzureSqlDatabase
ResourceType = ResourceType.SqlDatabase
};

_metrics.Add(metric);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
namespace Promitor.Scraper.Tests.Unit.Serialization.v1.Providers
{
[Category("Unit")]
public class AzureSqlDatabaseDeserializerTests : ResourceDeserializerTest
public class SqlDatabaseDeserializerTests : ResourceDeserializerTest
{
private readonly AzureSqlDatabaseDeserializer _deserializer;
private readonly SqlDatabaseDeserializer _deserializer;

public AzureSqlDatabaseDeserializerTests()
public SqlDatabaseDeserializerTests()
{
_deserializer = new AzureSqlDatabaseDeserializer(NullLogger.Instance);
_deserializer = new SqlDatabaseDeserializer(NullLogger.Instance);
}

[Fact]
public void Deserialize_ServerNameSupplied_SetsServerName()
{
YamlAssert.PropertySet<AzureSqlDatabaseResourceV1, AzureResourceDefinitionV1, string>(
YamlAssert.PropertySet<SqlDatabaseResourceV1, AzureResourceDefinitionV1, string>(
_deserializer,
"serverName: promitor-sql-server",
"promitor-sql-server",
Expand All @@ -31,7 +31,7 @@ public void Deserialize_ServerNameSupplied_SetsServerName()
[Fact]
public void Deserialize_ServerNameNotSupplied_Null()
{
YamlAssert.PropertyNull<AzureSqlDatabaseResourceV1, AzureResourceDefinitionV1>(
YamlAssert.PropertyNull<SqlDatabaseResourceV1, AzureResourceDefinitionV1>(
_deserializer,
"resourceGroupName: promitor-group",
c => c.ServerName);
Expand All @@ -40,7 +40,7 @@ public void Deserialize_ServerNameNotSupplied_Null()
[Fact]
public void Deserialize_DatabaseNameSupplied_SetsDatabaseName()
{
YamlAssert.PropertySet<AzureSqlDatabaseResourceV1, AzureResourceDefinitionV1, string>(
YamlAssert.PropertySet<SqlDatabaseResourceV1, AzureResourceDefinitionV1, string>(
_deserializer,
"databaseName: promitor-db",
"promitor-db",
Expand All @@ -50,15 +50,15 @@ public void Deserialize_DatabaseNameSupplied_SetsDatabaseName()
[Fact]
public void Deserialize_DatabaseNameNotSupplied_Null()
{
YamlAssert.PropertyNull<AzureSqlDatabaseResourceV1, AzureResourceDefinitionV1>(
YamlAssert.PropertyNull<SqlDatabaseResourceV1, AzureResourceDefinitionV1>(
_deserializer,
"resourceGroupName: promitor-group",
c => c.DatabaseName);
}

protected override IDeserializer<AzureResourceDefinitionV1> CreateDeserializer()
{
return new AzureSqlDatabaseDeserializer(NullLogger.Instance);
return new SqlDatabaseDeserializer(NullLogger.Instance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
namespace Promitor.Scraper.Tests.Unit.Validation.Metrics.ResourceTypes
{
[Category("Unit")]
public class AzureSqlDatabaseMetricsDeclarationValidationStepTests
public class SqlDatabaseMetricsDeclarationValidationStepTests
{
private readonly IMapper _mapper;

public AzureSqlDatabaseMetricsDeclarationValidationStepTests()
public SqlDatabaseMetricsDeclarationValidationStepTests()
{
var config = new MapperConfiguration(c => c.AddProfile<V1MappingProfile>());
_mapper = config.CreateMapper();
}

[Fact]
public void AzureSqlDatabaseMetricsDeclaration_DeclarationWithoutAzureMetricName_Fails()
public void SqlDatabaseMetricsDeclaration_DeclarationWithoutAzureMetricName_Fails()
{
// Arrange
var rawDeclaration = MetricsDeclarationBuilder.WithMetadata()
.WithAzureSqlDatabaseMetric(azureMetricName: string.Empty)
.WithSqlDatabaseMetric(azureMetricName: string.Empty)
.Build(_mapper);
var metricsDeclarationProvider = new MetricsDeclarationProviderStub(rawDeclaration, _mapper);

Expand All @@ -37,11 +37,11 @@ public void AzureSqlDatabaseMetricsDeclaration_DeclarationWithoutAzureMetricName
}

[Fact]
public void AzureSqlDatabaseMetricsDeclaration_DeclarationWithoutAzureMetricDescription_Succeeds()
public void SqlDatabaseMetricsDeclaration_DeclarationWithoutAzureMetricDescription_Succeeds()
{
// Arrange
var rawDeclaration = MetricsDeclarationBuilder.WithMetadata()
.WithAzureSqlDatabaseMetric(metricDescription: string.Empty)
.WithSqlDatabaseMetric(metricDescription: string.Empty)
.Build(_mapper);
var metricsDeclarationProvider = new MetricsDeclarationProviderStub(rawDeclaration, _mapper);

Expand All @@ -54,11 +54,11 @@ public void AzureSqlDatabaseMetricsDeclaration_DeclarationWithoutAzureMetricDesc
}

[Fact]
public void AzureSqlDatabaseMetricsDeclaration_DeclarationWithoutServerName_Fails()
public void SqlDatabaseMetricsDeclaration_DeclarationWithoutServerName_Fails()
{
// Arrange
var rawDeclaration = MetricsDeclarationBuilder.WithMetadata()
.WithAzureSqlDatabaseMetric(serverName: string.Empty)
.WithSqlDatabaseMetric(serverName: string.Empty)
.Build(_mapper);
var metricsDeclarationProvider = new MetricsDeclarationProviderStub(rawDeclaration, _mapper);

Expand All @@ -71,11 +71,11 @@ public void AzureSqlDatabaseMetricsDeclaration_DeclarationWithoutServerName_Fail
}

[Fact]
public void AzureSqlDatabaseMetricsDeclaration_DeclarationWithoutDatabaseName_Fails()
public void SqlDatabaseMetricsDeclaration_DeclarationWithoutDatabaseName_Fails()
{
// Arrange
var rawDeclaration = MetricsDeclarationBuilder.WithMetadata()
.WithAzureSqlDatabaseMetric(databaseName: string.Empty)
.WithSqlDatabaseMetric(databaseName: string.Empty)
.Build(_mapper);
var metricsDeclarationProvider = new MetricsDeclarationProviderStub(rawDeclaration, _mapper);

Expand Down

0 comments on commit 7c7a2e2

Please sign in to comment.