Skip to content

Commit

Permalink
Automatically apply logs/metrics defaults based on DataStreamName.Type (
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz authored Jan 31, 2023
1 parent f872973 commit 2387486
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.Collections.Generic;
using System.Linq;
using Elastic.Ingest.Elasticsearch.Serialization;
using Elastic.Ingest.Transport;

Expand All @@ -28,10 +30,13 @@ public DataStreamChannel(DataStreamChannelOptions<TEvent> options) : base(option
/// <returns>A tuple of (name, body) describing the index template</returns>
protected override (string, string) GetDefaultIndexTemplate(string name, string match, string mappingsName, string settingsName)
{
var additionalComponents = GetInferredComponentTemplates();
var additionalComponentsJson = string.Join(", ", additionalComponents.Select(a => $"\"{a}\""));

var indexTemplateBody = @$"{{
""index_patterns"": [""{match}""],
""data_stream"": {{ }},
""composed_of"": [ ""{mappingsName}"", ""{settingsName}"", ""data-streams-mappings"" ],
""composed_of"": [ ""{mappingsName}"", ""{settingsName}"", {additionalComponentsJson} ],
""priority"": 201,
""_meta"": {{
""description"": ""Template installed by .NET ingest libraries (https://github.com/elastic/elastic-ingest-dotnet)"",
Expand All @@ -40,5 +45,16 @@ protected override (string, string) GetDefaultIndexTemplate(string name, string
}}";
return (name, indexTemplateBody);
}

protected List<string> GetInferredComponentTemplates()
{
var additionalComponents = new List<string> { "data-streams-mappings" };
// if we know the type of data is logs or metrics apply certain defaults that Elasticsearch ships with.
if (Options.DataStream.Type.ToLowerInvariant() == "logs")
additionalComponents.AddRange(new[] { "logs-settings", "logs-mappings" });
else if (Options.DataStream.Type.ToLowerInvariant() == "metrics")
additionalComponents.AddRange(new[] { "metrics-settings", "metrics-mappings" });
return additionalComponents;
}
}
}

0 comments on commit 2387486

Please sign in to comment.