-
-
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.
* Adjust .gitignore to exclude .DS_Store * Add config doc for network interfaces. * Add Network Interface Resource Definition * Add Network interface deserializer * Adjust index * Add Network Interface to Deserializer Factory * Add Network Interface Scraper support * Add validator. * Bugfix to Network interface scraper. * Add unit test for Network Interface. * Fix doc typo * Add link to Microsoft docs for azure network interface. * I hate you git
- Loading branch information
1 parent
6968e8a
commit 0a40a13
Showing
14 changed files
with
316 additions
and
3 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 |
---|---|---|
|
@@ -293,4 +293,8 @@ __pycache__/ | |
# Local Jekyll output | ||
_site/* | ||
docs/_site/* | ||
*.orig | ||
|
||
#MAC | ||
.DS_Store | ||
|
||
*.orig |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
layout: default | ||
title: Azure Network Interface Declaration | ||
--- | ||
|
||
## Azure Network Interface | ||
You can declare to scrape an [Azure Network Interface](https://docs.microsoft.com/en-us/azure/virtual-network/virtual-network-network-interface) via the `NetworkInterface` resource type. | ||
|
||
The following fields need to be provided: | ||
- `networkInterfaceName` - The name of the network interface | ||
|
||
All supported metrics are documented in the official [Azure Monitor documentation](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftnetworknetworkinterfaces). | ||
|
||
Example: | ||
```yaml | ||
- name: demo_azuresnetworkinterface_bytesreceivedrate | ||
description: "Number of bytes the Network Interface sent" | ||
resourceType: NetworkInterface | ||
networkInterfaceName: promitor-network-interface | ||
azureMetricConfiguration: | ||
metricName: BytesReceivedRate | ||
aggregation: | ||
type: Average | ||
``` | ||
[← back to metrics declarations](/configuration/metrics)<br /> | ||
[← back to introduction](/) |
8 changes: 8 additions & 0 deletions
8
...re.Scraping/Configuration/Model/Metrics/ResourceTypes/NetworkInterfaceMetricDefinition.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 NetworkInterfaceMetricDefinition : MetricDefinition | ||
{ | ||
public string NetworkInterfaceName { get; set; } | ||
public override ResourceType ResourceType { get; } = ResourceType.NetworkInterface; | ||
} | ||
} |
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/NetworkInterfaceMetricDeserializer.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 NetworkInterfaceMetricDeserializer : GenericAzureMetricDeserializer | ||
{ | ||
/// <summary>Deserializes the specified Network Interface metric node from the YAML configuration file.</summary> | ||
/// <param name="metricNode">The metric node containing 'networkInterfaceName' parameter pointing to an instance of a Network Interface</param> | ||
/// <returns>A new <see cref="MetricDefinition"/> object (strongly typed as a <see cref="NetworkInterfaceMetricDefinition"/>) </returns> | ||
internal override MetricDefinition Deserialize(YamlMappingNode metricNode) | ||
{ | ||
var metricDefinition = base.DeserializeMetricDefinition<NetworkInterfaceMetricDefinition>(metricNode); | ||
var networkInterfaceName = metricNode.Children[new YamlScalarNode("networkInterfaceName")]; | ||
|
||
metricDefinition.NetworkInterfaceName = networkInterfaceName?.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/NetworkInterfaceScraper.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 | ||
{ | ||
internal class NetworkInterfaceScraper : Scraper<NetworkInterfaceMetricDefinition> | ||
{ | ||
private const string ResourceUriTemplate = "subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/networkInterfaces/{2}"; | ||
|
||
public NetworkInterfaceScraper(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, NetworkInterfaceMetricDefinition metricDefinition, AggregationType aggregationType, TimeSpan aggregationInterval) | ||
{ | ||
var resourceUri = string.Format(ResourceUriTemplate, AzureMetadata.SubscriptionId, AzureMetadata.ResourceGroupName, metricDefinition.NetworkInterfaceName); | ||
|
||
var metricName = metricDefinition.AzureMetricConfiguration.MetricName; | ||
var foundMetricValue = await AzureMonitorClient.QueryMetricAsync(metricName, aggregationType, aggregationInterval, resourceUri); | ||
|
||
return foundMetricValue; | ||
} | ||
} | ||
} |
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
...craper.Host/Validation/MetricDefinitions/ResourceTypes/NetworkInterfaceMetricValidator.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 NetworkInterfaceMetricValidator : MetricValidator<NetworkInterfaceMetricDefinition> | ||
{ | ||
protected override IEnumerable<string> Validate(NetworkInterfaceMetricDefinition networkInterfaceMetricDefinition) | ||
{ | ||
Guard.NotNull(networkInterfaceMetricDefinition, nameof(networkInterfaceMetricDefinition)); | ||
|
||
var errorMessages = new List<string>(); | ||
|
||
if (string.IsNullOrWhiteSpace(networkInterfaceMetricDefinition.NetworkInterfaceName)) | ||
{ | ||
errorMessages.Add("No network interface 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
77 changes: 77 additions & 0 deletions
77
...zation/MetricsDeclaration/MetricsDeclarationWithNetworkInterfaceYamlSerializationTests.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,77 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using Bogus; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Promitor.Core.Scraping.Configuration.Model; | ||
using Promitor.Core.Scraping.Configuration.Model.Metrics; | ||
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes; | ||
using Promitor.Core.Scraping.Configuration.Serialization.Core; | ||
using Xunit; | ||
|
||
namespace Promitor.Scraper.Tests.Unit.Serialization.MetricsDeclaration | ||
{ | ||
[Category(category: "Unit")] | ||
public class MetricsDeclarationWithNetworkInterfaceYamlSerializationTests : YamlSerializationTests<NetworkInterfaceMetricDefinition> | ||
{ | ||
[Theory] | ||
[InlineData("promitor1", @"01:00", @"2:00")] | ||
[InlineData(null, null, null)] | ||
public void YamlSerialization_SerializeAndDeserializeValidConfigForNetworkInterface_SucceedsWithIdenticalOutput(string resourceGroupName, string defaultScrapingInterval, string metricScrapingInterval) | ||
{ | ||
// Arrange | ||
var azureMetadata = GenerateBogusAzureMetadata(); | ||
var networkInterfaceMetricDefinition = GenerateBogusNetworkInterfaceMetricDefinition(resourceGroupName, metricScrapingInterval); | ||
var metricDefaults = GenerateBogusMetricDefaults(defaultScrapingInterval); | ||
var scrapingConfiguration = new Core.Scraping.Configuration.Model.MetricsDeclaration | ||
{ | ||
AzureMetadata = azureMetadata, | ||
MetricDefaults = metricDefaults, | ||
Metrics = new List<MetricDefinition> | ||
{ | ||
networkInterfaceMetricDefinition | ||
} | ||
}; | ||
var configurationSerializer = new ConfigurationSerializer(NullLogger.Instance); | ||
|
||
// Act | ||
var serializedConfiguration = configurationSerializer.Serialize(scrapingConfiguration); | ||
var deserializedConfiguration = configurationSerializer.Deserialize(serializedConfiguration); | ||
|
||
// Assert | ||
Assert.NotNull(deserializedConfiguration); | ||
AssertAzureMetadata(deserializedConfiguration, azureMetadata); | ||
AssertMetricDefaults(deserializedConfiguration, metricDefaults); | ||
Assert.NotNull(deserializedConfiguration.Metrics); | ||
Assert.Single(deserializedConfiguration.Metrics); | ||
var deserializedMetricDefinition = deserializedConfiguration.Metrics.FirstOrDefault(); | ||
AssertMetricDefinition(deserializedMetricDefinition, networkInterfaceMetricDefinition); | ||
var deserializedNetworkInterfaceMetricDefinition = deserializedMetricDefinition as NetworkInterfaceMetricDefinition; | ||
AssertNetworkInterfaceMetricDefinition(deserializedNetworkInterfaceMetricDefinition, networkInterfaceMetricDefinition); | ||
} | ||
|
||
private static void AssertNetworkInterfaceMetricDefinition(NetworkInterfaceMetricDefinition deserializedNetworkInterfaceMetricDefinition, NetworkInterfaceMetricDefinition networkInterfaceMetricDefinition) | ||
{ | ||
Assert.NotNull(deserializedNetworkInterfaceMetricDefinition); | ||
Assert.Equal(networkInterfaceMetricDefinition.NetworkInterfaceName, deserializedNetworkInterfaceMetricDefinition.NetworkInterfaceName); | ||
} | ||
|
||
private NetworkInterfaceMetricDefinition GenerateBogusNetworkInterfaceMetricDefinition(string resourceGroupName, string metricScrapingInterval) | ||
{ | ||
var bogusScrapingInterval = GenerateBogusScrapingInterval(metricScrapingInterval); | ||
var bogusAzureMetricConfiguration = GenerateBogusAzureMetricConfiguration(); | ||
Faker<NetworkInterfaceMetricDefinition> bogusGenerator = new Faker<NetworkInterfaceMetricDefinition>() | ||
.StrictMode(ensureRulesForAllProperties: true) | ||
.RuleFor(metricDefinition => metricDefinition.Name, faker => faker.Name.FirstName()) | ||
.RuleFor(metricDefinition => metricDefinition.Description, faker => faker.Lorem.Sentence(wordCount: 6)) | ||
.RuleFor(metricDefinition => metricDefinition.ResourceType, faker => ResourceType.NetworkInterface) | ||
.RuleFor(metricDefinition => metricDefinition.NetworkInterfaceName, faker => faker.Name.LastName()) | ||
.RuleFor(metricDefinition => metricDefinition.AzureMetricConfiguration, faker => bogusAzureMetricConfiguration) | ||
.RuleFor(metricDefinition => metricDefinition.ResourceGroupName, faker => resourceGroupName) | ||
.RuleFor(metricDefinition => metricDefinition.Scraping, faker => bogusScrapingInterval) | ||
.Ignore(metricDefinition => metricDefinition.ResourceGroupName); | ||
|
||
return bogusGenerator.Generate(); | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
...alidation/Metrics/ResourceTypes/NetworkInterfaceMetricsDeclarationValidationStepsTests.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,97 @@ | ||
using System.ComponentModel; | ||
using Promitor.Scraper.Host.Validation.Steps; | ||
using Promitor.Scraper.Tests.Unit.Builders; | ||
using Promitor.Scraper.Tests.Unit.Stubs; | ||
using Xunit; | ||
|
||
namespace Promitor.Scraper.Tests.Unit.Validation.Metrics.ResourceTypes | ||
{ | ||
[Category("Unit")] | ||
public class NetworkInterfaceMetricsDeclarationValidationStepTests | ||
{ | ||
[Fact] | ||
public void NetworkInterfaceMetricsDeclaration_DeclarationWithoutAzureMetricName_Succeeds() | ||
{ | ||
// Arrange | ||
var rawDeclaration = MetricsDeclarationBuilder.WithMetadata() | ||
.WithNetworkInterfaceMetric(azureMetricName: string.Empty) | ||
.Build(); | ||
var metricsDeclarationProvider = new MetricsDeclarationProviderStub(rawDeclaration); | ||
|
||
// Act | ||
var scrapingScheduleValidationStep = new MetricsDeclarationValidationStep(metricsDeclarationProvider); | ||
var validationResult = scrapingScheduleValidationStep.Run(); | ||
|
||
// Assert | ||
Assert.False(validationResult.IsSuccessful, "Validation is successful"); | ||
} | ||
|
||
[Fact] | ||
public void NetworkInterfaceMetricsDeclaration_DeclarationWithoutMetricDescription_Succeeded() | ||
{ | ||
// Arrange | ||
var rawDeclaration = MetricsDeclarationBuilder.WithMetadata() | ||
.WithNetworkInterfaceMetric(metricDescription: string.Empty) | ||
.Build(); | ||
var metricsDeclarationProvider = new MetricsDeclarationProviderStub(rawDeclaration); | ||
|
||
// Act | ||
var scrapingScheduleValidationStep = new MetricsDeclarationValidationStep(metricsDeclarationProvider); | ||
var validationResult = scrapingScheduleValidationStep.Run(); | ||
|
||
// Assert | ||
Assert.True(validationResult.IsSuccessful, "Validation was not successful"); | ||
} | ||
|
||
[Fact] | ||
public void NetworkInterfaceMetricsDeclaration_DeclarationWithoutMetricName_Fails() | ||
{ | ||
// Arrange | ||
var rawDeclaration = MetricsDeclarationBuilder.WithMetadata() | ||
.WithNetworkInterfaceMetric(string.Empty) | ||
.Build(); | ||
var metricsDeclarationProvider = new MetricsDeclarationProviderStub(rawDeclaration); | ||
|
||
// Act | ||
var scrapingScheduleValidationStep = new MetricsDeclarationValidationStep(metricsDeclarationProvider); | ||
var validationResult = scrapingScheduleValidationStep.Run(); | ||
|
||
// Assert | ||
Assert.False(validationResult.IsSuccessful, "Validation is successful"); | ||
} | ||
|
||
[Fact] | ||
public void NetworkInterfaceMetricsDeclaration_DeclarationWithoutNetworkInterfaceName_Fails() | ||
{ | ||
// Arrange | ||
var rawDeclaration = MetricsDeclarationBuilder.WithMetadata() | ||
.WithNetworkInterfaceMetric(networkInterfaceName: string.Empty) | ||
.Build(); | ||
var metricsDeclarationProvider = new MetricsDeclarationProviderStub(rawDeclaration); | ||
|
||
// Act | ||
var scrapingScheduleValidationStep = new MetricsDeclarationValidationStep(metricsDeclarationProvider); | ||
var validationResult = scrapingScheduleValidationStep.Run(); | ||
|
||
// Assert | ||
Assert.False(validationResult.IsSuccessful, "Validation is successful"); | ||
} | ||
|
||
[Fact] | ||
public void NetworkInterfaceMetricsDeclaration_ValidDeclaration_Succeeds() | ||
{ | ||
// Arrange | ||
var rawMetricsDeclaration = MetricsDeclarationBuilder.WithMetadata() | ||
.WithNetworkInterfaceMetric() | ||
.Build(); | ||
var metricsDeclarationProvider = new MetricsDeclarationProviderStub(rawMetricsDeclaration); | ||
|
||
// Act | ||
var scrapingScheduleValidationStep = new MetricsDeclarationValidationStep(metricsDeclarationProvider); | ||
var validationResult = scrapingScheduleValidationStep.Run(); | ||
|
||
// Assert | ||
Assert.True(validationResult.IsSuccessful, "Validation was not successful"); | ||
} | ||
} | ||
} |