Skip to content

Commit

Permalink
Add description to ingest processors (#4871) (#4882)
Browse files Browse the repository at this point in the history
This commit adds description to ingest processors to allow
users to explain the purpose of a specific processor instance.

Co-authored-by: Russ Cam <[email protected]>
  • Loading branch information
github-actions[bot] and russcam authored Jul 27, 2020
1 parent 65ef88f commit 09fcdc3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
17 changes: 16 additions & 1 deletion src/Nest/Ingest/Processor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Elasticsearch.Net.Utf8Json;
Expand All @@ -18,6 +18,14 @@ public interface IProcessor
[IgnoreDataMember]
string Name { get; }

/// <summary>
/// A description to explain the purpose of the specific processor instance.
/// <para />
/// Valid in Elasticsearch 7.9.0+
/// </summary>
[DataMember(Name = "description")]
string Description { get; set; }

/// <summary>
/// If a processor fails, call these processors instead. Read more about handling failures here:
/// https://www.elastic.co/guide/en/elasticsearch/reference/current/handling-failure-in-pipelines.html
Expand Down Expand Up @@ -54,6 +62,9 @@ public abstract class ProcessorBase : IProcessor
/// <inheritdoc cref="IProcessor.OnFailure"/>
public IEnumerable<IProcessor> OnFailure { get; set; }
protected abstract string Name { get; }
/// <inheritdoc cref="IProcessor.Description"/>
public string Description { get; set; }

string IProcessor.Name => Name;
}

Expand All @@ -65,11 +76,15 @@ public abstract class ProcessorDescriptorBase<TProcessorDescriptor, TProcessorIn
{
protected abstract string Name { get; }
string IProcessor.Name => Name;
string IProcessor.Description { get; set; }
IEnumerable<IProcessor> IProcessor.OnFailure { get; set; }
string IProcessor.If { get; set; }
string IProcessor.Tag { get; set; }
bool? IProcessor.IgnoreFailure { get; set; }

/// <inheritdoc cref="IProcessor.Description"/>
public TProcessorDescriptor Description(string description) => Assign(description, (a, v) => a.Description = v);

/// <inheritdoc cref="IProcessor.OnFailure"/>
public TProcessorDescriptor OnFailure(IEnumerable<IProcessor> processors) => Assign(processors.ToListOrNullIfEmpty(), (a, v) => a.OnFailure = v);

Expand Down
9 changes: 6 additions & 3 deletions tests/Tests/Ingest/ProcessorAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class Append : ProcessorAssertion
public override string Key => "append";
}

[SkipVersion("<7.8.0", "Empty Value bug in versions less than Elasticsearch 7.8.0")]
[SkipVersion("<7.9.0", "Description added in 7.9.0")]
public class Csv : ProcessorAssertion
{
public override Func<ProcessorsDescriptor, IPromise<IList<IProcessor>>> Fluent => d => d
Expand All @@ -84,22 +84,25 @@ public class Csv : ProcessorAssertion
.TargetFields(new[] { "targetField1", "targetField2" })
.EmptyValue("empty")
.Trim()
.Description("parses CSV")
);

public override IProcessor Initializer => new CsvProcessor
{
Field = "name",
TargetFields = new[] { "targetField1", "targetField2" },
EmptyValue = "empty",
Trim = true
Trim = true,
Description = "parses CSV"
};

public override object Json => new
{
field = "name",
target_fields = new[] { "targetField1", "targetField2" },
empty_value = "empty",
trim = true
trim = true,
description = "parses CSV"
};

public override string Key => "csv";
Expand Down

0 comments on commit 09fcdc3

Please sign in to comment.