Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
Adding aliases when creating index. (#290)
Browse files Browse the repository at this point in the history
* Github releases added to yaml

* Create new release

* fix title of changelog (#211)

* Added feature to add index aliases while registering template. Index aliases are required for assigning rollover jobs to indexes.

* changing elk address to default 127.0.0.1

* comments added

* changed template according to test. added "aliases" property

* added assignment in constructor (ommited in previous commit).
Changed Sample project program.cs back to original version

* Removed indexAliases parameter from LoggerConfigurationElasticsearchExtensions.Elasticsearch not to change signature. (Caused breaking change)

* Changed comment on IndexAliases field in ElasticsearchSinkOptions.
Added one index alias in template tests for ES7. (Accordingly changed template_v7.json
  • Loading branch information
jorjika authored and mivano committed Nov 26, 2019
1 parent e16bb2e commit 463c878
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Changelog

8.0
* Adds Elasticsearch 7.0 support #256
* Adds DetectElasticsearchVersion to the sink that will detect the running cluster version. Something we now use to support sending Esv6 templates to Elasticsearch 7.x and Esv7 templates to Elasticsearch 6.x which should simplify upgrades.
* Adds an integration test project. Spins up a 6.x and 7.x elasticsearch single node cluster in succession and asserts the default and the mixed mode through DetectElasticsearchVersion works.
* Dropped support for net45 and netstandard 1.3

7.1
* DurableElasticsearchSink is rewritten to use the same base code as the sink for Serilog.Sinks.Seq. Nuget Serilog.Sinks.File is now used instead of deprecated Serilog.Sinks.RollingFile. Lots of new fintuning options for file storage is added in ElasticsearchSinkOptions. Updated Serilog.Sinks.Elasticsearch.Sample.Main with SetupLoggerWithPersistantStorage with all available options for durable mode.
* Changed datatype on singleEventSizePostingLimit from int to long? with default value null. to make it possible ro reuse code from Sinks.Seq .
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ The Serilog Elasticsearch sink project is a sink (basically a writer) for the Se
* Automatically create the right mappings for the best usage of the log events in ES or automatically upload your own custom mapping.
* 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.


## Quick start

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public static LoggerConfiguration Elasticsearch(

return loggerSinkConfiguration.Sink(
sink,
restrictedToMinimumLevel : options.MinimumLogEventLevel ?? LevelAlias.Minimum,
levelSwitch : options.LevelSwitch
restrictedToMinimumLevel: options.MinimumLogEventLevel ?? LevelAlias.Minimum,
levelSwitch: options.LevelSwitch
);
}

Expand Down Expand Up @@ -101,7 +101,7 @@ public static LoggerConfiguration Elasticsearch(
LoggingLevelSwitch levelSwitch)
{
return Elasticsearch(loggerSinkConfiguration, nodeUris, indexFormat, templateName, typeName, batchPostingLimit, period, inlineFields, restrictedToMinimumLevel, bufferBaseFilename,
bufferFileSizeLimitBytes, bufferLogShippingInterval, connectionGlobalHeaders, levelSwitch, 5, EmitEventFailureHandling.WriteToSelfLog, 100000, null, false,
bufferFileSizeLimitBytes, bufferLogShippingInterval, connectionGlobalHeaders, levelSwitch, 5, EmitEventFailureHandling.WriteToSelfLog, 100000, null, false,
AutoRegisterTemplateVersion.ESv2, false, RegisterTemplateRecovery.IndexAnyway, null, null, null);
}

Expand Down Expand Up @@ -155,7 +155,7 @@ public static LoggerConfiguration Elasticsearch(
bool inlineFields = false,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
string bufferBaseFilename = null,
long? bufferFileSizeLimitBytes = null,
long? bufferFileSizeLimitBytes = null,
long bufferLogShippingInterval = 5000,
string connectionGlobalHeaders = null,
LoggingLevelSwitch levelSwitch = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,23 @@ private static object GetTemplateESv7(ElasticsearchSinkOptions options, string d
};
mappings = discoveredVersion?.StartsWith("6.") ?? false ? new { _doc = mappings } : mappings;

Dictionary<string, object> aliases = new Dictionary<string, object>();

//If index alias or aliases are specified
if (options.IndexAliases?.Length > 0)
foreach (var alias in options.IndexAliases)
{
//Added blank object for alias to make look like this in JSON:
//"alias_1" : {}
aliases.Add(alias, new object());
}

return new
{
index_patterns = new[] {templateMatchString},
index_patterns = new[] { templateMatchString },
settings = settings,
mappings = mappings
mappings = mappings,
aliases = aliases,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ public class ElasticsearchSinkOptions
/// </summary>
public int? NumberOfReplicas { get; set; }

/// <summary>
/// Index aliases. Sets alias/aliases to an index in elasticsearch.
/// Tested and works with ElasticSearch 7.x
/// When using the <see cref="AutoRegisterTemplate"/> feature, this allows you to set index aliases.
/// If not provided, index aliases will be blank.
/// </summary>
public string[] IndexAliases { get; set; }

///<summary>
/// Connection configuration to use for connecting to the cluster.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Serilog.Parsing;

namespace Serilog.Sinks.Elasticsearch.Tests
{
{
public class IndexDeciderTests : ElasticsearchSinkTestsBase
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public Sendsv7TemplateTests()
{
_options.AutoRegisterTemplate = true;
_options.AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7;
_options.IndexAliases = new string[] { "logstash" };

var loggerConfig = new LoggerConfiguration()
.MinimumLevel.Debug()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,8 @@
}
}
}
},
"aliases": {
"logstash": {}
}
}

0 comments on commit 463c878

Please sign in to comment.