Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update runtime model to support multiple resources per metric #666

Merged
merged 10 commits into from
Aug 17, 2019
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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@

namespace Promitor.Core.Scraping.Configuration.Model.Metrics
{
public abstract class MetricDefinition
public class MetricDefinition
{
protected MetricDefinition()
public MetricDefinition()
{
}

protected MetricDefinition(string name,
string description,
string resourceGroupName,
Dictionary<string, string> labels,
Scraping scraping, AzureMetricConfiguration azureMetricConfiguration)
public MetricDefinition(PrometheusMetricDefinition prometheusMetricDefinition,
Scraping scraping,
AzureMetricConfiguration azureMetricConfiguration,
ResourceType resourceType,
List<AzureResourceDefinition> resources)
{
AzureMetricConfiguration = azureMetricConfiguration;
Description = description;
Name = name;
ResourceGroupName = resourceGroupName;
Labels = labels;
PrometheusMetricDefinition = prometheusMetricDefinition;
Scraping = scraping;
ResourceType = resourceType;
Resources = resources;
}

/// <summary>
Expand All @@ -28,34 +27,39 @@ protected MetricDefinition(string name,
public AzureMetricConfiguration AzureMetricConfiguration { get; set; }

/// <summary>
/// Description concerning metric that will be made available in the scraping endpoint
/// The details of the prometheus metric that will be created.
/// </summary>
public string Description { get; set; }
public PrometheusMetricDefinition PrometheusMetricDefinition { get; set; }

/// <summary>
/// Name of the metric to use when exposing in the scraping endpoint
/// Gets or sets the scraping model.
/// </summary>
public string Name { get; set; }
public Scraping Scraping { get; set; } = new Scraping();

/// <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.
/// Type of resource that is configured
/// </summary>
public string ResourceGroupName { get; set; }
public ResourceType ResourceType { get; set; }

/// <summary>
/// Type of resource that is configured
/// Gets or sets the list of resources to scrape.
/// </summary>
public abstract ResourceType ResourceType { get; }
public List<AzureResourceDefinition> Resources { get; set; }

/// <summary>
/// Collection of custom labels to add to every metric
/// Creates a <see cref="ScrapeDefinition{TResourceDefinition}"/> object for the specified resource.
/// </summary>
public Dictionary<string, string> Labels { get; set; } = new Dictionary<string, string>();

/// <summary>
/// Gets or sets the scraping model.
/// </summary>
public Scraping Scraping { get; set; } = new Scraping();
/// <param name="resource">The resource to scrape.</param>
/// <param name="azureMetadata">The Azure global metadata.</param>
/// <returns>The scrape definition.</returns>
public ScrapeDefinition<AzureResourceDefinition> CreateScrapeDefinition(AzureResourceDefinition resource, AzureMetadata azureMetadata)
{
return new ScrapeDefinition<AzureResourceDefinition>(
AzureMetricConfiguration,
PrometheusMetricDefinition,
Scraping,
resource,
string.IsNullOrEmpty(resource.ResourceGroupName) ? azureMetadata.ResourceGroupName : resource.ResourceGroupName);
}
}
}
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)
adamconnelly marked this conversation as resolved.
Show resolved Hide resolved
{
tomkerkhove marked this conversation as resolved.
Show resolved Hide resolved
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; }
}
}

This file was deleted.

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; }
}
}

This file was deleted.

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; }
}
}

This file was deleted.

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; }
}
}

This file was deleted.

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; }
}
}

This file was deleted.

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; }
}
}

This file was deleted.

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; }
}
}
Loading