-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update runtime model to support multiple resources per metric (#666)
* Alter MetricDefinition to allow multiple resources I've updated `MetricDefinition` to support multiple resources so that we can define a single prometheus metric that is used to store the values for multiple Azure resources. In order to do this, I've changed `MetricDefinition` so that it doesn't describe an Azure resource anymore, and created `AzureResourceDefinition` to be the base class for each resource type. I've also created a `PrometheusMetricDefinition` class to contain the details of the prometheus metric being defined. In addition, I've added a new class, `ScrapeDefinition`, that describes a single Azure resource being scraped. This is used in the places where `MetricDefinition` would have been used previously as part of scraping. * Convert MetricDefinition implementations - Updated all the `MetricDefinition` implementations to inherit from `AzureResourceDefinition` instead. * Update scrapers I've updated the scraper implementations to work with the new MetricDefinition format. I couldn't come up with a neat way of making MetricDefinition generic without ending up with a nightmare, so for now what I've done is altered the signature of `ScrapeResourceAsync` to accept both the `ScrapeDefinition` object, as well as the `AzureResourceDefinition` cast to the correct type for the subclass. * Update plumbing code Updated a couple of the objects used to configure the scraping to handle multiple resources per metric. * Update validation objects - Removed the `MetricValidator` abstract class because it doesn't add anything now that we can't cast the `MetricDefinition` to a specific resource type. - Updated the validators to validate all the resources in the metric definition. * Update unit tests to handle new MetricDefinition - Updating `MetricsDeclarationBuilder` to use v1 Builder objects instead of the model objects. - Updating the tests to handle the fact that a `MetricDefinition` isn't a resource anymore. * Rename AzureResourceDefinition subclasses When I was making the initial set of changes, I didn't want to make too many changes at once, so I held off on renaming the subclasses of `AzureResourceDefinition`. This change renames them all from `{Type}MetricDefinition` to `{Type}ResourceDefinition` to make it clearer what they are. * Populate MetricsDeclarationBuilder.Version I realised that the Version property wasn't being populated on either the model object or the serialization object. I've removed it from the model object since it isn't versioned. I've also updated the v1 ConfigurationSerializer to just set the version to `v1` since it only handles the v1 format. * fixup! Populate MetricsDeclarationBuilder.Version * fixup! Populate MetricsDeclarationBuilder.Version
- Loading branch information
1 parent
b437697
commit 6d67d5a
Showing
73 changed files
with
840 additions
and
564 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/Promitor.Core.Scraping/Configuration/Model/Metrics/AzureResourceDefinition.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,26 @@ | ||
namespace Promitor.Core.Scraping.Configuration.Model.Metrics | ||
{ | ||
/// <summary> | ||
/// Describes a resource in Azure that can be scraped. Inheriting classes can add whatever | ||
/// additional information is required to scrape a particular Azure resource. | ||
/// </summary> | ||
public abstract class AzureResourceDefinition | ||
{ | ||
protected AzureResourceDefinition(ResourceType resourceType, string resourceGroupName) | ||
{ | ||
ResourceType = resourceType; | ||
ResourceGroupName = resourceGroupName; | ||
} | ||
|
||
/// <summary> | ||
/// Type of resource that is configured | ||
/// </summary> | ||
public ResourceType ResourceType { get; } | ||
|
||
/// <summary> | ||
/// Specify a resource group to scrape that defers from the default resource group. | ||
/// This enables you to do multi-resource group scraping with one configuration file. | ||
/// </summary> | ||
public string ResourceGroupName { 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
41 changes: 41 additions & 0 deletions
41
src/Promitor.Core.Scraping/Configuration/Model/Metrics/PrometheusMetricDefinition.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,41 @@ | ||
using System.Collections.Generic; | ||
using GuardNet; | ||
|
||
namespace Promitor.Core.Scraping.Configuration.Model.Metrics | ||
{ | ||
/// <summary> | ||
/// Contains the details of the prometheus metric that will be created. | ||
/// </summary> | ||
public class PrometheusMetricDefinition | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PrometheusMetricDefinition"/> class. | ||
/// </summary> | ||
/// <param name="name">Name of the metric to use when exposing in the scraping endpoint.</param> | ||
/// <param name="description">Description concerning metric that will be made available in the scraping endpoint.</param> | ||
/// <param name="labels">Collection of custom labels to add to every metric.</param> | ||
public PrometheusMetricDefinition(string name, string description, Dictionary<string, string> labels) | ||
{ | ||
Guard.NotNull(labels, nameof(labels)); | ||
|
||
Name = name; | ||
Description = description; | ||
Labels = labels; | ||
} | ||
|
||
/// <summary> | ||
/// Name of the metric to use when exposing in the scraping endpoint | ||
/// </summary> | ||
public string Name { get; } | ||
|
||
/// <summary> | ||
/// Description concerning metric that will be made available in the scraping endpoint | ||
/// </summary> | ||
public string Description { get; } | ||
|
||
/// <summary> | ||
/// Collection of custom labels to add to every metric | ||
/// </summary> | ||
public Dictionary<string, string> Labels { get; } | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
...e.Scraping/Configuration/Model/Metrics/ResourceTypes/ContainerInstanceMetricDefinition.cs
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
...Scraping/Configuration/Model/Metrics/ResourceTypes/ContainerInstanceResourceDefinition.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.Model.Metrics.ResourceTypes | ||
{ | ||
public class ContainerInstanceResourceDefinition : AzureResourceDefinition | ||
{ | ||
public ContainerInstanceResourceDefinition(string resourceGroupName, string containerGroup) | ||
: base(ResourceType.ContainerInstance, resourceGroupName) | ||
{ | ||
ContainerGroup = containerGroup; | ||
} | ||
|
||
public string ContainerGroup { get; } | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
...e.Scraping/Configuration/Model/Metrics/ResourceTypes/ContainerRegistryMetricDefinition.cs
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
...Scraping/Configuration/Model/Metrics/ResourceTypes/ContainerRegistryResourceDefinition.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.Model.Metrics.ResourceTypes | ||
{ | ||
public class ContainerRegistryResourceDefinition : AzureResourceDefinition | ||
{ | ||
public ContainerRegistryResourceDefinition(string resourceGroupName, string registryName) | ||
: base(ResourceType.ContainerRegistry, resourceGroupName) | ||
{ | ||
RegistryName = registryName; | ||
} | ||
|
||
public string RegistryName { get; } | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
...mitor.Core.Scraping/Configuration/Model/Metrics/ResourceTypes/CosmosDbMetricDefinition.cs
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
...tor.Core.Scraping/Configuration/Model/Metrics/ResourceTypes/CosmosDbResourceDefinition.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.Model.Metrics.ResourceTypes | ||
{ | ||
public class CosmosDbResourceDefinition : AzureResourceDefinition | ||
{ | ||
public CosmosDbResourceDefinition(string resourceGroupName, string dbName) | ||
: base(ResourceType.CosmosDb, resourceGroupName) | ||
{ | ||
DbName = dbName; | ||
} | ||
|
||
public string DbName { get; } | ||
} | ||
} |
22 changes: 0 additions & 22 deletions
22
...r.Core.Scraping/Configuration/Model/Metrics/ResourceTypes/GenericAzureMetricDefinition.cs
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
...Core.Scraping/Configuration/Model/Metrics/ResourceTypes/GenericAzureResourceDefinition.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,15 @@ | ||
namespace Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes | ||
{ | ||
public class GenericAzureResourceDefinition : AzureResourceDefinition | ||
{ | ||
public GenericAzureResourceDefinition(string resourceGroupName, string filter, string resourceUri) | ||
: base(ResourceType.Generic, resourceGroupName) | ||
{ | ||
Filter = filter; | ||
ResourceUri = resourceUri; | ||
} | ||
|
||
public string Filter { get; } | ||
public string ResourceUri { get; } | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
...re.Scraping/Configuration/Model/Metrics/ResourceTypes/NetworkInterfaceMetricDefinition.cs
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
....Scraping/Configuration/Model/Metrics/ResourceTypes/NetworkInterfaceResourceDefinition.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.Model.Metrics.ResourceTypes | ||
{ | ||
public class NetworkInterfaceResourceDefinition : AzureResourceDefinition | ||
{ | ||
public NetworkInterfaceResourceDefinition(string resourceGroupName, string networkInterfaceName) | ||
: base(ResourceType.NetworkInterface, resourceGroupName) | ||
{ | ||
NetworkInterfaceName = networkInterfaceName; | ||
} | ||
|
||
public string NetworkInterfaceName { get; } | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
...tor.Core.Scraping/Configuration/Model/Metrics/ResourceTypes/PostgreSqlMetricDefinition.cs
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
...r.Core.Scraping/Configuration/Model/Metrics/ResourceTypes/PostgreSqlResourceDefinition.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.Model.Metrics.ResourceTypes | ||
{ | ||
public class PostgreSqlResourceDefinition : AzureResourceDefinition | ||
{ | ||
public PostgreSqlResourceDefinition(string resourceGroupName, string serverName) | ||
: base(ResourceType.PostgreSql, resourceGroupName) | ||
{ | ||
ServerName = serverName; | ||
} | ||
|
||
public string ServerName { get; } | ||
} | ||
} |
Oops, something went wrong.