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,30 @@
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)
{
}

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; set; }
adamconnelly marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,59 @@

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>
/// Configuration about the Azure Monitor metric to scrape
/// </summary>
public AzureMetricConfiguration AzureMetricConfiguration { get; set; }

/// <summary>
/// Description concerning metric that will be made available in the scraping endpoint
/// </summary>
public string Description { get; set; }

/// <summary>
/// Name of the metric to use when exposing in the scraping endpoint
/// </summary>
public string Name { get; set; }
public PrometheusMetricDefinition PrometheusMetricDefinition { get; set; }

/// <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.
/// Gets or sets the scraping model.
/// </summary>
public string ResourceGroupName { get; set; }
public Scraping Scraping { get; set; } = new Scraping();

/// <summary>
/// Type of resource that is configured
/// Type of resource that is configured
/// </summary>
public abstract ResourceType ResourceType { get; }
public ResourceType ResourceType { get; set; }

/// <summary>
/// Collection of custom labels to add to every metric
/// Gets or sets the list of resources to scrape.
/// </summary>
public Dictionary<string, string> Labels { get; set; } = new Dictionary<string, string>();
public List<AzureResourceDefinition> Resources { get; set; }

/// <summary>
/// Gets or sets the scraping model.
/// Creates a <see cref="ScrapeDefinition{TResourceDefinition}"/> object for the specified resource.
/// </summary>
public Scraping Scraping { get; set; } = new Scraping();
/// <param name="resource">The resource to scrape.</param>
/// <returns>The scrape definition.</returns>
public ScrapeDefinition<AzureResourceDefinition> CreateScrapeDefinition(AzureResourceDefinition resource)
{
return new ScrapeDefinition<AzureResourceDefinition>(
AzureMetricConfiguration,
PrometheusMetricDefinition,
Scraping,
resource);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;

namespace Promitor.Core.Scraping.Configuration.Model.Metrics
{
public class PrometheusMetricDefinition
{
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
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,17 @@
namespace Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes
{
public class ContainerInstanceResourceDefinition : AzureResourceDefinition
{
public ContainerInstanceResourceDefinition() : base(ResourceType.ContainerInstance)
{
}

public ContainerInstanceResourceDefinition(string resourceGroupName, string containerGroup)
: base(ResourceType.ContainerInstance, resourceGroupName)
{
ContainerGroup = containerGroup;
}

public string ContainerGroup { get; set; }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes
{
public class ContainerRegistryResourceDefinition : AzureResourceDefinition
{
public ContainerRegistryResourceDefinition() : base(ResourceType.ContainerRegistry)
adamconnelly marked this conversation as resolved.
Show resolved Hide resolved
{
}

public ContainerRegistryResourceDefinition(string resourceGroupName, string registryName)
: base(ResourceType.ContainerRegistry, resourceGroupName)
{
RegistryName = registryName;
}

public string RegistryName { get; set; }
adamconnelly marked this conversation as resolved.
Show resolved Hide resolved
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes
{
public class CosmosDbResourceDefinition : AzureResourceDefinition
{
public CosmosDbResourceDefinition() : base(ResourceType.CosmosDb)
{
}

public CosmosDbResourceDefinition(string resourceGroupName, string dbName)
: base(ResourceType.CosmosDb, resourceGroupName)
{
DbName = dbName;
}

public string DbName { get; set; }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes
{
public class GenericAzureResourceDefinition : AzureResourceDefinition
{
public GenericAzureResourceDefinition() : base(ResourceType.Generic)
{
}

public GenericAzureResourceDefinition(string resourceGroupName, string filter, string resourceUri)
: base(ResourceType.Generic, resourceGroupName)
{
Filter = filter;
ResourceUri = resourceUri;
}

public string Filter { get; set; }
public string ResourceUri { get; set; }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes
{
public class NetworkInterfaceResourceDefinition : AzureResourceDefinition
{
public NetworkInterfaceResourceDefinition() : base(ResourceType.NetworkInterface)
{
}

public NetworkInterfaceResourceDefinition(string resourceGroupName, string networkInterfaceName)
: base(ResourceType.NetworkInterface, resourceGroupName)
{
NetworkInterfaceName = networkInterfaceName;
}

public string NetworkInterfaceName { get; set; }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes
{
public class PostgreSqlResourceDefinition : AzureResourceDefinition
{
public PostgreSqlResourceDefinition() : base(ResourceType.PostgreSql)
{
}

public PostgreSqlResourceDefinition(string resourceGroupName, string serverName)
: base(ResourceType.PostgreSql, resourceGroupName)
{
ServerName = serverName;
}

public string ServerName { get; set; }
}
}
Loading