From 376ec1e05dcf05e40ed841fe4e00d2fd6404f851 Mon Sep 17 00:00:00 2001 From: Michiel van Oudheusden Date: Thu, 2 Feb 2023 09:48:10 +0100 Subject: [PATCH] Create v9.0.0 (#509) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Create codeql-analysis.yml (#370) * fix: Correct comment about default TypeName (#393) The default TypeName was changed to '_doc' in #298 * Proper handling of TypeName = null from appsettings.json (#420) Co-authored-by: Marius Wingerei * Add `ElasticsearchSinkOptions.BufferFileRollingInterval` option (#416) * Add `ElasticsearchSinkOptions.BufferFileRollingInterval` option - Using this option we can customize buffer file rolling interval. The default is `RollingInterval.Day` (so no changes here). In some cases higher granularity may be needed. - Changed regular expression for FileSet to get buffer files to support different rolling interval file name formats - from Infinite to Minute. All of them are different amount of digits representing date - 0(Infinite), 4(Year),..., 12 (Minute). So replaced expression part for day format `(?\\d{8})` with the expression for all interval date `(?\\d{0,12})`. * Add tests for the desired functionality, which fail now. - Return code to support only Daily rolling interval - Add RollingIntervalExtensions.cs (origin: Serilog.Sinks.File) with InternalVisible attribute to be able to test - Add InternalVisible to FileSet.cs to be able to test it - Sign tests assembly the same way as Serilog.Sinks.Elasticsearch for InternalVisible to work * Support different rolling intervals for DurableElasticsearchSink rolling files. - Make support only for intervals like Day, Hour, Minute. As for less frequent intervals we cannot get specific date (specific day) for passing to _getIndexForEvent in `ElasticsearchPayloadReader`. - Support handling rolling files for different intervals in `ElasticsearchPayloadReader` and `FileSet` by using corresponding formats and search patterns. - Add tests of changed code - for `ElasticsearchPayloadReader` and `FileSet` * Remove redundant spaces * Fix internal or IntelliSense typos (#406) Cleaning up a few very minor typos in internal methods or exposed via IntelliSense: * "semi column" -> "semi-colon" * "preforming" -> "performing" * "CreatePlayLoad" -> "CreatePayload" Co-authored-by: Bo Flynn * Clean package sources * clean obsolete .net versions * updated packages * added dependabot * Bump actions/setup-dotnet from 1 to 2 (#431) Bumps [actions/setup-dotnet](https://github.com/actions/setup-dotnet) from 1 to 2. - [Release notes](https://github.com/actions/setup-dotnet/releases) - [Commits](https://github.com/actions/setup-dotnet/compare/v1...v2) --- updated-dependencies: - dependency-name: actions/setup-dotnet dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump actions/checkout from 2 to 3 (#427) Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump actions/cache from 2 to 3 (#429) Bumps [actions/cache](https://github.com/actions/cache) from 2 to 3. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump actions/download-artifact from 2 to 3 (#424) Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 2 to 3. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * added dependencies * copy local files * updating versions * publish test results * remove old nuspec and updated icons * added icon * updates * fix build * multiple packages * name * cicd * skip test for now as it is flaky * version * Names * use correct folder * older version * diffferent way of pushing * enviroment * Remove app veyor and dotnet-version * Use repo owner * use dotnet nuget * logging * remove @ * --skip-duplicate * update project url * Updated changelog * paths * use correct output path * remove the source * skip duplicates * Bump actions/setup-dotnet from 2 to 3.0.2 (#478) Bumps [actions/setup-dotnet](https://github.com/actions/setup-dotnet) from 2 to 3.0.2. - [Release notes](https://github.com/actions/setup-dotnet/releases) - [Commits](https://github.com/actions/setup-dotnet/compare/v2...v3.0.2) --- updated-dependencies: - dependency-name: actions/setup-dotnet dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Update cicd.yaml * Bump actions/download-artifact from 1 to 3 (#439) Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 1 to 3. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v1...v3) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump actions/upload-artifact from 2 to 3 (#438) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 2 to 3. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Update cicd.yaml * fix file references in the Visual Studio Solution file. (#461) Co-authored-by: Nenad Vicentic * Bump actions/setup-dotnet from 3.0.2 to 3.0.3 (#487) Bumps [actions/setup-dotnet](https://github.com/actions/setup-dotnet) from 3.0.2 to 3.0.3. - [Release notes](https://github.com/actions/setup-dotnet/releases) - [Commits](https://github.com/actions/setup-dotnet/compare/v3.0.2...v3.0.3) --- updated-dependencies: - dependency-name: actions/setup-dotnet dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump github/codeql-action from 1 to 2 (#426) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 1 to 2. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/v1...v2) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Automatically handle `TypeName` parameter for different versions of Elasticsearch (<7, 7 or higher) (#462) * fix file references in the Visual Studio Solution file. * Do not set `TypeName` by default any more. * last version of Elasticsearch that supported user-defined `_type` field - v6.8.x is running out of support on 2022-02-10 (https://www.elastic.co/support/eol) * Automatically handle `ElasticsearchSinkOptions.TypeName` for different versions Elasticsearch (<7, 7+) when `ElasticsearchSinkOptions.DetectElasticsearchVersion` is enabled. * Add unit test for automatic settings of `TypeName` when `DetectElasticsearchVersion` is set to `true`. - Two methods used - instantiate `ElasticsearchSinkState` directly and via `LoggerConfiguration` * Add Elasticsearch v8 template + parsing of Elasticsearch major version to `int` + decision branch for which version of index-template API to use + removal of obsolete `ElasticsearchTemplateProvider.GetTemplate(...)` method overload. * Upgrade to .NET 6.0 and update test-frameworks related NuGet pacakges * Upgrade to Elasticsearch.NET 7.17.5 + handle new "preflight" request https://discuss.elastic.co/t/the-client-is-unable-to-verify-that-the-server-is-elasticsearch-due-to-an-unsuccessful-product-check-call-some-functionality-may-not-be-compatible-if-the-server-is-running-an-unsupported-product/310969/9 "The 7.16 client performs a pre-flight GET request to the root URL of the server before the first request.". * Make `ConnectionStub` a bit more robust . * Use `System.Version` to parse Elasticsearch server version number (similar to what `Elasticsearch.Net` does) * Update NuGet packages * Replace obsolete NuGet package `Serilog.Sinks.ColoredConsole` with `Serilog.Sinks.Console` * Update `Serilog.Sinks.PeriodicBatching` package and reimplent `ElasticsearchSink` so that it does not use obsolete `PeriodicBatchingSink` constructor. * Better handling of Elasticsearch server version number in mocked `ConnectionStub` * Cleanup: refactor to use single `JsonEquals` method. * Turn on `DetectElasticSearchVersion` option by default. Assume version 7 on fallback. * Cleanup: remove unused namespaces * Cleanup: move `ElasticsearchSinkTestsBase` into `Stubs` subfolder. * Refactor: extract `ConnectionStub` into a separate file. * Fix: json comparison in .NET Framework 4.6+ * Run unit-tests on multiple .NET frameworks. * Cleanup: remove unused NUnit runner package. * Use newer, built-in compilation constants. https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives#conditional-compilation * Use standard MSBuild property `IsPackable` for clarity. * Cleanup: remove unused package refrence. * Update GitHub actions * docs: updated documentation to reflect changes in behavior of the sink. Co-authored-by: Nenad Vicentic * Update dotnet sdk * disable net48 tests * set api key * Remove support for Elasticsearch v2 and v5. (#488) * Remove support for Elasticsearch v2 and v5. * Code-conventions: add rule for underscore `_` on private fields (as it already is in the code). * Remove GitHub's `set-output` command deprication warning. Co-authored-by: Nenad Vicentic * added path for tests * fix: Example in README is incorrect #402 (#496) * Applying right versioning * Update AssemblyInfo.cs * Remove `AssemblyInfo.cs` and move attributes to the `*.csproj` file. This enables setting assembly version via command line and CI. (#501) 1. Build and pack: dotnet build -c Release -p:Version=9.0.0-beta11 dotnet pack -c Release --no-build -p:Version=9.0.0-beta11 2. Pack (with implicit build) dotnet pack -c Release -p:Version=9.0.0-beta11 Co-authored-by: Nenad Vicentic * Read Elasticsearch server version from a root page response (#502) Co-authored-by: Nenad Vicentic * Versioning and permission for unit tests * [no ci] * #498 Disable `PublicSign` to fix strong-name signature verification issue of assemblies from public NuGet package: (#504) > Could not load file or assembly 'Serilog.Formatting.Elasticsearch' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)" Co-authored-by: Nenad Vicentic * [no ci] --------- Signed-off-by: dependabot[bot] Co-authored-by: Mikkel Nylander Bundgaard Co-authored-by: mariwing Co-authored-by: Marius Wingerei Co-authored-by: Andrey Kozlov Co-authored-by: Bo Flynn Co-authored-by: Bo Flynn Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Nenad Vićentić Co-authored-by: Nenad Vicentic --- .editorconfig | 16 ++ .github/dependabot.yml | 16 ++ .github/workflows/cicd.yaml | 150 ++++++++++++++ .github/workflows/codeql-analysis.yml | 73 +++++++ .vscode/tasks.json | 15 +- .vscode/tasks.json.old | 16 ++ Build.ps1 | 52 ----- CHANGES.md | 32 +++ README.md | 76 ++++++- appveyor.yml | 39 ---- assets/serilog-sink-nuget.png | Bin 0 -> 20852 bytes global.json | 5 - nuget.config | 3 +- .../Program.cs | 2 - .../Serilog.Sinks.Elasticsearch.Sample.csproj | 15 +- serilog-sinks-elasticsearch.sln | 5 +- ...og.Formatting.ElasticSearch.Symbols.nuspec | 22 -- .../Serilog.Formatting.ElasticSearch.nuspec | 21 -- .../Serilog.Formatting.Elasticsearch.csproj | 43 ++-- ...gerConfigurationElasticSearchExtensions.cs | 25 ++- .../Properties/AssemblyInfo.cs | 15 -- ...Serilog.Sinks.ElasticSearch.Symbols.nuspec | 26 --- .../Serilog.Sinks.ElasticSearch.nuspec | 24 --- .../Serilog.Sinks.Elasticsearch.csproj | 62 +++--- .../Elasticsearch/DurableElasticsearchSink.cs | 10 +- .../Elasticsearch/ElasticsearchLogClient.cs | 2 +- .../Elasticsearch/ElasticsearchLogShipper.cs | 7 +- .../ElasticsearchPayloadReader.cs | 17 +- .../RollingIntervalExtensions.cs | 55 +++++ .../Sinks/ElasticSearch/Durable/FileSet.cs | 11 +- .../Sinks/ElasticSearch/Durable/LogShipper.cs | 6 +- .../Sinks/ElasticSearch/ElasticSearchSink.cs | 77 +++---- .../ElasticSearchTemplateProvider.cs | 75 +++---- .../ElasticSearch/ElasticsearchSinkOptions.cs | 20 +- .../ElasticSearch/ElasticsearchSinkState.cs | 82 ++++---- .../ElasticsearchVersionManager.cs | 84 ++++++++ .../Elasticsearch6/Elasticsearch6X.cs | 2 +- .../Elasticsearch6/Elasticsearch6XUsing7X.cs | 2 +- .../Elasticsearch7/Elasticsearch7X.cs | 2 +- .../Elasticsearch7/Elasticsearch7XUsing6X.cs | 2 +- ...inks.Elasticsearch.IntegrationTests.csproj | 52 ++++- .../BulkActionTests.cs | 22 +- .../CustomIndexTypeNameTests.cs | 9 +- .../ElasticsearchSinkUniformityTestsBase.cs | 5 +- .../Discrepancies/NoSerializerTests.cs | 5 +- .../Domain/BulkAction.cs | 3 - .../ElasticSearchLogShipperTests.cs | 8 +- .../ElasticsearchJsonFormatterTests.cs | 1 - .../ElasticsearchPayloadReaderTests.cs | 86 ++++++++ .../ElasticsearchSinkTests.cs | 93 +++++++++ .../ElasticsearchSinkTestsBase.cs | 196 ------------------ .../ExceptionAsJsonObjectFormatterTests.cs | 3 +- .../FileSetTests.cs | 74 +++++++ .../IndexDeciderTests.cs | 4 +- .../InlineFieldsTests.cs | 2 +- .../Properties/AssemblyInfo.cs | 1 - .../PropertyNameTests.cs | 2 +- .../RealExceptionNoSerializerTests.cs | 2 +- .../RealExceptionTests.cs | 3 +- .../Serilog.Sinks.Elasticsearch.Tests.csproj | 98 +++++---- .../Stubs/ConnectionStub.cs | 126 +++++++++++ .../Stubs/ElasticsearchSinkTestsBase.cs | 137 ++++++++++++ ...verVersionHandlesUnavailableServerTests.cs | 1 + .../Templating/DiscoverVersionTests.cs | 5 +- .../DoNotRegisterTemplateIfItExists.cs | 3 +- .../Templating/OverwriteTemplateTests.cs | 9 +- .../Templating/RegisterCustomTemplateTests.cs | 6 +- ...dsTemplateHandlesUnavailableServerTests.cs | 1 + .../Templating/SendsTemplateTests.cs | 27 +-- .../Templating/Sendsv5TemplateTests.cs | 66 ------ .../Templating/Sendsv6TemplateTests.cs | 28 +-- .../Templating/Sendsv7TemplateTests.cs | 28 +-- .../Templating/Sendsv8TemplateTests.cs | 48 +++++ .../Templating/SetElasticsearchSinkOptions.cs | 1 + .../SetFiveReplicasInTemplateTests.cs | 26 +-- .../Templating/SetTwoShardsInTemplateTests.cs | 26 +-- .../SetZeroReplicasInTemplateTests.cs | 26 +-- .../Templating/TemplateMatchTests.cs | 9 +- .../Templating/template_2shards.json | 83 -------- .../Templating/template_5replicas.json | 82 -------- .../Templating/template_v7_no-aliases.json | 77 +++++++ .../{template_v5.json => template_v8.json} | 43 ++-- ... => template_v8_no-aliases_0replicas.json} | 61 +++--- ...on => template_v8_no-aliases_2shards.json} | 62 +++--- ... => template_v8_no-aliases_5replicas.json} | 62 +++--- .../TestDataHelper.cs | 3 - 86 files changed, 1690 insertions(+), 1232 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/cicd.yaml create mode 100644 .github/workflows/codeql-analysis.yml create mode 100644 .vscode/tasks.json.old delete mode 100644 Build.ps1 delete mode 100644 appveyor.yml create mode 100644 assets/serilog-sink-nuget.png delete mode 100644 global.json delete mode 100644 src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.ElasticSearch.Symbols.nuspec delete mode 100644 src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.ElasticSearch.nuspec delete mode 100644 src/Serilog.Sinks.Elasticsearch/Properties/AssemblyInfo.cs delete mode 100644 src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.ElasticSearch.Symbols.nuspec delete mode 100644 src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.ElasticSearch.nuspec create mode 100644 src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/RollingIntervalExtensions.cs create mode 100644 src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchVersionManager.cs create mode 100644 test/Serilog.Sinks.Elasticsearch.Tests/ElasticsearchPayloadReaderTests.cs create mode 100644 test/Serilog.Sinks.Elasticsearch.Tests/ElasticsearchSinkTests.cs delete mode 100644 test/Serilog.Sinks.Elasticsearch.Tests/ElasticsearchSinkTestsBase.cs create mode 100644 test/Serilog.Sinks.Elasticsearch.Tests/FileSetTests.cs create mode 100644 test/Serilog.Sinks.Elasticsearch.Tests/Stubs/ConnectionStub.cs create mode 100644 test/Serilog.Sinks.Elasticsearch.Tests/Stubs/ElasticsearchSinkTestsBase.cs delete mode 100644 test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv5TemplateTests.cs create mode 100644 test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv8TemplateTests.cs delete mode 100644 test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_2shards.json delete mode 100644 test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_5replicas.json create mode 100644 test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v7_no-aliases.json rename test/Serilog.Sinks.Elasticsearch.Tests/Templating/{template_v5.json => template_v8.json} (73%) rename test/Serilog.Sinks.Elasticsearch.Tests/Templating/{template_v2.json => template_v8_no-aliases_0replicas.json} (59%) rename test/Serilog.Sinks.Elasticsearch.Tests/Templating/{template.json => template_v8_no-aliases_2shards.json} (59%) rename test/Serilog.Sinks.Elasticsearch.Tests/Templating/{template_0replicas.json => template_v8_no-aliases_5replicas.json} (58%) diff --git a/.editorconfig b/.editorconfig index 9bdbb34e..5ae50828 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,3 +6,19 @@ indent_size = 4 [*.csproj] indent_size = 2 + +# Code files +[*.{cs,csx,vb,vbx}] +############################### +# Naming Conventions # +############################### +# Underscore for private fields +dotnet_naming_rule.private_members_with_underscore.symbols = private_fields +dotnet_naming_rule.private_members_with_underscore.style = prefix_underscore +dotnet_naming_rule.private_members_with_underscore.severity = suggestion + +dotnet_naming_symbols.private_fields.applicable_kinds = field +dotnet_naming_symbols.private_fields.applicable_accessibilities = private + +dotnet_naming_style.prefix_underscore.capitalization = camel_case +dotnet_naming_style.prefix_underscore.required_prefix = _ diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..79b78fec --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,16 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "nuget" + directory: "/" # Location of package manifests + schedule: + interval: "daily" + + - package-ecosystem: "github-actions" + directory: "/" # Location of package manifests + schedule: + interval: "daily" \ No newline at end of file diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml new file mode 100644 index 00000000..06f22817 --- /dev/null +++ b/.github/workflows/cicd.yaml @@ -0,0 +1,150 @@ +name: Continuous Integration + +on: + push: + pull_request: + release: + types: + - published +env: + Configuration: Release + ContinuousIntegrationBuild: true + DOTNET_CLI_TELEMETRY_OPTOUT: true + DOTNET_NOLOGO: true + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true + + # GitHub Packages Feed settings + GITHUB_FEED: https://nuget.pkg.github.com/serilog-contrib/ + GITHUB_USER: mivano + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + package: + runs-on: ubuntu-latest + name: Run tests and create NuGet package + outputs: + coverage-reports: ${{ steps.dotnet-test.outputs.coverage-reports }} + version: ${{ steps.dotnet-pack.outputs.version }} + nupkg-filename: ${{ steps.dotnet-pack.outputs.nupkg-filename }} + release-body: ${{ steps.tag-message.outputs.release-notes }} + steps: + - name: Checkout git repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install .NET SDK + uses: actions/setup-dotnet@v3.0.3 + with: + dotnet-version: '7.0.x' + + - name: Retrieve cached NuGet packages + uses: actions/cache@v3 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + + - name: Restore NuGet packages + run: dotnet restore + + - name: Build solution + run: dotnet build --no-restore -c Release + + - name: Run tests + run: dotnet test --no-build -c Release --logger "html;LogFileName=TestResults-${{ runner.os }}.html" --logger "trx;LogFileName=TestResults-${{ runner.os }}.trx" --logger GitHubActions + id: dotnet-test + + - name: Upload received files from failing tests + uses: actions/upload-artifact@v3 + if: failure() + with: + name: Received-${{ runner.os }} + path: "**/*.received.*" + + - name: Upload test results + uses: actions/upload-artifact@v3 + if: always() + with: + name: TestResults-${{ runner.os }} + path: test/Serilog.Sinks.Elasticsearch.Tests/TestResults/TestResults-${{ runner.os }}.html + + - name: Test Report + uses: dorny/test-reporter@v1 + if: always() + with: + name: Test Results (${{ runner.os }}) + path: '**.trx' + reporter: dotnet-trx + + - name: Create NuGet packages + run: dotnet pack --no-build -c Release --version-suffix "ci-$GITHUB_RUN_ID" --include-symbols --include-source --output . + id: dotnet-pack + + - name: Upload NuGet package artifact + uses: actions/upload-artifact@v3 + with: + name: nuget + path: '**/*.nupkg' + + prerelease: + needs: package + name: Create prerelease + if: github.ref == 'refs/heads/dev' + runs-on: ubuntu-latest + steps: + - name: Download Artifact + uses: actions/download-artifact@v3 + with: + name: nuget + path: nuget + - name: Push to GitHub Feed + run: | + dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/serilog-contrib/index.json" + + for f in ./nuget/*.nupkg + do + echo $f + dotnet nuget push $f --source "github" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate + done + + publish: + runs-on: ubuntu-latest + needs: package + if: github.event_name == 'release' + name: Publish NuGet package + steps: + - name: Checkout git repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install .NET SDK + uses: actions/setup-dotnet@v3.0.3 + + - name: Retrieve cached NuGet packages + uses: actions/cache@v3 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + + - name: Restore NuGet packages + run: dotnet restore + + - name: Create Release NuGet package + run: | + arrTag=(${GITHUB_REF//\// }) + VERSION="${arrTag[2]}" + VERSION="${VERSION//v}" + dotnet pack -v normal -c Release --include-symbols --include-source -p:Version=$VERSION -o ./nuget + + - name: Push to GitHub Feed + run: | + dotnet nuget add source --username $GITHUB_USER --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/serilog-contrib/index.json" + + for f in ./nuget/*.nupkg + do + dotnet nuget push $f --source "github" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate + done + + - name: Publish NuGet package on nuget.org + run: dotnet nuget push ./nuget/*.nupkg --api-key "${{ secrets.NUGET_API_KEY }}" --skip-duplicate diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 00000000..ceb06dd7 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,73 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# ******** NOTE ******** + +name: "CodeQL" + +on: + push: + branches: [ dev, master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ dev ] + schedule: + - cron: '27 7 * * 6' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: [ 'csharp' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more... + # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup dotnet + uses: actions/setup-dotnet@v3.0.3 + with: + dotnet-version: '6.0.x' + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 41fffdd6..01d05bc1 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,16 +1,21 @@ { - "version": "0.1.0", + "version": "2.0.0", "command": "dotnet", - "isShellCommand": true, "args": [], "tasks": [ { - "taskName": "build", + "label": "build", + "type": "shell", + "command": "dotnet", "args": [ + "build", "${workspaceRoot}/sample/Serilog.Sinks.Elasticsearch.Sample/Serilog.Sinks.Elasticsearch.Sample.csproj" ], - "isBuildCommand": true, - "problemMatcher": "$msCompile" + "problemMatcher": "$msCompile", + "group": { + "_id": "build", + "isDefault": false + } } ] } \ No newline at end of file diff --git a/.vscode/tasks.json.old b/.vscode/tasks.json.old new file mode 100644 index 00000000..41fffdd6 --- /dev/null +++ b/.vscode/tasks.json.old @@ -0,0 +1,16 @@ +{ + "version": "0.1.0", + "command": "dotnet", + "isShellCommand": true, + "args": [], + "tasks": [ + { + "taskName": "build", + "args": [ + "${workspaceRoot}/sample/Serilog.Sinks.Elasticsearch.Sample/Serilog.Sinks.Elasticsearch.Sample.csproj" + ], + "isBuildCommand": true, + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/Build.ps1 b/Build.ps1 deleted file mode 100644 index 044678db..00000000 --- a/Build.ps1 +++ /dev/null @@ -1,52 +0,0 @@ -echo "In directory: $PSScriptRoot" - -$solution = "serilog-sinks-elasticsearch.sln" -$test = "test\\Serilog.Sinks.Elasticsearch.Tests\\Serilog.Sinks.Elasticsearch.Tests.csproj" -$testIntegration = "test\\Serilog.Sinks.Elasticsearch.IntegrationTests\\Serilog.Sinks.Elasticsearch.IntegrationTests.csproj" -[string[]]$projects = @( - ("src\\Serilog.Sinks.Elasticsearch\\Serilog.Sinks.Elasticsearch.csproj"), - ("src\\Serilog.Formatting.Elasticsearch\\Serilog.Formatting.Elasticsearch.csproj") -) - -function Invoke-Build() -{ - Write-Output "Building" - - if(Test-Path .\artifacts) { - echo "build: Cleaning .\artifacts" - Remove-Item .\artifacts -Force -Recurse - } - - & dotnet test $test -c Release - if($LASTEXITCODE -ne 0) - { - Write-Output "The tests failed" - exit 1 - } - - Write-Output "Running integration tests" - # Tee-Object forces console redirection on vstest which magically makes Console.WriteLine works again. - # This allows you to see the console out of Elastic.Xunit while its running - & dotnet test $testIntegration -c Release | Tee-Object -Variable integ - if($LASTEXITCODE -ne 0) - { - Write-Output "The integration tests failed" - exit 1 - } - - Write-Output "Creating packages" - foreach ($project in $projects) - { - & dotnet pack $project -c Release -o ..\..\artifacts -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg /p:PackageVersion=$env:GitVersion_NuGetVersionV2 - } - - if($LASTEXITCODE -ne 0) - { - Write-Output "Packing the sink failed" - exit 1 - } - Write-Output "Building done" -} - -$ErrorActionPreference = "Stop" -Invoke-Build diff --git a/CHANGES.md b/CHANGES.md index 8e94e8a9..662ea84e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,7 +6,39 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [9.0.0] - 2023-01-23 +### Added + - PR #462 + - PR #488 + +### Major Changes +- `DetectElasticsearchVersion` is set to `true` by default. +- When `DetectElasticsearchVersion` is set to `false` Elasticsearch version 7 is assumed (as it has broadest wire-compatibility at the moment - v7 and v8) +- When `DetectElasticsearchVersion` is set to `true`, `TypeName` is handled automatically across different versions of Elasticserach (6.x to 8.x). For example, user-defined name will NOT be used on v7 and v8. Also, correct templates endpoint will be picked up. +- Elasticsearch 8.x endpoint for templates is supported (`_index_template`) +- Internal class `ElasticsearchVersionManager` has been added, mainly to handle situations where detection of version fails or when it is disabled. In the case of fallback, sink will assume "default" version 7. +- Elasticsearch.NET client version 7.15.2 (latest version 7, until new `Elastic.Clients.Elasticsearch` 8.x catches up functional parity with 7.x). +- Elasticsearch server versions 2 and 5 are no longer supported. + +### Other Changes +- Nuget pacakges have been updated (except for the Elasticsearch integration-tests related packages) +- Most of the `ElasticserachSink` functionality has been moved into internal `BatchedElasticsearchSink` class that inherits from `IBatchedLogEventSink`, so it complies with new recommended way of integration with `PeriodicBatchingSink` and we don't use obsolete constructors. +- `ConnectionStub` was moved out of `ElasticsearchSinkTestsBase` and extended. Both are now in `/Stubs` subfolder. Newer versions of Elasticsearch.NET client are now using "pre-flight" request to determine if endpoint is Elasticsearch and if it is indeed between 6.x and 8.x. `ConnectionStub` had to accommodate for that. +- Unit tests have been fixed/added accordingly, running on multiple target frameworks (`net6`, `net7` and `net48`). +- Built-in .NET SDK conditional compilation symbols are now used (e.g NETFRAMEWORK). + +## [9.0.0] - 2022-04-29 + +### Fixed + - Dropped support for old .NET framework, and now uses .NET Core. Previous versions were out of support by MS anyway. + - Fixed the build so it uses GitHub Actions as AppVeyor was not working + - Created packages in GitHub Packages + +### Added + - PR #420 + - PR #416 + - PR #406 ## [8.4.1] - 2020-09-28 ### Fixed - Make sure TypeName is set to `_doc` when setting the template version to `ESv7`. diff --git a/README.md b/README.md index e2c0a240..65f12f3f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Serilog.Sinks.Elasticsearch [![Build status](https://ci.appveyor.com/api/projects/status/bk367tcnx9qt2sjy/branch/master?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-elasticsearch/branch/master) [![NuGet Badge](https://img.shields.io/nuget/v/Serilog.Sinks.Elasticsearch.svg)](https://www.nuget.org/packages/Serilog.Sinks.Elasticsearch) +# Serilog.Sinks.Elasticsearch [![Continuous Integration](https://github.com/serilog-contrib/serilog-sinks-elasticsearch/actions/workflows/cicd.yaml/badge.svg?branch=dev)](https://github.com/serilog-contrib/serilog-sinks-elasticsearch/actions/workflows/cicd.yaml) [![NuGet Badge](https://img.shields.io/nuget/v/Serilog.Sinks.Elasticsearch.svg)](https://www.nuget.org/packages/Serilog.Sinks.Elasticsearch) This repository contains two nuget packages: `Serilog.Sinks.Elasticsearch` and `Serilog.Formatting.Elasticsearch`. @@ -30,6 +30,7 @@ The Serilog Elasticsearch sink project is a sink (basically a writer) for the Se * Starting from version 3, compatible with Elasticsearch 2. * Version 6.x supports the new Elasticsearch.net version 6.x library. * From version 8.x there is support for Elasticsearch.net version 7. +* From version 9.x there is support for Elasticsearch.net version 8. Version detection is enabled by default, in which case `TypeName` is handled automatically across major versions 6, 7 and 8. Versions 2 and 5 of Elasticsearch are no longer supported. Version 9.0.0 of the sink targets netstandard2.0 and therefore can be run on any .NET Framework that supports it (both .NET Core and .NET Framework), however, we are focused on testing it with .NET 6.0 to make the maintenance simpler. ## Quick start @@ -40,16 +41,80 @@ The Serilog Elasticsearch sink project is a sink (basically a writer) for the Se Install-Package serilog.sinks.elasticsearch ``` -Register the sink in code or using the appSettings reader (from v2.0.42+) as shown below. Make sure to specify the version of ES you are targeting. Be aware that the AutoRegisterTemplate option will not overwrite an existing template. +Simplest way to register this sink is to use default configuration: + +```csharp +var loggerConfig = new LoggerConfiguration() + .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9200"))); +``` + +Or, if using .NET Core and `Serilog.Settings.Configuration` Nuget package and `appsettings.json`, default configuration would look like this: + +```json +{ + "Serilog": { + "Using": [ "Serilog.Sinks.Elasticsearch" ], + "MinimumLevel": "Warning", + "WriteTo": [ + { + "Name": "Elasticsearch", + "Args": { + "nodeUris": "http://localhost:9200" + } + } + ], + "Enrich": [ "FromLogContext", "WithMachineName" ], + "Properties": { + "Application": "ImmoValuation.Swv - Web" + } + } +} +``` + +More elaborate configuration, using additional Nuget packages (e.g. `Serilog.Enrichers.Environment`) would look like: + +```json +{ + "Serilog": { + "Using": [ "Serilog.Sinks.Elasticsearch" ], + "MinimumLevel": "Warning", + "WriteTo": [ + { + "Name": "Elasticsearch", + "Args": { + "nodeUris": "http://localhost:9200" + } + } + ], + "Enrich": [ "FromLogContext", "WithMachineName" ], + "Properties": { + "Application": "My app" + } + } +} +``` + +This way the sink will detect version of Elasticsearch server (`DetectElasticsearchVersion` is set to `true` by default) and handle `TypeName` behavior correctly, based on the server version (6.x, 7.x or 8.x). + +### Disable detection of Elasticsearch server version + +Alternatively, `DetectElasticsearchVersion` can be set to `false` and certain option can be configured manually. In that case, the sink will assume version 7 of Elasticsearch, but options will be ignored due to a potential version incompatibility. + +For example, you can configure the sink to force registeration of v6 index template. Be aware that the AutoRegisterTemplate option will not overwrite an existing template. ```csharp var loggerConfig = new LoggerConfiguration() .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9200") ){ + DetectElasticsearchVersion = false, AutoRegisterTemplate = true, AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6 }); ``` +### Configurable properties + +Besides a registration of the sink in the code, it is possible to register it using appSettings reader (from v2.0.42+) reader (from v2.0.42+) as shown below. + This example shows the options that are currently available when using the appSettings reader. ```xml @@ -75,7 +140,8 @@ This example shows the options that are currently available when using the appSe - + + @@ -278,6 +344,10 @@ Option BufferFileSizeLimitBytes is added The maximum size, in bytes, to which th ### Breaking changes +#### Version 9 + +* Dropped support for 456 and sticking now with NETSTANDARD + #### Version 7 * Nuget Serilog.Sinks.File is now used instead of deprecated Serilog.Sinks.RollingFile diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 66f4f1dd..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,39 +0,0 @@ -version: '{build}' -image: Visual Studio 2017 -skip_tags: true -build_script: -- ps: ./Build.ps1 -test: off -artifacts: - - path: artifacts/Serilog.Sinks.Elasticsearch*.*nupkg - - path: artifacts/Serilog.Formatting.Elasticsearch*.*nupkg -only_commits: - files: - - serilog-sinks-elasticsearch.sln - - src/Serilog.Sinks.Elasticsearch/ - - src/Serilog.Formatting.Elasticsearch/ - - nuget.config - - Build.ps1 - - assets/ - - appveyor.yml - - test/Serilog.Sinks.Elasticsearch.Tests/ -deploy: -- provider: NuGet - api_key: - secure: jWslQvxA4UMn98aYnsFDBfl8A2vAXUjtmmPZNxZnbJvMW/JV55iQ1fRcqD9B70sK - on: - branch: /^(master|dev)$/ -- provider: GitHub - auth_token: - secure: XSO0LDYd89yw5rAQ8HvAgdX7NBo1m4bEqHlj0NZxtA6zKunLwCSYoVHU+k3cvQIP - on: - branch: master - artifact: /Serilog.*\.nupkg/ - tag: v$(appveyor_build_version) -install: - - choco install gitversion.portable -y -assembly_info: - patch: false -before_build: - - dotnet restore serilog-sinks-elasticsearch.sln - - ps: gitversion /l console /output buildserver /updateAssemblyInfo \ No newline at end of file diff --git a/assets/serilog-sink-nuget.png b/assets/serilog-sink-nuget.png new file mode 100644 index 0000000000000000000000000000000000000000..a77d65c42658e49e801aebde26b767d3916e6971 GIT binary patch literal 20852 zcmb4rbyQVbwD%#UyQEW4T0%rRBqRhW=@yWbM!G{95hMgex}~L4K?M;6=}=HW_Uc!k3`d+#;ZoWEMe+}BVd#G}PSp-_Y>$_m;j6dL?58VUy+{xE)0Vhev@ zy348P;J}wZj&(Hr9oJR)p*sr2CXM`u7WP5g0KR$EL(#zFfs3t&x5X11l()AxpS|;A zcPk558$OpOkFvHTXi+F;l!}6^j!*VRj<2!W<3I1&TC6t|9;(_k=-_eO zQ)tAAD6Ggg=^NB&B(AfG*-%l5;CVBlp%ATVpR>RexWX;+^<%rYt?JRq$eN)0_F3DA zlKV*e(Lbp*PZ}?)!8%#_ukXKnos3%Vi7>AUmM3AynVw!GDk$j3&z~_K^V4}4DD~HUmVG#48d=x&e7`%2 zUd+{DX}*1{DCO;hyz>_edmF4MmDIkQN40E9Nf}AZ=`D}Lh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5u(Eq96T!Yz4!#EzP&ZutMv8}M_qSU&k_Cu#kLv=;c z3aXT}#2z$^ z=X^Tf&Ybhkd*0{&{Qm#vzz|%ib{-jW02i(pY~PPI?(iI%zATzSr97JoV=y?s8tF^;++q z4(Zh$4TtK3S)b&@+R~>4c3?yX9lcP6yj~*$1duQ}qy{QLiIxpW)?mt43br{UQ(&JV zX}OLLJXBpWo<;(a1}(PhZP#sItyUZThAEWS@JYW-H=+<5)=2~ND;v|CtV)z#e4P&G zKf*?!!z1%b{)?nii{P+ph61dEYyCPvYKkPWxD}K1s}d}^D&N9m-GyU1^!d2?rv2mTK&?HE zXOYP9V^}$6C4@$PzUd+WLI*Pu=*foj`J9fqM^1WWat-s9MqJo3^ z&ld9CSVIW_1HxJjZ|Bz;gpM1YFt-8G$eJMM59%xefsmM&_Z>Z4 z$9ARPgd|lSL}*wvw=!aU0&hdj3T|pcJ?!^vIB_J@r6&C6Ht;5(XA!CBDpys*&a>#{ z3+0#3Ku)ck&8|^sSp*}k2j~s1LL?Lhq@}%}We$v|OGJ3?pKxewn)-Y>WjOg9oYlKVV|A#D zqR+A;8ZYYVBIB_`$>On3pE}wr$5NBx<54fCLi`&KGUFxyS{4pAg&zde-tj+-PC9mc zUY|5`S!{-?dY{zuD|6v?O6wXfzt^5E3lv75#JO6NtDQ$iN1=Vrn+Ta18+$ar)hZNn zn0~QFv$|VeGHCaThyl+PYS7J7>n$KDAu8i&CGYQ<%kcK`Df;8AHCbc$``h=VMdb(; zlS%*rn=FPXkX}ur)^8H(D>a$~Wf?hE3jCEp*#3Ionv)Cbu)ps=7+(dSI501&!gpqN zc6-lMr%ZOHEE4lV9e8sXroq{|A6!}#g&al_5aSE~2RkkK AFaQ7m literal 0 HcmV?d00001 diff --git a/global.json b/global.json deleted file mode 100644 index 99d2533c..00000000 --- a/global.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "sdk": { - "version": "2.1.807" - } -} \ No newline at end of file diff --git a/nuget.config b/nuget.config index a81fc3ec..81b3d073 100644 --- a/nuget.config +++ b/nuget.config @@ -8,8 +8,7 @@ - - + diff --git a/sample/Serilog.Sinks.Elasticsearch.Sample/Program.cs b/sample/Serilog.Sinks.Elasticsearch.Sample/Program.cs index b8640806..765d0c86 100644 --- a/sample/Serilog.Sinks.Elasticsearch.Sample/Program.cs +++ b/sample/Serilog.Sinks.Elasticsearch.Sample/Program.cs @@ -4,8 +4,6 @@ using System.Reflection.Metadata.Ecma335; using System.Threading; using Microsoft.Extensions.Configuration; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using Serilog; using Serilog.Core; using Serilog.Debugging; diff --git a/sample/Serilog.Sinks.Elasticsearch.Sample/Serilog.Sinks.Elasticsearch.Sample.csproj b/sample/Serilog.Sinks.Elasticsearch.Sample/Serilog.Sinks.Elasticsearch.Sample.csproj index 20f60c18..2e04d39f 100644 --- a/sample/Serilog.Sinks.Elasticsearch.Sample/Serilog.Sinks.Elasticsearch.Sample.csproj +++ b/sample/Serilog.Sinks.Elasticsearch.Sample/Serilog.Sinks.Elasticsearch.Sample.csproj @@ -2,16 +2,17 @@ Exe - netcoreapp2.1 + net6.0 + false - - - - - - + + + + + + diff --git a/serilog-sinks-elasticsearch.sln b/serilog-sinks-elasticsearch.sln index 50f5d5d2..f36d10e7 100644 --- a/serilog-sinks-elasticsearch.sln +++ b/serilog-sinks-elasticsearch.sln @@ -5,15 +5,12 @@ MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Files", "Files", "{148431F6-5BA9-4987-80CF-DF9F23F54947}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig - .gitattributes = .gitattributes + .gitattributes = .gitattributes .gitignore = .gitignore - appveyor.yml = appveyor.yml - Build.ps1 = Build.ps1 CHANGES.md = CHANGES.md LICENSE = LICENSE nuget.config = nuget.config README.md = README.md - global.json = global.json EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Elasticsearch", "src\Serilog.Sinks.Elasticsearch\Serilog.Sinks.Elasticsearch.csproj", "{EEB0D119-687E-444E-BF14-9BDAEC9BA3EF}" diff --git a/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.ElasticSearch.Symbols.nuspec b/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.ElasticSearch.Symbols.nuspec deleted file mode 100644 index 88c88466..00000000 --- a/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.ElasticSearch.Symbols.nuspec +++ /dev/null @@ -1,22 +0,0 @@ - - - - Serilog.Formatting.Elasticsearch - $version$ - Michiel van Oudheusden, Martijn Laarman, Mogens Heller Grabe - The perfect way for .NET apps formatting structured log events to Elasticsearch JSON. This package contains the formatter used for the Elasticsearch Sink. - en-US - http://serilog.net - http://www.apache.org/licenses/LICENSE-2.0 - http://serilog.net/images/serilog-sink-nuget.png - serilog logging elasticsearch - - - - - - - - - - diff --git a/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.ElasticSearch.nuspec b/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.ElasticSearch.nuspec deleted file mode 100644 index 50f0444a..00000000 --- a/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.ElasticSearch.nuspec +++ /dev/null @@ -1,21 +0,0 @@ - - - - Serilog.Formatting.Elasticsearch - $version$ - Michiel van Oudheusden, Martijn Laarman, Mogens Heller Grabe, Konstantin Erman - The perfect way for .NET apps formatting structured log events to Elasticsearch JSON. This package contains the formatter used for the Elasticsearch Sink. - en-US - http://serilog.net - http://www.apache.org/licenses/LICENSE-2.0 - http://serilog.net/images/serilog-sink-nuget.png - - serilog logging elasticsearch formatters - - - - - - - - diff --git a/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.Elasticsearch.csproj b/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.Elasticsearch.csproj index 7bab4bfc..e9bf5713 100644 --- a/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.Elasticsearch.csproj +++ b/src/Serilog.Formatting.Elasticsearch/Serilog.Formatting.Elasticsearch.csproj @@ -1,44 +1,37 @@  - - 6.0.0 - alpha Michiel van Oudheusden, Martijn Laarman, Mogens Heller Grabe, Serilog Contributors - net45;netstandard1.3;netstandard2.0 + Serilog.Sinks.Elasticsearch + Serilog sink for Elasticsearch + Copyright © Serilog Contributors 2023 + + + + netstandard2.0 true true Serilog.Formatting.Elasticsearch ../../assets/Serilog.snk true - true + false Serilog.Formatting.Elasticsearch serilog;elasticsearch;logging;event;formatting - https://github.com/serilog/serilog-sinks-elasticsearch/blob/master/CHANGES.md - http://serilog.net/images/serilog-sink-nuget.png - https://github.com/serilog/serilog-sinks-elasticsearch - http://www.apache.org/licenses/LICENSE-2.0 - https://github.com/serilog/serilog-sinks-elasticsearch + https://github.com/serilog-contrib/serilog-sinks-elasticsearch/blob/master/CHANGES.md + serilog-sink-nuget.png + https://github.com/serilog-contrib/serilog-sinks-elasticsearch + Apache-2.0 + https://github.com/serilog-contrib/serilog-sinks-elasticsearch git - 1.6.1 - false - false - false - false - false - false Serilog.Formatting.ElasticSearch - + - - - $(DefineConstants);NO_SERIALIZATION - - + - + + - + diff --git a/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs b/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs index 7e3ec182..aff44145 100644 --- a/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs +++ b/src/Serilog.Sinks.Elasticsearch/LoggerConfigurationElasticSearchExtensions.cs @@ -70,7 +70,7 @@ public static LoggerConfiguration Elasticsearch( /// Overload to allow basic configuration through AppSettings. /// /// Options for the sink. - /// A comma or semi column separated list of URIs for Elasticsearch nodes. + /// A comma or semi-colon separated list of URIs for Elasticsearch nodes. /// /// /// @@ -82,7 +82,7 @@ public static LoggerConfiguration Elasticsearch( /// /// /// - /// A comma or semi column separated list of key value pairs of headers to be added to each elastic http request + /// A comma or semi-colon separated list of key value pairs of headers to be added to each elastic http request [Obsolete("New code should not be compiled against this obsolete overload"), EditorBrowsable(EditorBrowsableState.Never)] public static LoggerConfiguration Elasticsearch( this LoggerSinkConfiguration loggerSinkConfiguration, @@ -102,14 +102,14 @@ public static LoggerConfiguration Elasticsearch( { return Elasticsearch(loggerSinkConfiguration, nodeUris, indexFormat, templateName, typeName, batchPostingLimit, period, inlineFields, restrictedToMinimumLevel, bufferBaseFilename, bufferFileSizeLimitBytes, bufferLogShippingInterval, connectionGlobalHeaders, levelSwitch, 5, EmitEventFailureHandling.WriteToSelfLog, 100000, null, false, - AutoRegisterTemplateVersion.ESv2, false, RegisterTemplateRecovery.IndexAnyway, null, null, null); + AutoRegisterTemplateVersion.ESv7, false, RegisterTemplateRecovery.IndexAnyway, null, null, null); } /// /// Overload to allow basic configuration through AppSettings. /// /// Options for the sink. - /// A comma or semi column separated list of URIs for Elasticsearch nodes. + /// A comma or semi-colon separated list of URIs for Elasticsearch nodes. /// /// /// @@ -122,7 +122,7 @@ public static LoggerConfiguration Elasticsearch( /// /// /// - /// A comma or semi column separated list of key value pairs of headers to be added to each elastic http request + /// A comma or semi-colon separated list of key value pairs of headers to be added to each elastic http request /// The connection timeout (in seconds) when sending bulk operations to elasticsearch (defaults to 5). /// Specifies how failing emits should be handled. /// The maximum number of events that will be held in-memory while waiting to ship them to Elasticsearch. Beyond this limit, events will be dropped. The default is 100,000. Has no effect on durable log shipping. @@ -143,6 +143,7 @@ public static LoggerConfiguration Elasticsearch( /// Sink to use when Elasticsearch is unable to accept the events. This is optionally and depends on the EmitEventFailure setting. /// The maximum length of an event allowed to be posted to Elasticsearch.default null /// Add custom elasticsearch settings to the template + /// Turns on detection of elasticsearch version via background HTTP call. This will also set `TypeName` automatically, according to the version of Elasticsearch. /// Configures the OpType being used when inserting document in batch. Must be set to create for data streams. /// LoggerConfiguration object /// is . @@ -151,7 +152,7 @@ public static LoggerConfiguration Elasticsearch( string nodeUris, string indexFormat = null, string templateName = null, - string typeName = "logevent", + string typeName = null, int batchPostingLimit = 50, int period = 2, bool inlineFields = false, @@ -166,7 +167,7 @@ public static LoggerConfiguration Elasticsearch( int queueSizeLimit = 100000, string pipelineName = null, bool autoRegisterTemplate = false, - AutoRegisterTemplateVersion autoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv2, + AutoRegisterTemplateVersion? autoRegisterTemplateVersion = null, bool overwriteTemplate = false, RegisterTemplateRecovery registerTemplateFailure = RegisterTemplateRecovery.IndexAnyway, string deadLetterIndexName = null, @@ -182,7 +183,8 @@ public static LoggerConfiguration Elasticsearch( long? singleEventSizePostingLimit = null, int? bufferFileCountLimit = null, Dictionary templateCustomSettings = null, - ElasticOpType batchAction = ElasticOpType.Index) + ElasticOpType batchAction = ElasticOpType.Index, + bool detectElasticsearchVersion = true) { if (string.IsNullOrEmpty(nodeUris)) throw new ArgumentNullException(nameof(nodeUris), "No Elasticsearch node(s) specified."); @@ -204,11 +206,6 @@ public static LoggerConfiguration Elasticsearch( options.TemplateName = templateName; } - if (!string.IsNullOrWhiteSpace(typeName)) - { - options.TypeName = typeName; - } - options.BatchPostingLimit = batchPostingLimit; options.BatchAction = batchAction; options.SingleEventSizePostingLimit = singleEventSizePostingLimit; @@ -275,6 +272,8 @@ public static LoggerConfiguration Elasticsearch( options.TemplateCustomSettings = templateCustomSettings; + options.DetectElasticsearchVersion = detectElasticsearchVersion; + return Elasticsearch(loggerSinkConfiguration, options); } } diff --git a/src/Serilog.Sinks.Elasticsearch/Properties/AssemblyInfo.cs b/src/Serilog.Sinks.Elasticsearch/Properties/AssemblyInfo.cs deleted file mode 100644 index c5f05dfe..00000000 --- a/src/Serilog.Sinks.Elasticsearch/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -[assembly: AssemblyTitle("Serilog.Sinks.Elasticsearch")] -[assembly: AssemblyDescription("Serilog sink for Elasticsearch")] -[assembly: AssemblyCopyright("Copyright © Serilog Contributors 2018")] - -[assembly: InternalsVisibleTo("Serilog.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c" + - "6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9" + - "d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b818" + - "94191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066" + - "b19485ec")] -[assembly: AssemblyVersion("6.0.0.0")] -[assembly: AssemblyInformationalVersion("6.0.0-unstable.32+Branch.dev.Sha.7e77498e8afaaec96b508de3e8ec6bd3891b3556")] -[assembly: AssemblyFileVersion("6.0.0.0")] diff --git a/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.ElasticSearch.Symbols.nuspec b/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.ElasticSearch.Symbols.nuspec deleted file mode 100644 index 9932b8fb..00000000 --- a/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.ElasticSearch.Symbols.nuspec +++ /dev/null @@ -1,26 +0,0 @@ - - - - Serilog.Sinks.Elasticsearch - $version$ - Michiel van Oudheusden, Martijn Laarman, Mogens Heller Grabe - The perfect way for .NET apps to write structured log events to Elasticsearch. - en-US - http://serilog.net - http://www.apache.org/licenses/LICENSE-2.0 - http://serilog.net/images/serilog-sink-nuget.png - serilog logging elasticsearch - - - - - - - - - - - - - - diff --git a/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.ElasticSearch.nuspec b/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.ElasticSearch.nuspec deleted file mode 100644 index c6ba9cc7..00000000 --- a/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.ElasticSearch.nuspec +++ /dev/null @@ -1,24 +0,0 @@ - - - - Serilog.Sinks.Elasticsearch - $version$ - Michiel van Oudheusden, Martijn Laarman, Mogens Heller Grabe, Konstantin Erman - The perfect way for .NET apps to write structured log events to Elasticsearch. - en-US - http://serilog.net - http://www.apache.org/licenses/LICENSE-2.0 - http://serilog.net/images/serilog-sink-nuget.png - - serilog logging elasticsearch - - - - - - - - - - - diff --git a/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.Elasticsearch.csproj b/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.Elasticsearch.csproj index 96b1af35..a1f4e2bf 100644 --- a/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.Elasticsearch.csproj +++ b/src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.Elasticsearch.csproj @@ -1,31 +1,27 @@  - - 6.0.0 - alpha Michiel van Oudheusden, Martijn Laarman, Mogens Heller Grabe, Serilog Contributors - net461;netstandard2.0 + Serilog.Sinks.Elasticsearch + Serilog sink for Elasticsearch + Copyright © Serilog Contributors 2023 + + + netstandard2.0 true + latest true Serilog.Sinks.Elasticsearch ../../assets/Serilog.snk true - true + false Serilog.Sinks.Elasticsearch serilog;elasticsearch;logging;event;collector - https://github.com/serilog/serilog-sinks-elasticsearch/blob/master/CHANGES.md - http://serilog.net/images/serilog-sink-nuget.png - https://github.com/serilog/serilog-sinks-elasticsearch - http://www.apache.org/licenses/LICENSE-2.0 - https://github.com/serilog/serilog-sinks-elasticsearch + https://github.com/serilog-contrib/serilog-sinks-elasticsearch/blob/master/CHANGES.md + serilog-sink-nuget.png + https://github.com/serilog-contrib/serilog-sinks-elasticsearch + https://github.com/serilog-contrib/serilog-sinks-elasticsearch + Apache-2.0 git - 1.6.1 - false - false - false - false - false - false @@ -33,26 +29,28 @@ $(DefineConstants);DURABLE;THREADING_TIMER - - 1591;1701;1702 - $(DefineConstants);DURABLE;THREADING_TIMER;HRESULTS - - + - - - - - - - + + + + + + - - - + + + <_Parameter1>Serilog.Sinks.Elasticsearch.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b81894191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066b19485ec + + + + + + + diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/DurableElasticsearchSink.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/DurableElasticsearchSink.cs index 45c1da86..60377935 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/DurableElasticsearchSink.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/DurableElasticsearchSink.cs @@ -39,19 +39,17 @@ public DurableElasticsearchSink(ElasticsearchSinkOptions options) throw new ArgumentException("Cannot create the durable ElasticSearch sink without a buffer base file name!"); } - _sink = new LoggerConfiguration() .MinimumLevel.Verbose() .WriteTo.File(_state.DurableFormatter, options.BufferBaseFilename + FileNameSuffix, - rollingInterval: RollingInterval.Day, + rollingInterval: options.BufferFileRollingInterval, fileSizeLimitBytes: options.BufferFileSizeLimitBytes, rollOnFileSizeLimit: true, retainedFileCountLimit: options.BufferFileCountLimit, levelSwitch: _state.Options.LevelSwitch, encoding: Encoding.UTF8) .CreateLogger(); - var elasticSearchLogClient = new ElasticsearchLogClient( elasticLowLevelClient: _state.Client, @@ -63,7 +61,8 @@ public DurableElasticsearchSink(ElasticsearchSinkOptions options) typeName:_state.Options.TypeName, serialize:_state.Serialize, getIndexForEvent: _state.GetBufferedIndexForEvent, - elasticOpType: _state.Options.BatchAction); + elasticOpType: _state.Options.BatchAction, + rollingInterval: options.BufferFileRollingInterval); _shipper = new ElasticsearchLogShipper( bufferBaseFilename: _state.Options.BufferBaseFilename, @@ -75,7 +74,8 @@ public DurableElasticsearchSink(ElasticsearchSinkOptions options) payloadReader: payloadReader, retainedInvalidPayloadsLimitBytes: _state.Options.BufferRetainedInvalidPayloadsLimitBytes, bufferSizeLimitBytes: _state.Options.BufferFileSizeLimitBytes, - registerTemplateIfNeeded: _state.RegisterTemplateIfNeeded); + registerTemplateIfNeeded: _state.RegisterTemplateIfNeeded, + rollingInterval: options.BufferFileRollingInterval); } diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchLogClient.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchLogClient.cs index b3573e77..609d9590 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchLogClient.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchLogClient.cs @@ -86,7 +86,7 @@ private InvalidResult GetInvalidPayloadAsync(DynamicResponse baseResult, List> /// /// /// + /// public ElasticsearchLogShipper(string bufferBaseFilename, int batchPostingLimit, TimeSpan period, long? eventBodyLimitBytes, LoggingLevelSwitch levelControlSwitch, ILogClient> logClient, IPayloadReader> payloadReader, long? retainedInvalidPayloadsLimitBytes, - long? bufferSizeLimitBytes, Action registerTemplateIfNeeded) - : base(bufferBaseFilename, batchPostingLimit, period, eventBodyLimitBytes, - levelControlSwitch, logClient, payloadReader, retainedInvalidPayloadsLimitBytes, bufferSizeLimitBytes) + long? bufferSizeLimitBytes, Action registerTemplateIfNeeded, RollingInterval rollingInterval) + : base(bufferBaseFilename, batchPostingLimit, period, eventBodyLimitBytes, levelControlSwitch, logClient, + payloadReader, retainedInvalidPayloadsLimitBytes, bufferSizeLimitBytes, rollingInterval) { _registerTemplateIfNeeded = registerTemplateIfNeeded; } diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchPayloadReader.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchPayloadReader.cs index 21cf022a..73266667 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchPayloadReader.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/ElasticsearchPayloadReader.cs @@ -17,6 +17,7 @@ public class ElasticsearchPayloadReader: APayloadReader> private readonly Func _serialize; private readonly Func _getIndexForEvent; private readonly ElasticOpType _elasticOpType; + private readonly RollingInterval _rollingInterval; private List _payload; private int _count; private DateTime _date; @@ -29,14 +30,21 @@ public class ElasticsearchPayloadReader: APayloadReader> /// /// /// + /// public ElasticsearchPayloadReader(string pipelineName, string typeName, Func serialize, - Func getIndexForEvent, ElasticOpType elasticOpType) + Func getIndexForEvent, ElasticOpType elasticOpType, RollingInterval rollingInterval) { + if ((int)rollingInterval < (int)RollingInterval.Day) + { + throw new ArgumentException("Rolling intervals less frequent than RollingInterval.Day are not supported"); + } + _pipelineName = pipelineName; _typeName = typeName; _serialize = serialize; _getIndexForEvent = getIndexForEvent; _elasticOpType = elasticOpType; + _rollingInterval = rollingInterval; } /// @@ -64,8 +72,9 @@ protected override void InitPayLoad(string filename) throw new FormatException(string.Format("The file name '{0}' does not seem to follow the right file pattern - it must be named [whatever]-{{Date}}[_n].json", Path.GetFileName(filename))); } - var dateString = lastToken.Substring(0, 8); - _date = DateTime.ParseExact(dateString, "yyyyMMdd", CultureInfo.InvariantCulture); + var dateFormat = _rollingInterval.GetFormat(); + var dateString = lastToken.Substring(0, dateFormat.Length); + _date = DateTime.ParseExact(dateString, dateFormat, CultureInfo.InvariantCulture); } /// /// @@ -83,7 +92,7 @@ protected override List FinishPayLoad() protected override void AddToPayLoad(string nextLine) { var indexName = _getIndexForEvent(nextLine, _date); - var action = ElasticsearchSink.CreateElasticAction( + var action = BatchedElasticsearchSink.CreateElasticAction( opType: _elasticOpType, indexName: indexName, pipelineName: _pipelineName, id: _count + "_" + Guid.NewGuid(), diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/RollingIntervalExtensions.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/RollingIntervalExtensions.cs new file mode 100644 index 00000000..05f1e138 --- /dev/null +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/Elasticsearch/RollingIntervalExtensions.cs @@ -0,0 +1,55 @@ +using System; +using System.Runtime.CompilerServices; + +[assembly: + InternalsVisibleTo( + "Serilog.Sinks.Elasticsearch.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b81894191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066b19485ec")] + +namespace Serilog.Sinks.Elasticsearch.Durable +{ + internal static class RollingIntervalExtensions + { + // From https://github.com/serilog/serilog-sinks-file/blob/dev/src/Serilog.Sinks.File/Sinks/File/RollingIntervalExtensions.cs#L19 + public static string GetFormat(this RollingInterval interval) + { + switch (interval) + { + case RollingInterval.Infinite: + return ""; + case RollingInterval.Year: + return "yyyy"; + case RollingInterval.Month: + return "yyyyMM"; + case RollingInterval.Day: + return "yyyyMMdd"; + case RollingInterval.Hour: + return "yyyyMMddHH"; + case RollingInterval.Minute: + return "yyyyMMddHHmm"; + default: + throw new ArgumentException("Invalid rolling interval"); + } + } + + public static string GetMatchingDateRegularExpressionPart(this RollingInterval interval) + { + switch (interval) + { + case RollingInterval.Infinite: + return ""; + case RollingInterval.Year: + return "\\d{4}"; + case RollingInterval.Month: + return "\\d{6}"; + case RollingInterval.Day: + return "\\d{8}"; + case RollingInterval.Hour: + return "\\d{10}"; + case RollingInterval.Minute: + return "\\d{12}"; + default: + throw new ArgumentException("Invalid rolling interval"); + } + } + } +} \ No newline at end of file diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/FileSet.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/FileSet.cs index 133eb79e..739458af 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/FileSet.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/FileSet.cs @@ -19,9 +19,12 @@ using System.IO; using System.Linq; using System.Net; +using System.Runtime.CompilerServices; using System.Text.RegularExpressions; using Serilog.Debugging; - +[assembly: + InternalsVisibleTo( + "Serilog.Sinks.Elasticsearch.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b81894191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066b19485ec")] namespace Serilog.Sinks.Elasticsearch.Durable { /// @@ -36,14 +39,16 @@ class FileSet const string InvalidPayloadFilePrefix = "invalid-"; - public FileSet(string bufferBaseFilename) + public FileSet(string bufferBaseFilename, RollingInterval rollingInterval) { if (bufferBaseFilename == null) throw new ArgumentNullException(nameof(bufferBaseFilename)); _bookmarkFilename = Path.GetFullPath(bufferBaseFilename + ".bookmark"); _logFolder = Path.GetDirectoryName(_bookmarkFilename); _candidateSearchPath = Path.GetFileName(bufferBaseFilename) + "-*.json"; - _filenameMatcher = new Regex("^" + Regex.Escape(Path.GetFileName(bufferBaseFilename)) + "-(?\\d{8})(?_[0-9]{3,}){0,1}\\.json$"); + var dateRegularExpressionPart = rollingInterval.GetMatchingDateRegularExpressionPart(); + _filenameMatcher = new Regex("^" + Regex.Escape(Path.GetFileName(bufferBaseFilename)) + "-(?" + + dateRegularExpressionPart + ")(?_[0-9]{3,}){0,1}\\.json$"); } public BookmarkFile OpenBookmarkFile() diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/LogShipper.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/LogShipper.cs index a9a49666..8eb7f000 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/LogShipper.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/Durable/LogShipper.cs @@ -76,6 +76,7 @@ public class LogShipper : IDisposable /// /// /// + /// public LogShipper( string bufferBaseFilename, int batchPostingLimit, @@ -85,7 +86,8 @@ public LogShipper( ILogClient logClient, IPayloadReader payloadReader, long? retainedInvalidPayloadsLimitBytes, - long? bufferSizeLimitBytes) + long? bufferSizeLimitBytes, + RollingInterval rollingInterval = RollingInterval.Day) { _batchPostingLimit = batchPostingLimit; _eventBodyLimitBytes = eventBodyLimitBytes; @@ -95,7 +97,7 @@ public LogShipper( _connectionSchedule = new ExponentialBackoffConnectionSchedule(period); _retainedInvalidPayloadsLimitBytes = retainedInvalidPayloadsLimitBytes; _bufferSizeLimitBytes = bufferSizeLimitBytes; - _fileSet = new FileSet(bufferBaseFilename); + _fileSet = new FileSet(bufferBaseFilename, rollingInterval); _timer = new PortableTimer(c => OnTick()); SetTimer(); diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchSink.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchSink.cs index d695ed80..52c0871d 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchSink.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchSink.cs @@ -25,26 +25,39 @@ namespace Serilog.Sinks.Elasticsearch { + public sealed class ElasticsearchSink : PeriodicBatchingSink + { + public ElasticsearchSink(ElasticsearchSinkOptions options) + : this( + new BatchedElasticsearchSink(options), + new PeriodicBatchingSinkOptions + { + BatchSizeLimit = options.BatchPostingLimit, + Period = options.Period, + EagerlyEmitFirstEvent = true, + QueueLimit = (options.QueueSizeLimit == -1) ? null : new int?(options.QueueSizeLimit) + } + ) + { + } + + private ElasticsearchSink(IBatchedLogEventSink batchedSink, PeriodicBatchingSinkOptions options) + : base(batchedSink, options) + { + } + } /// /// Writes log events as documents to ElasticSearch. /// - public class ElasticsearchSink : PeriodicBatchingSink + internal sealed class BatchedElasticsearchSink : IBatchedLogEventSink { - private readonly ElasticsearchSinkState _state; - /// - /// Creates a new ElasticsearchSink instance with the provided options - /// - /// Options configuring how the sink behaves, may NOT be null - public ElasticsearchSink(ElasticsearchSinkOptions options) - : base(options.BatchPostingLimit, options.Period, options.QueueSizeLimit) + public BatchedElasticsearchSink(ElasticsearchSinkOptions options) { _state = ElasticsearchSinkState.Create(options); - _state.DiscoverClusterVersion(); _state.RegisterTemplateIfNeeded(); } - /// /// Emit a batch of log events, running to completion synchronously. /// @@ -54,7 +67,7 @@ public ElasticsearchSink(ElasticsearchSinkOptions options) /// or , /// not both. /// - protected override async Task EmitBatchAsync(IEnumerable events) + public async Task EmitBatchAsync(IEnumerable events) { DynamicResponse result; @@ -71,19 +84,9 @@ protected override async Task EmitBatchAsync(IEnumerable events) HandleResponse(events, result); } - /// - /// Emit a batch of log events, running to completion synchronously. - /// - /// The events to emit. - /// Response from Elasticsearch - protected virtual Task EmitBatchCheckedAsync(IEnumerable events) where T : class, IElasticsearchResponse, new() + public Task OnEmptyBatchAsync() { - // ReSharper disable PossibleMultipleEnumeration - if (events == null || !events.Any()) - return Task.FromResult(default(T)); - - var payload = CreatePlayLoad(events); - return _state.Client.BulkAsync(PostData.MultiJson(payload)); + return Task.CompletedTask; } /// @@ -91,14 +94,14 @@ protected override async Task EmitBatchAsync(IEnumerable events) /// /// The events to emit. /// Response from Elasticsearch - protected virtual T EmitBatchChecked(IEnumerable events) where T : class, IElasticsearchResponse, new() + private Task EmitBatchCheckedAsync(IEnumerable events) where T : class, IElasticsearchResponse, new() { // ReSharper disable PossibleMultipleEnumeration if (events == null || !events.Any()) - return null; + return Task.FromResult(default(T)); - var payload = CreatePlayLoad(events); - return _state.Client.Bulk(PostData.MultiJson(payload)); + var payload = CreatePayload(events); + return _state.Client.BulkAsync(PostData.MultiJson(payload)); } /// @@ -106,12 +109,12 @@ protected override async Task EmitBatchAsync(IEnumerable events) /// /// /// - protected virtual void HandleException(Exception ex, IEnumerable events) + private void HandleException(Exception ex, IEnumerable events) { if (_state.Options.EmitEventFailure.HasFlag(EmitEventFailureHandling.WriteToSelfLog)) { // ES reports an error, output the error to the selflog - SelfLog.WriteLine("Caught exception while preforming bulk operation to Elasticsearch: {0}", ex); + SelfLog.WriteLine("Caught exception while performing bulk operation to Elasticsearch: {0}", ex); } if (_state.Options.EmitEventFailure.HasFlag(EmitEventFailureHandling.WriteToFailureSink) && _state.Options.FailureSink != null) @@ -153,19 +156,7 @@ protected virtual void HandleException(Exception ex, IEnumerable event throw ex; } - // Helper function: checks if a given dynamic member / dictionary key exists at runtime - private static bool HasProperty(dynamic settings, string name) - { - if (settings is IDictionary) - return ((IDictionary)settings).ContainsKey(name); - - if (settings is System.Dynamic.DynamicObject) - return ((System.Dynamic.DynamicObject)settings).GetDynamicMemberNames().Contains(name); - - return settings.GetType().GetProperty(name) != null; - } - - private IEnumerable CreatePlayLoad(IEnumerable events) + private IEnumerable CreatePayload(IEnumerable events) { if (!_state.TemplateRegistrationSuccess && _state.Options.RegisterTemplateFailure == RegisterTemplateRecovery.FailSink) { @@ -280,7 +271,7 @@ internal static object CreateElasticAction(ElasticOpType opType, string indexNam : new ElasticIndexAction(actionPayload); return action; } - + sealed class ElasticCreateAction { public ElasticCreateAction(ElasticActionPayload payload) diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchTemplateProvider.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchTemplateProvider.cs index c69c19ca..2bb7641c 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchTemplateProvider.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchTemplateProvider.cs @@ -9,14 +9,6 @@ namespace Serilog.Sinks.Elasticsearch /// public enum AutoRegisterTemplateVersion { - /// - /// Elasticsearch version <= 2.4 - /// - ESv2 = 0, - /// - /// Elasticsearch version <= version 5.6 - /// - ESv5 = 1, /// /// Elasticsearch version >= version 6.0 /// @@ -24,57 +16,57 @@ public enum AutoRegisterTemplateVersion /// /// Elasticsearch version >= version 7.0 /// - ESv7 = 3 + ESv7 = 3, + /// + /// Elasticsearch version >= version 8.0 + /// + ESv8 = 4 } /// /// /// public class ElasticsearchTemplateProvider - { - [Obsolete("Use the overload taking ElasticsearchSinkOptions which takes IncludeTypeName into account")] - public static object GetTemplate( + { + public static object GetTemplate(ElasticsearchSinkOptions options, + int discoveredMajorVersion, Dictionary settings, string templateMatchString, - AutoRegisterTemplateVersion version = AutoRegisterTemplateVersion.ESv2) + AutoRegisterTemplateVersion version = AutoRegisterTemplateVersion.ESv7) { switch (version) { - case AutoRegisterTemplateVersion.ESv5: - return GetTemplateESv5(settings, templateMatchString); - case AutoRegisterTemplateVersion.ESv6: - return GetTemplateESv6(null, null, settings, templateMatchString); + case AutoRegisterTemplateVersion.ESv8: + return GetTemplateESv8(options, discoveredMajorVersion, settings, templateMatchString); case AutoRegisterTemplateVersion.ESv7: - return GetTemplateESv7(null, null, settings, templateMatchString); - case AutoRegisterTemplateVersion.ESv2: - return GetTemplateESv2(settings, templateMatchString); + return GetTemplateESv7(options, discoveredMajorVersion, settings, templateMatchString); + case AutoRegisterTemplateVersion.ESv6: + return GetTemplateESv6(options, discoveredMajorVersion, settings, templateMatchString); default: throw new ArgumentOutOfRangeException(nameof(version), version, null); } } - - public static object GetTemplate(ElasticsearchSinkOptions options, - string discoveredVersion, + + private static object GetTemplateESv8(ElasticsearchSinkOptions options, int discoveredMajorVersion, Dictionary settings, - string templateMatchString, - AutoRegisterTemplateVersion version = AutoRegisterTemplateVersion.ESv2) + string templateMatchString) { - switch (version) + dynamic templateV7 = GetTemplateESv7(options, discoveredMajorVersion, settings, templateMatchString); + + // wrap settings, mappings and aliases into template property. + return new { - case AutoRegisterTemplateVersion.ESv5: - return GetTemplateESv5(settings, templateMatchString); - case AutoRegisterTemplateVersion.ESv2: - return GetTemplateESv2(settings, templateMatchString); - case AutoRegisterTemplateVersion.ESv6: - return GetTemplateESv6(options, discoveredVersion, settings, templateMatchString); - case AutoRegisterTemplateVersion.ESv7: - return GetTemplateESv7(options, discoveredVersion, settings, templateMatchString); - default: - throw new ArgumentOutOfRangeException(nameof(version), version, null); - } + index_patterns = templateV7.index_patterns, + template = new + { + settings = templateV7.settings, + mappings = templateV7.mappings, + aliases = templateV7.aliases + } + }; } - private static object GetTemplateESv7(ElasticsearchSinkOptions options, string discoveredVersion, + private static object GetTemplateESv7(ElasticsearchSinkOptions options, int discoveredMajorVersion, Dictionary settings, string templateMatchString) { @@ -157,7 +149,7 @@ private static object GetTemplateESv7(ElasticsearchSinkOptions options, string d } } }; - mappings = discoveredVersion?.StartsWith("6.") ?? false ? new { _doc = mappings } : mappings; + mappings = discoveredMajorVersion == 6 ? new { _doc = mappings } : mappings; Dictionary aliases = new Dictionary(); @@ -170,6 +162,7 @@ private static object GetTemplateESv7(ElasticsearchSinkOptions options, string d aliases.Add(alias, new object()); } + return new { index_patterns = new[] { templateMatchString }, @@ -179,7 +172,7 @@ private static object GetTemplateESv7(ElasticsearchSinkOptions options, string d }; } - private static object GetTemplateESv6(ElasticsearchSinkOptions options, string discoveredVersion, + private static object GetTemplateESv6(ElasticsearchSinkOptions options, int discoveredMajorVersion, Dictionary settings, string templateMatchString) { @@ -263,7 +256,7 @@ private static object GetTemplateESv6(ElasticsearchSinkOptions options, string d } }; - mappings = discoveredVersion?.StartsWith("7.") ?? false ? (object) new { _doc = mappings} : new { _default_ = mappings}; + mappings = discoveredMajorVersion == 7 ? (object) new { _doc = mappings} : new { _default_ = mappings}; return new { diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs index 06de4ae2..f759be2e 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs @@ -38,9 +38,9 @@ public class ElasticsearchSinkOptions /// /// When using the feature, this allows to set the Elasticsearch version. Depending on the - /// version, a template will be selected. Defaults to pre 5.0. + /// version, a template will be selected. Defaults to 7.0. /// - public AutoRegisterTemplateVersion AutoRegisterTemplateVersion { get; set; } + public AutoRegisterTemplateVersion? AutoRegisterTemplateVersion { get; set; } /// /// Specifies the option on how to handle failures when writing the template to Elasticsearch. This is only applicable when using the AutoRegisterTemplate option. @@ -110,7 +110,7 @@ public class ElasticsearchSinkOptions public string DeadLetterIndexName { get; set; } /// - /// The default elasticsearch type name to use for the log events. Defaults to: logevent. + /// The default elasticsearch type name to use for the log events. Defaults to: null. /// public string TypeName { get; set; } @@ -273,6 +273,13 @@ public int QueueSizeLimit /// When set to true splits the StackTrace by new line and writes it as a an array of strings. /// public bool FormatStackTraceAsArray { get; set; } + + /// + /// The interval at which buffer log files will roll over to a new file. The default is . + /// Less frequent intervals like , , + /// are not supported. + /// + public RollingInterval BufferFileRollingInterval { get; set; } /// /// Configures the elasticsearch sink defaults @@ -281,7 +288,6 @@ public ElasticsearchSinkOptions() { this.IndexFormat = "logstash-{0:yyyy.MM.dd}"; this.DeadLetterIndexName = "deadletter-{0:yyyy.MM.dd}"; - this.TypeName = DefaultTypeName; this.Period = TimeSpan.FromSeconds(2); this.BatchPostingLimit = 50; this.SingleEventSizePostingLimit = null; @@ -294,19 +300,21 @@ public ElasticsearchSinkOptions() this.BufferFileSizeLimitBytes = 100L * 1024 * 1024; this.FormatStackTraceAsArray = false; this.ConnectionPool = new SingleNodeConnectionPool(_defaultNode); + this.BufferFileRollingInterval = RollingInterval.Day; } /// /// The default Elasticsearch type name used for Elasticsearch versions prior to 7. /// As of Elasticsearch 7 and up _type has been removed. /// - public static string DefaultTypeName { get; } = "_doc"; + public static string DefaultTypeName { get; } = "logevent"; /// /// Instructs the sink to auto detect the running Elasticsearch version. /// /// /// This information is used to attempt to register an older or newer template + /// and to decide which version of index-template API to use. /// /// /// @@ -321,7 +329,7 @@ public ElasticsearchSinkOptions() /// - using against Elasticsearch 7.x /// /// - public bool DetectElasticsearchVersion { get; set; } + public bool DetectElasticsearchVersion { get; set; } = true; /// /// Configures the elasticsearch sink diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs index c304a8f1..540e0d0a 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs @@ -14,16 +14,14 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Text.RegularExpressions; using Elasticsearch.Net; -using Elasticsearch.Net.Specification.CatApi; using Elasticsearch.Net.Specification.IndicesApi; using Serilog.Debugging; using Serilog.Events; using Serilog.Formatting; using Serilog.Formatting.Elasticsearch; +using Serilog.Sinks.Elasticsearch.Sinks.ElasticSearch; namespace Serilog.Sinks.Elasticsearch { @@ -51,12 +49,11 @@ public static ElasticsearchSinkState Create(ElasticsearchSinkOptions options) private readonly string _templateName; private readonly string _templateMatchString; private static readonly Regex IndexFormatRegex = new Regex(@"^(.*)(?:\{0\:.+\})(.*)$"); - private string _discoveredVersion; - public string DiscoveredVersion => _discoveredVersion; - private bool IncludeTypeName => - (DiscoveredVersion?.StartsWith("7.") ?? false) - && _options.AutoRegisterTemplateVersion == AutoRegisterTemplateVersion.ESv6; + private readonly ElasticsearchVersionManager _versionManager; + + private bool IncludeTypeName => _versionManager.EffectiveVersion.Major >= 7; + public ElasticsearchSinkOptions Options => _options; public IElasticLowLevelClient Client => _client; public ITextFormatter Formatter => _formatter; @@ -83,7 +80,6 @@ private ElasticsearchSinkState(ElasticsearchSinkOptions options) _options = options; - var configuration = new ConnectionConfiguration(options.ConnectionPool, options.Connection, options.Serializer) .RequestTimeout(options.ConnectionTimeout); @@ -100,6 +96,16 @@ private ElasticsearchSinkState(ElasticsearchSinkOptions options) _registerTemplateOnStartup = options.AutoRegisterTemplate; TemplateRegistrationSuccess = !_registerTemplateOnStartup; + + _versionManager = new ElasticsearchVersionManager(options.DetectElasticsearchVersion, _client); + + // Resolve typeName + if (_versionManager.EffectiveVersion.Major < 7) + _options.TypeName = string.IsNullOrWhiteSpace(_options.TypeName) + ? ElasticsearchSinkOptions.DefaultTypeName // "logevent" + : _options.TypeName; + else + _options.TypeName = null; } public static ITextFormatter CreateDefaultFormatter(ElasticsearchSinkOptions options) @@ -166,11 +172,20 @@ public void RegisterTemplateIfNeeded() } } - var result = _client.Indices.PutTemplateForAll(_templateName, GetTemplatePostData(), - new PutIndexTemplateRequestParameters - { - IncludeTypeName = IncludeTypeName ? true : (bool?)null - }); + StringResponse result; + if (_versionManager.EffectiveVersion.Major < 8) + { + result = _client.Indices.PutTemplateForAll(_templateName, GetTemplatePostData(), + new PutIndexTemplateRequestParameters + { + IncludeTypeName = IncludeTypeName ? true : (bool?)null + }); + } + else + { + // Default to version 8 API + result = _client.Indices.PutTemplateV2ForAll(_templateName, GetTemplatePostData()); + } if (!result.Success) { @@ -229,38 +244,23 @@ private object GetTemplateData() if (_options.NumberOfReplicas.HasValue && !settings.ContainsKey("number_of_replicas")) settings.Add("number_of_replicas", _options.NumberOfReplicas.Value.ToString()); + var effectiveTemplateVerson = + _options.AutoRegisterTemplateVersion ?? + _versionManager.EffectiveVersion.Major switch + { + >= 8 => AutoRegisterTemplateVersion.ESv8, + 7 => AutoRegisterTemplateVersion.ESv7, + 6 => AutoRegisterTemplateVersion.ESv6, + _ => throw new NotSupportedException() + }; + return ElasticsearchTemplateProvider.GetTemplate( _options, - DiscoveredVersion, + _versionManager.EffectiveVersion.Major, settings, _templateMatchString, - _options.AutoRegisterTemplateVersion); + effectiveTemplateVerson); } - - public void DiscoverClusterVersion() - { - if (!_options.DetectElasticsearchVersion) return; - - try - { - - var response = _client.Cat.Nodes(new CatNodesRequestParameters() - { - Headers = new[] { "v" } - }); - if (!response.Success) return; - - _discoveredVersion = response.Body.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries) - .FirstOrDefault(); - - if (_discoveredVersion?.StartsWith("7.") ?? false) - _options.TypeName = "_doc"; - } - catch (Exception ex) - { - SelfLog.WriteLine("Failed to discover the cluster version. {0}", ex); - } - } } } diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchVersionManager.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchVersionManager.cs new file mode 100644 index 00000000..124b1764 --- /dev/null +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchVersionManager.cs @@ -0,0 +1,84 @@ +#nullable enable +using Elasticsearch.Net; +using Elasticsearch.Net.Specification.CatApi; +using Serilog.Debugging; +using System; +using System.Linq; + +namespace Serilog.Sinks.Elasticsearch.Sinks.ElasticSearch +{ + /// + /// Encapsulates detection of Elasticsearch version + /// and fallback in case of detection failiure. + /// + internal class ElasticsearchVersionManager + { + private readonly bool _detectElasticsearchVersion; + private readonly IElasticLowLevelClient _client; + + /// + /// We are defaulting to version 7.17.0 + /// as currently supported versions are 7 and 8, + /// while version 8 retains wire backward compatibility with 7.17.0 + /// and index backward compatibility with 7.0.0 + /// + public readonly Version DefaultVersion = new(7, 17); + public Version? DetectedVersion { get; private set; } + public bool DetectionAttempted { get; private set; } + + public ElasticsearchVersionManager( + bool detectElasticsearchVersion, + IElasticLowLevelClient client) + { + _detectElasticsearchVersion = detectElasticsearchVersion; + _client = client ?? throw new ArgumentNullException(nameof(client)); + } + + public Version EffectiveVersion + { + get + { + if (DetectedVersion is not null) + return DetectedVersion; + + if (_detectElasticsearchVersion == false + || DetectionAttempted == true) + return DefaultVersion; + + // Attemp once + DetectedVersion = DiscoverClusterVersion(); + + return DetectedVersion ?? DefaultVersion; + } + } + + internal Version? DiscoverClusterVersion() + { + try + { + var response = _client.DoRequest(HttpMethod.GET, "/"); + if (!response.Success) return null; + + var discoveredVersion = response.Dictionary["version"]["number"]; + + if (!discoveredVersion.HasValue) + return null; + + if (discoveredVersion.Value is not string strVersion) + return null; + + return new Version(strVersion); + + } + catch (Exception ex) + { + SelfLog.WriteLine("Failed to discover the cluster version. {0}", ex); + return null; + } + finally + { + DetectionAttempted = true; + } + } + } +} diff --git a/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Elasticsearch6/Elasticsearch6X.cs b/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Elasticsearch6/Elasticsearch6X.cs index f120fa46..e0110ab9 100644 --- a/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Elasticsearch6/Elasticsearch6X.cs +++ b/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Elasticsearch6/Elasticsearch6X.cs @@ -48,7 +48,7 @@ public SetupSerilog() { var loggerConfig = new LoggerConfiguration() .MinimumLevel.Information() - .WriteTo.ColoredConsole() + .WriteTo.Console() .WriteTo.Elasticsearch( ElasticsearchSinkOptionsFactory.Create(IndexPrefix, TemplateName, o => { diff --git a/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Elasticsearch6/Elasticsearch6XUsing7X.cs b/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Elasticsearch6/Elasticsearch6XUsing7X.cs index f2a38a82..26cbec10 100644 --- a/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Elasticsearch6/Elasticsearch6XUsing7X.cs +++ b/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Elasticsearch6/Elasticsearch6XUsing7X.cs @@ -47,7 +47,7 @@ public SetupSerilog() { var loggerConfig = new LoggerConfiguration() .MinimumLevel.Information() - .WriteTo.ColoredConsole() + .WriteTo.Console() .WriteTo.Elasticsearch( ElasticsearchSinkOptionsFactory.Create(IndexPrefix, TemplateName, o => { diff --git a/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Elasticsearch7/Elasticsearch7X.cs b/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Elasticsearch7/Elasticsearch7X.cs index dea4b051..5a3ff54d 100644 --- a/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Elasticsearch7/Elasticsearch7X.cs +++ b/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Elasticsearch7/Elasticsearch7X.cs @@ -44,7 +44,7 @@ public SetupSerilog() { var loggerConfig = new LoggerConfiguration() .MinimumLevel.Information() - .WriteTo.ColoredConsole() + .WriteTo.Console() .WriteTo.Elasticsearch( ElasticsearchSinkOptionsFactory.Create(IndexPrefix, TemplateName, o => { diff --git a/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Elasticsearch7/Elasticsearch7XUsing6X.cs b/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Elasticsearch7/Elasticsearch7XUsing6X.cs index 6ec69890..274506b6 100644 --- a/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Elasticsearch7/Elasticsearch7XUsing6X.cs +++ b/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Elasticsearch7/Elasticsearch7XUsing6X.cs @@ -44,7 +44,7 @@ public SetupSerilog() { var loggerConfig = new LoggerConfiguration() .MinimumLevel.Information() - .WriteTo.ColoredConsole() + .WriteTo.Console() .WriteTo.Elasticsearch( ElasticsearchSinkOptionsFactory.Create(IndexPrefix, TemplateName, o => { diff --git a/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Serilog.Sinks.Elasticsearch.IntegrationTests.csproj b/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Serilog.Sinks.Elasticsearch.IntegrationTests.csproj index 4c4476b7..ea4d8b2f 100644 --- a/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Serilog.Sinks.Elasticsearch.IntegrationTests.csproj +++ b/test/Serilog.Sinks.Elasticsearch.IntegrationTests/Serilog.Sinks.Elasticsearch.IntegrationTests.csproj @@ -1,11 +1,13 @@  - netcoreapp2.1;net461 + net6.0 $(NoWarn);xUnit1013 True latest True + false + true @@ -14,15 +16,49 @@ + - - - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - - - + + + + + + + + + + + + true + + $([MSBuild]::EnsureTrailingSlash($([System.IO.Path]::GetFullPath($([System.IO.Path]::Combine($(MSBuildProjectDirectory),'..','coverage')))))) + + cobertura + + + + + $([MSBuild]::EnsureTrailingSlash('$(CoverletOutput)report')) + xdg-open + open + explorer + + + + + + + + + diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/BulkActionTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/BulkActionTests.cs index 7a6e1241..0cbd17dd 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/BulkActionTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/BulkActionTests.cs @@ -3,13 +3,14 @@ using FluentAssertions; using Serilog.Events; using Serilog.Parsing; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; using Xunit; namespace Serilog.Sinks.Elasticsearch.Tests { public class BulkActionTests : ElasticsearchSinkTestsBase { - [Fact] + [Fact(Skip = "Flaky test on GitHub actions")] public void DefaultBulkActionV7() { _options.IndexFormat = "logs"; @@ -26,11 +27,11 @@ public void DefaultBulkActionV7() bulkJsonPieces[0].Should().Be(expectedAction); } - [Fact] + [Fact(Skip = "Flaky test on GitHub actions")] public void BulkActionV7OverrideTypeName() { _options.IndexFormat = "logs"; - _options.TypeName = "logevent"; // This is the default value when creating the sink via configuration + _options.TypeName = null; // This is the default value, starting v9.0.0 _options.AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7; _options.PipelineName = null; using (var sink = new ElasticsearchSink(_options)) @@ -42,9 +43,9 @@ public void BulkActionV7OverrideTypeName() var bulkJsonPieces = this.AssertSeenHttpPosts(_seenHttpPosts, 2, 1); const string expectedAction = @"{""index"":{""_type"":""_doc"",""_index"":""logs""}}"; bulkJsonPieces[0].Should().Be(expectedAction); - } - - [Fact] + } + + [Fact(Skip = "Flaky test on GitHub actions")] public void DefaultBulkActionV8() { _options.IndexFormat = "logs"; @@ -60,8 +61,9 @@ public void DefaultBulkActionV8() const string expectedAction = @"{""index"":{""_index"":""logs""}}"; bulkJsonPieces[0].Should().Be(expectedAction); } - - [Fact] + + + [Fact(Skip = "Flaky test on GitHub actions")] public void BulkActionDataStreams() { _options.IndexFormat = "logs-my-stream"; @@ -79,8 +81,8 @@ public void BulkActionDataStreams() const string expectedAction = @"{""create"":{""_index"":""logs-my-stream""}}"; bulkJsonPieces[0].Should().Be(expectedAction); } - - [Fact] + + [Fact(Skip = "Flaky test on GitHub actions")] public void PipelineAction() { _options.IndexFormat = "logs-my-stream"; diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/CustomIndexTypeNameTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/CustomIndexTypeNameTests.cs index d3f44b53..c870334a 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/CustomIndexTypeNameTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/CustomIndexTypeNameTests.cs @@ -1,16 +1,21 @@ using System; using System.Collections.Generic; -using System.Linq; using FluentAssertions; using Serilog.Events; using Serilog.Parsing; -using Serilog.Sinks.Elasticsearch; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; using Xunit; namespace Serilog.Sinks.Elasticsearch.Tests { public class CustomIndexTypeNameTests : ElasticsearchSinkTestsBase { + public CustomIndexTypeNameTests() + : base("6.0.0") + { + + } + [Fact] public void CustomIndex_And_TypeName_EndsUpInTheOutput() { diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Discrepancies/ElasticsearchSinkUniformityTestsBase.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Discrepancies/ElasticsearchSinkUniformityTestsBase.cs index 3e4ba9d6..1e3e474d 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Discrepancies/ElasticsearchSinkUniformityTestsBase.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Discrepancies/ElasticsearchSinkUniformityTestsBase.cs @@ -2,6 +2,7 @@ using System.Runtime.Serialization; using Elasticsearch.Net; using FluentAssertions; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; namespace Serilog.Sinks.Elasticsearch.Tests.Discrepancies { @@ -17,7 +18,7 @@ public void ThrowAndLogAndCatchBulkOutput(string exceptionMessage) var loggerConfig = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.WithMachineName() - .WriteTo.ColoredConsole() + .WriteTo.Console() .WriteTo.Elasticsearch(_options); var logger = loggerConfig.CreateLogger(); @@ -54,7 +55,7 @@ public void ThrowAndLogAndCatchBulkOutput(string exceptionMessage) .And.Be(exceptionMessage); var realException = firstEvent.Exceptions[0]; #if !NO_SERIALIZATION -#if !PARTIALLY_SERIALIZATION +#if NETFRAMEWORK realException.ExceptionMethod.Should().NotBeNull(); realException.ExceptionMethod.Name.Should().NotBeNullOrWhiteSpace(); realException.ExceptionMethod.AssemblyName.Should().NotBeNullOrWhiteSpace(); diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Discrepancies/NoSerializerTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Discrepancies/NoSerializerTests.cs index a5f99651..c4571d06 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Discrepancies/NoSerializerTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Discrepancies/NoSerializerTests.cs @@ -1,7 +1,4 @@ -using System; -using System.Linq; -using FluentAssertions; -using Xunit; +using Xunit; namespace Serilog.Sinks.Elasticsearch.Tests.Discrepancies { diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Domain/BulkAction.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Domain/BulkAction.cs index c754acf7..f9693bce 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Domain/BulkAction.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Domain/BulkAction.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Serilog.Events; diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/ElasticSearchLogShipperTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/ElasticSearchLogShipperTests.cs index 7de82f56..5bbe8866 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/ElasticSearchLogShipperTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/ElasticSearchLogShipperTests.cs @@ -1,10 +1,4 @@ -using Serilog.Debugging; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using Xunit; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; namespace Serilog.Sinks.Elasticsearch.Tests { diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/ElasticsearchJsonFormatterTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/ElasticsearchJsonFormatterTests.cs index d62a611f..f93ba0e7 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/ElasticsearchJsonFormatterTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/ElasticsearchJsonFormatterTests.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using Serilog.Formatting.Elasticsearch; using Xunit; diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/ElasticsearchPayloadReaderTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/ElasticsearchPayloadReaderTests.cs new file mode 100644 index 00000000..c24f2485 --- /dev/null +++ b/test/Serilog.Sinks.Elasticsearch.Tests/ElasticsearchPayloadReaderTests.cs @@ -0,0 +1,86 @@ +using System; +using System.IO; +using System.Text; +using FluentAssertions; +using Serilog.Sinks.Elasticsearch.Durable; +using Xunit; + +namespace Serilog.Sinks.Elasticsearch.Tests; + +public class ElasticsearchPayloadReaderTests : IDisposable +{ + private readonly string _tempFileFullPathTemplate; + private string _bufferFileName; + + public ElasticsearchPayloadReaderTests() + { + _tempFileFullPathTemplate = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")) + "-{0}.json"; + } + + public void Dispose() + { + if (!string.IsNullOrEmpty(_bufferFileName)) + { + System.IO.File.Delete(_bufferFileName); + } + } + + [Theory] + [InlineData(RollingInterval.Day)] + [InlineData(RollingInterval.Hour)] + [InlineData(RollingInterval.Minute)] + public void ReadPayload_ShouldReadSpecifiedTypesOfRollingFile(RollingInterval rollingInterval) + { + // Arrange + var format = rollingInterval.GetFormat(); + var payloadReader = new ElasticsearchPayloadReader("testPipelineName", + "TestTypeName", + null, + (_, _) => "TestIndex", + ElasticOpType.Index, + rollingInterval); + var lines = new[] + { + rollingInterval.ToString() + }; + _bufferFileName = string.Format(_tempFileFullPathTemplate, + string.IsNullOrEmpty(format) ? string.Empty : new DateTime(2000, 1, 1).ToString(format)); + // Important to use UTF8 with BOM if we are starting from 0 position + System.IO.File.WriteAllLines(_bufferFileName, lines, new UTF8Encoding(true)); + + // Act + var fileSetPosition = new FileSetPosition(0, _bufferFileName); + var count = 0; + var payload = payloadReader.ReadPayload(int.MaxValue, + null, + ref fileSetPosition, + ref count, + _bufferFileName); + + // Assert + // Thus we ensure that file was properly handled by PayloadReader + payload.Count.Should().Be(lines.Length * 2); + payload[1].Should().Be(lines[0]); + } + + [Theory] + [InlineData(RollingInterval.Infinite)] + [InlineData(RollingInterval.Year)] + [InlineData(RollingInterval.Month)] + public void ElasticsearchPayloadReader_CannotUseRollingIntervalLessFrequentThanDay(RollingInterval rollingInterval) + { + // Arrange + + // Act + Action act = () => new ElasticsearchPayloadReader("testPipelineName", + "TestTypeName", + null, + (_, _) => "TestIndex", + ElasticOpType.Index, + rollingInterval); + + // Assert + act.Should().Throw() + .WithMessage("Rolling intervals less frequent than RollingInterval.Day are not supported"); + } +} \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/ElasticsearchSinkTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/ElasticsearchSinkTests.cs new file mode 100644 index 00000000..ce940659 --- /dev/null +++ b/test/Serilog.Sinks.Elasticsearch.Tests/ElasticsearchSinkTests.cs @@ -0,0 +1,93 @@ +using Elasticsearch.Net; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; +using System.Text; +using Xunit; + +namespace Serilog.Sinks.Elasticsearch.Tests +{ + public class ElasticsearchSinkTests + { + [Theory] + [InlineData("8.0.0", "my-logevent", null)] + [InlineData("7.17.5", "my-logevent", null)] + [InlineData("6.8.1", "my-logevent", "my-logevent")] + [InlineData("8.0.0", null, null)] + [InlineData("7.17.5", null, null)] + [InlineData("6.8.1", null, "logevent")] + public void Ctor_DetectElasticsearchVersionSetToTrue_SetsTypeName(string elasticVersion, string configuredTypeName, string expectedTypeName) + { + /* ARRANGE */ + var options = new ElasticsearchSinkOptions + { + Connection = FakeProductCheckResponse(elasticVersion), + TypeName = configuredTypeName + }; + + /* ACT */ + _ = ElasticsearchSinkState.Create(options); + + /* Assert */ + Assert.Equal(expectedTypeName, options.TypeName); + } + + [Theory] + [InlineData("8.0.0", "my-logevent", null)] + [InlineData("7.17.5", "my-logevent", null)] + [InlineData("6.8.1", "my-logevent", null)] + [InlineData("8.0.0", null, null)] + [InlineData("7.17.5", null, null)] + [InlineData("6.8.1", null, null)] + public void Ctor_DetectElasticsearchVersionSetToFalseAssumesVersion7_SetsTypeNameToNull(string elasticVersion, string configuredTypeName, string expectedTypeName) + { + /* ARRANGE */ + var options = new ElasticsearchSinkOptions + { + Connection = FakeProductCheckResponse(elasticVersion), + DetectElasticsearchVersion = false, + TypeName = configuredTypeName + }; + + /* ACT */ + _ = ElasticsearchSinkState.Create(options); + + /* Assert */ + Assert.Equal(expectedTypeName, options.TypeName); + } + + [Theory] + [InlineData("8.0.0", "my-logevent", null)] + [InlineData("7.17.5", "my-logevent", null)] + [InlineData("6.8.1", "my-logevent", "my-logevent")] + [InlineData("8.0.0", null, null)] + [InlineData("7.17.5", null, null)] + [InlineData("6.8.1", null, "logevent")] + public void CreateLogger_DetectElasticsearchVersionSetToTrue_SetsTypeName(string elasticVersion, string configuredTypeName, string expectedTypeName) + { + /* ARRANGE */ + var options = new ElasticsearchSinkOptions + { + Connection = FakeProductCheckResponse(elasticVersion), + DetectElasticsearchVersion = true, + TypeName = configuredTypeName + }; + + var loggerConfig = new LoggerConfiguration() + .MinimumLevel.Debug() + .Enrich.WithMachineName() + .WriteTo.Console() + .WriteTo.Elasticsearch(options); + + /* ACT */ + _ = loggerConfig.CreateLogger(); + + /* Assert */ + Assert.Equal(expectedTypeName, options.TypeName); + } + + private static IConnection FakeProductCheckResponse(string responseText) + { + var productCheckResponse = ConnectionStub.ModifiedProductCheckResponse(responseText); + return new InMemoryConnection(productCheckResponse); + } + } +} diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/ElasticsearchSinkTestsBase.cs b/test/Serilog.Sinks.Elasticsearch.Tests/ElasticsearchSinkTestsBase.cs deleted file mode 100644 index 6fe5c84d..00000000 --- a/test/Serilog.Sinks.Elasticsearch.Tests/ElasticsearchSinkTestsBase.cs +++ /dev/null @@ -1,196 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Elasticsearch.Net; -using FluentAssertions; -using Nest; -using Xunit; -using Serilog.Debugging; -using Serilog.Sinks.Elasticsearch.Tests.Domain; -using Nest.JsonNetSerializer; -using System.Collections; -using System.Threading; - -namespace Serilog.Sinks.Elasticsearch.Tests -{ - public abstract class ElasticsearchSinkTestsBase - { - static readonly TimeSpan TinyWait = TimeSpan.FromMilliseconds(50); - protected readonly IConnection _connection; - protected readonly ElasticsearchSinkOptions _options; - protected List _seenHttpPosts = new List(); - protected List _seenHttpHeads = new List(); - protected List> _seenHttpGets = new List>(); - protected List> _seenHttpPuts = new List>(); - private IElasticsearchSerializer _serializer; - - protected int _templateExistsReturnCode = 404; - - protected ElasticsearchSinkTestsBase() - { - _seenHttpPosts = new List(); - _seenHttpHeads = new List(); - _seenHttpGets = new List>(); - _seenHttpPuts = new List>(); - - var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200")); - _connection = new ConnectionStub(_seenHttpPosts, _seenHttpHeads, _seenHttpPuts, _seenHttpGets, () => _templateExistsReturnCode); - _serializer = JsonNetSerializer.Default(LowLevelRequestResponseSerializer.Instance, new ConnectionSettings(connectionPool, _connection)); - - _options = new ElasticsearchSinkOptions(connectionPool) - { - BatchPostingLimit = 2, - //Period = TinyWait, - Connection = _connection, - Serializer = _serializer, - PipelineName = "testPipe", - }; - } - - /// - /// Returns the posted serilog messages and validates the entire bulk in the process - /// - /// - /// - protected IList GetPostedLogEvents(int expectedCount) - { - this._seenHttpPosts.Should().NotBeNullOrEmpty(); - var totalBulks = this._seenHttpPosts.SelectMany(p => p.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries)).ToList(); - totalBulks.Should().NotBeNullOrEmpty().And.HaveCount(expectedCount * 2); - - var bulkActions = new List(); - for (var i = 0; i < totalBulks.Count; i += 2) - { - BulkOperation action; - try - { - action = this.Deserialize(totalBulks[i]); - } - catch (Exception e) - { - throw new Exception($"Can not deserialize into BulkOperation \r\n:{totalBulks[i]}", e); - } - action.IndexAction.Should().NotBeNull(); - action.IndexAction.Index.Should().NotBeNullOrEmpty().And.StartWith("logstash-"); - action.IndexAction.Type.Should().NotBeNullOrEmpty().And.Be("_doc"); - - SerilogElasticsearchEvent actionMetaData; - try - { - actionMetaData = this.Deserialize(totalBulks[i + 1]); - } - catch (Exception e) - { - throw new Exception( - $"Can not deserialize into SerilogElasticsearchMessage \r\n:{totalBulks[i + 1]}", e); - } - actionMetaData.Should().NotBeNull(); - bulkActions.Add(actionMetaData); - } - return bulkActions; - } - - protected T Deserialize(string json) - { - return this._serializer.Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(json))); - } - - protected async Task ThrowAsync() - { - await Task.Delay(1); - throw new Exception("boom!"); - } - - protected string[] AssertSeenHttpPosts(List _seenHttpPosts, int lastN, int expectedNumberOfRequests = 2) - { - _seenHttpPosts.Should().NotBeEmpty().And.HaveCount(expectedNumberOfRequests); - var json = string.Join("", _seenHttpPosts); - var bulkJsonPieces = json.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); - - bulkJsonPieces.Count().Should().BeGreaterOrEqualTo(lastN); - var skip = Math.Max(0, bulkJsonPieces.Count() - lastN); - - return bulkJsonPieces.Skip(skip).Take(lastN).ToArray(); - } - - - public class ConnectionStub : InMemoryConnection - { - private Func _templateExistReturnCode; - private List _seenHttpHeads; - private List> _seenHttpGets; - private List _seenHttpPosts; - private List> _seenHttpPuts; - - public ConnectionStub( - List _seenHttpPosts, - List _seenHttpHeads, - List> _seenHttpPuts, - List> _seenHttpGets, - Func templateExistReturnCode - ) - { - this._seenHttpPosts = _seenHttpPosts; - this._seenHttpHeads = _seenHttpHeads; - this._seenHttpPuts = _seenHttpPuts; - this._seenHttpGets = _seenHttpGets; - this._templateExistReturnCode = templateExistReturnCode; - } - - public override TReturn Request(RequestData requestData) - { - var ms = new MemoryStream(); - if (requestData.PostData != null) - requestData.PostData.Write(ms, new ConnectionConfiguration()); - - switch (requestData.Method) - { - case HttpMethod.PUT: - _seenHttpPuts.Add(Tuple.Create(requestData.Uri, Encoding.UTF8.GetString(ms.ToArray()))); - break; - case HttpMethod.POST: - _seenHttpPosts.Add(Encoding.UTF8.GetString(ms.ToArray())); - break; - case HttpMethod.GET: - _seenHttpGets.Add(Tuple.Create(requestData.Uri, this._templateExistReturnCode())); - break; - case HttpMethod.HEAD: - _seenHttpHeads.Add(this._templateExistReturnCode()); - break; - } - - var responseStream = new MemoryStream(); - return ResponseBuilder.ToResponse(requestData, null, this._templateExistReturnCode(), Enumerable.Empty(), responseStream); - } - - public override async Task RequestAsync(RequestData requestData, CancellationToken cancellationToken) - { - var ms = new MemoryStream(); - if (requestData.PostData != null) - await requestData.PostData.WriteAsync(ms, new ConnectionConfiguration(), cancellationToken); - - switch (requestData.Method) - { - case HttpMethod.PUT: - _seenHttpPuts.Add(Tuple.Create(requestData.Uri, Encoding.UTF8.GetString(ms.ToArray()))); - break; - case HttpMethod.POST: - _seenHttpPosts.Add(Encoding.UTF8.GetString(ms.ToArray())); - break; - case HttpMethod.GET: - _seenHttpGets.Add(Tuple.Create(requestData.Uri, this._templateExistReturnCode())); - break; - case HttpMethod.HEAD: - _seenHttpHeads.Add(this._templateExistReturnCode()); - break; - } - - var responseStream = new MemoryStream(); - return await ResponseBuilder.ToResponseAsync(requestData, null, this._templateExistReturnCode(), Enumerable.Empty(), responseStream, null, cancellationToken); - } - } - } -} \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/ExceptionAsJsonObjectFormatterTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/ExceptionAsJsonObjectFormatterTests.cs index aa1b76f7..92a2322f 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/ExceptionAsJsonObjectFormatterTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/ExceptionAsJsonObjectFormatterTests.cs @@ -9,6 +9,7 @@ using Serilog.Formatting.Elasticsearch; using Serilog.Parsing; using Serilog.Sinks.Elasticsearch.Tests.Domain; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; namespace Serilog.Sinks.Elasticsearch.Tests { @@ -51,7 +52,7 @@ public void WhenLogging_WithException_ExceptionShouldBeRenderedInExceptionField( var exceptionInfo = eventWritten.Exception; exceptionInfo.Should().NotBeNull(); exceptionInfo.Message.Should().Be(expectedExceptionMessage); -#if !DOTNETCORE +#if NETFRAMEWORK exceptionInfo.ClassName.Should().Be("System.Exception"); #endif } diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/FileSetTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/FileSetTests.cs new file mode 100644 index 00000000..609a5cea --- /dev/null +++ b/test/Serilog.Sinks.Elasticsearch.Tests/FileSetTests.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using FluentAssertions; +using Serilog.Sinks.Elasticsearch.Durable; +using Xunit; + +namespace Serilog.Sinks.Elasticsearch.Tests; + +public class FileSetTests : IDisposable +{ + private readonly string _fileNameBase; + private readonly string _tempFileFullPathTemplate; + private Dictionary _bufferFileNames; + + public FileSetTests() + { + _fileNameBase = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")); + _tempFileFullPathTemplate = _fileNameBase + "-{0}.json"; + } + + public void Dispose() + { + foreach (var bufferFileName in _bufferFileNames.Values) + { + System.IO.File.Delete(bufferFileName); + } + } + + [Theory] + [InlineData(RollingInterval.Day)] + [InlineData(RollingInterval.Hour)] + [InlineData(RollingInterval.Infinite)] + [InlineData(RollingInterval.Minute)] + [InlineData(RollingInterval.Month)] + [InlineData(RollingInterval.Year)] + // Ensures that from all presented files FileSet gets only files with specified rolling interval and not the others. + public void GetBufferFiles_ReturnsOnlySpecifiedTypeOfRollingFile(RollingInterval rollingInterval) + { + // Arrange + var format = rollingInterval.GetFormat(); + _bufferFileNames = GenerateFilesUsingFormat(format); + var fileSet = new FileSet(_fileNameBase, rollingInterval); + var bufferFileForInterval = _bufferFileNames[rollingInterval]; + + // Act + var bufferFiles = fileSet.GetBufferFiles(); + + // Assert + bufferFiles.Should().BeEquivalentTo(bufferFileForInterval); + } + + /// + /// Generates buffer files for all RollingIntervals and returns dictionary of {rollingInterval, fileName} pairs. + /// + /// + /// + private Dictionary GenerateFilesUsingFormat(string format) + { + var result = new Dictionary(); + foreach (var rollingInterval in Enum.GetValues(typeof(RollingInterval))) + { + var bufferFileName = string.Format(_tempFileFullPathTemplate, + string.IsNullOrEmpty(format) ? string.Empty : new DateTime(2000, 1, 1).ToString(format)); + var lines = new[] {rollingInterval.ToString()}; + // Important to use UTF8 with BOM if we are starting from 0 position + System.IO.File.WriteAllLines(bufferFileName, lines, new UTF8Encoding(true)); + result.Add((RollingInterval) rollingInterval, bufferFileName); + } + + return result; + } +} \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/IndexDeciderTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/IndexDeciderTests.cs index 77fbd894..18439d9d 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/IndexDeciderTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/IndexDeciderTests.cs @@ -1,13 +1,13 @@ using System; using System.Collections.Generic; -using System.Linq; using FluentAssertions; using Xunit; using Serilog.Events; using Serilog.Parsing; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; namespace Serilog.Sinks.Elasticsearch.Tests -{ +{ public class IndexDeciderTests : ElasticsearchSinkTestsBase { [Fact] diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/InlineFieldsTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/InlineFieldsTests.cs index c409ec51..c9ccb8ef 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/InlineFieldsTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/InlineFieldsTests.cs @@ -1,10 +1,10 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using FluentAssertions; using Serilog.Events; using Serilog.Parsing; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; using Xunit; namespace Serilog.Sinks.Elasticsearch.Tests diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Properties/AssemblyInfo.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Properties/AssemblyInfo.cs index 7f8e8012..a40a0fb5 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Properties/AssemblyInfo.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/PropertyNameTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/PropertyNameTests.cs index ed6d8832..cb7217ed 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/PropertyNameTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/PropertyNameTests.cs @@ -1,11 +1,11 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using FluentAssertions; using Xunit; using Serilog.Events; using Serilog.Parsing; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; namespace Serilog.Sinks.Elasticsearch.Tests { diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/RealExceptionNoSerializerTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/RealExceptionNoSerializerTests.cs index 9c69af3e..8143a293 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/RealExceptionNoSerializerTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/RealExceptionNoSerializerTests.cs @@ -1,11 +1,11 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using FluentAssertions; using Xunit; using Serilog.Events; using Serilog.Parsing; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; namespace Serilog.Sinks.Elasticsearch.Tests { diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/RealExceptionTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/RealExceptionTests.cs index 0f6caf23..1063e882 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/RealExceptionTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/RealExceptionTests.cs @@ -1,12 +1,11 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using FluentAssertions; -using Nest; using Xunit; using Serilog.Events; using Serilog.Parsing; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; namespace Serilog.Sinks.Elasticsearch.Tests { diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Serilog.Sinks.Elasticsearch.Tests.csproj b/test/Serilog.Sinks.Elasticsearch.Tests/Serilog.Sinks.Elasticsearch.Tests.csproj index eb20c2fe..90ac70cd 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Serilog.Sinks.Elasticsearch.Tests.csproj +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Serilog.Sinks.Elasticsearch.Tests.csproj @@ -1,13 +1,14 @@  - netcoreapp2.1;net461 + net6.0;net7.0 Serilog.Sinks.Elasticsearch.Tests Serilog.Sinks.Elasticsearch.Tests True latest True + false true false @@ -21,27 +22,32 @@ false false false + true + ..\..\assets\Serilog.snk + true - - - - - + + + + + + + Serilog.snk + - - - + + + + + - - - @@ -50,39 +56,55 @@ - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + true + + $([MSBuild]::EnsureTrailingSlash($([System.IO.Path]::GetFullPath($([System.IO.Path]::Combine($(MSBuildProjectDirectory),'..','coverage')))))) + + cobertura + - - - + + + $([MSBuild]::EnsureTrailingSlash('$(CoverletOutput)report')) + xdg-open + open + explorer + + + + + - - $(DefineConstants);DOTNETCORE;PARTIALLY_SERIALIZATION - + + + diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Stubs/ConnectionStub.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Stubs/ConnectionStub.cs new file mode 100644 index 00000000..fdc0fadf --- /dev/null +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Stubs/ConnectionStub.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Threading.Tasks; +using Elasticsearch.Net; +using System.Threading; + +namespace Serilog.Sinks.Elasticsearch.Tests.Stubs +{ + internal class ConnectionStub : InMemoryConnection + { + private readonly Func _templateExistReturnCode; + private readonly List _seenHttpHeads; + private readonly List> _seenHttpGets; + private readonly List _seenHttpPosts; + private readonly List> _seenHttpPuts; + + private readonly string _productVersion; + + /// + /// Elasticsearch.NET client version 7.16 or higher + /// uses pre-flight request, before any other request is served, + /// to check product (Elasticsearch) and version of the product. + /// It can be seen on property. + /// + private bool _productCheckDone; + + public ConnectionStub( + List _seenHttpPosts, + List _seenHttpHeads, + List> _seenHttpPuts, + List> _seenHttpGets, + Func templateExistReturnCode, + string productVersion = "8.6.0" + ) : base() + { + this._seenHttpPosts = _seenHttpPosts; + this._seenHttpHeads = _seenHttpHeads; + this._seenHttpPuts = _seenHttpPuts; + this._seenHttpGets = _seenHttpGets; + _templateExistReturnCode = templateExistReturnCode; + _productVersion = productVersion; + } + + public override TReturn Request(RequestData requestData) + { + if (_productCheckDone == false) + { + if (requestData.Method != HttpMethod.GET || requestData.PathAndQuery != string.Empty) + throw new InvalidOperationException( + $"{nameof(ConnectionStub)} expects first request" + + $" to be productCheck pre-flight request"); + + _productCheckDone = true; + return ReturnConnectionStatus(requestData); // hard-coded root page returned + } + + byte[] responseBytes = Array.Empty(); + if (requestData.PostData != null) + { + using var ms = new MemoryStream(); + requestData.PostData.Write(ms, new ConnectionConfiguration()); + responseBytes = ms.ToArray(); + } + + int responseStatusCode = 200; + string contentType = null; + InMemoryHttpResponse productCheckResponse = null; + + switch (requestData.Method) + { + case HttpMethod.PUT: + _seenHttpPuts.Add(Tuple.Create(requestData.Uri, Encoding.UTF8.GetString(responseBytes))); + break; + case HttpMethod.POST: + _seenHttpPosts.Add(Encoding.UTF8.GetString(responseBytes)); + break; + case HttpMethod.GET: + switch (requestData.Uri.PathAndQuery.ToLower()) + { + case "/": + productCheckResponse = ModifiedProductCheckResponse(_productVersion); + break; + case "/_cat/nodes?h=v": + responseBytes = Encoding.UTF8.GetBytes(_productVersion); + contentType = "text/plain; charset=UTF-8"; + break; + } + _seenHttpGets.Add(Tuple.Create(requestData.Uri, responseStatusCode)); + break; + case HttpMethod.HEAD: + if (requestData.Uri.PathAndQuery.ToLower().StartsWith("/_template/")) + { + responseStatusCode = _templateExistReturnCode(); + } + _seenHttpHeads.Add(responseStatusCode); + break; + } + + return ReturnConnectionStatus(requestData, productCheckResponse, responseBytes, responseStatusCode, contentType); + } + + public override Task RequestAsync(RequestData requestData, CancellationToken cancellationToken) + { + return Task.FromResult(Request(requestData)); + } + + public static InMemoryHttpResponse ModifiedProductCheckResponse(string productVersion) + { + var productCheckResponse = ValidProductCheckResponse(); + if (productVersion is not null) + { + using var originalMemoryStream = new MemoryStream(productCheckResponse.ResponseBytes, false); + { + var json = LowLevelRequestResponseSerializer.Instance.Deserialize(originalMemoryStream); + json["version"]["number"] = productVersion; + using var modifiedMemoryStream = new MemoryStream(); + LowLevelRequestResponseSerializer.Instance.Serialize(json, modifiedMemoryStream); + productCheckResponse.ResponseBytes = modifiedMemoryStream.ToArray(); + } + } + return productCheckResponse; + } + } +} \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Stubs/ElasticsearchSinkTestsBase.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Stubs/ElasticsearchSinkTestsBase.cs new file mode 100644 index 00000000..e5b0717a --- /dev/null +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Stubs/ElasticsearchSinkTestsBase.cs @@ -0,0 +1,137 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Elasticsearch.Net; +using FluentAssertions; +using Nest; +using Serilog.Sinks.Elasticsearch.Tests.Domain; +using Nest.JsonNetSerializer; +using Newtonsoft.Json.Linq; + +namespace Serilog.Sinks.Elasticsearch.Tests.Stubs +{ + public abstract partial class ElasticsearchSinkTestsBase + { + static readonly TimeSpan TinyWait = TimeSpan.FromMilliseconds(50); + protected readonly IConnection _connection; + protected readonly ElasticsearchSinkOptions _options; + protected List _seenHttpPosts = new List(); + protected List _seenHttpHeads = new List(); + protected List> _seenHttpGets = new List>(); + protected List> _seenHttpPuts = new List>(); + private IElasticsearchSerializer _serializer; + + protected int _templateExistsReturnCode = 404; + + protected ElasticsearchSinkTestsBase(string productVersion = "8.6.0") + { + _seenHttpPosts = new List(); + _seenHttpHeads = new List(); + _seenHttpGets = new List>(); + _seenHttpPuts = new List>(); + + var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200")); + _connection = new ConnectionStub(_seenHttpPosts, + _seenHttpHeads, + _seenHttpPuts, + _seenHttpGets, + () => _templateExistsReturnCode, + productVersion); + _serializer = JsonNetSerializer.Default(LowLevelRequestResponseSerializer.Instance, new ConnectionSettings(connectionPool, _connection)); + + _options = new ElasticsearchSinkOptions(connectionPool) + { + BatchPostingLimit = 2, + //Period = TinyWait, + Connection = _connection, + Serializer = _serializer, + PipelineName = "testPipe", + }; + } + + /// + /// Returns the posted serilog messages and validates the entire bulk in the process + /// + /// + /// + protected IList GetPostedLogEvents(int expectedCount) + { + _seenHttpPosts.Should().NotBeNullOrEmpty(); + var totalBulks = _seenHttpPosts.SelectMany(p => p.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries)).ToList(); + totalBulks.Should().NotBeNullOrEmpty().And.HaveCount(expectedCount * 2); + + var bulkActions = new List(); + for (var i = 0; i < totalBulks.Count; i += 2) + { + BulkOperation action; + try + { + action = Deserialize(totalBulks[i]); + } + catch (Exception e) + { + throw new Exception($"Can not deserialize into BulkOperation \r\n:{totalBulks[i]}", e); + } + action.IndexAction.Should().NotBeNull(); + action.IndexAction.Index.Should().NotBeNullOrEmpty().And.StartWith("logstash-"); + action.IndexAction.Type.Should().BeNull(); + + SerilogElasticsearchEvent actionMetaData; + try + { + actionMetaData = Deserialize(totalBulks[i + 1]); + } + catch (Exception e) + { + throw new Exception( + $"Can not deserialize into SerilogElasticsearchMessage \r\n:{totalBulks[i + 1]}", e); + } + actionMetaData.Should().NotBeNull(); + bulkActions.Add(actionMetaData); + } + return bulkActions; + } + + protected T Deserialize(string json) + { + return _serializer.Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(json))); + } + + protected async Task ThrowAsync() + { + await Task.Delay(1); + throw new Exception("boom!"); + } + + protected string[] AssertSeenHttpPosts(List _seenHttpPosts, int lastN, int expectedNumberOfRequests = 2) + { + _seenHttpPosts.Should().NotBeEmpty().And.HaveCount(expectedNumberOfRequests); + var json = string.Join("", _seenHttpPosts); + var bulkJsonPieces = json.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); + + bulkJsonPieces.Count().Should().BeGreaterOrEqualTo(lastN); + var skip = Math.Max(0, bulkJsonPieces.Count() - lastN); + + return bulkJsonPieces.Skip(skip).Take(lastN).ToArray(); + } + + protected void JsonEquals(string json, string embeddedResourceNameEndsWith) + { +#if NETFRAMEWORK + var assembly = System.Reflection.Assembly.GetExecutingAssembly(); +#else + var assembly = GetType().Assembly; +#endif + var expected = TestDataHelper.ReadEmbeddedResource(assembly, embeddedResourceNameEndsWith); + + var nJson = JObject.Parse(json); + var nOtherJson = JObject.Parse(expected); + var equals = JToken.DeepEquals(nJson, nOtherJson); + if (equals) return; + expected.Should().BeEquivalentTo(json); + } + } +} \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/DiscoverVersionHandlesUnavailableServerTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/DiscoverVersionHandlesUnavailableServerTests.cs index b80446f4..90ff885a 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/DiscoverVersionHandlesUnavailableServerTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/DiscoverVersionHandlesUnavailableServerTests.cs @@ -4,6 +4,7 @@ using FluentAssertions; using Xunit; using Serilog.Debugging; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; namespace Serilog.Sinks.Elasticsearch.Tests.Templating { diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/DiscoverVersionTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/DiscoverVersionTests.cs index 7d767744..9e4b3395 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/DiscoverVersionTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/DiscoverVersionTests.cs @@ -1,5 +1,6 @@ using System; using FluentAssertions; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; using Xunit; namespace Serilog.Sinks.Elasticsearch.Tests.Templating @@ -15,7 +16,7 @@ public DiscoverVersionTests() var loggerConfig = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.WithMachineName() - .WriteTo.ColoredConsole() + .WriteTo.Console() .WriteTo.Elasticsearch(_options); var logger = loggerConfig.CreateLogger(); @@ -33,7 +34,7 @@ public DiscoverVersionTests() public void TemplatePutToCorrectUrl() { var uri = _templateGet.Item1; - uri.AbsolutePath.Should().Be("/_cat/nodes"); + uri.AbsolutePath.Should().Be("/"); } } } \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/DoNotRegisterTemplateIfItExists.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/DoNotRegisterTemplateIfItExists.cs index 96300ab6..4cef9730 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/DoNotRegisterTemplateIfItExists.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/DoNotRegisterTemplateIfItExists.cs @@ -1,5 +1,6 @@ using System; using FluentAssertions; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; using Xunit; namespace Serilog.Sinks.Elasticsearch.Tests.Templating @@ -14,7 +15,7 @@ private void DoRegister() var loggerConfig = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.WithMachineName() - .WriteTo.ColoredConsole() + .WriteTo.Console() .WriteTo.Elasticsearch(_options); var logger = loggerConfig.CreateLogger(); diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/OverwriteTemplateTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/OverwriteTemplateTests.cs index a37936f6..aa63d1a5 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/OverwriteTemplateTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/OverwriteTemplateTests.cs @@ -1,16 +1,13 @@ using System; -using System.IO; -using System.Reflection; using FluentAssertions; -using Newtonsoft.Json.Linq; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; using Xunit; namespace Serilog.Sinks.Elasticsearch.Tests.Templating { public class OverwriteTemplateTests : ElasticsearchSinkTestsBase { - - public void DoRegister() + private void DoRegister() { _templateExistsReturnCode = 200; @@ -19,7 +16,7 @@ public void DoRegister() var loggerConfig = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.WithMachineName() - .WriteTo.ColoredConsole() + .WriteTo.Console() .WriteTo.Elasticsearch(_options); var logger = loggerConfig.CreateLogger(); diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/RegisterCustomTemplateTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/RegisterCustomTemplateTests.cs index 40e59d3e..3379f113 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/RegisterCustomTemplateTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/RegisterCustomTemplateTests.cs @@ -1,8 +1,6 @@ using System; -using System.IO; -using System.Reflection; using FluentAssertions; -using Newtonsoft.Json.Linq; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; using Xunit; namespace Serilog.Sinks.Elasticsearch.Tests.Templating @@ -19,7 +17,7 @@ public RegisterCustomTemplateTests() var loggerConfig = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.WithMachineName() - .WriteTo.ColoredConsole() + .WriteTo.Console() .WriteTo.Elasticsearch(_options); var logger = loggerConfig.CreateLogger(); diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SendsTemplateHandlesUnavailableServerTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SendsTemplateHandlesUnavailableServerTests.cs index 2f1b0a51..cf85bea1 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SendsTemplateHandlesUnavailableServerTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SendsTemplateHandlesUnavailableServerTests.cs @@ -4,6 +4,7 @@ using FluentAssertions; using Xunit; using Serilog.Debugging; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; namespace Serilog.Sinks.Elasticsearch.Tests.Templating { diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SendsTemplateTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SendsTemplateTests.cs index 161d0bac..9e86c119 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SendsTemplateTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SendsTemplateTests.cs @@ -1,7 +1,6 @@ using System; -using System.Reflection; using FluentAssertions; -using Newtonsoft.Json.Linq; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; using Xunit; namespace Serilog.Sinks.Elasticsearch.Tests.Templating @@ -12,12 +11,13 @@ public class SendsTemplateTests : ElasticsearchSinkTestsBase public SendsTemplateTests() { + _options.DetectElasticsearchVersion = false; _options.AutoRegisterTemplate = true; var loggerConfig = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.WithMachineName() - .WriteTo.ColoredConsole() + .WriteTo.Console() .WriteTo.Elasticsearch(_options); var logger = loggerConfig.CreateLogger(); @@ -32,10 +32,9 @@ public SendsTemplateTests() } [Fact] - public void ShouldRegisterTheCorrectTemplateOnRegistration() + public void ShouldRegisterTheVersion7TemplateOnRegistrationWhenDetectElasticsearchVersionFalse() { - var method = typeof(SendsTemplateTests).GetMethod(nameof(ShouldRegisterTheCorrectTemplateOnRegistration)); - JsonEquals(_templatePut.Item2, method, "template"); + JsonEquals(_templatePut.Item2, "template_v7_no-aliases.json"); } [Fact] @@ -44,21 +43,5 @@ public void TemplatePutToCorrectUrl() var uri = _templatePut.Item1; uri.AbsolutePath.Should().Be("/_template/serilog-events-template"); } - - protected void JsonEquals(string json, MethodBase method, string fileName = null) - { -#if DOTNETCORE - var assembly = typeof(SendsTemplateTests).GetTypeInfo().Assembly; -#else - var assembly = Assembly.GetExecutingAssembly(); -#endif - var expected = TestDataHelper.ReadEmbeddedResource(assembly, "template.json"); - - var nJson = JObject.Parse(json); - var nOtherJson = JObject.Parse(expected); - var equals = JToken.DeepEquals(nJson, nOtherJson); - if (equals) return; - expected.Should().BeEquivalentTo(json); - } } } \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv5TemplateTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv5TemplateTests.cs deleted file mode 100644 index 625dcc9d..00000000 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv5TemplateTests.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Reflection; -using FluentAssertions; -using Newtonsoft.Json.Linq; -using Xunit; - -namespace Serilog.Sinks.Elasticsearch.Tests.Templating -{ - public class Sendsv5TemplateTests : ElasticsearchSinkTestsBase - { - private readonly Tuple _templatePut; - - public Sendsv5TemplateTests() - { - _options.AutoRegisterTemplate = true; - _options.AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv5; - - var loggerConfig = new LoggerConfiguration() - .MinimumLevel.Debug() - .Enrich.WithMachineName() - .WriteTo.ColoredConsole() - .WriteTo.Elasticsearch(_options); - - var logger = loggerConfig.CreateLogger(); - using (logger as IDisposable) - { - logger.Error("Test exception. Should not contain an embedded exception object."); - } - - this._seenHttpPosts.Should().NotBeNullOrEmpty().And.HaveCount(1); - this._seenHttpPuts.Should().NotBeNullOrEmpty().And.HaveCount(1); - _templatePut = this._seenHttpPuts[0]; - } - - [Fact] - public void ShouldRegisterTheCorrectTemplateOnRegistration() - { - - var method = typeof(Sendsv5TemplateTests).GetMethod(nameof(ShouldRegisterTheCorrectTemplateOnRegistration)); - JsonEquals(_templatePut.Item2, method, "template_v5.json"); - } - - [Fact] - public void TemplatePutToCorrectUrl() - { - var uri = _templatePut.Item1; - uri.AbsolutePath.Should().Be("/_template/serilog-events-template"); - } - - protected void JsonEquals(string json, MethodBase method, string fileName = null) - { -#if DOTNETCORE - var assembly = typeof(Sendsv5TemplateTests).GetTypeInfo().Assembly; -#else - var assembly = Assembly.GetExecutingAssembly(); -#endif - var expected = TestDataHelper.ReadEmbeddedResource(assembly, fileName ?? "template.json"); - - var nJson = JObject.Parse(json); - var nOtherJson = JObject.Parse(expected); - var equals = JToken.DeepEquals(nJson, nOtherJson); - if (equals) return; - expected.Should().BeEquivalentTo(json); - } - } -} \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv6TemplateTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv6TemplateTests.cs index 8764aae2..fc3018ac 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv6TemplateTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv6TemplateTests.cs @@ -1,7 +1,6 @@ using System; -using System.Reflection; using FluentAssertions; -using Newtonsoft.Json.Linq; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; using Xunit; namespace Serilog.Sinks.Elasticsearch.Tests.Templating @@ -11,6 +10,7 @@ public class Sendsv6TemplateTests : ElasticsearchSinkTestsBase private readonly Tuple _templatePut; public Sendsv6TemplateTests() + : base("6.0.0") { _options.AutoRegisterTemplate = true; _options.AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6; @@ -18,7 +18,7 @@ public Sendsv6TemplateTests() var loggerConfig = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.WithMachineName() - .WriteTo.ColoredConsole() + .WriteTo.Console() .WriteTo.Elasticsearch(_options); var logger = loggerConfig.CreateLogger(); @@ -33,11 +33,9 @@ public Sendsv6TemplateTests() } [Fact] - public void ShouldRegisterTheCorrectTemplateOnRegistration() + public void ShouldRegisterTheVersion6TemplateOnRegistrationWhenDetectedElasticsearchVersionIsV6() { - - var method = typeof(Sendsv6TemplateTests).GetMethod(nameof(ShouldRegisterTheCorrectTemplateOnRegistration)); - JsonEquals(_templatePut.Item2, method, "template_v6.json"); + JsonEquals(_templatePut.Item2, "template_v6.json"); } [Fact] @@ -46,21 +44,5 @@ public void TemplatePutToCorrectUrl() var uri = _templatePut.Item1; uri.AbsolutePath.Should().Be("/_template/serilog-events-template"); } - - protected void JsonEquals(string json, MethodBase method, string fileName = null) - { -#if DOTNETCORE - var assembly = typeof(Sendsv6TemplateTests).GetTypeInfo().Assembly; -#else - var assembly = Assembly.GetExecutingAssembly(); -#endif - var expected = TestDataHelper.ReadEmbeddedResource(assembly, fileName ?? "template.json"); - - var nJson = JObject.Parse(json); - var nOtherJson = JObject.Parse(expected); - var equals = JToken.DeepEquals(nJson, nOtherJson); - if (equals) return; - expected.Should().BeEquivalentTo(json); - } } } \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv7TemplateTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv7TemplateTests.cs index 9413d1ed..e8d695f6 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv7TemplateTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv7TemplateTests.cs @@ -1,7 +1,6 @@ using System; -using System.Reflection; using FluentAssertions; -using Newtonsoft.Json.Linq; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; using Xunit; namespace Serilog.Sinks.Elasticsearch.Tests.Templating @@ -11,6 +10,7 @@ public class Sendsv7TemplateTests : ElasticsearchSinkTestsBase private readonly Tuple _templatePut; public Sendsv7TemplateTests() + : base("7.0.0") { _options.AutoRegisterTemplate = true; _options.AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7; @@ -19,7 +19,7 @@ public Sendsv7TemplateTests() var loggerConfig = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.WithMachineName() - .WriteTo.ColoredConsole() + .WriteTo.Console() .WriteTo.Elasticsearch(_options); var logger = loggerConfig.CreateLogger(); @@ -34,11 +34,9 @@ public Sendsv7TemplateTests() } [Fact] - public void ShouldRegisterTheCorrectTemplateOnRegistration() + public void ShouldRegisterTheVersion7TemplateOnRegistrationWhenDetectedElasticsearchVersionIsV7() { - - var method = typeof(Sendsv7TemplateTests).GetMethod(nameof(ShouldRegisterTheCorrectTemplateOnRegistration)); - JsonEquals(_templatePut.Item2, method, "template_v7.json"); + JsonEquals(_templatePut.Item2, "template_v7.json"); } [Fact] @@ -47,21 +45,5 @@ public void TemplatePutToCorrectUrl() var uri = _templatePut.Item1; uri.AbsolutePath.Should().Be("/_template/serilog-events-template"); } - - protected void JsonEquals(string json, MethodBase method, string fileName = null) - { -#if DOTNETCORE - var assembly = typeof(Sendsv7TemplateTests).GetTypeInfo().Assembly; -#else - var assembly = Assembly.GetExecutingAssembly(); -#endif - var expected = TestDataHelper.ReadEmbeddedResource(assembly, fileName ?? "template.json"); - - var nJson = JObject.Parse(json); - var nOtherJson = JObject.Parse(expected); - var equals = JToken.DeepEquals(nJson, nOtherJson); - if (equals) return; - expected.Should().BeEquivalentTo(json); - } } } \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv8TemplateTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv8TemplateTests.cs new file mode 100644 index 00000000..22de419f --- /dev/null +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/Sendsv8TemplateTests.cs @@ -0,0 +1,48 @@ +using System; +using FluentAssertions; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; +using Xunit; + +namespace Serilog.Sinks.Elasticsearch.Tests.Templating +{ + public class Sendsv8TemplateTests : ElasticsearchSinkTestsBase + { + private readonly Tuple _templatePut; + + public Sendsv8TemplateTests() + { + _options.AutoRegisterTemplate = true; + _options.AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv8; + _options.IndexAliases = new string[] { "logstash" }; + + var loggerConfig = new LoggerConfiguration() + .MinimumLevel.Debug() + .Enrich.WithMachineName() + .WriteTo.Console() + .WriteTo.Elasticsearch(_options); + + var logger = loggerConfig.CreateLogger(); + using (logger as IDisposable) + { + logger.Error("Test exception. Should not contain an embedded exception object."); + } + + this._seenHttpPosts.Should().NotBeNullOrEmpty().And.HaveCount(1); + this._seenHttpPuts.Should().NotBeNullOrEmpty().And.HaveCount(1); + _templatePut = this._seenHttpPuts[0]; + } + + [Fact] + public void ShouldRegisterTheVersion6TemplateOnRegistrationWhenDetectedElasticsearchVersionIsV8() + { + JsonEquals(_templatePut.Item2, "template_v8.json"); + } + + [Fact] + public void TemplatePutToCorrectUrl() + { + var uri = _templatePut.Item1; + uri.AbsolutePath.Should().Be("/_index_template/serilog-events-template"); + } + } +} \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SetElasticsearchSinkOptions.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SetElasticsearchSinkOptions.cs index ba4e24da..f48f5638 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SetElasticsearchSinkOptions.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SetElasticsearchSinkOptions.cs @@ -1,5 +1,6 @@ using System; using FluentAssertions; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; using Xunit; namespace Serilog.Sinks.Elasticsearch.Tests.Templating diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SetFiveReplicasInTemplateTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SetFiveReplicasInTemplateTests.cs index 602e3377..29654081 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SetFiveReplicasInTemplateTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SetFiveReplicasInTemplateTests.cs @@ -1,7 +1,6 @@ using System; -using System.Reflection; using FluentAssertions; -using Newtonsoft.Json.Linq; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; using Xunit; namespace Serilog.Sinks.Elasticsearch.Tests.Templating @@ -18,7 +17,7 @@ public SetFiveReplicasInTemplateTests() var loggerConfig = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.WithMachineName() - .WriteTo.ColoredConsole() + .WriteTo.Console() .WriteTo.Elasticsearch(_options); var logger = loggerConfig.CreateLogger(); @@ -35,31 +34,14 @@ public SetFiveReplicasInTemplateTests() [Fact] public void ShouldRegisterTheCorrectTemplateOnRegistration() { - var method = typeof(SendsTemplateTests).GetMethod(nameof(ShouldRegisterTheCorrectTemplateOnRegistration)); - JsonEquals(_templatePut.Item2, method, "template"); + JsonEquals(_templatePut.Item2, "template_v8_no-aliases_5replicas.json"); } [Fact] public void TemplatePutToCorrectUrl() { var uri = _templatePut.Item1; - uri.AbsolutePath.Should().Be("/_template/serilog-events-template"); - } - - protected void JsonEquals(string json, MethodBase method, string fileName = null) - { -#if DOTNETCORE - var assembly = typeof(SendsTemplateTests).GetTypeInfo().Assembly; -#else - var assembly = Assembly.GetExecutingAssembly(); -#endif - var expected = TestDataHelper.ReadEmbeddedResource(assembly, "template_5replicas.json"); - - var nJson = JObject.Parse(json); - var nOtherJson = JObject.Parse(expected); - var equals = JToken.DeepEquals(nJson, nOtherJson); - if (equals) return; - expected.Should().BeEquivalentTo(json); + uri.AbsolutePath.Should().Be("/_index_template/serilog-events-template"); } } } \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SetTwoShardsInTemplateTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SetTwoShardsInTemplateTests.cs index 4a06c4d6..0543365c 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SetTwoShardsInTemplateTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SetTwoShardsInTemplateTests.cs @@ -1,7 +1,6 @@ using System; -using System.Reflection; using FluentAssertions; -using Newtonsoft.Json.Linq; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; using Xunit; namespace Serilog.Sinks.Elasticsearch.Tests.Templating @@ -19,7 +18,7 @@ public SetTwoShardsInTemplateTests() var loggerConfig = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.WithMachineName() - .WriteTo.ColoredConsole() + .WriteTo.Console() .WriteTo.Elasticsearch(_options); var logger = loggerConfig.CreateLogger(); @@ -36,31 +35,14 @@ public SetTwoShardsInTemplateTests() [Fact] public void ShouldRegisterTheCorrectTemplateOnRegistration() { - var method = typeof(SendsTemplateTests).GetMethod(nameof(ShouldRegisterTheCorrectTemplateOnRegistration)); - JsonEquals(_templatePut.Item2, method, "template"); + JsonEquals(_templatePut.Item2, "template_v8_no-aliases_2shards.json"); } [Fact] public void TemplatePutToCorrectUrl() { var uri = _templatePut.Item1; - uri.AbsolutePath.Should().Be("/_template/serilog-events-template"); - } - - protected void JsonEquals(string json, MethodBase method, string fileName = null) - { -#if DOTNETCORE - var assembly = typeof(SendsTemplateTests).GetTypeInfo().Assembly; -#else - var assembly = Assembly.GetExecutingAssembly(); -#endif - var expected = TestDataHelper.ReadEmbeddedResource(assembly, "template_2shards.json"); - - var nJson = JObject.Parse(json); - var nOtherJson = JObject.Parse(expected); - var equals = JToken.DeepEquals(nJson, nOtherJson); - if (equals) return; - expected.Should().BeEquivalentTo(json); + uri.AbsolutePath.Should().Be("/_index_template/serilog-events-template"); } } } \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SetZeroReplicasInTemplateTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SetZeroReplicasInTemplateTests.cs index 47c87812..60b7451c 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SetZeroReplicasInTemplateTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/SetZeroReplicasInTemplateTests.cs @@ -1,7 +1,6 @@ using System; -using System.Reflection; using FluentAssertions; -using Newtonsoft.Json.Linq; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; using Xunit; namespace Serilog.Sinks.Elasticsearch.Tests.Templating @@ -18,7 +17,7 @@ public SetZeroReplicasInTemplateTests() var loggerConfig = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.WithMachineName() - .WriteTo.ColoredConsole() + .WriteTo.Console() .WriteTo.Elasticsearch(_options); var logger = loggerConfig.CreateLogger(); @@ -35,31 +34,14 @@ public SetZeroReplicasInTemplateTests() [Fact] public void ShouldRegisterTheCorrectTemplateOnRegistration() { - var method = typeof(SendsTemplateTests).GetMethod(nameof(ShouldRegisterTheCorrectTemplateOnRegistration)); - JsonEquals(_templatePut.Item2, method, "template"); + JsonEquals(_templatePut.Item2, "template_v8_no-aliases_0replicas.json"); } [Fact] public void TemplatePutToCorrectUrl() { var uri = _templatePut.Item1; - uri.AbsolutePath.Should().Be("/_template/serilog-events-template"); - } - - protected void JsonEquals(string json, MethodBase method, string fileName = null) - { -#if DOTNETCORE - var assembly = typeof(SendsTemplateTests).GetTypeInfo().Assembly; -#else - var assembly = Assembly.GetExecutingAssembly(); -#endif - var expected = TestDataHelper.ReadEmbeddedResource(assembly, "template_0replicas.json"); - - var nJson = JObject.Parse(json); - var nOtherJson = JObject.Parse(expected); - var equals = JToken.DeepEquals(nJson, nOtherJson); - if (equals) return; - expected.Should().BeEquivalentTo(json); + uri.AbsolutePath.Should().Be("/_index_template/serilog-events-template"); } } } \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/TemplateMatchTests.cs b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/TemplateMatchTests.cs index 16b549a2..2fe1fcc6 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/TemplateMatchTests.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/TemplateMatchTests.cs @@ -1,8 +1,6 @@ using System; -using System.IO; -using System.Reflection; using FluentAssertions; -using Newtonsoft.Json.Linq; +using Serilog.Sinks.Elasticsearch.Tests.Stubs; using Xunit; namespace Serilog.Sinks.Elasticsearch.Tests.Templating @@ -12,6 +10,7 @@ public class TemplateMatchTests : ElasticsearchSinkTestsBase private readonly Tuple _templatePut; public TemplateMatchTests() + : base("7.0.0") { _options.AutoRegisterTemplate = true; _options.IndexFormat = "dailyindex-{0:yyyy.MM.dd}-mycompany"; @@ -19,7 +18,7 @@ public TemplateMatchTests() var loggerConfig = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.WithMachineName() - .WriteTo.ColoredConsole() + .WriteTo.Console() .WriteTo.Elasticsearch(_options); var logger = loggerConfig.CreateLogger(); @@ -46,7 +45,7 @@ public void TemplatePutToCorrectUrl() public void TemplateMatchShouldReflectConfiguredIndexFormat() { var json = this._templatePut.Item2; - json.Should().Contain(@"""template"":""dailyindex-*-mycompany"""); + json.Should().Contain(@"""index_patterns"":[""dailyindex-*-mycompany""]"); } } diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_2shards.json b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_2shards.json deleted file mode 100644 index 82a097f1..00000000 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_2shards.json +++ /dev/null @@ -1,83 +0,0 @@ -{ - "template": "logstash-*", - "settings": { - "index.refresh_interval": "5s", - "number_of_shards": "2", - "number_of_replicas": "0" - }, - "mappings": { - "_default_": { - "_all": { - "enabled": true, - "omit_norms" : true - }, - "dynamic_templates": [ - { - "numerics_in_fields": { - "path_match":"fields\\.[\\d+]$", - "match_pattern":"regex", - "mapping": { - "type":"string", - "index":"analyzed", - "omit_norms":true - } - } - }, - { - "string_fields": { - "match": "*", - "match_mapping_type": "string", - "mapping": { - "type": "string", - "index": "analyzed", - "omit_norms": true, - "fields": { - "raw": { - "type": "string", - "index": "not_analyzed", - "ignore_above": 256 - } - } - } - } - } - ], - "properties": { - "message": { - "type": "string", - "index": "analyzed" - }, - "exceptions": { - "type": "nested", - "properties": { - "Depth": { - "type": "integer" - }, - "RemoteStackIndex": { - "type": "integer" - }, - "HResult": { - "type": "integer" - }, - "StackTraceString": { - "type": "string", - "index": "analyzed" - }, - "RemoteStackTraceString": { - "type": "string", - "index": "analyzed" - }, - "ExceptionMessage": { - "type": "object", - "properties": { - "MemberType": { - "type": "integer" - } - } - } - } - } - } - } - } -} \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_5replicas.json b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_5replicas.json deleted file mode 100644 index 50c4035f..00000000 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_5replicas.json +++ /dev/null @@ -1,82 +0,0 @@ -{ - "template": "logstash-*", - "settings": { - "index.refresh_interval": "5s", - "number_of_replicas": "5" - }, - "mappings": { - "_default_": { - "_all": { - "enabled": true, - "omit_norms" : true - }, - "dynamic_templates": [ - { - "numerics_in_fields": { - "path_match":"fields\\.[\\d+]$", - "match_pattern":"regex", - "mapping": { - "type":"string", - "index":"analyzed", - "omit_norms":true - } - } - }, - { - "string_fields": { - "match": "*", - "match_mapping_type": "string", - "mapping": { - "type": "string", - "index": "analyzed", - "omit_norms": true, - "fields": { - "raw": { - "type": "string", - "index": "not_analyzed", - "ignore_above": 256 - } - } - } - } - } - ], - "properties": { - "message": { - "type": "string", - "index": "analyzed" - }, - "exceptions": { - "type": "nested", - "properties": { - "Depth": { - "type": "integer" - }, - "RemoteStackIndex": { - "type": "integer" - }, - "HResult": { - "type": "integer" - }, - "StackTraceString": { - "type": "string", - "index": "analyzed" - }, - "RemoteStackTraceString": { - "type": "string", - "index": "analyzed" - }, - "ExceptionMessage": { - "type": "object", - "properties": { - "MemberType": { - "type": "integer" - } - } - } - } - } - } - } - } -} \ No newline at end of file diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v7_no-aliases.json b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v7_no-aliases.json new file mode 100644 index 00000000..07bbb617 --- /dev/null +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v7_no-aliases.json @@ -0,0 +1,77 @@ +{ + "index_patterns": [ "logstash-*" ], + "settings": { + "index.refresh_interval": "5s" + }, + "mappings": { + "dynamic_templates": [ + { + "numerics_in_fields": { + "path_match": "fields\\.[\\d+]$", + "match_pattern": "regex", + "mapping": { + "type": "text", + "index": true, + "norms": false + } + } + }, + { + "string_fields": { + "match": "*", + "match_mapping_type": "string", + "mapping": { + "type": "text", + "index": true, + "norms": false, + "fields": { + "raw": { + "type": "keyword", + "index": true, + "ignore_above": 256 + } + } + } + } + } + ], + "properties": { + "message": { + "type": "text", + "index": true + }, + "exceptions": { + "type": "nested", + "properties": { + "Depth": { + "type": "integer" + }, + "RemoteStackIndex": { + "type": "integer" + }, + "HResult": { + "type": "integer" + }, + "StackTraceString": { + "type": "text", + "index": true + }, + "RemoteStackTraceString": { + "type": "text", + "index": true + }, + "ExceptionMessage": { + "type": "object", + "properties": { + "MemberType": { + "type": "integer" + } + } + } + } + } + } + }, + "aliases": { + } +} diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v5.json b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v8.json similarity index 73% rename from test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v5.json rename to test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v8.json index cee50c8e..af3f5b3e 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v5.json +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v8.json @@ -1,25 +1,21 @@ { - "template": "logstash-*", - "settings": { - "index.refresh_interval": "5s" - }, - "mappings": { - "_default_": { - "_all": { - "enabled": true, - "norms" : false - }, + "index_patterns": [ "logstash-*" ], + "template": { + "settings": { + "index.refresh_interval": "5s" + }, + "mappings": { "dynamic_templates": [ { - "numerics_in_fields": { - "path_match":"fields\\.[\\d+]$", - "match_pattern":"regex", - "mapping": { - "type":"text", - "index":true, - "norms":false - } - } + "numerics_in_fields": { + "path_match": "fields\\.[\\d+]$", + "match_pattern": "regex", + "mapping": { + "type": "text", + "index": true, + "norms": false + } + } }, { "string_fields": { @@ -43,7 +39,7 @@ "properties": { "message": { "type": "text", - "index": "analyzed" + "index": true }, "exceptions": { "type": "nested", @@ -59,11 +55,11 @@ }, "StackTraceString": { "type": "text", - "index": "analyzed" + "index": true }, "RemoteStackTraceString": { "type": "text", - "index": "analyzed" + "index": true }, "ExceptionMessage": { "type": "object", @@ -76,6 +72,9 @@ } } } + }, + "aliases": { + "logstash": {} } } } diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v2.json b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v8_no-aliases_0replicas.json similarity index 59% rename from test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v2.json rename to test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v8_no-aliases_0replicas.json index 6a45a045..e076ad76 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v2.json +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v8_no-aliases_0replicas.json @@ -1,38 +1,35 @@ { - "template": "logstash-*", - "settings": { - "index.refresh_interval": "5s" - }, - "mappings": { - "_default_": { - "_all": { - "enabled": true, - "omit_norms" : true - }, + "index_patterns": [ "logstash-*" ], + "template": { + "settings": { + "index.refresh_interval": "5s", + "number_of_replicas": "0" + }, + "mappings": { "dynamic_templates": [ { - "numerics_in_fields": { - "path_match":"fields\\.[\\d+]$", - "match_pattern":"regex", - "mapping": { - "type":"string", - "index":"analyzed", - "omit_norms":true - } - } + "numerics_in_fields": { + "path_match": "fields\\.[\\d+]$", + "match_pattern": "regex", + "mapping": { + "type": "text", + "index": true, + "norms": false + } + } }, { "string_fields": { "match": "*", "match_mapping_type": "string", "mapping": { - "type": "string", - "index": "analyzed", - "omit_norms": true, + "type": "text", + "index": true, + "norms": false, "fields": { "raw": { - "type": "string", - "index": "not_analyzed", + "type": "keyword", + "index": true, "ignore_above": 256 } } @@ -42,8 +39,8 @@ ], "properties": { "message": { - "type": "string", - "index": "analyzed" + "type": "text", + "index": true }, "exceptions": { "type": "nested", @@ -58,12 +55,12 @@ "type": "integer" }, "StackTraceString": { - "type": "string", - "index": "analyzed" + "type": "text", + "index": true }, "RemoteStackTraceString": { - "type": "string", - "index": "analyzed" + "type": "text", + "index": true }, "ExceptionMessage": { "type": "object", @@ -76,6 +73,8 @@ } } } + }, + "aliases": { } } -} \ No newline at end of file +} diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template.json b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v8_no-aliases_2shards.json similarity index 59% rename from test/Serilog.Sinks.Elasticsearch.Tests/Templating/template.json rename to test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v8_no-aliases_2shards.json index 6a45a045..8caee924 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template.json +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v8_no-aliases_2shards.json @@ -1,38 +1,36 @@ { - "template": "logstash-*", - "settings": { - "index.refresh_interval": "5s" - }, - "mappings": { - "_default_": { - "_all": { - "enabled": true, - "omit_norms" : true - }, + "index_patterns": [ "logstash-*" ], + "template": { + "settings": { + "index.refresh_interval": "5s", + "number_of_shards": "2", + "number_of_replicas": "0" + }, + "mappings": { "dynamic_templates": [ { - "numerics_in_fields": { - "path_match":"fields\\.[\\d+]$", - "match_pattern":"regex", - "mapping": { - "type":"string", - "index":"analyzed", - "omit_norms":true - } - } + "numerics_in_fields": { + "path_match": "fields\\.[\\d+]$", + "match_pattern": "regex", + "mapping": { + "type": "text", + "index": true, + "norms": false + } + } }, { "string_fields": { "match": "*", "match_mapping_type": "string", "mapping": { - "type": "string", - "index": "analyzed", - "omit_norms": true, + "type": "text", + "index": true, + "norms": false, "fields": { "raw": { - "type": "string", - "index": "not_analyzed", + "type": "keyword", + "index": true, "ignore_above": 256 } } @@ -42,8 +40,8 @@ ], "properties": { "message": { - "type": "string", - "index": "analyzed" + "type": "text", + "index": true }, "exceptions": { "type": "nested", @@ -58,12 +56,12 @@ "type": "integer" }, "StackTraceString": { - "type": "string", - "index": "analyzed" + "type": "text", + "index": true }, "RemoteStackTraceString": { - "type": "string", - "index": "analyzed" + "type": "text", + "index": true }, "ExceptionMessage": { "type": "object", @@ -76,6 +74,8 @@ } } } + }, + "aliases": { } } -} \ No newline at end of file +} diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_0replicas.json b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v8_no-aliases_5replicas.json similarity index 58% rename from test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_0replicas.json rename to test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v8_no-aliases_5replicas.json index 82b465b4..4b89a3fc 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_0replicas.json +++ b/test/Serilog.Sinks.Elasticsearch.Tests/Templating/template_v8_no-aliases_5replicas.json @@ -1,39 +1,35 @@ { - "template": "logstash-*", - "settings": { - "index.refresh_interval": "5s", - "number_of_replicas": "0" - }, - "mappings": { - "_default_": { - "_all": { - "enabled": true, - "omit_norms" : true - }, + "index_patterns": [ "logstash-*" ], + "template": { + "settings": { + "index.refresh_interval": "5s", + "number_of_replicas": "5" + }, + "mappings": { "dynamic_templates": [ { - "numerics_in_fields": { - "path_match":"fields\\.[\\d+]$", - "match_pattern":"regex", - "mapping": { - "type":"string", - "index":"analyzed", - "omit_norms":true - } - } + "numerics_in_fields": { + "path_match": "fields\\.[\\d+]$", + "match_pattern": "regex", + "mapping": { + "type": "text", + "index": true, + "norms": false + } + } }, { "string_fields": { "match": "*", "match_mapping_type": "string", "mapping": { - "type": "string", - "index": "analyzed", - "omit_norms": true, + "type": "text", + "index": true, + "norms": false, "fields": { "raw": { - "type": "string", - "index": "not_analyzed", + "type": "keyword", + "index": true, "ignore_above": 256 } } @@ -43,8 +39,8 @@ ], "properties": { "message": { - "type": "string", - "index": "analyzed" + "type": "text", + "index": true }, "exceptions": { "type": "nested", @@ -59,12 +55,12 @@ "type": "integer" }, "StackTraceString": { - "type": "string", - "index": "analyzed" + "type": "text", + "index": true }, "RemoteStackTraceString": { - "type": "string", - "index": "analyzed" + "type": "text", + "index": true }, "ExceptionMessage": { "type": "object", @@ -77,6 +73,8 @@ } } } + }, + "aliases": { } } -} \ No newline at end of file +} diff --git a/test/Serilog.Sinks.Elasticsearch.Tests/TestDataHelper.cs b/test/Serilog.Sinks.Elasticsearch.Tests/TestDataHelper.cs index dd1b37a1..3f3644a8 100644 --- a/test/Serilog.Sinks.Elasticsearch.Tests/TestDataHelper.cs +++ b/test/Serilog.Sinks.Elasticsearch.Tests/TestDataHelper.cs @@ -1,10 +1,7 @@ using System; -using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; namespace Serilog.Sinks.Elasticsearch.Tests {