From 5a36114d1c16259044afddbd439afe9a03937576 Mon Sep 17 00:00:00 2001 From: Koen Metsu Date: Tue, 2 May 2017 22:38:57 +0200 Subject: [PATCH 1/5] Add support for number_of_shards (#106) --- .../Sinks/ElasticSearch/ElasticsearchSinkOptions.cs | 6 ++++++ .../Sinks/ElasticSearch/ElasticsearchSinkState.cs | 13 +++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs index eb065230..46a2105d 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs @@ -50,6 +50,12 @@ public class ElasticsearchSinkOptions /// public bool OverwriteTemplate { get; set; } + /// + /// When using the feature, this allows you to override the default number of shards. + /// If not provided, this will default to the default number_of_shards configured in Elasticsearch. + /// + public int? NumberOfShards { get; set; } + /// /// Connection configuration to use for connecting to the cluster. /// diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs index fe693955..b4ab9296 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs @@ -133,13 +133,18 @@ public void RegisterTemplateIfNeeded() } else { + var settings = new Dictionary + { + {"index.refresh_interval", "5s"} + }; + + if (_options.NumberOfShards.HasValue) + settings.Add("number_of_shards", _options.NumberOfShards.Value.ToString()); + var result = this._client.IndicesPutTemplateForAll(this._templateName, new { template = this._templateMatchString, - settings = new Dictionary - { - {"index.refresh_interval", "5s"} - }, + settings = settings, mappings = new { _default_ = new From 49c9964ab14dea563186d53cdac2479ef69500e3 Mon Sep 17 00:00:00 2001 From: Michiel van Oudheusden Date: Wed, 3 May 2017 23:07:48 +0200 Subject: [PATCH 2/5] +semver: minor --- CHANGES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index fb2cd8cf..4924d81f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,6 @@ +5.1 + * You can specify the number of shards when creating the template mapping. + 5.0 * To make the sink work in line with the other sinks, there is a breaking change as described in PR (https://github.com/serilog/serilog-sinks-elasticsearch/pull/94). minimumLogEventLevel is renamed to restrictedToMinimumLevel. The behaviour is now also consistent when you set the minimum level. From 71593dab33b71a6a3798ffccfbd2a4ee304c835d Mon Sep 17 00:00:00 2001 From: Michiel van Oudheusden Date: Wed, 3 May 2017 23:16:06 +0200 Subject: [PATCH 3/5] Small adjustment --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 4924d81f..e68e86bc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,5 @@ 5.1 - * You can specify the number of shards when creating the template mapping. + * You can specify the number of shards when creating the template mapping. This will only apply to newly created indices. 5.0 * To make the sink work in line with the other sinks, there is a breaking change as described in PR (https://github.com/serilog/serilog-sinks-elasticsearch/pull/94). minimumLogEventLevel is renamed to restrictedToMinimumLevel. The behaviour is now also consistent when you set the minimum level. From b1f27b44d0950c337401777668d06a92a97dabca Mon Sep 17 00:00:00 2001 From: Michiel van Oudheusden Date: Thu, 4 May 2017 00:10:45 +0200 Subject: [PATCH 4/5] Fixing build script --- Build.ps1 | 3 +-- src/Serilog.Sinks.Elasticsearch/project.json | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Build.ps1 b/Build.ps1 index ad9d6651..21f6946c 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -12,7 +12,6 @@ function Invoke-Build() Remove-Item .\artifacts -Force -Recurse } - & dotnet restore $test --verbosity Warning & dotnet restore $project --verbosity Warning @@ -22,7 +21,7 @@ function Invoke-Build() Write-Output "Determining version number using gitversion" & cd $projectFolder - & dotnet gitversion $project --verbosity Warning + & dotnet gitversion --verbosity Warning & cd "..\\.." } else diff --git a/src/Serilog.Sinks.Elasticsearch/project.json b/src/Serilog.Sinks.Elasticsearch/project.json index 289439c0..8da1cf10 100644 --- a/src/Serilog.Sinks.Elasticsearch/project.json +++ b/src/Serilog.Sinks.Elasticsearch/project.json @@ -1,5 +1,5 @@ { - "version": "4.1.1", + "version": "5.1.0", "buildOptions": { "warningsAsErrors": true, "keyFile": "../../assets/Serilog.snk", From fd62138fde995e81b58d71e436907ec59784e4b3 Mon Sep 17 00:00:00 2001 From: jackstu Date: Fri, 19 May 2017 17:53:17 +0200 Subject: [PATCH 5/5] Add support for number_of_replicas (#108) --- .../Sinks/ElasticSearch/ElasticsearchSinkOptions.cs | 6 ++++++ .../Sinks/ElasticSearch/ElasticsearchSinkState.cs | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs index 46a2105d..f1b3d0dd 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkOptions.cs @@ -55,6 +55,12 @@ public class ElasticsearchSinkOptions /// If not provided, this will default to the default number_of_shards configured in Elasticsearch. /// public int? NumberOfShards { get; set; } + + /// + /// When using the feature, this allows you to override the default number of replicas. + /// If not provided, this will default to the default number_of_replicas configured in Elasticsearch. + /// + public int? NumberOfReplicas { get; set; } /// /// Connection configuration to use for connecting to the cluster. diff --git a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs index b4ab9296..c8df96f3 100644 --- a/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs +++ b/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticsearchSinkState.cs @@ -140,6 +140,9 @@ public void RegisterTemplateIfNeeded() if (_options.NumberOfShards.HasValue) settings.Add("number_of_shards", _options.NumberOfShards.Value.ToString()); + + if (_options.NumberOfReplicas.HasValue) + settings.Add("number_of_replicas", _options.NumberOfReplicas.Value.ToString()); var result = this._client.IndicesPutTemplateForAll(this._templateName, new {