Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to tranport 0.5.1 and .NET 8 SDK #78

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

using Elastic.Ingest.Elasticsearch.DataStreams;
using Elastic.Ingest.Elasticsearch.Serialization;
using Elastic.Transport.Diagnostics;
using Performance.Common;
using static Elastic.Transport.HttpMethod;

namespace Elastic.Ingest.Elasticsearch.Benchmarks.Benchmarks;

Expand Down Expand Up @@ -47,10 +45,7 @@ public async Task WriteToStreamAsync()
{
MemoryStream.Position = 0;
var bytes = BulkRequestDataFactory.GetBytes(_data, _options!, _ => _bulkOperationHeader);
var requestData = new RequestData(
POST, "/_bulk", PostData.ReadOnlyMemory(bytes),
_transportConfiguration!, null!, ((ITransportConfiguration)_transportConfiguration!).MemoryStreamFactory, new OpenTelemetryData()
);
await requestData.PostData.WriteAsync(MemoryStream, _transportConfiguration!, CancellationToken.None);
var postData = PostData.ReadOnlyMemory(bytes);
await postData.WriteAsync(MemoryStream, _transportConfiguration!, false, CancellationToken.None);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// See the LICENSE file in the project root for more information

using Elastic.Ingest.Elasticsearch.Serialization;
using Elastic.Transport.Diagnostics;
using Performance.Common;
using static Elastic.Transport.HttpMethod;

namespace Elastic.Ingest.Elasticsearch.Benchmarks.Benchmarks;

Expand Down Expand Up @@ -46,10 +44,7 @@ public async Task WriteToStreamAsync()
{
MemoryStream.Position = 0;
var bytes = BulkRequestDataFactory.GetBytes(_data, _options!, e => BulkRequestDataFactory.CreateBulkOperationHeaderForIndex(e, _options!, true));
var requestData = new RequestData(
POST, "/_bulk", PostData.ReadOnlyMemory(bytes),
_transportConfiguration!, null!, ((ITransportConfiguration)_transportConfiguration!).MemoryStreamFactory, new OpenTelemetryData()
);
await requestData.PostData.WriteAsync(MemoryStream, _transportConfiguration!, CancellationToken.None);
var postData = PostData.ReadOnlyMemory(bytes);
await postData.WriteAsync(MemoryStream, _transportConfiguration!, false, CancellationToken.None);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// See the LICENSE file in the project root for more information

using Elastic.Ingest.Elasticsearch.Serialization;
using Elastic.Transport.Diagnostics;
using Performance.Common;
using static Elastic.Transport.HttpMethod;

namespace Elastic.Ingest.Elasticsearch.Benchmarks.Benchmarks;

Expand Down Expand Up @@ -45,10 +43,7 @@ public async Task DynamicIndexName_WriteToStreamAsync()
{
MemoryStream.Position = 0;
var bytes = BulkRequestDataFactory.GetBytes(_data, _options!, e => BulkRequestDataFactory.CreateBulkOperationHeaderForIndex(e, _options!, false));
var requestData = new RequestData(
POST, "/_bulk", PostData.ReadOnlyMemory(bytes),
_transportConfiguration!, null!, ((ITransportConfiguration)_transportConfiguration!).MemoryStreamFactory, new OpenTelemetryData()
);
await requestData.PostData.WriteAsync(MemoryStream, _transportConfiguration!, CancellationToken.None);
var postData = PostData.ReadOnlyMemory(bytes);
await postData.WriteAsync(MemoryStream, _transportConfiguration!, false, CancellationToken.None);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DebugType>pdbonly</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using BenchmarkDotNet.Running;
using System.Globalization;
using Elastic.Ingest.Elasticsearch.Benchmarks.Benchmarks;
using Perfolizer.Metrology;

#if DEBUG
// MANUALLY RUN A BENCHMARKED METHOD DURING DEBUGGING
Expand All @@ -35,7 +36,7 @@
Console.ReadKey();
#else
var config = ManualConfig.Create(DefaultConfig.Instance);
config.SummaryStyle = new SummaryStyle(CultureInfo.CurrentCulture, true, BenchmarkDotNet.Columns.SizeUnit.B, null!, ratioStyle: BenchmarkDotNet.Columns.RatioStyle.Percentage);
config.SummaryStyle = new SummaryStyle(CultureInfo.CurrentCulture, true, SizeUnit.B, null!, ratioStyle: BenchmarkDotNet.Columns.RatioStyle.Percentage);
config.AddDiagnoser(MemoryDiagnoser.Default);

BenchmarkRunner.Run<BulkRequestCreationWithTemplatedIndexNameBenchmarks>(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Profiler.Api" Version="1.3.0" />
<PackageReference Include="JetBrains.Profiler.Api" Version="1.4.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
MemoryProfiler.ForceGc();
MemoryProfiler.CollectAllocations(true);

var configuration = new TransportConfiguration(cloudId, new BasicAuthentication("elastic", elasticPassword))
var configuration = new TransportConfigurationDescriptor(cloudId, new BasicAuthentication("elastic", elasticPassword))
.ServerCertificateValidationCallback((a,b,c,d) => true); // Trust the local certificate if we're passing through Fiddler with SSL decryption

var transport = new DistributedTransport(configuration);
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Performance.Common/Performance.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
10 changes: 5 additions & 5 deletions build/scripts/CommandLine.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ with
interface IArgParserTemplate with
member this.Usage =
match this with
| Clean _ -> "clean known output locations"
| Build _ -> "Run build"
| Test _ -> "Runs build then tests"
| Release _ -> "runs build, tests, and create and validates the packages shy of publishing them"
| Publish _ -> "Runs the full release"
| Clean -> "clean known output locations"
| Build -> "Run build"
| Test -> "Runs build then tests"
| Release -> "runs build, tests, and create and validates the packages shy of publishing them"
| Publish -> "Runs the full release"

| SingleTarget _ -> "Runs the provided sub command without running their dependencies"
| Token _ -> "Token to be used to authenticate with github"
Expand Down
2 changes: 1 addition & 1 deletion build/scripts/Targets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let private test (arguments:ParseResults<Arguments>) =
let junitOutput = Path.Combine(Paths.Output.FullName, "junit-{assembly}-{framework}-test-results.xml")
let loggerPathArgs = sprintf "LogFilePath=%s" junitOutput
let loggerArg = sprintf "--logger:\"junit;%s\"" loggerPathArgs
exec "dotnet" ["test"; "-c"; "RELEASE"; loggerArg] |> ignore
exec "dotnet" ["test"; "-c"; "Release"; "--filter"; "FullyQualifiedName!~Elastic.Ingest.Elasticsearch.IntegrationTests"; loggerArg] |> ignore

let private generatePackages (arguments:ParseResults<Arguments>) =
let output = Paths.RootRelative Paths.Output.FullName
Expand Down
2 changes: 1 addition & 1 deletion build/scripts/scripts.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
15 changes: 10 additions & 5 deletions examples/Elastic.Ingest.Apm.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ private static int Main(string[] args)
}

var config = new TransportConfiguration(new Uri(args[0]))
.EnableDebugMode()
.Authentication(new ApiKey(args[1]));
//TODO needs
var transport = new DistributedTransport<TransportConfiguration>(config);
{
DebugMode = true,
Authentication = new ApiKey(args[1])
};

var transport = new DistributedTransport(config);

var numberOfEvents = 800;
var maxBufferSize = 200;
Expand All @@ -48,6 +50,7 @@ private static int Main(string[] args)
ExportMaxRetries = 3,
ExportBackoffPeriod = times => TimeSpan.FromMilliseconds(1),
};

var channelOptions = new ApmChannelOptions(transport)
{
BufferOptions = options,
Expand All @@ -63,9 +66,11 @@ private static int Main(string[] args)
ExportRetryCallback = (list) => Interlocked.Increment(ref _retries),
ExportExceptionCallback = (e) => _exception = e
};

var channel = new ApmChannel(channelOptions);

string Id() => RandomGenerator.GenerateRandomBytesAsString(8);
static string Id() => RandomGenerator.GenerateRandomBytesAsString(8);

var random = new Random();
for (var i = 0; i < numberOfEvents; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion examples/playground/playground.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.302",
"version": "8.0.100",
"rollForward": "latestFeature",
"allowPrerelease": false
}
Expand Down
4 changes: 2 additions & 2 deletions src/Elastic.Channels/BufferedChannelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ async Task FlushBufferAsync()

private ValueTask<bool> PublishAsync(IOutboundBuffer<TEvent> buffer)
{
async Task<bool> AsyncSlowPath(IOutboundBuffer<TEvent> b)
async Task<bool> AsyncSlowPathAsync(IOutboundBuffer<TEvent> b)
{
var maxRetries = Options.BufferOptions.ExportMaxRetries;
for (var i = 0; i <= maxRetries; i++)
Expand All @@ -418,7 +418,7 @@ async Task<bool> AsyncSlowPath(IOutboundBuffer<TEvent> b)

return OutChannel.Writer.TryWrite(buffer)
? new ValueTask<bool>(true)
: new ValueTask<bool>(AsyncSlowPath(buffer));
: new ValueTask<bool>(AsyncSlowPathAsync(buffer));
}

/// <inheritdoc cref="object.ToString"/>>
Expand Down
24 changes: 3 additions & 21 deletions src/Elastic.Ingest.Apm/ApmChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using Elastic.Channels;
Expand All @@ -18,28 +16,13 @@

namespace Elastic.Ingest.Apm;

internal static class ApmChannelStatics
{
public static readonly byte[] LineFeed = { (byte)'\n' };

public static readonly DefaultRequestParameters RequestParams = new()
{
RequestConfiguration = new RequestConfiguration { ContentType = "application/x-ndjson" }
};

public static readonly JsonSerializerOptions SerializerOptions = new()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, MaxDepth = 64, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
};
}

/// <summary>
/// An <see cref="TransportChannelBase{TChannelOptions,TEvent,TResponse,TBulkResponseItem}"/> implementation that sends V2 intake API data
/// to APM server.
/// </summary>
public class ApmChannel : TransportChannelBase<ApmChannelOptions, IIntakeObject, EventIntakeResponse, IntakeErrorItem>
{
/// <inheritdoc cref="ApmChannel"/>
/// <inheritdoc cref="ApmChannel"/>
public ApmChannel(ApmChannelOptions options) : base(options) { }

//retry if APM server returns 429
Expand All @@ -64,14 +47,14 @@ public ApmChannel(ApmChannelOptions options) : base(options) { }

/// <inheritdoc cref="BufferedChannelBase{TChannelOptions,TEvent,TResponse}.ExportAsync"/>
protected override Task<EventIntakeResponse> ExportAsync(ITransport transport, ArraySegment<IIntakeObject> page, CancellationToken ctx = default) =>
transport.RequestAsync<EventIntakeResponse>(HttpMethod.POST, "/intake/v2/events",
transport.RequestAsync<EventIntakeResponse>(new EndpointPath(HttpMethod.POST, "/intake/v2/events"),
PostData.StreamHandler(page,
(_, _) =>
{
/* NOT USED */
},
async (b, stream, ctx) => { await WriteBufferToStreamAsync(b, stream, ctx).ConfigureAwait(false); })
, ApmChannelStatics.RequestParams, ctx);
, default, ApmChannelStatics.RequestConfig, ctx);

private async Task WriteStanzaToStreamAsync(Stream stream, CancellationToken ctx)
{
Expand Down Expand Up @@ -114,7 +97,6 @@ private async Task WriteBufferToStreamAsync(IReadOnlyCollection<IIntakeObject> b
};
var dictionary = new Dictionary<string, object>() { { type, @event } };


await JsonSerializer.SerializeAsync(stream, dictionary, dictionary.GetType(), ApmChannelStatics.SerializerOptions, ctx)
.ConfigureAwait(false);

Expand Down
22 changes: 22 additions & 0 deletions src/Elastic.Ingest.Apm/ApmChannelStatics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// 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.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
using Elastic.Transport;

namespace Elastic.Ingest.Apm;

internal static class ApmChannelStatics
{
public static readonly byte[] LineFeed = [(byte)'\n'];

public static readonly RequestConfiguration RequestConfig = new() { ContentType = "application/x-ndjson" };

public static readonly JsonSerializerOptions SerializerOptions = new()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, MaxDepth = 64, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public DataStreamChannel(DataStreamChannelOptions<TEvent> options, ICollection<I
{
var dataStream = Options.DataStream.ToString();

_url = $"{dataStream}/{base.BulkUrl}";
_url = $"{dataStream}/{base.BulkPathAndQuery}";

_fixedHeader = new CreateOperation();
}
Expand All @@ -37,8 +37,8 @@ public DataStreamChannel(DataStreamChannelOptions<TEvent> options, ICollection<I
/// <inheritdoc cref="ElasticsearchChannelBase{TEvent,TChannelOptions}.TemplateWildcard"/>
protected override string TemplateWildcard => Options.DataStream.GetNamespaceWildcard();

/// <inheritdoc cref="ElasticsearchChannelBase{TEvent, TChannelOptions}.BulkUrl"/>
protected override string BulkUrl => _url;
/// <inheritdoc cref="ElasticsearchChannelBase{TEvent, TChannelOptions}.BulkPathAndQuery"/>
protected override string BulkPathAndQuery => _url;

/// <summary>
/// Gets a default index template for the current <see cref="DataStreamChannel{TEvent}"/>
Expand Down
Loading