-
-
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 Container Registry scraper (#455)
Provide Container Registry scraper Closes #325 ### Configuration ```yaml azureMetadata: tenantId: c8819874-9e56-4e3f-b1a8-1c0325138f27 subscriptionId: 0f9d7fea-99e8-4768-8672-06a28514f77e resourceGroupName: promitor-sources metricDefaults: aggregation: interval: 01:00:00 metrics: - name: demo_generic_total_pull_count description: "Amount of images that were pulled from the container registry" resourceType: ContainerRegistry registryName: promitor azureMetricConfiguration: metricName: TotalPullCount aggregation: type: Average ``` ### Output ```yaml # HELP demo_generic_total_pull_count Amount of images that were pulled from the container registry # TYPE demo_generic_total_pull_count gauge demo_generic_total_pull_count 1 1553635305491 ``` ### Portal ![image](https://user-images.githubusercontent.com/4345663/55034449-b5015280-4fd2-11e9-8332-f10033d647dd.png)
- Loading branch information
1 parent
e347fc2
commit 71244fc
Showing
17 changed files
with
529 additions
and
155 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
layout: default | ||
title: Azure Container Registry Declaration | ||
--- | ||
|
||
## Azure Container Registry | ||
You can declare to scrape an Azure Container Registry via the `ContainerRegistry` resource type. | ||
|
||
The following fields need to be provided: | ||
- `containerGroup` - The name of the container group | ||
|
||
All supported metrics are not documented in the official [Azure Monitor documentation](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported) documentation yet, but it's being added via [this PR](https://github.com/MicrosoftDocs/azure-docs/pull/27991). | ||
|
||
Example: | ||
```yaml | ||
name: demo_container_registry_total_pull_count | ||
description: "Amount of images that were pulled from the container registry" | ||
resourceType: ContainerRegistry | ||
registryName: promitor | ||
azureMetricConfiguration: | ||
metricName: TotalPullCount | ||
aggregation: | ||
type: Average | ||
``` | ||
[← back to metrics declarations](/configuration/metrics)<br /> | ||
[← back to introduction](/) |
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
8 changes: 8 additions & 0 deletions
8
...e.Scraping/Configuration/Model/Metrics/ResourceTypes/ContainerRegistryMetricDefinition.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,8 @@ | ||
namespace Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes | ||
{ | ||
public class ContainerRegistryMetricDefinition : MetricDefinition | ||
{ | ||
public string RegistryName { get; set; } | ||
public override ResourceType ResourceType { get; } = ResourceType.ContainerRegistry; | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...Scraping/Configuration/Serialization/Deserializers/ContainerRegistryMetricDeserializer.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,22 @@ | ||
using Promitor.Core.Scraping.Configuration.Model.Metrics; | ||
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes; | ||
using YamlDotNet.RepresentationModel; | ||
|
||
namespace Promitor.Core.Scraping.Configuration.Serialization.Deserializers | ||
{ | ||
internal class ContainerRegistryMetricDeserializer : GenericAzureMetricDeserializer | ||
{ | ||
/// <summary>Deserializes the specified Container Registry metric node from the YAML configuration file.</summary> | ||
/// <param name="metricNode">The metric node to deserialize to Container Registry configuration</param> | ||
/// <returns>A new <see cref="MetricDefinition"/> object (strongly typed as a <see cref="ContainerRegistryMetricDefinition"/>) </returns> | ||
internal override MetricDefinition Deserialize(YamlMappingNode metricNode) | ||
{ | ||
var metricDefinition = base.DeserializeMetricDefinition<ContainerRegistryMetricDefinition>(metricNode); | ||
|
||
var registryName = metricNode.Children[new YamlScalarNode("registryName")]; | ||
metricDefinition.RegistryName = registryName?.ToString(); | ||
|
||
return metricDefinition; | ||
} | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/Promitor.Core.Scraping/ResourceTypes/ContainerRegistryScraper.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 System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Management.Monitor.Fluent.Models; | ||
using Microsoft.Extensions.Logging; | ||
using Promitor.Core.Scraping.Configuration.Model; | ||
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes; | ||
using Promitor.Core.Telemetry.Interfaces; | ||
using Promitor.Integrations.AzureMonitor; | ||
|
||
namespace Promitor.Core.Scraping.ResourceTypes | ||
{ | ||
public class ContainerRegistryScraper : Scraper<ContainerRegistryMetricDefinition> | ||
{ | ||
private const string ResourceUriTemplate = "subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.ContainerRegistry/registries/{2}"; | ||
|
||
public ContainerRegistryScraper(AzureMetadata azureMetadata, MetricDefaults metricDefaults, AzureMonitorClient azureMonitorClient, ILogger logger, IExceptionTracker exceptionTracker) | ||
: base(azureMetadata, metricDefaults, azureMonitorClient, logger, exceptionTracker) | ||
{ | ||
} | ||
|
||
protected override async Task<double> ScrapeResourceAsync(string subscriptionId, string resourceGroupName, ContainerRegistryMetricDefinition metricDefinition, AggregationType aggregationType, TimeSpan aggregationInterval) | ||
{ | ||
var resourceUri = string.Format(ResourceUriTemplate, subscriptionId, resourceGroupName, metricDefinition.RegistryName); | ||
|
||
var metricName = metricDefinition.AzureMetricConfiguration.MetricName; | ||
var foundMetricValue = await AzureMonitorClient.QueryMetricAsync(metricName, aggregationType, aggregationInterval, resourceUri); | ||
|
||
return 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
23 changes: 23 additions & 0 deletions
23
...raper.Host/Validation/MetricDefinitions/ResourceTypes/ContainerRegistryMetricValidator.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,23 @@ | ||
using System.Collections.Generic; | ||
using GuardNet; | ||
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes; | ||
|
||
namespace Promitor.Scraper.Host.Validation.MetricDefinitions.ResourceTypes | ||
{ | ||
internal class ContainerRegistryMetricValidator : MetricValidator<ContainerRegistryMetricDefinition> | ||
{ | ||
protected override IEnumerable<string> Validate(ContainerRegistryMetricDefinition containerRegistryMetricDefinition) | ||
{ | ||
Guard.NotNull(containerRegistryMetricDefinition, nameof(containerRegistryMetricDefinition)); | ||
|
||
var errorMessages = new List<string>(); | ||
|
||
if (string.IsNullOrWhiteSpace(containerRegistryMetricDefinition.RegistryName)) | ||
{ | ||
errorMessages.Add("No registry name is configured"); | ||
} | ||
|
||
return errorMessages; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.