Skip to content

Commit

Permalink
Serverless header adjustments (#7992)
Browse files Browse the repository at this point in the history
  • Loading branch information
flobernd committed Dec 1, 2023
1 parent 3596735 commit 0bd1b15
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 92 deletions.
6 changes: 3 additions & 3 deletions benchmarks/Benchmarks/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
},
"Elastic.Transport": {
"type": "Transitive",
"resolved": "0.4.16",
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg=="
"resolved": "0.4.17",
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg=="
},
"Elasticsearch.Net": {
"type": "Transitive",
Expand Down Expand Up @@ -1172,7 +1172,7 @@
"elastic.clients.elasticsearch": {
"type": "Project",
"dependencies": {
"Elastic.Transport": "[0.4.16, )"
"Elastic.Transport": "[0.4.17, )"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/Profiling/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
},
"Elastic.Transport": {
"type": "Transitive",
"resolved": "0.4.16",
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg=="
"resolved": "0.4.17",
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg=="
},
"Microsoft.Build.Tasks.Git": {
"type": "Transitive",
Expand Down Expand Up @@ -88,7 +88,7 @@
"elastic.clients.elasticsearch": {
"type": "Project",
"dependencies": {
"Elastic.Transport": "[0.4.16, )"
"Elastic.Transport": "[0.4.17, )"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
},
"Elastic.Transport": {
"type": "Transitive",
"resolved": "0.4.16",
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
"resolved": "0.4.17",
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Buffers": "4.5.1",
Expand Down Expand Up @@ -152,7 +152,7 @@
"elastic.clients.elasticsearch": {
"type": "Project",
"dependencies": {
"Elastic.Transport": "[0.4.16, )"
"Elastic.Transport": "[0.4.17, )"
}
}
},
Expand Down Expand Up @@ -192,8 +192,8 @@
},
"Elastic.Transport": {
"type": "Transitive",
"resolved": "0.4.16",
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
"resolved": "0.4.17",
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Buffers": "4.5.1",
Expand Down Expand Up @@ -341,7 +341,7 @@
"elastic.clients.elasticsearch": {
"type": "Project",
"dependencies": {
"Elastic.Transport": "[0.4.16, )"
"Elastic.Transport": "[0.4.17, )"
}
}
},
Expand Down Expand Up @@ -390,8 +390,8 @@
},
"Elastic.Transport": {
"type": "Transitive",
"resolved": "0.4.16",
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
"resolved": "0.4.17",
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Buffers": "4.5.1",
Expand Down Expand Up @@ -538,7 +538,7 @@
"elastic.clients.elasticsearch": {
"type": "Project",
"dependencies": {
"Elastic.Transport": "[0.4.16, )"
"Elastic.Transport": "[0.4.17, )"
}
}
},
Expand Down Expand Up @@ -578,8 +578,8 @@
},
"Elastic.Transport": {
"type": "Transitive",
"resolved": "0.4.16",
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
"resolved": "0.4.17",
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Buffers": "4.5.1",
Expand Down Expand Up @@ -718,7 +718,7 @@
"elastic.clients.elasticsearch": {
"type": "Project",
"dependencies": {
"Elastic.Transport": "[0.4.16, )"
"Elastic.Transport": "[0.4.17, )"
}
}
},
Expand Down Expand Up @@ -758,8 +758,8 @@
},
"Elastic.Transport": {
"type": "Transitive",
"resolved": "0.4.16",
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
"resolved": "0.4.17",
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Buffers": "4.5.1",
Expand Down Expand Up @@ -867,7 +867,7 @@
"elastic.clients.elasticsearch": {
"type": "Project",
"dependencies": {
"Elastic.Transport": "[0.4.16, )"
"Elastic.Transport": "[0.4.17, )"
}
}
},
Expand Down Expand Up @@ -907,8 +907,8 @@
},
"Elastic.Transport": {
"type": "Transitive",
"resolved": "0.4.16",
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg=="
"resolved": "0.4.17",
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg=="
},
"Microsoft.Build.Tasks.Git": {
"type": "Transitive",
Expand Down Expand Up @@ -964,7 +964,7 @@
"elastic.clients.elasticsearch": {
"type": "Project",
"dependencies": {
"Elastic.Transport": "[0.4.16, )"
"Elastic.Transport": "[0.4.17, )"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@

using System;
using System.Diagnostics.CodeAnalysis;

using Elastic.Transport;
using Elastic.Transport.Products.Elasticsearch;

namespace Elastic.Clients.Elasticsearch.Serverless;

internal sealed class ElasticsearchClientProductRegistration : ElasticsearchProductRegistration
{
public ElasticsearchClientProductRegistration(Type markerType) : base(markerType) { }
private readonly MetaHeaderProvider _metaHeaderProvider;

public ElasticsearchClientProductRegistration(Type markerType) : base(markerType)
{
var identifier = ServiceIdentifier;
if (!string.IsNullOrEmpty(identifier))
_metaHeaderProvider = new ServerlessMetaHeaderProvider(markerType, identifier);
}

public static ElasticsearchClientProductRegistration DefaultForElasticsearchClientsElasticsearch { get; } = new(typeof(ElasticsearchClient));

public override string ServiceIdentifier => "esv";

public override string DefaultMimeType => null; // Prevent base 'ElasticsearchProductRegistration' from sending the compatibility header

public override MetaHeaderProvider MetaHeaderProvider => _metaHeaderProvider;

/// <summary>
/// Elastic.Clients.Elasticsearch handles 404 in its <see cref="ElasticsearchResponse.IsValidResponse" />, we do not want the low level client throwing
/// exceptions
Expand All @@ -41,3 +51,46 @@ public override bool TryGetServerErrorReason<TResponse>(TResponse response, [Not
return !string.IsNullOrEmpty(reason);
}
}

public sealed class ServerlessMetaHeaderProvider : MetaHeaderProvider
{
private readonly MetaHeaderProducer[] _producers;

/// <inheritdoc cref="MetaHeaderProvider.Producers"/>
public override MetaHeaderProducer[] Producers => _producers;

public ServerlessMetaHeaderProvider(Type clientType, string serviceIdentifier)
{
var version = ReflectionVersionInfo.Create(clientType);

_producers = new MetaHeaderProducer[]
{
new DefaultMetaHeaderProducer(version, serviceIdentifier),
new ApiVersionMetaHeaderProducer(version)
};
}
}

public class ApiVersionMetaHeaderProducer : MetaHeaderProducer
{
private readonly string _apiVersion;

public override string HeaderName => "Elastic-Api-Version";

public override string ProduceHeaderValue(RequestData requestData) => _apiVersion;

public ApiVersionMetaHeaderProducer(VersionInfo version)
{
var meta = version.Metadata;

if (meta is null || meta.Length != 8)
{
_apiVersion = "2023-10-31"; // Fall back to the earliest version
return;
}

// Metadata format: 20231031

_apiVersion = $"{meta.Substring(0, 4)}-{meta.Substring(4, 2)}-{meta.Substring(6, 2)}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<Nullable>annotations</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Elastic.Transport" Version="0.4.16" />
<PackageReference Include="Elastic.Transport" Version="0.4.17" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.3.44">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
36 changes: 18 additions & 18 deletions src/Elastic.Clients.Elasticsearch.Serverless/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
},
"Elastic.Transport": {
"type": "Direct",
"requested": "[0.4.16, )",
"resolved": "0.4.16",
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
"requested": "[0.4.17, )",
"resolved": "0.4.17",
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Buffers": "4.5.1",
Expand Down Expand Up @@ -172,9 +172,9 @@
},
"Elastic.Transport": {
"type": "Direct",
"requested": "[0.4.16, )",
"resolved": "0.4.16",
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
"requested": "[0.4.17, )",
"resolved": "0.4.17",
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Buffers": "4.5.1",
Expand Down Expand Up @@ -356,9 +356,9 @@
},
"Elastic.Transport": {
"type": "Direct",
"requested": "[0.4.16, )",
"resolved": "0.4.16",
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
"requested": "[0.4.17, )",
"resolved": "0.4.17",
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Buffers": "4.5.1",
Expand Down Expand Up @@ -548,9 +548,9 @@
},
"Elastic.Transport": {
"type": "Direct",
"requested": "[0.4.16, )",
"resolved": "0.4.16",
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
"requested": "[0.4.17, )",
"resolved": "0.4.17",
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Buffers": "4.5.1",
Expand Down Expand Up @@ -723,9 +723,9 @@
},
"Elastic.Transport": {
"type": "Direct",
"requested": "[0.4.16, )",
"resolved": "0.4.16",
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
"requested": "[0.4.17, )",
"resolved": "0.4.17",
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Buffers": "4.5.1",
Expand Down Expand Up @@ -867,9 +867,9 @@
},
"Elastic.Transport": {
"type": "Direct",
"requested": "[0.4.16, )",
"resolved": "0.4.16",
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg=="
"requested": "[0.4.17, )",
"resolved": "0.4.17",
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg=="
},
"Microsoft.NETFramework.ReferenceAssemblies": {
"type": "Direct",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<Nullable>annotations</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Elastic.Transport" Version="0.4.16" />
<PackageReference Include="Elastic.Transport" Version="0.4.17" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.3.44">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down

0 comments on commit 0bd1b15

Please sign in to comment.