Skip to content

Commit

Permalink
Update to latest Ingest and Transport libraries (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz authored Mar 28, 2024
1 parent de4f107 commit 79ef258
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Elastic.Elasticsearch.Ephemeral" Version="0.4.3" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.0.4" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.12.1" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions examples/Elastic.Serilog.Sinks.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Elastic.Serilog.Sinks.Example;
using Elastic.Elasticsearch.Ephemeral;
using Elastic.Ingest.Elasticsearch;
using Elastic.Transport;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Elastic.Elasticsearch.Ephemeral" Version="0.4.3" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.0.4" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.12.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ public ElasticsearchBenchmarkExporter(ElasticsearchBenchmarkExporterOptions opti
{
Options = options;
var config = Options.CreateTransportConfiguration();
Transport = new DefaultHttpTransport<TransportConfiguration>(config);
Transport = new DistributedTransport<TransportConfiguration>(config);
}

// ReSharper disable once UnusedMember.Global
/// <summary> Exports benchmark results to Elasticsearch </summary>
public ElasticsearchBenchmarkExporter(ElasticsearchBenchmarkExporterOptions options, Func<ElasticsearchBenchmarkExporterOptions, TransportConfiguration> configure)
{
Options = options;
Transport = new DefaultHttpTransport<TransportConfiguration>(configure(Options));
Transport = new DistributedTransport<TransportConfiguration>(configure(Options));
}


private HttpTransport<TransportConfiguration> Transport { get; }
private ITransport<TransportConfiguration> Transport { get; }
private ElasticsearchBenchmarkExporterOptions Options { get; }

// We only log when we cannot write to Elasticsearch
Expand Down
4 changes: 2 additions & 2 deletions src/Elastic.Extensions.Logging/ElasticsearchLoggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private static NodePool CreateNodePool(ElasticsearchLoggerOptions loggerOptions)
}
}

private static HttpTransport CreateTransport(ElasticsearchLoggerOptions loggerOptions)
private static ITransport CreateTransport(ElasticsearchLoggerOptions loggerOptions)
{
// TODO: Check if Uri has changed before recreating
// TODO: Injectable factory? Or some way of testing.
Expand All @@ -137,7 +137,7 @@ private static HttpTransport CreateTransport(ElasticsearchLoggerOptions loggerOp
if (loggerOptions.ShipTo.NodePoolType != NodePoolType.Cloud)
config = SetAuthenticationOnTransport(loggerOptions, config);

var transport = new DefaultHttpTransport<TransportConfiguration>(config);
var transport = new DistributedTransport<TransportConfiguration>(config);
return transport;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Elastic.Extensions.Logging/LoggingBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ Action<ElasticsearchChannelOptionsBase<LogEvent>> configureChannel

/// <summary>
/// Log to Elasticsearch
/// <para>This overload also allows you to reuse an instance of <see cref="HttpTransport"/></para>
/// <para>This overload also allows you to reuse an instance of <see cref="ITransport"/></para>
/// <para>Further configuration can be provided through the <paramref name="configure"/> parameter</para>
/// <para>Expert channel configuration can be provided to the <paramref name="configureChannel"/> parameter</para>
/// </summary>
public static ILoggingBuilder AddElasticsearch(
this ILoggingBuilder builder,
HttpTransport transport,
ITransport transport,
Action<ElasticsearchLoggerOptions>? configure = null,
Action<ElasticsearchChannelOptionsBase<LogEvent>>? configureChannel = null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public class ElasticsearchLoggerOptions : IEcsDocumentCreationOptions
public string[]? Tags { get; set; }

/// <summary>
/// Allows the direct setting of a <see cref="HttpTransport{TConfiguration}"/> to be used to communicate with Elasticsearch.
/// Allows the direct setting of a <see cref="ITransport{TConfiguration}"/> to be used to communicate with Elasticsearch.
/// <para>If set takes precedence over <see cref="ShipTo"/> </para>
/// </summary>
public HttpTransport? Transport { get; set; }
public ITransport? Transport { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Elastic.Ingest.Elasticsearch" Version="0.5.5" />
<PackageReference Include="Elastic.Ingest.Elasticsearch" Version="0.6.0" />
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions src/Elastic.Serilog.Sinks/ElasticsearchSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ public class ElasticsearchSinkOptions : ElasticsearchSinkOptions<EcsDocument>
public ElasticsearchSinkOptions() { }

/// <inheritdoc cref="ElasticsearchSinkOptions"/>
public ElasticsearchSinkOptions(HttpTransport transport) : base(transport) { }
public ElasticsearchSinkOptions(ITransport transport) : base(transport) { }
}

/// <inheritdoc cref="ElasticsearchSinkOptions{TEcsDocument}"/>
public class ElasticsearchSinkOptions<TEcsDocument> where TEcsDocument : EcsDocument, new()
{
/// <inheritdoc cref="ElasticsearchSinkOptions"/>
public ElasticsearchSinkOptions() : this(new DefaultHttpTransport(TransportHelper.Default())) { }
public ElasticsearchSinkOptions() : this(new DistributedTransport(TransportHelper.Default())) { }

/// <inheritdoc cref="ElasticsearchSinkOptions"/>
public ElasticsearchSinkOptions(HttpTransport transport) => Transport = transport;
public ElasticsearchSinkOptions(ITransport transport) => Transport = transport;

/// <inheritdoc cref="HttpTransport{TConfiguration}"/>
internal HttpTransport Transport { get; }
/// <inheritdoc cref="ITransport{TConfiguration}"/>
internal ITransport Transport { get; }

/// <inheritdoc cref="EcsTextFormatterConfiguration{TEcsDocument}"/>
public EcsTextFormatterConfiguration<TEcsDocument> TextFormatting { get; set; } = new();
Expand Down
12 changes: 6 additions & 6 deletions src/Elastic.Serilog.Sinks/ElasticsearchSinkExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static LoggerConfiguration Elasticsearch(
var transportConfig = useSniffing ? TransportHelper.Static(nodes) : TransportHelper.Sniffing(nodes);
configureTransport?.Invoke(transportConfig);

var sinkOptions = new ElasticsearchSinkOptions(new DefaultHttpTransport(transportConfig));
var sinkOptions = new ElasticsearchSinkOptions(new DistributedTransport(transportConfig));
configureOptions?.Invoke(sinkOptions);

return loggerConfiguration.Sink(new ElasticsearchSink(sinkOptions), restrictedToMinimumLevel, levelSwitch);
Expand All @@ -80,7 +80,7 @@ public static LoggerConfiguration Elasticsearch<TEcsDocument>(
{
var transportConfig = useSniffing ? TransportHelper.Static(nodes) : TransportHelper.Sniffing(nodes);
configureTransport?.Invoke(transportConfig);
var sinkOptions = new ElasticsearchSinkOptions<TEcsDocument>(new DefaultHttpTransport(transportConfig));
var sinkOptions = new ElasticsearchSinkOptions<TEcsDocument>(new DistributedTransport(transportConfig));
configureOptions?.Invoke(sinkOptions);

return loggerConfiguration.Sink(new ElasticsearchSink<TEcsDocument>(sinkOptions), restrictedToMinimumLevel, levelSwitch);
Expand All @@ -104,7 +104,7 @@ public static LoggerConfiguration ElasticCloud(
{
var transportConfig = TransportHelper.Cloud(cloudId, apiKey);
configureTransport?.Invoke(transportConfig);
var sinkOptions = new ElasticsearchSinkOptions(new DefaultHttpTransport(transportConfig));
var sinkOptions = new ElasticsearchSinkOptions(new DistributedTransport(transportConfig));
configureOptions?.Invoke(sinkOptions);

return loggerConfiguration.Sink(new ElasticsearchSink(sinkOptions), restrictedToMinimumLevel, levelSwitch);
Expand All @@ -129,7 +129,7 @@ public static LoggerConfiguration ElasticCloud<TEcsDocument>(
{
var transportConfig = TransportHelper.Cloud(cloudId, apiKey);
configureTransport?.Invoke(transportConfig);
var sinkOptions = new ElasticsearchSinkOptions<TEcsDocument>(new DefaultHttpTransport(transportConfig));
var sinkOptions = new ElasticsearchSinkOptions<TEcsDocument>(new DistributedTransport(transportConfig));
configureOptions?.Invoke(sinkOptions);

return loggerConfiguration.Sink(new ElasticsearchSink<TEcsDocument>(sinkOptions), restrictedToMinimumLevel, levelSwitch);
Expand All @@ -154,7 +154,7 @@ public static LoggerConfiguration ElasticCloud(
{
var transportConfig = TransportHelper.Cloud(cloudId, username, password);
configureTransport?.Invoke(transportConfig);
var sinkOptions = new ElasticsearchSinkOptions(new DefaultHttpTransport(transportConfig));
var sinkOptions = new ElasticsearchSinkOptions(new DistributedTransport(transportConfig));
configureOptions?.Invoke(sinkOptions);

return loggerConfiguration.Sink(new ElasticsearchSink(sinkOptions), restrictedToMinimumLevel, levelSwitch);
Expand All @@ -180,7 +180,7 @@ public static LoggerConfiguration ElasticCloud<TEcsDocument>(
{
var transportConfig = TransportHelper.Cloud(cloudId, username, password);
configureTransport?.Invoke(transportConfig);
var sinkOptions = new ElasticsearchSinkOptions<TEcsDocument>(new DefaultHttpTransport(transportConfig));
var sinkOptions = new ElasticsearchSinkOptions<TEcsDocument>(new DistributedTransport(transportConfig));
configureOptions?.Invoke(sinkOptions);

return loggerConfiguration.Sink(new ElasticsearchSink<TEcsDocument>(sinkOptions), restrictedToMinimumLevel, levelSwitch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.0.4" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.12.1" />
<PackageReference Include="Elastic.Elasticsearch.Xunit" Version="0.4.3" />
<PackageReference Include="Elastic.Ingest.Elasticsearch" Version="0.5.5" />
<PackageReference Include="Elastic.Ingest.Elasticsearch" Version="0.6.0" />

</ItemGroup>

Expand Down

0 comments on commit 79ef258

Please sign in to comment.