From c4f41f8e68dc9686236cf6b8441def9137dd4885 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Fri, 9 Feb 2024 11:57:33 +0100 Subject: [PATCH 1/5] github-action: listen for all the workflow runs (#359) --- .github/workflows/opentelemetry.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/opentelemetry.yml b/.github/workflows/opentelemetry.yml index defb9d9b..16d0101e 100644 --- a/.github/workflows/opentelemetry.yml +++ b/.github/workflows/opentelemetry.yml @@ -1,17 +1,16 @@ --- +# Look up results at https://ela.st/oblt-ci-cd-stats +# There will be one service per GitHub repository, including the org name, and one Transaction per Workflow. name: OpenTelemetry Export Trace on: workflow_run: - workflows: - - pre-commit - - release - - release-main - - test - - test-reporter - - update-specs + workflows: [ "*" ] types: [completed] +permissions: + contents: read + jobs: otel-export-trace: runs-on: ubuntu-latest From de4f10766ef3cc54ae0440b8988115df76a69e1d Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 11 Mar 2024 15:28:24 +0100 Subject: [PATCH 2/5] security: add permissions block to workflows (#360) --- .github/workflows/test-reporter.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test-reporter.yml b/.github/workflows/test-reporter.yml index 065635f6..33c323c6 100644 --- a/.github/workflows/test-reporter.yml +++ b/.github/workflows/test-reporter.yml @@ -8,6 +8,10 @@ on: types: - completed +permissions: + contents: read + actions: read + jobs: report: runs-on: ubuntu-latest From 79ef25894d808dffba67fe59609a73dd64bcc6e2 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Thu, 28 Mar 2024 16:05:09 +0100 Subject: [PATCH 3/5] Update to latest Ingest and Transport libraries (#364) --- .../Elastic.Serilog.Sinks.Example.csproj | 2 +- examples/Elastic.Serilog.Sinks.Example/Program.cs | 1 + .../aspnetcore-with-extensions-logging.csproj | 2 +- .../ElasticsearchBenchmarkExporter.cs | 6 +++--- .../ElasticsearchLoggerProvider.cs | 4 ++-- .../LoggingBuilderExtensions.cs | 4 ++-- .../Options/ElasticsearchLoggerOptions.cs | 4 ++-- .../Elastic.Ingest.Elasticsearch.CommonSchema.csproj | 2 +- src/Elastic.Serilog.Sinks/ElasticsearchSink.cs | 10 +++++----- .../ElasticsearchSinkExtensions.cs | 12 ++++++------ .../Elasticsearch.IntegrationDefaults.csproj | 4 ++-- 11 files changed, 26 insertions(+), 25 deletions(-) diff --git a/examples/Elastic.Serilog.Sinks.Example/Elastic.Serilog.Sinks.Example.csproj b/examples/Elastic.Serilog.Sinks.Example/Elastic.Serilog.Sinks.Example.csproj index 34cc4e9f..782ccf14 100644 --- a/examples/Elastic.Serilog.Sinks.Example/Elastic.Serilog.Sinks.Example.csproj +++ b/examples/Elastic.Serilog.Sinks.Example/Elastic.Serilog.Sinks.Example.csproj @@ -12,7 +12,7 @@ - + diff --git a/examples/Elastic.Serilog.Sinks.Example/Program.cs b/examples/Elastic.Serilog.Sinks.Example/Program.cs index 66c16b1b..6d9d755a 100644 --- a/examples/Elastic.Serilog.Sinks.Example/Program.cs +++ b/examples/Elastic.Serilog.Sinks.Example/Program.cs @@ -9,6 +9,7 @@ using Elastic.Serilog.Sinks.Example; using Elastic.Elasticsearch.Ephemeral; using Elastic.Ingest.Elasticsearch; +using Elastic.Transport; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; diff --git a/examples/aspnetcore-with-extensions-logging/aspnetcore-with-extensions-logging.csproj b/examples/aspnetcore-with-extensions-logging/aspnetcore-with-extensions-logging.csproj index 6b14af2b..f259b915 100644 --- a/examples/aspnetcore-with-extensions-logging/aspnetcore-with-extensions-logging.csproj +++ b/examples/aspnetcore-with-extensions-logging/aspnetcore-with-extensions-logging.csproj @@ -9,7 +9,7 @@ - + diff --git a/src/Elastic.CommonSchema.BenchmarkDotNetExporter/ElasticsearchBenchmarkExporter.cs b/src/Elastic.CommonSchema.BenchmarkDotNetExporter/ElasticsearchBenchmarkExporter.cs index 568bc115..76b214d9 100644 --- a/src/Elastic.CommonSchema.BenchmarkDotNetExporter/ElasticsearchBenchmarkExporter.cs +++ b/src/Elastic.CommonSchema.BenchmarkDotNetExporter/ElasticsearchBenchmarkExporter.cs @@ -33,7 +33,7 @@ public ElasticsearchBenchmarkExporter(ElasticsearchBenchmarkExporterOptions opti { Options = options; var config = Options.CreateTransportConfiguration(); - Transport = new DefaultHttpTransport(config); + Transport = new DistributedTransport(config); } // ReSharper disable once UnusedMember.Global @@ -41,11 +41,11 @@ public ElasticsearchBenchmarkExporter(ElasticsearchBenchmarkExporterOptions opti public ElasticsearchBenchmarkExporter(ElasticsearchBenchmarkExporterOptions options, Func configure) { Options = options; - Transport = new DefaultHttpTransport(configure(Options)); + Transport = new DistributedTransport(configure(Options)); } - private HttpTransport Transport { get; } + private ITransport Transport { get; } private ElasticsearchBenchmarkExporterOptions Options { get; } // We only log when we cannot write to Elasticsearch diff --git a/src/Elastic.Extensions.Logging/ElasticsearchLoggerProvider.cs b/src/Elastic.Extensions.Logging/ElasticsearchLoggerProvider.cs index 00fe5609..1a25d7a9 100644 --- a/src/Elastic.Extensions.Logging/ElasticsearchLoggerProvider.cs +++ b/src/Elastic.Extensions.Logging/ElasticsearchLoggerProvider.cs @@ -125,7 +125,7 @@ private static NodePool CreateNodePool(ElasticsearchLoggerOptions loggerOptions) } } - private static HttpTransport CreateTransport(ElasticsearchLoggerOptions loggerOptions) + private static ITransport CreateTransport(ElasticsearchLoggerOptions loggerOptions) { // TODO: Check if Uri has changed before recreating // TODO: Injectable factory? Or some way of testing. @@ -137,7 +137,7 @@ private static HttpTransport CreateTransport(ElasticsearchLoggerOptions loggerOp if (loggerOptions.ShipTo.NodePoolType != NodePoolType.Cloud) config = SetAuthenticationOnTransport(loggerOptions, config); - var transport = new DefaultHttpTransport(config); + var transport = new DistributedTransport(config); return transport; } diff --git a/src/Elastic.Extensions.Logging/LoggingBuilderExtensions.cs b/src/Elastic.Extensions.Logging/LoggingBuilderExtensions.cs index 8ba5d319..34825d0a 100644 --- a/src/Elastic.Extensions.Logging/LoggingBuilderExtensions.cs +++ b/src/Elastic.Extensions.Logging/LoggingBuilderExtensions.cs @@ -129,13 +129,13 @@ Action> configureChannel /// /// Log to Elasticsearch - /// This overload also allows you to reuse an instance of + /// This overload also allows you to reuse an instance of /// Further configuration can be provided through the parameter /// Expert channel configuration can be provided to the parameter /// public static ILoggingBuilder AddElasticsearch( this ILoggingBuilder builder, - HttpTransport transport, + ITransport transport, Action? configure = null, Action>? configureChannel = null ) diff --git a/src/Elastic.Extensions.Logging/Options/ElasticsearchLoggerOptions.cs b/src/Elastic.Extensions.Logging/Options/ElasticsearchLoggerOptions.cs index 9656912b..35793e6b 100644 --- a/src/Elastic.Extensions.Logging/Options/ElasticsearchLoggerOptions.cs +++ b/src/Elastic.Extensions.Logging/Options/ElasticsearchLoggerOptions.cs @@ -81,9 +81,9 @@ public class ElasticsearchLoggerOptions : IEcsDocumentCreationOptions public string[]? Tags { get; set; } /// - /// Allows the direct setting of a to be used to communicate with Elasticsearch. + /// Allows the direct setting of a to be used to communicate with Elasticsearch. /// If set takes precedence over /// - public HttpTransport? Transport { get; set; } + public ITransport? Transport { get; set; } } } diff --git a/src/Elastic.Ingest.Elasticsearch.CommonSchema/Elastic.Ingest.Elasticsearch.CommonSchema.csproj b/src/Elastic.Ingest.Elasticsearch.CommonSchema/Elastic.Ingest.Elasticsearch.CommonSchema.csproj index 7c6f0d74..cd43a297 100644 --- a/src/Elastic.Ingest.Elasticsearch.CommonSchema/Elastic.Ingest.Elasticsearch.CommonSchema.csproj +++ b/src/Elastic.Ingest.Elasticsearch.CommonSchema/Elastic.Ingest.Elasticsearch.CommonSchema.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/Elastic.Serilog.Sinks/ElasticsearchSink.cs b/src/Elastic.Serilog.Sinks/ElasticsearchSink.cs index 1b99127b..fe4fc3f8 100644 --- a/src/Elastic.Serilog.Sinks/ElasticsearchSink.cs +++ b/src/Elastic.Serilog.Sinks/ElasticsearchSink.cs @@ -26,20 +26,20 @@ public class ElasticsearchSinkOptions : ElasticsearchSinkOptions public ElasticsearchSinkOptions() { } /// - public ElasticsearchSinkOptions(HttpTransport transport) : base(transport) { } + public ElasticsearchSinkOptions(ITransport transport) : base(transport) { } } /// public class ElasticsearchSinkOptions where TEcsDocument : EcsDocument, new() { /// - public ElasticsearchSinkOptions() : this(new DefaultHttpTransport(TransportHelper.Default())) { } + public ElasticsearchSinkOptions() : this(new DistributedTransport(TransportHelper.Default())) { } /// - public ElasticsearchSinkOptions(HttpTransport transport) => Transport = transport; + public ElasticsearchSinkOptions(ITransport transport) => Transport = transport; - /// - internal HttpTransport Transport { get; } + /// + internal ITransport Transport { get; } /// public EcsTextFormatterConfiguration TextFormatting { get; set; } = new(); diff --git a/src/Elastic.Serilog.Sinks/ElasticsearchSinkExtensions.cs b/src/Elastic.Serilog.Sinks/ElasticsearchSinkExtensions.cs index 3276caef..fafb58b7 100644 --- a/src/Elastic.Serilog.Sinks/ElasticsearchSinkExtensions.cs +++ b/src/Elastic.Serilog.Sinks/ElasticsearchSinkExtensions.cs @@ -56,7 +56,7 @@ public static LoggerConfiguration Elasticsearch( var transportConfig = useSniffing ? TransportHelper.Static(nodes) : TransportHelper.Sniffing(nodes); configureTransport?.Invoke(transportConfig); - var sinkOptions = new ElasticsearchSinkOptions(new DefaultHttpTransport(transportConfig)); + var sinkOptions = new ElasticsearchSinkOptions(new DistributedTransport(transportConfig)); configureOptions?.Invoke(sinkOptions); return loggerConfiguration.Sink(new ElasticsearchSink(sinkOptions), restrictedToMinimumLevel, levelSwitch); @@ -80,7 +80,7 @@ public static LoggerConfiguration Elasticsearch( { var transportConfig = useSniffing ? TransportHelper.Static(nodes) : TransportHelper.Sniffing(nodes); configureTransport?.Invoke(transportConfig); - var sinkOptions = new ElasticsearchSinkOptions(new DefaultHttpTransport(transportConfig)); + var sinkOptions = new ElasticsearchSinkOptions(new DistributedTransport(transportConfig)); configureOptions?.Invoke(sinkOptions); return loggerConfiguration.Sink(new ElasticsearchSink(sinkOptions), restrictedToMinimumLevel, levelSwitch); @@ -104,7 +104,7 @@ public static LoggerConfiguration ElasticCloud( { var transportConfig = TransportHelper.Cloud(cloudId, apiKey); configureTransport?.Invoke(transportConfig); - var sinkOptions = new ElasticsearchSinkOptions(new DefaultHttpTransport(transportConfig)); + var sinkOptions = new ElasticsearchSinkOptions(new DistributedTransport(transportConfig)); configureOptions?.Invoke(sinkOptions); return loggerConfiguration.Sink(new ElasticsearchSink(sinkOptions), restrictedToMinimumLevel, levelSwitch); @@ -129,7 +129,7 @@ public static LoggerConfiguration ElasticCloud( { var transportConfig = TransportHelper.Cloud(cloudId, apiKey); configureTransport?.Invoke(transportConfig); - var sinkOptions = new ElasticsearchSinkOptions(new DefaultHttpTransport(transportConfig)); + var sinkOptions = new ElasticsearchSinkOptions(new DistributedTransport(transportConfig)); configureOptions?.Invoke(sinkOptions); return loggerConfiguration.Sink(new ElasticsearchSink(sinkOptions), restrictedToMinimumLevel, levelSwitch); @@ -154,7 +154,7 @@ public static LoggerConfiguration ElasticCloud( { var transportConfig = TransportHelper.Cloud(cloudId, username, password); configureTransport?.Invoke(transportConfig); - var sinkOptions = new ElasticsearchSinkOptions(new DefaultHttpTransport(transportConfig)); + var sinkOptions = new ElasticsearchSinkOptions(new DistributedTransport(transportConfig)); configureOptions?.Invoke(sinkOptions); return loggerConfiguration.Sink(new ElasticsearchSink(sinkOptions), restrictedToMinimumLevel, levelSwitch); @@ -180,7 +180,7 @@ public static LoggerConfiguration ElasticCloud( { var transportConfig = TransportHelper.Cloud(cloudId, username, password); configureTransport?.Invoke(transportConfig); - var sinkOptions = new ElasticsearchSinkOptions(new DefaultHttpTransport(transportConfig)); + var sinkOptions = new ElasticsearchSinkOptions(new DistributedTransport(transportConfig)); configureOptions?.Invoke(sinkOptions); return loggerConfiguration.Sink(new ElasticsearchSink(sinkOptions), restrictedToMinimumLevel, levelSwitch); diff --git a/tests-integration/Elasticsearch.IntegrationDefaults/Elasticsearch.IntegrationDefaults.csproj b/tests-integration/Elasticsearch.IntegrationDefaults/Elasticsearch.IntegrationDefaults.csproj index 678b00ab..7e11fe5c 100644 --- a/tests-integration/Elasticsearch.IntegrationDefaults/Elasticsearch.IntegrationDefaults.csproj +++ b/tests-integration/Elasticsearch.IntegrationDefaults/Elasticsearch.IntegrationDefaults.csproj @@ -9,9 +9,9 @@ - + - + From ebd321d9f50b76602e8bcde02e02ec23312868ec Mon Sep 17 00:00:00 2001 From: Andrei Chasovskikh Date: Thu, 28 Mar 2024 16:58:51 +0100 Subject: [PATCH 4/5] Update readme in ASP.NET Core with Serilog example (#337) Co-authored-by: Andrei Chasovskikh --- examples/aspnetcore-with-serilog/README.md | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/examples/aspnetcore-with-serilog/README.md b/examples/aspnetcore-with-serilog/README.md index 83ca7854..07ebc97b 100644 --- a/examples/aspnetcore-with-serilog/README.md +++ b/examples/aspnetcore-with-serilog/README.md @@ -33,19 +33,13 @@ public static IWebHost BuildWebHost(string[] args) => .UseStartup() .UseSerilog((ctx, config) => { - config.ReadFrom.Configuration(ctx.Configuration); - - // Ensure HttpContextAccessor is accessible + // Ensure HttpContextAccessor is accessible var httpAccessor = ctx.Configuration.Get(); - - // Create a formatter configuration to se this accessor - var formatterConfig = new EcsTextFormatterConfiguration(); - formatterConfig.MapHttpContext(httpAccessor); - - // Write events to the console using this configration - var formatter = new EcsTextFormatter(formatterConfig); - config.WriteTo.Console(formatter); + config + .ReadFrom.Configuration(ctx.Configuration) + .Enrich.WithEcsHttpContext(httpAccessor) + .WriteTo.Async(a => a.Console(new EcsTextFormatter())); }) .UseKestrel() .Build(); From 7c9345404571550e9008b0ec56766fcd035d25c9 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Thu, 28 Mar 2024 17:16:30 +0100 Subject: [PATCH 5/5] Add test-docs workflow to satisfy required workflow actions when only doc changes occcur (#366) --- .github/workflows/test-docs.yml | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/test-docs.yml diff --git a/.github/workflows/test-docs.yml b/.github/workflows/test-docs.yml new file mode 100644 index 00000000..59a8daae --- /dev/null +++ b/.github/workflows/test-docs.yml @@ -0,0 +1,34 @@ +# This workflow sets the 'test' status check to success in case it's a docs only PR and e2e.yml is not triggered +# https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks +name: test # The name must be the same as in test.yml + +on: + pull_request: + paths-ignore: # This expression needs to match the paths ignored on e2e.yml. + - '**' + - '!*.md' + - '!*.asciidoc' + - '!docs/**' + +permissions: + contents: read + +## Concurrency only allowed in the main branch. +## So old builds running for old commits within the same Pull Request are cancelled +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} + +jobs: + + test-windows: + runs-on: windows-latest + + steps: + - run: 'echo "Not required for docs"' + + test-linux: + runs-on: ubuntu-latest + + steps: + - run: 'echo "Not required for docs"' \ No newline at end of file