From 22b3b5efd50b3dfec1d1cbc1c0a668b2840e743a Mon Sep 17 00:00:00 2001 From: dinavinter Date: Thu, 9 Feb 2023 14:42:13 +0200 Subject: [PATCH 1/7] change fields to setters to allow serialization --- Directory.Build.props | 4 +-- .../Counters/EventCounterData.cs | 36 +++++++++++++------ .../Options/HttpClientHandlerOptions.cs | 4 +-- .../Options/HttpClientOptions.cs | 10 +++--- .../Options/HttpConnectionOptions.cs | 5 ++- .../Options/HttpTelemetryOptions.cs | 2 +- .../PollyOptions/CircuitBreakerOptions.cs | 10 +++--- .../PollyOptions/TransientHttpPolicy.cs | 8 ++--- .../Tracing/Options/TracingActivityOptions.cs | 4 +-- .../Options/TracingEnrichmentOptions.cs | 10 +++--- .../Tracing/Options/TracingTagsOptions.cs | 16 ++++----- .../OpenTelemetryOptionsBuilder.cs | 7 ++-- Http.Client.Options/Tracing/Tcp/TcpTracer.cs | 8 ++--- .../Tracing/Tracers/ConfigTracer.cs | 14 ++++---- .../Tracing/Tracers/ConnectionTracer.cs | 18 +++++----- .../Tracing/Tracers/ErrorTracer.cs | 12 +++---- .../Tracing/Tracers/FlowTracer.cs | 24 ++++++------- .../Tracing/Tracers/RequestTracer.cs | 14 ++++---- .../Tracing/Tracers/ResponseTracer.cs | 4 +-- 19 files changed, 114 insertions(+), 96 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 4a9ab1b..9ec0ee3 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,8 +4,8 @@ - 7.1.0 - + 7.2.1 +false true true true diff --git a/Http.Client.Options/Counters/EventCounterData.cs b/Http.Client.Options/Counters/EventCounterData.cs index 4171ca7..478cd75 100644 --- a/Http.Client.Options/Counters/EventCounterData.cs +++ b/Http.Client.Options/Counters/EventCounterData.cs @@ -1,21 +1,35 @@ using System; using System.Collections.Generic; using System.Diagnostics.Tracing; +using System.Linq; namespace Http.Options.Counters { + public class Counters + { + public const string Name = "Name"; + public const string Mean = "Mean"; + public const string StandardDeviation = "StandardDeviation"; + public const string Count = "Count"; + public const string IntervalSec = "IntervalSec"; + public const string Min = "Min"; + public const string Max = "Max"; + } + public class EventCounterData { public EventCounterData(EventWrittenEventArgs eventData) { - var payload = (IDictionary) eventData.Payload[0]; - Name = payload["Name"].ToString(); - Mean = GetDouble(payload, "Mean"); - StandardDeviation = GetDouble(payload, "StandardDeviation"); - Count = GetDouble(payload, "Count"); - IntervalSec = GetDouble(payload, "IntervalSec"); - Min = GetDouble(payload, "Min"); - Max = GetDouble(payload, "Max"); + if (eventData.Payload?.FirstOrDefault() is IDictionary payload) + { + Name = payload["Name"].ToString(); + Mean = GetDouble(payload, "Mean"); + StandardDeviation = GetDouble(payload, "StandardDeviation"); + Count = GetDouble(payload, "Count"); + IntervalSec = GetDouble(payload, "IntervalSec"); + Min = GetDouble(payload, "Min"); + Max = GetDouble(payload, "Max"); + } } private static double? GetDouble(IDictionary payload, string id) @@ -29,12 +43,12 @@ public EventCounterData(EventWrittenEventArgs eventData) float value => value, long value => value, decimal value => (double) value, - {} when double.TryParse(payloadValue.ToString(), out var value) => value, + { } when double.TryParse(payloadValue.ToString(), out var value) => value, _ => null }; } - + public string Name { get; } public double? Mean { get; } public double? StandardDeviation { get; } @@ -43,7 +57,7 @@ public EventCounterData(EventWrittenEventArgs eventData) public double? Min { get; } public double? Max { get; } } - + public static class EventCounterDataExtensions { public static bool IsEventCounter(this EventWrittenEventArgs eventData) diff --git a/Http.Client.Options/Options/HttpClientHandlerOptions.cs b/Http.Client.Options/Options/HttpClientHandlerOptions.cs index dde8d7c..47e1671 100644 --- a/Http.Client.Options/Options/HttpClientHandlerOptions.cs +++ b/Http.Client.Options/Options/HttpClientHandlerOptions.cs @@ -7,12 +7,12 @@ namespace Http.Options { public class HttpClientHandlerOptions { - public int? MaxConnection = null; + public int? MaxConnection { get; set; } = null; //the default is 2 min //this would consume a bit more memory but enable more efficient caching for http connections //(HttpMessageHandler can be reused as long as it is not expired) - public double HandlerLifeTimeMinutes = 10; + public double HandlerLifeTimeMinutes{ get; set; } = 10; public void ConfigureHttpClientBuilder(HttpMessageHandlerBuilder httpClientBuilder) { diff --git a/Http.Client.Options/Options/HttpClientOptions.cs b/Http.Client.Options/Options/HttpClientOptions.cs index 37b4094..a18048c 100644 --- a/Http.Client.Options/Options/HttpClientOptions.cs +++ b/Http.Client.Options/Options/HttpClientOptions.cs @@ -10,11 +10,11 @@ public class HttpClientOptions { public string ServiceName; - public HttpPollyOptions Polly = new HttpPollyOptions(); - public HttpTimeoutOptions Timeout = new HttpTimeoutOptions(); - public HttpClientHandlerOptions Handler = new HttpClientHandlerOptions(); - public HttpConnectionOptions Connection = new HttpConnectionOptions(); - public HttpTelemetryOptions Telemetry = new HttpTelemetryOptions(); + public HttpPollyOptions Polly { get; set; }= new HttpPollyOptions(); + public HttpTimeoutOptions Timeout { get; set; }= new HttpTimeoutOptions(); + public HttpClientHandlerOptions Handler { get; set; }= new HttpClientHandlerOptions(); + public HttpConnectionOptions Connection { get; set; }= new HttpConnectionOptions(); + public HttpTelemetryOptions Telemetry { get; set; }= new HttpTelemetryOptions(); public HttpClientOptions() { diff --git a/Http.Client.Options/Options/HttpConnectionOptions.cs b/Http.Client.Options/Options/HttpConnectionOptions.cs index 2ffbe12..fb09a89 100644 --- a/Http.Client.Options/Options/HttpConnectionOptions.cs +++ b/Http.Client.Options/Options/HttpConnectionOptions.cs @@ -21,8 +21,11 @@ public class HttpConnectionOptions public int Port { get; set; } = 80; public string Server { get; set; } + + public string Url { get; set; } - public Uri BaseUrl => new Uri($@"{Schema}://{Server}:{Port}/"); + + public Uri BaseUrl => new Uri(Url ?? $@"{Schema}://{Server}:{Port}/"); public int? TimeoutMS { diff --git a/Http.Client.Options/Options/HttpTelemetryOptions.cs b/Http.Client.Options/Options/HttpTelemetryOptions.cs index 3f35ea2..866efeb 100644 --- a/Http.Client.Options/Options/HttpTelemetryOptions.cs +++ b/Http.Client.Options/Options/HttpTelemetryOptions.cs @@ -23,7 +23,7 @@ public void ConfigureHttpClientBuilder(HttpMessageHandlerBuilder httpClientBuild } } - private IEnumerable Handlers(IServiceProvider serviceProvider) + protected IEnumerable Handlers(IServiceProvider serviceProvider) { if (Counter) diff --git a/Http.Client.Options/PollyOptions/CircuitBreakerOptions.cs b/Http.Client.Options/PollyOptions/CircuitBreakerOptions.cs index a278ca0..21c8b12 100644 --- a/Http.Client.Options/PollyOptions/CircuitBreakerOptions.cs +++ b/Http.Client.Options/PollyOptions/CircuitBreakerOptions.cs @@ -18,19 +18,19 @@ public class BrokenCircuitStatus public class CircuitBreakerOptions : PolicyOptions { /// The failure threshold at which the circuit will break (a number between 0 and 1; eg 0.5 represents breaking if 50% or more of actions result in a handled failure. - public double FailureThreshold = 0.8; + public double FailureThreshold { get; set; } = 0.8; ///The duration of the time slice over which failure ratios are assessed in MS. - public double SamplingDuration = 1000; + public double SamplingDuration { get; set; }= 1000; ///The minimum throughput: this many actions or more must pass through the circuit in the time-slice, for statistics to be considered significant and the circuit-breaker to come into action - public int MinimumThroughput = 10; + public int MinimumThroughput { get; set; }= 10; ///The duration the circuit will stay open before resetting in MS. - public double DurationOfBreak = 1000; + public double DurationOfBreak { get; set; }= 1000; /// fail, log, none - public string FailPolicy = "fail"; + public string FailPolicy{ get; set; } = "fail"; private IAsyncPolicy _policy; diff --git a/Http.Client.Options/PollyOptions/TransientHttpPolicy.cs b/Http.Client.Options/PollyOptions/TransientHttpPolicy.cs index 6094bfe..a40acfe 100644 --- a/Http.Client.Options/PollyOptions/TransientHttpPolicy.cs +++ b/Http.Client.Options/PollyOptions/TransientHttpPolicy.cs @@ -13,12 +13,12 @@ namespace Http.Options { public class HttpPollyOptions { - public CircuitBreakerOptions CircuitBreaker = + public CircuitBreakerOptions CircuitBreaker { get; set; }= new CircuitBreakerOptions(); - public RetryPolicyOptions Retry = new RetryPolicyOptions(); - public TimeoutPolicyOptions Timeout = new TimeoutPolicyOptions(); - public BulkheadPolicyOptions Bulkhead = new BulkheadPolicyOptions(); + public RetryPolicyOptions Retry { get; set; }= new RetryPolicyOptions(); + public TimeoutPolicyOptions Timeout { get; set; }= new TimeoutPolicyOptions(); + public BulkheadPolicyOptions Bulkhead { get; set; }= new BulkheadPolicyOptions(); public void ConfigureHttpClientBuilder(HttpMessageHandlerBuilder httpClientBuilder, diff --git a/Http.Client.Options/Tracing/Options/TracingActivityOptions.cs b/Http.Client.Options/Tracing/Options/TracingActivityOptions.cs index 1e63b87..55c8cf1 100644 --- a/Http.Client.Options/Tracing/Options/TracingActivityOptions.cs +++ b/Http.Client.Options/Tracing/Options/TracingActivityOptions.cs @@ -6,8 +6,8 @@ namespace Http.Options.Tracing public class TracingActivityOptions { public ActivitySource Source = new ActivitySource("http-options-activity-source"); - public string ActivityName = "http-options-activity"; - public string ActivityService= "http-options-service"; + public string ActivityName { get; set; } = "http-options-activity"; + public string ActivityService { get; set; } = "http-options-service"; public Activity StartActivity( ) { diff --git a/Http.Client.Options/Tracing/Options/TracingEnrichmentOptions.cs b/Http.Client.Options/Tracing/Options/TracingEnrichmentOptions.cs index 61eaa03..8be94cb 100644 --- a/Http.Client.Options/Tracing/Options/TracingEnrichmentOptions.cs +++ b/Http.Client.Options/Tracing/Options/TracingEnrichmentOptions.cs @@ -37,7 +37,7 @@ public void OnError(Action onError) ErrorEnrichment.Add(new HttpErrorEnrichment(onError)); } - public void EnrichException(HttpTracingActivity ctx, + internal void EnrichException(HttpTracingActivity ctx, Exception requestMessage) { foreach (var enrichment in ErrorEnrichment) @@ -46,7 +46,7 @@ public void EnrichException(HttpTracingActivity ctx, } } - public void EnrichRequest(HttpTracingActivity ctx, + internal void EnrichRequest(HttpTracingActivity ctx, HttpRequestMessage requestMessage) { foreach (var enrichment in RequestEnrichment) @@ -55,7 +55,7 @@ public void EnrichRequest(HttpTracingActivity ctx, } } - public void EnrichRequest(HttpTracingActivity ctx, + internal void EnrichRequest(HttpTracingActivity ctx, HttpWebRequest requestMessage) { foreach (var enrichment in RequestEnrichment) @@ -64,7 +64,7 @@ public void EnrichRequest(HttpTracingActivity ctx, } } - public void EnrichResponse(HttpTracingActivity ctx, + internal void EnrichResponse(HttpTracingActivity ctx, HttpResponseMessage responseMessage) { foreach (var enrichment in ResponseEnrichment) @@ -73,7 +73,7 @@ public void EnrichResponse(HttpTracingActivity ctx, } } - public void EnrichResponse(HttpTracingActivity ctx, HttpWebResponse responseMessage) + internal void EnrichResponse(HttpTracingActivity ctx, HttpWebResponse responseMessage) { { foreach (var enrichment in ResponseEnrichment) diff --git a/Http.Client.Options/Tracing/Options/TracingTagsOptions.cs b/Http.Client.Options/Tracing/Options/TracingTagsOptions.cs index 94d340a..b311af1 100644 --- a/Http.Client.Options/Tracing/Options/TracingTagsOptions.cs +++ b/Http.Client.Options/Tracing/Options/TracingTagsOptions.cs @@ -5,14 +5,14 @@ namespace Http.Options.Tracing { public class TracingTagsOptions { - public readonly ConfigTracer Config = new ConfigTracer(); - public readonly RequestTracer Request = new RequestTracer(); - public readonly ResponseTracer Response = new ResponseTracer(); - public readonly FlowTracer Context = new FlowTracer(); - public readonly ErrorTracer Error = new ErrorTracer(); - public readonly ConnectionTracer Connection = new ConnectionTracer(); - public readonly TcpTracer Tcp = new TcpTracer(); - public readonly CountersTracer Counter = new CountersTracer(); + public ConfigTracer Config { get; set; } = new ConfigTracer(); + public RequestTracer Request { get; set; } = new RequestTracer(); + public ResponseTracer Response { get; set; } = new ResponseTracer(); + public FlowTracer Context { get; set; } = new FlowTracer(); + public ErrorTracer Error { get; set; } = new ErrorTracer(); + public ConnectionTracer Connection { get; set; } = new ConnectionTracer(); + public TcpTracer Tcp { get; set; } = new TcpTracer(); + public CountersTracer Counter { get; set; } = new CountersTracer(); public void ConfigureTracingOptions(HttpTracingOptions options ) { diff --git a/Http.Client.Options/Tracing/OptionsBuilder/OpenTelemetryOptionsBuilder.cs b/Http.Client.Options/Tracing/OptionsBuilder/OpenTelemetryOptionsBuilder.cs index 7ebf7ab..553cbf1 100644 --- a/Http.Client.Options/Tracing/OptionsBuilder/OpenTelemetryOptionsBuilder.cs +++ b/Http.Client.Options/Tracing/OptionsBuilder/OpenTelemetryOptionsBuilder.cs @@ -1,11 +1,12 @@ using System; using Http.Client.Options.Tracing; -using Http.Options.Tracing.HttpEnrichment; +using Http.Options.Counters; using Http.Options.Tracing.OpenTelemetry; +using Http.Options.Tracing.Processors; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; -using OpenTelemetry; -using OpenTelemetry.Resources; using OpenTelemetry.Trace; namespace Http.Options.Tracing.OptionsBuilder diff --git a/Http.Client.Options/Tracing/Tcp/TcpTracer.cs b/Http.Client.Options/Tracing/Tcp/TcpTracer.cs index 8d307f5..f95aea4 100644 --- a/Http.Client.Options/Tracing/Tcp/TcpTracer.cs +++ b/Http.Client.Options/Tracing/Tcp/TcpTracer.cs @@ -9,12 +9,12 @@ namespace Http.Options.Tracing.Tcp { public class TcpTracer { - public TimeSpan Period = TimeSpan.FromMinutes(1); - public bool Enabled = false; + public TimeSpan Period { get; set; } = TimeSpan.FromMinutes(1); + public bool Enabled{ get; set; } = false; private static readonly TcpConnectionsEnumerator ConnectionsEnumerator = new TcpConnectionsEnumerator(); - public TracingTagAction AllConnections = "tcp.connections.all"; - public TracingTagAction TotalConnection = "tcp.connections.total"; + public TracingTagAction AllConnections { get; set; } = "tcp.connections.all"; + public TracingTagAction TotalConnection { get; set; } = "tcp.connections.total"; public readonly TracingTagGroup ConnectionState = new TracingTagGroup(TcpStateName, enabled: false); diff --git a/Http.Client.Options/Tracing/Tracers/ConfigTracer.cs b/Http.Client.Options/Tracing/Tracers/ConfigTracer.cs index d841e2d..7f14c60 100644 --- a/Http.Client.Options/Tracing/Tracers/ConfigTracer.cs +++ b/Http.Client.Options/Tracing/Tracers/ConfigTracer.cs @@ -6,13 +6,13 @@ namespace Http.Options.Tracing { public class ConfigTracer { - public TracingTag Server = "config.server"; - public TracingTag Port = "config.port"; - public TracingTag Schema = "config.schema"; - public TracingTag Name = "config.name"; - public TracingTag Timeout = "config.timeout"; - public TracingTag MaxConnection = "config.handler.maxConnection"; - public TracingTag LifeTimeMinutes = "config.handler.lifeTimeMinutes"; + public TracingTag Server { get; set; } = "config.server"; + public TracingTag Port { get; set; } = "config.port"; + public TracingTag Schema { get; set; } = "config.schema"; + public TracingTag Name { get; set; } = "config.name"; + public TracingTag Timeout { get; set; } = "config.timeout"; + public TracingTag MaxConnection { get; set; } = "config.handler.maxConnection"; + public TracingTag LifeTimeMinutes { get; set; } = "config.handler.lifeTimeMinutes"; public void Trace(HttpTracingActivity tracing ) diff --git a/Http.Client.Options/Tracing/Tracers/ConnectionTracer.cs b/Http.Client.Options/Tracing/Tracers/ConnectionTracer.cs index c642f20..b946f22 100644 --- a/Http.Client.Options/Tracing/Tracers/ConnectionTracer.cs +++ b/Http.Client.Options/Tracing/Tracers/ConnectionTracer.cs @@ -11,15 +11,15 @@ public ConnectionTracer() { } - public TracingTag Count = "connection.count"; - public TracingTag ConnectionsLimit = "connection.limit"; - public TracingTag ConnectionsTimeout = "connection.timeout"; - public TracingTag IdleSince = "connection.idleSince"; - public TracingTag MaxIdleTime = "connection.maxIdleTime"; - public TracingTag ReceiveBufferSize = "connection.receiveBufferSize"; - public TracingTag UseNagleAlgorithm = "connection.useNagle"; - public TracingTag ConnectionId = "connection.id"; - public TracingTag ConnectionGroup= "connection.group"; + public TracingTag Count { get; set; } = "connection.count"; + public TracingTag ConnectionsLimit { get; set; } = "connection.limit"; + public TracingTag ConnectionsTimeout { get; set; } = "connection.timeout"; + public TracingTag IdleSince { get; set; } = "connection.idleSince"; + public TracingTag MaxIdleTime { get; set; } = "connection.maxIdleTime"; + public TracingTag ReceiveBufferSize { get; set; } = "connection.receiveBufferSize"; + public TracingTag UseNagleAlgorithm{ get; set; } = "connection.useNagle"; + public TracingTag ConnectionId { get; set; } = "connection.id"; + public TracingTag ConnectionGroup{ get; set; } = "connection.group"; public void Trace(HttpTracingActivity tracing, HttpWebRequest request) { diff --git a/Http.Client.Options/Tracing/Tracers/ErrorTracer.cs b/Http.Client.Options/Tracing/Tracers/ErrorTracer.cs index 36f5e8b..55015ad 100644 --- a/Http.Client.Options/Tracing/Tracers/ErrorTracer.cs +++ b/Http.Client.Options/Tracing/Tracers/ErrorTracer.cs @@ -7,12 +7,12 @@ namespace Http.Options.Tracing { public class ErrorTracer { - public TracingTag Error =OpenTelemetryConventions.AttributeExceptionMessage; - public TracingTag Type =OpenTelemetryConventions.AttributeExceptionType; - public TracingTag StackTrace = OpenTelemetryConventions.AttributeExceptionStacktrace ; - public TracingTag InnerError = "exception.inner.message" ; - public TracingTag InnerType = "exception.inner.type" ; - public TracingTag InnerStackTrace = "exception.inner.stackTrace" ; + public TracingTag Error { get; set; } =OpenTelemetryConventions.AttributeExceptionMessage; + public TracingTag Type { get; set; } =OpenTelemetryConventions.AttributeExceptionType; + public TracingTag StackTrace { get; set; } = OpenTelemetryConventions.AttributeExceptionStacktrace ; + public TracingTag InnerError { get; set; } = "exception.inner.message" ; + public TracingTag InnerType { get; set; } = "exception.inner.type" ; + public TracingTag InnerStackTrace{ get; set; } = "exception.inner.stackTrace" ; public void Trace(HttpTracingActivity activity, Exception exception) { diff --git a/Http.Client.Options/Tracing/Tracers/FlowTracer.cs b/Http.Client.Options/Tracing/Tracers/FlowTracer.cs index 8ffc139..549d199 100644 --- a/Http.Client.Options/Tracing/Tracers/FlowTracer.cs +++ b/Http.Client.Options/Tracing/Tracers/FlowTracer.cs @@ -7,21 +7,21 @@ namespace Http.Options.Tracing { public class FlowTracer { - public TracingTag Timestamp = "timestamp"; - public TracingTag RequestStart = "time.start"; - public TracingTag RequestEnd = "time.end"; - public TracingTag TotalTime = "time.duration"; - - public TracingTag HttpRequestStart = "time.http.start"; - public TracingTag HttpRequestEnd = "time.http.end"; - public TracingTag HttpTotalTime = "time.http.duration"; + public TracingTag Timestamp { get; set; } = "timestamp"; + public TracingTag RequestStart { get; set; } = "time.start"; + public TracingTag RequestEnd { get; set; } = "time.end"; + public TracingTag TotalTime { get; set; } = "time.duration"; + + public TracingTag HttpRequestStart { get; set; } = "time.http.start"; + public TracingTag HttpRequestEnd { get; set; } = "time.http.end"; + public TracingTag HttpTotalTime { get; set; } = "time.http.duration"; - public TracingTag HandlerDelta = "time.delta.ms"; - public TracingTag HandlerDeltaOnStart = "time.delta.start.ms"; - public TracingTag HandlerDeltaOnEnd = "time.delta.end.ms"; + public TracingTag HandlerDelta { get; set; } = "time.delta.ms"; + public TracingTag HandlerDeltaOnStart { get; set; } = "time.delta.start.ms"; + public TracingTag HandlerDeltaOnEnd { get; set; } = "time.delta.end.ms"; - public TracingTag CorrelationsId = "correlation.id"; + public TracingTag CorrelationsId { get; set; } = "correlation.id"; public void TraceStart(HttpTracingActivity activity) { diff --git a/Http.Client.Options/Tracing/Tracers/RequestTracer.cs b/Http.Client.Options/Tracing/Tracers/RequestTracer.cs index 6105b67..350c545 100644 --- a/Http.Client.Options/Tracing/Tracers/RequestTracer.cs +++ b/Http.Client.Options/Tracing/Tracers/RequestTracer.cs @@ -9,13 +9,13 @@ namespace Http.Options.Tracing { public class RequestTracer { - public TracingTag Method = OpenTelemetryConventions.AttributeHttpMethod; - public TracingTag Url = OpenTelemetryConventions.AttributeHttpUrl; - public TracingTag Schema = OpenTelemetryConventions.AttributeHttpScheme; - public TracingTag Host = OpenTelemetryConventions.AttributeHttpTarget; - public TracingTag RequestPath = OpenTelemetryConventions.AttributeHttpRoute; - public TracingTag RequestLength = OpenTelemetryConventions.AttributeHttpRequestContentLength; - public TracingTag Port = OpenTelemetryConventions.AttributeHttpHostPort; + public TracingTag Method { get; set; } = OpenTelemetryConventions.AttributeHttpMethod; + public TracingTag Url { get; set; } = OpenTelemetryConventions.AttributeHttpUrl; + public TracingTag Schema { get; set; } = OpenTelemetryConventions.AttributeHttpScheme; + public TracingTag Host { get; set; } = OpenTelemetryConventions.AttributeHttpTarget; + public TracingTag RequestPath { get; set; } = OpenTelemetryConventions.AttributeHttpRoute; + public TracingTag RequestLength { get; set; } = OpenTelemetryConventions.AttributeHttpRequestContentLength; + public TracingTag Port { get; set; } = OpenTelemetryConventions.AttributeHttpHostPort; public void Trace(HttpTracingActivity tracing, HttpRequestMessage request) { diff --git a/Http.Client.Options/Tracing/Tracers/ResponseTracer.cs b/Http.Client.Options/Tracing/Tracers/ResponseTracer.cs index 137cac5..37d1ff5 100644 --- a/Http.Client.Options/Tracing/Tracers/ResponseTracer.cs +++ b/Http.Client.Options/Tracing/Tracers/ResponseTracer.cs @@ -10,8 +10,8 @@ namespace Http.Options.Tracing { public class ResponseTracer { - public TracingTag ContentLength = OpenTelemetryConventions.AttributeHttpResponseContentLength; - public TracingTag HttpStatusCode = OpenTelemetryConventions.AttributeHttpStatusCode; + public TracingTag ContentLength { get; set; } = OpenTelemetryConventions.AttributeHttpResponseContentLength; + public TracingTag HttpStatusCode { get; set; } = OpenTelemetryConventions.AttributeHttpStatusCode; public void Trace(HttpTracingActivity activity, HttpResponseMessage httpResponseMessage) { From b85ac39325f4a067ea3d8a2c33af3fd2c2ecd4f1 Mon Sep 17 00:00:00 2001 From: Dina Vinter Date: Fri, 10 Feb 2023 02:48:56 +0200 Subject: [PATCH 2/7] Create version-sweeper.yml --- .github/workflows/version-sweeper.yml | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/version-sweeper.yml diff --git a/.github/workflows/version-sweeper.yml b/.github/workflows/version-sweeper.yml new file mode 100644 index 0000000..cf06e35 --- /dev/null +++ b/.github/workflows/version-sweeper.yml @@ -0,0 +1,47 @@ +# The name used in the GitHub UI for the workflow +name: '.net version sweeper' + +# When to run this action: +# - Scheduled on the first of every month +# - Manually runable from the GitHub UI with a reason +on: + schedule: + - cron: '0 0 1 * *' + workflow_dispatch: + inputs: + reason: + description: 'The reason for running the workflow' + required: true + default: 'Manual run' + +# Run on the latest version of Ubuntu +jobs: + version-sweep: + runs-on: ubuntu-latest + permissions: + contents: read + issues: write + statuses: write + + # Checkout the repo into the workspace within the VM + steps: + - uses: actions/checkout@v2 + + # If triggered manually, print the reason why + - name: 'Print manual run reason' + if: ${{ github.event_name == 'workflow_dispatch' }} + run: | + echo "Reason: ${{ github.event.inputs.reason }}" + + # Run the .NET version sweeper + # Issues will be automatically created for any non-ignored projects that are targeting non-LTS versions + - name: .NET version sweeper + id: dotnet-version-sweeper + uses: dotnet/versionsweeper@v1.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + owner: ${{ github.repository_owner }} + name: ${{ github.repository }} + branch: ${{ github.ref }} + sdkCompliance: true From 08ec55c5dd1b89d144a9a29610c6e506f9bb7a02 Mon Sep 17 00:00:00 2001 From: dinavinter Date: Mon, 13 Mar 2023 11:51:40 +0200 Subject: [PATCH 3/7] feat(core): support compression --- .../Options/HttpClientCompressionOptions.cs | 57 +++++++++++++++++++ .../Options/HttpClientOptions.cs | 6 +- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 Http.Client.Options/Options/HttpClientCompressionOptions.cs diff --git a/Http.Client.Options/Options/HttpClientCompressionOptions.cs b/Http.Client.Options/Options/HttpClientCompressionOptions.cs new file mode 100644 index 0000000..4111a97 --- /dev/null +++ b/Http.Client.Options/Options/HttpClientCompressionOptions.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Http; + +namespace Http.Options +{ + public class HttpClientCompressionOptions + { + private static List EncodingHeaders = new List + { + new StringWithQualityHeaderValue("gzip"), + new StringWithQualityHeaderValue("deflate"), + }; + + public HttpClientCompressionOptions() + { + AutomaticDecompression = true; + Encoding = new Dictionary + { + ["gzip"] = true, + ["deflate"] = true, + }; + } + + public bool AutomaticDecompression { get; set; } + public Dictionary Encoding { get; set; } + + public void ConfigureHttpClientBuilder(HttpMessageHandlerBuilder httpClientBuilder) + { + // var handler= new HttpClientHandler() + + if (httpClientBuilder.PrimaryHandler is HttpClientHandler httpClientHandler) + { + if (AutomaticDecompression && httpClientHandler.SupportsAutomaticDecompression) + { + httpClientHandler.AutomaticDecompression = DecompressionMethods.Brotli | + DecompressionMethods.Deflate | + DecompressionMethods.GZip; + } + } + } + + public void ConfigureHttpClient(HttpClient httpClient) + { + foreach (var headerValue in EncodingHeaders.Where(x => + Encoding.TryGetValue(x.Value, out var enabled) && enabled)) + { + httpClient.DefaultRequestHeaders.AcceptEncoding.Add(headerValue); + } + } + } +} \ No newline at end of file diff --git a/Http.Client.Options/Options/HttpClientOptions.cs b/Http.Client.Options/Options/HttpClientOptions.cs index a18048c..c7e8ef6 100644 --- a/Http.Client.Options/Options/HttpClientOptions.cs +++ b/Http.Client.Options/Options/HttpClientOptions.cs @@ -14,7 +14,8 @@ public class HttpClientOptions public HttpTimeoutOptions Timeout { get; set; }= new HttpTimeoutOptions(); public HttpClientHandlerOptions Handler { get; set; }= new HttpClientHandlerOptions(); public HttpConnectionOptions Connection { get; set; }= new HttpConnectionOptions(); - public HttpTelemetryOptions Telemetry { get; set; }= new HttpTelemetryOptions(); + public HttpTelemetryOptions Telemetry { get; set; }= new HttpTelemetryOptions(); + public HttpClientCompressionOptions Compression { get; set; }= new HttpClientCompressionOptions(); public HttpClientOptions() { @@ -48,6 +49,7 @@ protected virtual void ConfigureHttpMessageHandlerBuilder(HttpMessageHandlerBuil Timeout?.ConfigureHttpClientBuilder(builder); Telemetry?.ConfigureHttpClientBuilder(builder, services); Polly?.ConfigureHttpClientBuilder(builder, services); + Compression?.ConfigureHttpClientBuilder(builder); // builder.AdditionalHandlers.Insert(0, new HttpClientScopeHandler(builder, this)); } @@ -57,6 +59,7 @@ protected virtual void ConfigureHttpMessageHandlerBuilder(HttpMessageHandlerBuil protected virtual void ConfigureHttpClient(HttpClient httpClient) { Connection?.ConfigureHttpClient(httpClient); + Compression?.ConfigureHttpClient(httpClient); } @@ -92,6 +95,7 @@ public void Configure(string name, HttpClientOptions options) options.Handler = Handler ?? options.Handler; options.Polly = Polly ?? options.Polly; options.Telemetry = Telemetry ?? options.Telemetry; + options.Compression = Compression ?? options.Compression; } public void Configure(HttpClientOptions options) From 79db69536008e203452e0a5506af44f1c4d5a657 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 13 Mar 2023 11:36:09 +0000 Subject: [PATCH 4/7] chore(release): 8.0.0-beta.1 [skip ci] # [8.0.0-beta.1](https://github.com/dinavinter/Http.Options/compare/v7.2.0...v8.0.0-beta.1) (2023-03-13) ### Bug Fixes * release ([b034c67](https://github.com/dinavinter/Http.Options/commit/b034c67e478ee0a18fc77ff35c120daf3a120f8d)) ### chore * drop support for net5.0 ([88c7f40](https://github.com/dinavinter/Http.Options/commit/88c7f409a75c4669c9cb252ab6a91bceb40b590b)) ### Features * **core:** change fields to auto properties to allow serialization - this required for using microsoft.extensions.options from a config file. ([5900fca](https://github.com/dinavinter/Http.Options/commit/5900fca0678b3dea3b16ee98f9fa6f2cda9a9df5)) * **core:** support compression ([b09e868](https://github.com/dinavinter/Http.Options/commit/b09e868782a60159e41d7dffd54685e8c86e8a4c)) ### BREAKING CHANGES * Drop support for net5.0 or lower net versions. --- CHANGELOG.md | 23 +++++++++++++++++++++++ Directory.Build.props | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0664b1..71ba941 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,28 @@ # Semantic Versioning Changelog +# [8.0.0-beta.1](https://github.com/dinavinter/Http.Options/compare/v7.2.0...v8.0.0-beta.1) (2023-03-13) + + +### Bug Fixes + +* release ([b034c67](https://github.com/dinavinter/Http.Options/commit/b034c67e478ee0a18fc77ff35c120daf3a120f8d)) + + +### chore + +* drop support for net5.0 ([88c7f40](https://github.com/dinavinter/Http.Options/commit/88c7f409a75c4669c9cb252ab6a91bceb40b590b)) + + +### Features + +* **core:** change fields to auto properties to allow serialization - this required for using microsoft.extensions.options from a config file. ([5900fca](https://github.com/dinavinter/Http.Options/commit/5900fca0678b3dea3b16ee98f9fa6f2cda9a9df5)) +* **core:** support compression ([b09e868](https://github.com/dinavinter/Http.Options/commit/b09e868782a60159e41d7dffd54685e8c86e8a4c)) + + +### BREAKING CHANGES + +* Drop support for net5.0 or lower net versions. + # [7.3.0-prerelease.1](https://github.com/dinavinter/Http.Options/compare/v7.2.0...v7.3.0-prerelease.1) (2023-02-10) diff --git a/Directory.Build.props b/Directory.Build.props index 214dd2c..06df293 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,7 +4,7 @@ - 7.3.0-beta.1 + 8.0.0-beta.1 false true true From a34b6e26847d71fa0499718846b3a272024aa864 Mon Sep 17 00:00:00 2001 From: dinavinter Date: Mon, 13 Mar 2023 13:49:24 +0200 Subject: [PATCH 5/7] chore(ci): approve release and test actions --- .github/workflows/NET472.yml | 21 --------------------- .github/workflows/NET60.yml | 5 +++-- .github/workflows/dotnet.yml | 25 ------------------------- .github/workflows/release.yml | 1 + 4 files changed, 4 insertions(+), 48 deletions(-) delete mode 100644 .github/workflows/NET472.yml delete mode 100644 .github/workflows/dotnet.yml diff --git a/.github/workflows/NET472.yml b/.github/workflows/NET472.yml deleted file mode 100644 index 9269f36..0000000 --- a/.github/workflows/NET472.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: .NET472 - -on: [push, pull_request] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Setup .NET - uses: actions/setup-dotnet@v1 - with: - dotnet-version: net472 - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --no-restore - - name: Test - run: dotnet test --no-build --verbosity normal diff --git a/.github/workflows/NET60.yml b/.github/workflows/NET60.yml index c8c52f4..6f1b4cf 100644 --- a/.github/workflows/NET60.yml +++ b/.github/workflows/NET60.yml @@ -1,10 +1,11 @@ name: .NET60 on: + workflow_dispatch: push: - branches: [ master ] + branches: [ main, master, beta, release, prerelease] pull_request: - branches: [ master ] + branches: [ main, master, beta, release, prerelease ] jobs: build: diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml deleted file mode 100644 index 59d6e7f..0000000 --- a/.github/workflows/dotnet.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: .NET50 - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Setup .NET - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 5.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --no-restore - - name: Test - run: dotnet test --no-build --verbosity normal diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f1262c4..fcc6200 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,6 +5,7 @@ on: branches: - "beta" - "prerelease" + - "master" env: PROJECT_PATH: 'Http.Client.Options/Http.Client.Options.csproj' PACKAGE_OUTPUT_DIRECTORY: ${{ github.workspace }}/output From 5e75cbeeb8949ad9b84e35012cf64e2a8b98fb82 Mon Sep 17 00:00:00 2001 From: dinavinter Date: Tue, 14 Mar 2023 01:08:28 +0200 Subject: [PATCH 6/7] chore(deps): support net7 --- .github/workflows/NET60.yml | 26 ---------- .github/workflows/release.yml | 24 +++++---- .github/workflows/test.yml | 51 +++++++++++++++++++ .../Http.Options.PlaygroundCore.csproj | 30 +++++++---- Directory.Build.props | 1 + .../Http.Client.Options.WireServer.csproj | 3 +- .../Http.Client.Options.csproj | 3 +- .../Http.Options.Benchmarks.csproj | 3 +- .../Http.Options.UnitTests.csproj | 21 ++++---- .../HttpClientThroghtputTests.cs | 1 - Http.Options.sln | 1 + 11 files changed, 102 insertions(+), 62 deletions(-) delete mode 100644 .github/workflows/NET60.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/NET60.yml b/.github/workflows/NET60.yml deleted file mode 100644 index 6f1b4cf..0000000 --- a/.github/workflows/NET60.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: .NET60 - -on: - workflow_dispatch: - push: - branches: [ main, master, beta, release, prerelease] - pull_request: - branches: [ main, master, beta, release, prerelease ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Setup .NET - uses: actions/setup-dotnet@v2 - with: - dotnet-version: 6.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --no-restore --framework net6.0 - - name: Test - run: dotnet test --no-build --verbosity normal --framework net6.0 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fcc6200..e641899 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Release +name: release on: workflow_dispatch: push: @@ -6,33 +6,37 @@ on: - "beta" - "prerelease" - "master" + + env: PROJECT_PATH: 'Http.Client.Options/Http.Client.Options.csproj' PACKAGE_OUTPUT_DIRECTORY: ${{ github.workspace }}/output NUGET_PUSH_URL: ${{ secrets.NUGET_PUSH_URL }} NUGET_TOKEN: ${{ secrets.NUGET_TOKEN }} - DOTNET_VERSION: '6.0.x' - TARGET_FRAMEWORKS: 'net6.0' jobs: - + test: + uses: ./test.yml@beta + release: + needs: test name: Release - runs-on: ${{ matrix.os }} strategy: matrix: os: [ ubuntu-latest ] + runs-on: ${{ matrix.os }} steps: - name: Checkout uses: actions/checkout@v3 + - name: Setup .NET - uses: actions/setup-dotnet@v2 - with: - dotnet-version: ${{ env.DOTNET_VERSION }} - + uses: actions/setup-dotnet@v3 + + - run: echo '${{ steps.stepid.outputs.dotnet-version }}' + - name: Install dependencies run: dotnet restore - + - name: Semantic Release id: release uses: cycjimmy/semantic-release-action@v3 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..137e733 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,51 @@ +name: dotnet test + +on: + workflow_dispatch: + push: + branches: [ main, master, beta, release, prerelease] + pull_request: + branches: [ main, master, beta, release, prerelease ] + +jobs: + build: + + + runs-on: ubuntu-latest + strategy: + matrix: + dotnet: [ '6.*', '7.*'] + name: Test w/t ${{ matrix.dotnet }} + steps: + - uses: actions/checkout@v3 + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: ${{ matrix.dotnet }} + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: dotnet build --no-restore + + - name: Test + run: dotnet test --no-build --logger trx --results-directory "test-results-${{ matrix.dotnet-version }}" + + - name: Upload dotnet test results + uses: actions/upload-artifact@v3 + with: + name: test-results-${{ matrix.dotnet-version }} + path: test-results-${{ matrix.dotnet-version }} + if: ${{ always() }} + - uses: dorny/test-reporter@v1 + with: + path: test-results-${{ matrix.dotnet-version }} + name: test-results-${{ matrix.dotnet-version }} + reporter: dotnet-trx + fail-on-error: 'true' + artifact: test-results-${{ matrix.dotnet-version }} + if: ${{ always() }} +# - name: Summery Report +# run: | +# echo "- Test w/t ${{ matrix.dotnet }} done" >> $GITHUB_STEP_SUMMARY + diff --git a/.playground/Http.Options.PlaygroundCore/Http.Options.PlaygroundCore.csproj b/.playground/Http.Options.PlaygroundCore/Http.Options.PlaygroundCore.csproj index 726214e..c66fadd 100644 --- a/.playground/Http.Options.PlaygroundCore/Http.Options.PlaygroundCore.csproj +++ b/.playground/Http.Options.PlaygroundCore/Http.Options.PlaygroundCore.csproj @@ -3,24 +3,34 @@ Exe net6.0 + + + + + + + + + + + + + - - - - - - - - - + + - + + + + + diff --git a/Directory.Build.props b/Directory.Build.props index 06df293..86874bc 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -9,6 +9,7 @@ true true true + net6.0;net7.0 diff --git a/Http.Client.Options.WireServer/Http.Client.Options.WireServer.csproj b/Http.Client.Options.WireServer/Http.Client.Options.WireServer.csproj index eda162b..39c76b3 100644 --- a/Http.Client.Options.WireServer/Http.Client.Options.WireServer.csproj +++ b/Http.Client.Options.WireServer/Http.Client.Options.WireServer.csproj @@ -2,9 +2,10 @@ true - net6.0 + $(TargetFrameworks) + diff --git a/Http.Client.Options/Http.Client.Options.csproj b/Http.Client.Options/Http.Client.Options.csproj index 307767c..b764095 100644 --- a/Http.Client.Options/Http.Client.Options.csproj +++ b/Http.Client.Options/Http.Client.Options.csproj @@ -2,11 +2,10 @@ Http.Options - 8 + 11 $(Version) $(Version) $(Version) - net6.0 diff --git a/Http.Options.Benchmarks/Http.Options.Benchmarks.csproj b/Http.Options.Benchmarks/Http.Options.Benchmarks.csproj index 97ace56..f9c9595 100644 --- a/Http.Options.Benchmarks/Http.Options.Benchmarks.csproj +++ b/Http.Options.Benchmarks/Http.Options.Benchmarks.csproj @@ -7,7 +7,8 @@ preview Exe Http.Options.Benchmarks - net6.0 + net6.0 + diff --git a/Http.Options.UnitTests/Http.Options.UnitTests.csproj b/Http.Options.UnitTests/Http.Options.UnitTests.csproj index 9c3b88a..c7a8f7d 100644 --- a/Http.Options.UnitTests/Http.Options.UnitTests.csproj +++ b/Http.Options.UnitTests/Http.Options.UnitTests.csproj @@ -6,21 +6,20 @@ latest - net6.0; - - - - - - - - - + + + + + + + + + @@ -29,7 +28,7 @@ - + diff --git a/Http.Options.UnitTests/HttpClientThroghtputTests.cs b/Http.Options.UnitTests/HttpClientThroghtputTests.cs index 639c5e7..5d3e325 100644 --- a/Http.Options.UnitTests/HttpClientThroghtputTests.cs +++ b/Http.Options.UnitTests/HttpClientThroghtputTests.cs @@ -13,7 +13,6 @@ using Http.Client.Options.Tracing; using Http.Options.Tracing.OpenTelemetry; using Http.Options.Tracing.Processors; -using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging.EventSource; using Newtonsoft.Json; diff --git a/Http.Options.sln b/Http.Options.sln index fecd583..c8cc60e 100644 --- a/Http.Options.sln +++ b/Http.Options.sln @@ -53,6 +53,7 @@ Global {11FF6998-A3EF-46CE-85FB-64624DEB49A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {11FF6998-A3EF-46CE-85FB-64624DEB49A4}.Release|Any CPU.ActiveCfg = Release|Any CPU {11FF6998-A3EF-46CE-85FB-64624DEB49A4}.Release|Any CPU.Build.0 = Release|Any CPU + {11FF6998-A3EF-46CE-85FB-64624DEB49A4}.Debug|Any CPU.Build.0 = Debug|Any CPU {5177538B-BD6E-49A0-B4BA-7D3BACADDAE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5177538B-BD6E-49A0-B4BA-7D3BACADDAE4}.Debug|Any CPU.Build.0 = Debug|Any CPU {5177538B-BD6E-49A0-B4BA-7D3BACADDAE4}.Release|Any CPU.ActiveCfg = Release|Any CPU From c82d80717ab7bf444a31b0dcbb39128af43e5931 Mon Sep 17 00:00:00 2001 From: dinavinter Date: Tue, 14 Mar 2023 02:11:57 +0200 Subject: [PATCH 7/7] chore(ci): fix test [skip ci] --- .github/workflows/test.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 137e733..8c47230 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,21 +29,20 @@ jobs: run: dotnet build --no-restore - name: Test - run: dotnet test --no-build --logger trx --results-directory "test-results-${{ matrix.dotnet-version }}" + run: dotnet test --no-build --logger trx --results-directory "reports/${{ matrix.dotnet }}/tests" - name: Upload dotnet test results uses: actions/upload-artifact@v3 with: - name: test-results-${{ matrix.dotnet-version }} - path: test-results-${{ matrix.dotnet-version }} + name: test-results-${{ matrix.dotnet }} + path: reports/${{ matrix.dotnet }}/tests if: ${{ always() }} - uses: dorny/test-reporter@v1 with: - path: test-results-${{ matrix.dotnet-version }} - name: test-results-${{ matrix.dotnet-version }} + path: reports/${{ matrix.dotnet }}/tests + name: Test report ${{ matrix.dotnet }} reporter: dotnet-trx fail-on-error: 'true' - artifact: test-results-${{ matrix.dotnet-version }} if: ${{ always() }} # - name: Summery Report # run: |