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

Use Resharper for code quality enforcement #415

Merged
merged 10 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .azure-devops/scraper-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ jobs:
command: test
projects: src/Promitor.Scraper.Tests.Unit/Promitor.Scraper.Tests.Unit.csproj

- task: alanwales.resharper-code-analysis.custom-build-task.ResharperCli@1
displayName: 'Automated code quality checks'
inputs:
SolutionOrProjectPath: src/Promitor.sln

- job: Docker_Job
displayName: Build Docker Image Tests
condition: succeeded()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ namespace Promitor.Core.Scraping.Configuration.Providers
{
public class MetricsDeclarationProvider : IMetricsDeclarationProvider
{
private readonly ConfigurationSerializer configurationSerializer;
private readonly ConfigurationSerializer _configurationSerializer;

public MetricsDeclarationProvider(ILogger logger)
{
configurationSerializer = new ConfigurationSerializer(logger);
_configurationSerializer = new ConfigurationSerializer(logger);
}

public virtual MetricsDeclaration Get()
{
var rawMetricsDeclaration = ReadRawDeclaration();

var config = configurationSerializer.Deserialize(rawMetricsDeclaration);
var config = _configurationSerializer.Deserialize(rawMetricsDeclaration);
return config;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ namespace Promitor.Core.Scraping.Configuration.Serialization
{
public class ConfigurationSerializer
{
private readonly ILogger logger;
private readonly ILogger _logger;
public ConfigurationSerializer(ILogger logger)
{
this.logger = logger;
_logger = logger;
}

public MetricsDeclaration Deserialize(string rawMetricsDeclaration)
Expand All @@ -40,23 +40,23 @@ private MetricsDeclaration InterpretYamlStream(YamlStream metricsDeclarationYaml
if (rootNode.Children.ContainsKey("azureMetadata"))
{
var azureMetadataNode = (YamlMappingNode) rootNode.Children[new YamlScalarNode("azureMetadata")];
var azureMetadataSerializer = new AzureMetadataDeserializer(logger);
var azureMetadataSerializer = new AzureMetadataDeserializer(_logger);
azureMetadata = azureMetadataSerializer.Deserialize(azureMetadataNode);
}

MetricDefaults metricDefaults = null;
if (rootNode.Children.ContainsKey("metricDefaults"))
{
var metricDefaultsNode = (YamlMappingNode) rootNode.Children[new YamlScalarNode("metricDefaults")];
var metricDefaultsSerializer = new MetricDefaultsDeserializer(logger);
var metricDefaultsSerializer = new MetricDefaultsDeserializer(_logger);
metricDefaults = metricDefaultsSerializer.Deserialize(metricDefaultsNode);
}

List<MetricDefinition> metrics = null;
if (rootNode.Children.ContainsKey("metrics"))
{
var metricsNode = (YamlSequenceNode) rootNode.Children[new YamlScalarNode("metrics")];
var metricsDeserializer = new MetricsDeserializer(logger);
var metricsDeserializer = new MetricsDeserializer(_logger);
metrics = metricsDeserializer.Deserialize(metricsNode);
}

Expand Down
14 changes: 0 additions & 14 deletions src/Promitor.Core.Scraping/Exceptions/ScrapingException.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Promitor.Core.Scraping.Configuration.Model;
using Promitor.Core.Scraping.Configuration.Model.Metrics;
using Promitor.Core.Scraping.Interfaces;
using Promitor.Core.Scraping.ResouceTypes;
using Promitor.Core.Scraping.ResourceTypes;
using Promitor.Core.Telemetry.Interfaces;
using Promitor.Integrations.AzureMonitor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Promitor.Core.Telemetry.Interfaces;
using Promitor.Integrations.AzureMonitor;

namespace Promitor.Core.Scraping.ResouceTypes
namespace Promitor.Core.Scraping.ResourceTypes
{
internal class GenericScraper : Scraper<GenericMetricDefinition>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Promitor.Core.Telemetry.Interfaces;
using Promitor.Integrations.AzureMonitor;

namespace Promitor.Core.Scraping.ResouceTypes
namespace Promitor.Core.Scraping.ResourceTypes
{
public class ServiceBusQueueScraper : Scraper<ServiceBusQueueMetricDefinition>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Promitor.Integrations.AzureMonitor;
using Promitor.Integrations.AzureStorage;

namespace Promitor.Core.Scraping.ResouceTypes
namespace Promitor.Core.Scraping.ResourceTypes
{
public class StorageQueueScraper: Scraper<StorageQueueMetricDefinition>
{
Expand Down
3 changes: 2 additions & 1 deletion src/Promitor.Core.Scraping/Scraper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Promitor.Core.Telemetry.Interfaces;
using Promitor.Integrations.AzureMonitor;
using MetricDefinition = Promitor.Core.Scraping.Configuration.Model.Metrics.MetricDefinition;
// ReSharper disable All

namespace Promitor.Core.Scraping
{
Expand Down Expand Up @@ -105,7 +106,7 @@ private TimeSpan DetermineMetricAggregationInterval(MetricDefinition metricDefin

if (MetricDefaults.Aggregation.Interval == null)
{
throw new Exception($"No default aggregation interval is configured nor on the metric configuration for '{metricDefinition.Name}'");
throw new Exception($"No default aggregation interval is configured nor on the metric configuration for '{metricDefinition?.Name}'");
}

return MetricDefaults.Aggregation.Interval.Value;
Expand Down
1 change: 1 addition & 0 deletions src/Promitor.Core.Telemetry/RuntimeLogger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging.Console;
#pragma warning disable 618

namespace Promitor.Core.Telemetry
{
Expand Down
4 changes: 2 additions & 2 deletions src/Promitor.Core/Serialization/Yaml/YamlSerialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ namespace Promitor.Core.Serialization.Yaml
{
public static class YamlSerialization
{
private static readonly INamingConvention NamingConvention = new CamelCaseNamingConvention();
private static readonly INamingConvention namingConvention = new CamelCaseNamingConvention();

public static ISerializer CreateSerializer()
{
var builder = new SerializerBuilder();
builder.WithNamingConvention(NamingConvention);
builder.WithNamingConvention(namingConvention);

return builder.Build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ private async Task<IMetric> GetRelevantMetric(string metricName, AggregationType
private MetricValue GetMostRecentMetricValue(string metricName, IReadOnlyList<TimeSeriesElement> timeSeries,
DateTime recordDateTime)
{
var timeSerie = timeSeries.FirstOrDefault(); // TODO: Can we really do this?
if (timeSerie == null)
var firstTimeSeries = timeSeries.FirstOrDefault(); // TODO: Can we really do this?
if (firstTimeSeries == null)
{
throw new MetricInformationNotFoundException(metricName, "No time series was found");
}

var relevantMetricValue = timeSerie.Data.Where(metricValue => metricValue.TimeStamp < recordDateTime)
var relevantMetricValue = firstTimeSeries.Data.Where(metricValue => metricValue.TimeStamp < recordDateTime)
.OrderByDescending(metricValue => metricValue.TimeStamp)
.FirstOrDefault();

Expand Down
2 changes: 1 addition & 1 deletion src/Promitor.Scraper.Host/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ COPY Promitor.Core/* Promitor.Core/
COPY Promitor.Core.Scraping/* Promitor.Core.Scraping/
COPY Promitor.Core.Telemetry/* Promitor.Core.Telemetry/
COPY Promitor.Integrations.AzureMonitor/* Promitor.Integrations.AzureMonitor/
COPY Promitor.Integrations.AzureStorageQueue/* Promitor.Integrations.AzureStorageQueue/
COPY Promitor.Integrations.AzureStorage/* Promitor.Integrations.AzureStorage/
COPY Promitor.Scraper.Host/* Promitor.Scraper.Host/
RUN dotnet --info
RUN dotnet publish Promitor.Scraper.Host/Promitor.Scraper.Host.csproj --configuration release -o app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ public static IApplicationBuilder UsePrometheusScraper(this IApplicationBuilder
return app;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private static string GetXmlDocumentationPath(IServiceCollection services)
return File.Exists(xmlDocumentationPath) ? xmlDocumentationPath : string.Empty;
}

// ReSharper disable once UnusedParameter.Local
private static void UnobservedJobHandlerHandler(object sender, UnobservedTaskExceptionEventArgs e, IServiceCollection services)
{
var exceptionTrackerService = services.FirstOrDefault(service => service.ServiceType == typeof(IExceptionTracker));
Expand All @@ -89,4 +90,4 @@ private static void UnobservedJobHandlerHandler(object sender, UnobservedTaskExc
e.SetObserved();
}
}
}
}
5 changes: 3 additions & 2 deletions src/Promitor.Scraper.Host/Extensions/IWebHostExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using GuardNet;
using Microsoft.AspNetCore.Hosting;
using Promitor.Scraper.Host.Validation;

// ReSharper disable once CheckNamespace
namespace Microsoft.AspNetCore.Hosting
namespace Promitor.Scraper.Host.Extensions
{
public static class IWebHostExtensions
public static class WebHostExtensions
{
public static IWebHost ValidateSetup(this IWebHost webHost)
{
Expand Down
1 change: 1 addition & 0 deletions src/Promitor.Scraper.Host/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Promitor.Core;
using Promitor.Scraper.Host.Extensions;

namespace Promitor.Scraper.Host
{
Expand Down
4 changes: 2 additions & 2 deletions src/Promitor.Scraper.Host/Scheduling/MetricScrapingJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Threading.Tasks;
using CronScheduler.AspNetCore;
using GuardNet;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Promitor.Core;
using Promitor.Core.Scraping.Configuration.Model;
Expand Down Expand Up @@ -35,6 +34,7 @@ public MetricScrapingJob(IMetricsDeclarationProvider metricsDeclarationProvider,
}

public string CronSchedule { get; set; }
// ReSharper disable once UnassignedGetOnlyAutoProperty
public string CronTimeZone { get; }
public bool RunImmediately { get; set; }

Expand Down Expand Up @@ -75,4 +75,4 @@ private async Task ScrapeMetric(AzureMetadata azureMetadata, MetricDefaults metr
await scraper.ScrapeAsync(metricDefinitionDefinition);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Promitor.Scraper.Host/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Promitor.Scraper.Host
{
public class Startup
{
public Startup(IHostingEnvironment env)
public Startup()
{
Configuration = BuildConfiguration();
ScrapeEndpointBasePath = ScrapeEndpoint.GetBasePath(Configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class AzureMetricConfigurationValidator

public AzureMetricConfigurationValidator(MetricDefaults metricDefaults)
{
this._metricDefaults = metricDefaults;
_metricDefaults = metricDefaults;
}

public List<string> Validate(AzureMetricConfiguration azureMetricConfiguration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface IMetricValidator<in TMetricDefinition>
/// </summary>
/// <param name="metricDefinition">Metric definition to validate</param>
/// <returns>List of validation errors</returns>
// ReSharper disable once UnusedMember.Global
List<string> Validate(TMetricDefinition metricDefinition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class MetricAggregationValidator

public MetricAggregationValidator(MetricDefaults metricDefaults)
{
this._metricDefaults = metricDefaults;
_metricDefaults = metricDefaults;
}

public List<string> Validate(MetricAggregation metricsAggregation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ namespace Promitor.Scraper.Host.Validation.MetricDefinitions
{
public class MetricsValidator
{
private readonly MetricDefaults metricDefaults;
private readonly MetricDefaults _metricDefaults;

public MetricsValidator(MetricDefaults metricDefaults)
{
this.metricDefaults = metricDefaults;
_metricDefaults = metricDefaults;
}

public List<string> Validate(List<MetricDefinition> metrics)
Expand Down Expand Up @@ -75,7 +75,7 @@ public List<string> Validate(MetricDefinition metric)

errorMessages.AddRange(metricDefinitionValidationErrors);

var metricAggregationValidator = new AzureMetricConfigurationValidator(metricDefaults);
var metricAggregationValidator = new AzureMetricConfigurationValidator(_metricDefaults);
var metricsConfigurationErrorMessages = metricAggregationValidator.Validate(metric.AzureMetricConfiguration);
errorMessages.AddRange(metricsConfigurationErrorMessages);

Expand Down
4 changes: 2 additions & 2 deletions src/Promitor.Scraper.Host/Validation/RuntimeValidator.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
using Promitor.Core.Scraping.Configuration.Providers;
using Promitor.Scraper.Host.Validation.Exceptions;
using Promitor.Scraper.Host.Validation.Interfaces;
using Promitor.Scraper.Host.Validation.Steps;
#pragma warning disable 618

namespace Promitor.Scraper.Host.Validation
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public ValidationResult Run()
var configurationPath = Environment.GetEnvironmentVariable(EnvironmentVariables.Configuration.Path);
if (string.IsNullOrWhiteSpace(configurationPath))
{
Logger.LogWarning("No scrape configuration path configured, falling back to default one on '{configurationPath}'.", Promitor.Core.Scraping.Constants.Defaults.MetricsDeclarationPath);
configurationPath = Promitor.Core.Scraping.Constants.Defaults.MetricsDeclarationPath;
Logger.LogWarning("No scrape configuration path configured, falling back to default one on '{configurationPath}'.", Core.Scraping.Constants.Defaults.MetricsDeclarationPath);
configurationPath = Core.Scraping.Constants.Defaults.MetricsDeclarationPath;
Environment.SetEnvironmentVariable(EnvironmentVariables.Configuration.Path, configurationPath);
}

Expand All @@ -35,7 +35,7 @@ public ValidationResult Run()
return ValidationResult.Failure(ComponentName, errorMessage);
}

Logger.LogInformation("Scrape configuration found at '{configurationPath}'", Promitor.Core.Scraping.Constants.Defaults.MetricsDeclarationPath);
Logger.LogInformation("Scrape configuration found at '{configurationPath}'", Core.Scraping.Constants.Defaults.MetricsDeclarationPath);
return ValidationResult.Successful(ComponentName);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using Cronos;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using Microsoft.Azure.KeyVault.Models;
using Microsoft.Azure.Management.Monitor.Fluent.Models;
using Microsoft.Extensions.Logging.Abstractions;
using Promitor.Core.Scraping.Configuration.Model;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Microsoft.Extensions.Logging.Abstractions;
using Promitor.Core.Scraping.Configuration.Providers;
using Promitor.Core.Scraping.Configuration.Providers.Interfaces;

namespace Promitor.Scraper.Tests.Unit.Stubs
{
public class MetricsDeclarationProviderStub : MetricsDeclarationProvider, IMetricsDeclarationProvider
public class MetricsDeclarationProviderStub : MetricsDeclarationProvider
{
private readonly string _rawMetricsDeclaration;

Expand Down
5 changes: 5 additions & 0 deletions src/Promitor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Promitor.Core", "Promitor.C
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Promitor.Integrations.AzureStorage", "Promitor.Integrations.AzureStorage\Promitor.Integrations.AzureStorage.csproj", "{F929434C-07FB-4B55-A8EE-5C77D8B49809}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B65C1C71-7334-4B28-B42E-EA5924CEAA84}"
ProjectSection(SolutionItems) = preProject
Promitor.sln.DotSettings = Promitor.sln.DotSettings
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
Loading