Skip to content

Commit

Permalink
Minor cleanups (#407)
Browse files Browse the repository at this point in the history
* delete whitespace

* Fix typo in namespace

* use pattern matching

* Unused namespace

* use var for local vars indicating their data types

* Make static method w/o state

* remove whitespace

* No need in variables for a one time used error message

* Make properties get-only as they should not be writeable by user code

* Remove unused namespace

* Private methods w/o state can be static

* Make test consistent
SeanFeldman authored and tomkerkhove committed Mar 18, 2019
1 parent 07f3e8b commit d136fab
Showing 21 changed files with 32 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Promitor.Core.Scraping.Configuration.Model.Metrics.ResouceTypes
namespace Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes
{
public class GenericMetricDefinition : MetricDefinition
{
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Promitor.Core.Scraping.Configuration.Model.Metrics.ResouceTypes
namespace Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes
{
public class ServiceBusQueueMetricDefinition : MetricDefinition
{
Original file line number Diff line number Diff line change
@@ -26,8 +26,7 @@ internal List<TObject> Deserialize(YamlSequenceNode nodes)
var deserializedObjects = new List<TObject>();
foreach (var item in nodes)
{
var metricNode = item as YamlMappingNode;
if (metricNode == null)
if (!(item is YamlMappingNode metricNode))
{
throw new SerializationException($"Failed parsing metrics because we couldn't cast an item to {nameof(YamlMappingNode)}");
}
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
using Microsoft.Extensions.Logging;
using Promitor.Core.Scraping.Configuration.Model;
using Promitor.Core.Scraping.Configuration.Model.Metrics;
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResouceTypes;
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes;
using YamlDotNet.RepresentationModel;

namespace Promitor.Core.Scraping.Configuration.Serialization
2 changes: 1 addition & 1 deletion src/Promitor.Core.Scraping/ResouceTypes/GenericScraper.cs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
using Microsoft.Azure.Management.Monitor.Fluent.Models;
using Microsoft.Extensions.Logging;
using Promitor.Core.Scraping.Configuration.Model;
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResouceTypes;
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes;
using Promitor.Core.Telemetry.Interfaces;
using Promitor.Integrations.AzureMonitor;

Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
using Microsoft.Azure.Management.Monitor.Fluent.Models;
using Microsoft.Extensions.Logging;
using Promitor.Core.Scraping.Configuration.Model;
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResouceTypes;
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes;
using Promitor.Core.Telemetry.Interfaces;
using Promitor.Integrations.AzureMonitor;

3 changes: 1 addition & 2 deletions src/Promitor.Core.Telemetry/RuntimeLogger.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
using Microsoft.Extensions.Logging.Console;

namespace Promitor.Core.Telemetry
{
2 changes: 1 addition & 1 deletion src/Promitor.Core/Serialization/Yaml/YamlSerialization.cs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ namespace Promitor.Core.Serialization.Yaml
public static class YamlSerialization
{
private static readonly INamingConvention NamingConvention = new CamelCaseNamingConvention();

public static ISerializer CreateSerializer()
{
var builder = new SerializerBuilder();
6 changes: 3 additions & 3 deletions src/Promitor.Integrations.AzureMonitor/AzureMonitorClient.cs
Original file line number Diff line number Diff line change
@@ -96,8 +96,8 @@ private TimeSpan DetermineAggregationInterval(string metricName, TimeSpan reques

private static TimeSpan GetClosestAggregationInterval(TimeSpan requestedAggregationInterval, IReadOnlyList<MetricAvailability> availableMetricPeriods)
{
TimeSpan closestAggregationIntervalDifference = TimeSpan.MaxValue;
TimeSpan closestAggregationInterval = TimeSpan.MaxValue;
var closestAggregationIntervalDifference = TimeSpan.MaxValue;
var closestAggregationInterval = TimeSpan.MaxValue;

foreach (var availableMetricPeriod in availableMetricPeriods)
{
@@ -155,7 +155,7 @@ private MetricValue GetMostRecentMetricValue(string metricName, IReadOnlyList<Ti
return relevantMetricValue;
}

private double InterpretMetricValue(AggregationType metricAggregation, MetricValue relevantMetricValue)
private static double InterpretMetricValue(AggregationType metricAggregation, MetricValue relevantMetricValue)
{
switch (metricAggregation)
{
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ public static IApplicationBuilder UsePrometheusScraper(this IApplicationBuilder
prometheusOptions.MapPath = scrapeEndpointPath;
prometheusOptions.UseDefaultCollectors = false;
});

return app;
}
}
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
using GuardNet;
using Promitor.Core.Scraping.Configuration.Model;
using Promitor.Core.Scraping.Configuration.Model.Metrics;
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResouceTypes;
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes;
using Promitor.Scraper.Host.Validation.MetricDefinitions.ResourceTypes;

namespace Promitor.Scraper.Host.Validation.MetricDefinitions
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResouceTypes;
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes;
using Promitor.Scraper.Host.Validation.MetricDefinitions.Interfaces;

namespace Promitor.Scraper.Host.Validation.MetricDefinitions.ResourceTypes
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResouceTypes;
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes;
using Promitor.Scraper.Host.Validation.MetricDefinitions.Interfaces;

namespace Promitor.Scraper.Host.Validation.MetricDefinitions.ResourceTypes
Original file line number Diff line number Diff line change
@@ -23,15 +23,13 @@ public ValidationResult Run()
var applicationId = Environment.GetEnvironmentVariable(EnvironmentVariables.Authentication.ApplicationId);
if (string.IsNullOrWhiteSpace(applicationId))
{
var errorMessage = "No application id was specified for Azure authentication";
return ValidationResult.Failure(ComponentName, errorMessage);
return ValidationResult.Failure(ComponentName, "No application id was specified for Azure authentication");
}

var applicationKey = Environment.GetEnvironmentVariable(EnvironmentVariables.Authentication.ApplicationKey);
if (string.IsNullOrWhiteSpace(applicationKey))
{
var errorMessage = "No application key was specified for Azure authentication";
return ValidationResult.Failure(ComponentName, errorMessage);
return ValidationResult.Failure(ComponentName, "No application key was specified for Azure authentication");
}

return ValidationResult.Successful(ComponentName);
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ public ValidationResult Run()
return validationErrors.Any() ? ValidationResult.Failure(ComponentName, validationErrors) : ValidationResult.Successful(ComponentName);
}

private List<string> DetectDuplicateMetrics(List<MetricDefinition> metrics)
private static List<string> DetectDuplicateMetrics(List<MetricDefinition> metrics)
{
var duplicateMetricNames = metrics.GroupBy(metric => metric.Name)
.Where(groupedMetrics => groupedMetrics.Count() > 1)
@@ -56,7 +56,7 @@ private List<string> DetectDuplicateMetrics(List<MetricDefinition> metrics)
return duplicateMetricNames;
}

private List<string> ValidateAzureMetadata(AzureMetadata azureMetadata)
private static List<string> ValidateAzureMetadata(AzureMetadata azureMetadata)
{
var errorMessages = new List<string>();

@@ -84,7 +84,7 @@ private List<string> ValidateAzureMetadata(AzureMetadata azureMetadata)
return errorMessages;
}

private List<string> ValidateMetrics(List<MetricDefinition> metrics, MetricDefaults metricDefaults)
private static List<string> ValidateMetrics(List<MetricDefinition> metrics, MetricDefaults metricDefaults)
{
var errorMessages = new List<string>();

3 changes: 1 addition & 2 deletions src/Promitor.Scraper.Host/Validation/Steps/ValidationStep.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;

namespace Promitor.Scraper.Host.Validation.Steps
{
6 changes: 3 additions & 3 deletions src/Promitor.Scraper.Host/Validation/ValidationResult.cs
Original file line number Diff line number Diff line change
@@ -17,10 +17,10 @@ private ValidationResult(string componentName, bool isSuccessful, string failure
Message = failureMessage;
}

public string ComponentName { get; set; }
public string ComponentName { get; }

public bool IsSuccessful { get; set; }
public string Message { get; set; }
public bool IsSuccessful { get; }
public string Message { get; }

public static ValidationResult Failure(string componentName, string failureMessage)
{
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
using Microsoft.Azure.Management.Monitor.Fluent.Models;
using Microsoft.Extensions.Logging.Abstractions;
using Promitor.Core.Scraping.Configuration.Model;
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResouceTypes;
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes;
using Promitor.Core.Scraping.Configuration.Serialization;

namespace Promitor.Scraper.Tests.Unit.Builders
Original file line number Diff line number Diff line change
@@ -12,8 +12,8 @@ public class FeatureFlagTests
public void FeatureFlag_FeatureIsConfiguredToBeOn_ReturnsOn()
{
// Arrange
const bool FlagState = true;
Environment.SetEnvironmentVariable("PROMITOR_FEATURE_TestFlag", FlagState.ToString());
const bool flagState = true;
Environment.SetEnvironmentVariable("PROMITOR_FEATURE_TestFlag", flagState.ToString());

// Act
var flagStatus = FeatureFlag.IsActive("TestFlag");
@@ -26,8 +26,8 @@ public void FeatureFlag_FeatureIsConfiguredToBeOn_ReturnsOn()
public void FeatureFlag_FeatureIsConfiguredToBeOff_ReturnsOff()
{
// Arrange
const bool FlagState = false;
Environment.SetEnvironmentVariable("PROMITOR_FEATURE_TestFlag", FlagState.ToString());
const bool flagState = false;
Environment.SetEnvironmentVariable("PROMITOR_FEATURE_TestFlag", flagState.ToString());

// Act
var flagStatus = FeatureFlag.IsActive("TestFlag");
@@ -50,7 +50,7 @@ public void FeatureFlag_FeatureIsNotConfigured_ReturnsOnByDefault()
public void FeatureFlag_FeatureIsNotConfiguredButDefaultStateIsOff_Returns0ff()
{
// Arrange
var defaultFlagState = false;
const bool defaultFlagState = false;

// Act
var flagStatus = FeatureFlag.IsActive("TestFlag", defaultFlagState: defaultFlagState);
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
using Bogus;
using Microsoft.Extensions.Logging.Abstractions;
using Promitor.Core.Scraping.Configuration.Model;
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResouceTypes;
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes;
using Promitor.Core.Scraping.Configuration.Serialization;
using Xunit;
using MetricDefinition = Promitor.Core.Scraping.Configuration.Model.Metrics.MetricDefinition;
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
using Bogus;
using Microsoft.Azure.Management.Monitor.Fluent.Models;
using Promitor.Core.Scraping.Configuration.Model;
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResouceTypes;
using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes;
using Xunit;
using MetricDefinition = Promitor.Core.Scraping.Configuration.Model.Metrics.MetricDefinition;

0 comments on commit d136fab

Please sign in to comment.