Skip to content

Added support for .NET Core 3.0 and AppMetrics 3.2.0 #32

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Elasticsearch.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpRenamePlacementToArrangementMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAlwaysTreatStructAsNotReorderableMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
Expand Down
12 changes: 6 additions & 6 deletions build/dependencies.props
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<Project>
<PropertyGroup>
<AppMetricsCoreVersion>2.0.0-*</AppMetricsCoreVersion>
<AppMetricsAspNetCoreVersion>2.0.0-*</AppMetricsAspNetCoreVersion>
<AspNetCoreVersion>2.0.0-*</AspNetCoreVersion>
<AppMetricsCoreVersion>3.2.0-*</AppMetricsCoreVersion>
<AppMetricsAspNetCoreVersion>3.2.0-*</AppMetricsAspNetCoreVersion>
<AspNetCoreVersion>3.2.0-*</AspNetCoreVersion>
<BenchmarkDotNetVersion>0.10.8</BenchmarkDotNetVersion>
<CoreFxVersion>4.4.0-*</CoreFxVersion>
<DependencyModelVersion>2.0.0-*</DependencyModelVersion>
<MoqVersion>4.7.49</MoqVersion>
<NewtonsoftVersion>10.0.2</NewtonsoftVersion>
<NewtonsoftVersion>12.0.2</NewtonsoftVersion>
<NETStandardLibraryNETFrameworkVersion>2.0.0-*</NETStandardLibraryNETFrameworkVersion>
<RuntimeFrameworkVersion Condition="'$(TargetFramework)'=='netcoreapp2.0'">2.0.0-*</RuntimeFrameworkVersion>
<RuntimeFrameworkVersion Condition="'$(TargetFramework)'=='netcoreapp3.0'">3.0.0</RuntimeFrameworkVersion>
<TestSdkVersion>15.3.0-*</TestSdkVersion>
<XunitVersion>2.3.0-beta2-*</XunitVersion>
<FluentAssertionsVersion>4.19.2</FluentAssertionsVersion>
<FluentAssertionsJsonVersion>4.19.0</FluentAssertionsJsonVersion>
<StyleCopAnalyzersVersion>1.0.0</StyleCopAnalyzersVersion>
<StyleCopAnalyzersVersion>1.1.118</StyleCopAnalyzersVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"projects": [ "src", "test", "benchmarks", "sandbox" ],
"sdk": {
"version": "2.0.0"
"version": "3.0.100"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;net472</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp3.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand All @@ -14,7 +14,7 @@

<ItemGroup>
<PackageReference Include="App.Metrics" Version="$(AppMetricsCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.0.0" />
<PackageReference Include="Serilog.Sinks.Literate" Version="3.0.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="3.3.3" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using App.Metrics.Scheduling;
using MetricsElasticsearchSandboxMvc.JustForTesting;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

// ReSharper disable CheckNamespace
namespace Microsoft.AspNetCore.Builder
Expand All @@ -24,7 +25,7 @@ public static class AppBuilderExtensions

public static IApplicationBuilder UseTestStuff(
this IApplicationBuilder app,
IApplicationLifetime lifetime,
IHostApplicationLifetime lifetime,
bool runSampleRequestsFromApp)
{
app.Use(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
<Import Project="..\..\build\common.props" />

<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;net472</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp3.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="App.Metrics.AspNetCore.Mvc" Version="$(AppMetricsAspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="$(AspNetCoreVersion)" />
<PackageReference Include="App.Metrics.AspNetCore.Mvc" Version="3.2.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" />
<PackageReference Include="Serilog.Sinks.Literate" Version="3.0.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="3.3.3" />
<PackageReference Include="Serilog.AspNetCore " Version="2.0.0" />

</ItemGroup>

<ItemGroup>
Expand All @@ -28,7 +30,7 @@
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="$(AspNetCoreVersion)" />
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions sandbox/MetricsElasticsearchSandboxMvc/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace MetricsElasticsearchSandboxMvc
{
Expand All @@ -18,7 +19,7 @@ public class Startup

public IConfiguration Configuration { get; }

public void Configure(IApplicationBuilder app, IApplicationLifetime lifetime)
public void Configure(IApplicationBuilder app, IHostApplicationLifetime lifetime)
{
app.UseTestStuff(lifetime, HaveAppRunSampleRequests);

Expand All @@ -29,7 +30,7 @@ public void ConfigureServices(IServiceCollection services)
{
services.AddTestStuff();

services.AddMvc(options => options.AddMetricsResourceFilter());
services.AddMvc(o => o.EnableEndpointRouting = false).AddMetrics();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@

<PropertyGroup>
<Description>App Metrics Formatting, formatting metrics data to Elasticsearch formats.</Description>
<TargetFrameworks>netstandard1.6;net452</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;net472</TargetFrameworks>
<PackageTags>appmetrics;elasticsearch</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="App.Metrics.Core" Version="$(AppMetricsCoreVersion)" />
<PackageReference Include="App.Metrics.Core" Version="3.2.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftVersion)" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="SourceLink.Create.CommandLine" Version="2.8.3" />
<PackageReference Update="StyleCop.Analyzers" Version="1.1.118" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,6 @@ public static class ElasticsearchFormatterConstants
{
public class ElasticsearchDefaults
{
public static readonly Dictionary<HistogramValueDataKeys, string> CustomHistogramDataKeys = new Dictionary<HistogramValueDataKeys, string>
{
{
HistogramValueDataKeys.Count,
"countHist"
},
{
HistogramValueDataKeys.UserLastValue,
"userLast"
},
{
HistogramValueDataKeys.UserMinValue,
"userMin"
},
{
HistogramValueDataKeys.UserMaxValue,
"userMax"
}
};

public static readonly Dictionary<MeterValueDataKeys, string> CustomMeterDataKeys = new Dictionary<MeterValueDataKeys, string>
{
{ MeterValueDataKeys.Count, "countMeter" },
{ MeterValueDataKeys.RateMean, "rateMean" }
};

public static readonly string[] SpecialChars = { @"\", @"/", " ", "-", "+", "=", "{", "}", "[", "]", ":", "&", "^", "~", "?", "!", "," };

public static readonly Func<string, string, string> MetricNameFormatter =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using App.Metrics.Formatters.Elasticsearch.Internal;
using App.Metrics.Serialization;
using Newtonsoft.Json;
Expand All @@ -23,8 +24,7 @@ public MetricSnapshotElasticsearchWriter(
TextWriter textWriter,
string elasticsearchIndex,
Func<string, string, string> metricNameFormatter = null,
Func<string, string> metricTagValueFormatter = null,
GeneratedMetricNameMapping dataKeys = null)
Func<string, string> metricTagValueFormatter = null)
{
if (string.IsNullOrWhiteSpace(elasticsearchIndex))
{
Expand All @@ -36,15 +36,8 @@ public MetricSnapshotElasticsearchWriter(
_bulkPayload = new BulkPayload(serializer, elasticsearchIndex);
_metricNameFormatter = metricNameFormatter ?? ElasticsearchFormatterConstants.ElasticsearchDefaults.MetricNameFormatter;
_metricTagValueFormatter = metricTagValueFormatter ?? ElasticsearchFormatterConstants.ElasticsearchDefaults.MetricTagValueFormatter;

MetricNameMapping = dataKeys ?? new GeneratedMetricNameMapping(
histogram: ElasticsearchFormatterConstants.ElasticsearchDefaults.CustomHistogramDataKeys,
meter: ElasticsearchFormatterConstants.ElasticsearchDefaults.CustomMeterDataKeys);
}

/// <inheritdoc />
public GeneratedMetricNameMapping MetricNameMapping { get; }

/// <inheritdoc />
public void Dispose()
{
Expand All @@ -53,7 +46,7 @@ public void Dispose()
}

/// <inheritdoc />
public void Write(string context, string name, object value, MetricTags tags, DateTime timestamp)
public void Write(string context, string name, string field, object value, MetricTags tags, DateTime timestamp)
{
var tagKeyValues = tags.ToDictionary(_metricTagValueFormatter);
var measurement = _metricNameFormatter(context, name);
Expand Down Expand Up @@ -97,9 +90,7 @@ protected virtual void Dispose(bool disposing)
if (disposing)
{
_bulkPayload.Write(_textWriter);
#if !NETSTANDARD1_6
_textWriter?.Close();
#endif
_textWriter?.Dispose();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@ public class MetricsElasticsearchDocumentFormattingOptions
{
public MetricsElasticsearchDocumentFormattingOptions()
{
MetricNameMapping = new GeneratedMetricNameMapping(
histogram: ElasticsearchFormatterConstants.ElasticsearchDefaults.CustomHistogramDataKeys,
meter: ElasticsearchFormatterConstants.ElasticsearchDefaults.CustomMeterDataKeys);
MetricTagFormatter = ElasticsearchFormatterConstants.ElasticsearchDefaults.MetricTagValueFormatter;
MetricNameFormatter = ElasticsearchFormatterConstants.ElasticsearchDefaults.MetricNameFormatter;
}

public Func<string, string, string> MetricNameFormatter { get; set; }

public Func<string, string> MetricTagFormatter { get; set; }

public GeneratedMetricNameMapping MetricNameMapping { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public MetricsElasticsearchOutputFormatter(string elasticsearchIndex)

_elasticsearchIndex = elasticsearchIndex;
_options = new MetricsElasticsearchDocumentFormattingOptions();
MetricFields = new MetricFields();
}

public MetricsElasticsearchOutputFormatter(
Expand All @@ -40,11 +41,15 @@ public MetricsElasticsearchOutputFormatter(

_elasticsearchIndex = elasticsearchIndex;
_options = options ?? throw new ArgumentNullException(nameof(options));
MetricFields = new MetricFields();
}

/// <inheritdoc />
public MetricsMediaTypeValue MediaType => new MetricsMediaTypeValue("text", "vnd.appmetrics.metrics.elasticsearch", "v1", "plain");

/// <inheritdoc />
public MetricFields MetricFields { get; set; }

/// <inheritdoc />
public Task WriteAsync(
Stream output,
Expand All @@ -60,22 +65,11 @@ public Task WriteAsync(

using (var streamWriter = new StreamWriter(output))
{
using (var textWriter = new MetricSnapshotElasticsearchWriter(
streamWriter,
_elasticsearchIndex,
_options.MetricNameFormatter,
_options.MetricTagFormatter,
_options.MetricNameMapping))
{
serializer.Serialize(textWriter, metricsData);
}
using var textWriter = new MetricSnapshotElasticsearchWriter(streamWriter, _elasticsearchIndex);
serializer.Serialize(textWriter, metricsData, MetricFields);
}

#if !NETSTANDARD1_6
return AppMetricsTaskHelper.CompletedTask();
#else
return Task.CompletedTask;
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<PropertyGroup>
<Description>Provides Elasticsearch reporting capability to App Metrics.</Description>
<TargetFrameworks>netstandard1.6;net452</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;net472</TargetFrameworks>
<PackageTags>appmetrics;reporting;elasticsearch</PackageTags>
</PropertyGroup>

Expand All @@ -13,7 +13,17 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="App.Metrics.Abstractions" Version="$(AppMetricsCoreVersion)" />
<Reference Include="System.Net.Http" targetFramework ="net472"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="App.Metrics.Abstractions" Version="3.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="SourceLink.Create.CommandLine" Version="2.8.3" />
<PackageReference Update="StyleCop.Analyzers" Version="1.1.118" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public MetricsReportingElasticsearchOptions()
public IFilterMetrics Filter { get; set; }

/// <summary>
/// Gets or sets the HTTP policy settings which allows circuit breaker configuration to be adjusted
/// Gets or sets the HTTP policy settings which allows circuit breaker configuration to be adjusted.
/// </summary>
/// <value>
/// The HTTP policy.
Expand All @@ -59,14 +59,14 @@ public MetricsReportingElasticsearchOptions()
public IMetricsOutputFormatter MetricsOutputFormatter { get; set; }

/// <summary>
/// Gets or sets the flush metrics interval
/// Gets or sets the flush metrics interval.
/// </summary>
/// <remarks>
/// This <see cref="TimeSpan" /> will apply to all configured reporters unless overriden by a specific reporters
/// options.
/// </remarks>
/// <value>
/// The <see cref="TimeSpan" /> to wait between reporting metrics
/// The <see cref="TimeSpan" /> to wait between reporting metrics.
/// </value>
public TimeSpan FlushInterval { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
<Import Project="..\..\build\common.props" />

<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;net472</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp3.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\App.Metrics.Reporting.Elasticsearch\App.Metrics.Reporting.Elasticsearch.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.Net.Http" targetFramework ="net472"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.0" />
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
<PackageReference Include="Moq" Version="$(MoqVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
Expand Down