Skip to content

Commit 6591f79

Browse files
Serverless header adjustments (#7992) (#7993)
Co-authored-by: Florian Bernd <[email protected]>
1 parent c929460 commit 6591f79

File tree

15 files changed

+145
-92
lines changed

15 files changed

+145
-92
lines changed

benchmarks/Benchmarks/packages.lock.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
},
6868
"Elastic.Transport": {
6969
"type": "Transitive",
70-
"resolved": "0.4.16",
71-
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg=="
70+
"resolved": "0.4.17",
71+
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg=="
7272
},
7373
"Elasticsearch.Net": {
7474
"type": "Transitive",
@@ -1172,7 +1172,7 @@
11721172
"elastic.clients.elasticsearch": {
11731173
"type": "Project",
11741174
"dependencies": {
1175-
"Elastic.Transport": "[0.4.16, )"
1175+
"Elastic.Transport": "[0.4.17, )"
11761176
}
11771177
}
11781178
}

benchmarks/Profiling/packages.lock.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
},
3232
"Elastic.Transport": {
3333
"type": "Transitive",
34-
"resolved": "0.4.16",
35-
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg=="
34+
"resolved": "0.4.17",
35+
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg=="
3636
},
3737
"Microsoft.Build.Tasks.Git": {
3838
"type": "Transitive",
@@ -88,7 +88,7 @@
8888
"elastic.clients.elasticsearch": {
8989
"type": "Project",
9090
"dependencies": {
91-
"Elastic.Transport": "[0.4.16, )"
91+
"Elastic.Transport": "[0.4.17, )"
9292
}
9393
}
9494
}

src/Elastic.Clients.Elasticsearch.JsonNetSerializer/packages.lock.json

+18-18
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
},
3838
"Elastic.Transport": {
3939
"type": "Transitive",
40-
"resolved": "0.4.16",
41-
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
40+
"resolved": "0.4.17",
41+
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
4242
"dependencies": {
4343
"Microsoft.CSharp": "4.7.0",
4444
"System.Buffers": "4.5.1",
@@ -152,7 +152,7 @@
152152
"elastic.clients.elasticsearch": {
153153
"type": "Project",
154154
"dependencies": {
155-
"Elastic.Transport": "[0.4.16, )"
155+
"Elastic.Transport": "[0.4.17, )"
156156
}
157157
}
158158
},
@@ -192,8 +192,8 @@
192192
},
193193
"Elastic.Transport": {
194194
"type": "Transitive",
195-
"resolved": "0.4.16",
196-
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
195+
"resolved": "0.4.17",
196+
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
197197
"dependencies": {
198198
"Microsoft.CSharp": "4.7.0",
199199
"System.Buffers": "4.5.1",
@@ -341,7 +341,7 @@
341341
"elastic.clients.elasticsearch": {
342342
"type": "Project",
343343
"dependencies": {
344-
"Elastic.Transport": "[0.4.16, )"
344+
"Elastic.Transport": "[0.4.17, )"
345345
}
346346
}
347347
},
@@ -390,8 +390,8 @@
390390
},
391391
"Elastic.Transport": {
392392
"type": "Transitive",
393-
"resolved": "0.4.16",
394-
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
393+
"resolved": "0.4.17",
394+
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
395395
"dependencies": {
396396
"Microsoft.CSharp": "4.7.0",
397397
"System.Buffers": "4.5.1",
@@ -538,7 +538,7 @@
538538
"elastic.clients.elasticsearch": {
539539
"type": "Project",
540540
"dependencies": {
541-
"Elastic.Transport": "[0.4.16, )"
541+
"Elastic.Transport": "[0.4.17, )"
542542
}
543543
}
544544
},
@@ -578,8 +578,8 @@
578578
},
579579
"Elastic.Transport": {
580580
"type": "Transitive",
581-
"resolved": "0.4.16",
582-
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
581+
"resolved": "0.4.17",
582+
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
583583
"dependencies": {
584584
"Microsoft.CSharp": "4.7.0",
585585
"System.Buffers": "4.5.1",
@@ -718,7 +718,7 @@
718718
"elastic.clients.elasticsearch": {
719719
"type": "Project",
720720
"dependencies": {
721-
"Elastic.Transport": "[0.4.16, )"
721+
"Elastic.Transport": "[0.4.17, )"
722722
}
723723
}
724724
},
@@ -758,8 +758,8 @@
758758
},
759759
"Elastic.Transport": {
760760
"type": "Transitive",
761-
"resolved": "0.4.16",
762-
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
761+
"resolved": "0.4.17",
762+
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
763763
"dependencies": {
764764
"Microsoft.CSharp": "4.7.0",
765765
"System.Buffers": "4.5.1",
@@ -867,7 +867,7 @@
867867
"elastic.clients.elasticsearch": {
868868
"type": "Project",
869869
"dependencies": {
870-
"Elastic.Transport": "[0.4.16, )"
870+
"Elastic.Transport": "[0.4.17, )"
871871
}
872872
}
873873
},
@@ -907,8 +907,8 @@
907907
},
908908
"Elastic.Transport": {
909909
"type": "Transitive",
910-
"resolved": "0.4.16",
911-
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg=="
910+
"resolved": "0.4.17",
911+
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg=="
912912
},
913913
"Microsoft.Build.Tasks.Git": {
914914
"type": "Transitive",
@@ -964,7 +964,7 @@
964964
"elastic.clients.elasticsearch": {
965965
"type": "Project",
966966
"dependencies": {
967-
"Elastic.Transport": "[0.4.16, )"
967+
"Elastic.Transport": "[0.4.17, )"
968968
}
969969
}
970970
}

src/Elastic.Clients.Elasticsearch.Serverless/Core/ElasticsearchClientProductRegistration.cs

+54-1
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,31 @@
44

55
using System;
66
using System.Diagnostics.CodeAnalysis;
7+
78
using Elastic.Transport;
89
using Elastic.Transport.Products.Elasticsearch;
910

1011
namespace Elastic.Clients.Elasticsearch.Serverless;
1112

1213
internal sealed class ElasticsearchClientProductRegistration : ElasticsearchProductRegistration
1314
{
14-
public ElasticsearchClientProductRegistration(Type markerType) : base(markerType) { }
15+
private readonly MetaHeaderProvider _metaHeaderProvider;
16+
17+
public ElasticsearchClientProductRegistration(Type markerType) : base(markerType)
18+
{
19+
var identifier = ServiceIdentifier;
20+
if (!string.IsNullOrEmpty(identifier))
21+
_metaHeaderProvider = new ServerlessMetaHeaderProvider(markerType, identifier);
22+
}
1523

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

1826
public override string ServiceIdentifier => "esv";
1927

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

30+
public override MetaHeaderProvider MetaHeaderProvider => _metaHeaderProvider;
31+
2232
/// <summary>
2333
/// Elastic.Clients.Elasticsearch handles 404 in its <see cref="ElasticsearchResponse.IsValidResponse" />, we do not want the low level client throwing
2434
/// exceptions
@@ -41,3 +51,46 @@ public override bool TryGetServerErrorReason<TResponse>(TResponse response, [Not
4151
return !string.IsNullOrEmpty(reason);
4252
}
4353
}
54+
55+
public sealed class ServerlessMetaHeaderProvider : MetaHeaderProvider
56+
{
57+
private readonly MetaHeaderProducer[] _producers;
58+
59+
/// <inheritdoc cref="MetaHeaderProvider.Producers"/>
60+
public override MetaHeaderProducer[] Producers => _producers;
61+
62+
public ServerlessMetaHeaderProvider(Type clientType, string serviceIdentifier)
63+
{
64+
var version = ReflectionVersionInfo.Create(clientType);
65+
66+
_producers = new MetaHeaderProducer[]
67+
{
68+
new DefaultMetaHeaderProducer(version, serviceIdentifier),
69+
new ApiVersionMetaHeaderProducer(version)
70+
};
71+
}
72+
}
73+
74+
public class ApiVersionMetaHeaderProducer : MetaHeaderProducer
75+
{
76+
private readonly string _apiVersion;
77+
78+
public override string HeaderName => "Elastic-Api-Version";
79+
80+
public override string ProduceHeaderValue(RequestData requestData) => _apiVersion;
81+
82+
public ApiVersionMetaHeaderProducer(VersionInfo version)
83+
{
84+
var meta = version.Metadata;
85+
86+
if (meta is null || meta.Length != 8)
87+
{
88+
_apiVersion = "2023-10-31"; // Fall back to the earliest version
89+
return;
90+
}
91+
92+
// Metadata format: 20231031
93+
94+
_apiVersion = $"{meta.Substring(0, 4)}-{meta.Substring(4, 2)}-{meta.Substring(6, 2)}";
95+
}
96+
}

src/Elastic.Clients.Elasticsearch.Serverless/Elastic.Clients.Elasticsearch.Serverless.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<Nullable>annotations</Nullable>
2222
</PropertyGroup>
2323
<ItemGroup>
24-
<PackageReference Include="Elastic.Transport" Version="0.4.16" />
24+
<PackageReference Include="Elastic.Transport" Version="0.4.17" />
2525
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.3.44">
2626
<PrivateAssets>all</PrivateAssets>
2727
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>

src/Elastic.Clients.Elasticsearch.Serverless/packages.lock.json

+18-18
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
},
2323
"Elastic.Transport": {
2424
"type": "Direct",
25-
"requested": "[0.4.16, )",
26-
"resolved": "0.4.16",
27-
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
25+
"requested": "[0.4.17, )",
26+
"resolved": "0.4.17",
27+
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
2828
"dependencies": {
2929
"Microsoft.CSharp": "4.7.0",
3030
"System.Buffers": "4.5.1",
@@ -172,9 +172,9 @@
172172
},
173173
"Elastic.Transport": {
174174
"type": "Direct",
175-
"requested": "[0.4.16, )",
176-
"resolved": "0.4.16",
177-
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
175+
"requested": "[0.4.17, )",
176+
"resolved": "0.4.17",
177+
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
178178
"dependencies": {
179179
"Microsoft.CSharp": "4.7.0",
180180
"System.Buffers": "4.5.1",
@@ -356,9 +356,9 @@
356356
},
357357
"Elastic.Transport": {
358358
"type": "Direct",
359-
"requested": "[0.4.16, )",
360-
"resolved": "0.4.16",
361-
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
359+
"requested": "[0.4.17, )",
360+
"resolved": "0.4.17",
361+
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
362362
"dependencies": {
363363
"Microsoft.CSharp": "4.7.0",
364364
"System.Buffers": "4.5.1",
@@ -548,9 +548,9 @@
548548
},
549549
"Elastic.Transport": {
550550
"type": "Direct",
551-
"requested": "[0.4.16, )",
552-
"resolved": "0.4.16",
553-
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
551+
"requested": "[0.4.17, )",
552+
"resolved": "0.4.17",
553+
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
554554
"dependencies": {
555555
"Microsoft.CSharp": "4.7.0",
556556
"System.Buffers": "4.5.1",
@@ -723,9 +723,9 @@
723723
},
724724
"Elastic.Transport": {
725725
"type": "Direct",
726-
"requested": "[0.4.16, )",
727-
"resolved": "0.4.16",
728-
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg==",
726+
"requested": "[0.4.17, )",
727+
"resolved": "0.4.17",
728+
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg==",
729729
"dependencies": {
730730
"Microsoft.CSharp": "4.7.0",
731731
"System.Buffers": "4.5.1",
@@ -867,9 +867,9 @@
867867
},
868868
"Elastic.Transport": {
869869
"type": "Direct",
870-
"requested": "[0.4.16, )",
871-
"resolved": "0.4.16",
872-
"contentHash": "O2LHqnQTWAF0+cic9zYkZJ8m95cG9AnkRbwkRZogroWXZHh8oY5ewVsQsF+wwNHs/YWnNIBTq/7yqaFklBB/Wg=="
870+
"requested": "[0.4.17, )",
871+
"resolved": "0.4.17",
872+
"contentHash": "T8QGwTt3E+5b3YCkctyp+aUzJRZKiKZbbngCvell9tqhqfN4Po+Fbsw2ilX5Qm0JFnoIUzpIFJyTK6mCVf4rkg=="
873873
},
874874
"Microsoft.NETFramework.ReferenceAssemblies": {
875875
"type": "Direct",

src/Elastic.Clients.Elasticsearch/Elastic.Clients.Elasticsearch.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<Nullable>annotations</Nullable>
2222
</PropertyGroup>
2323
<ItemGroup>
24-
<PackageReference Include="Elastic.Transport" Version="0.4.16" />
24+
<PackageReference Include="Elastic.Transport" Version="0.4.17" />
2525
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.3.44">
2626
<PrivateAssets>all</PrivateAssets>
2727
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>

0 commit comments

Comments
 (0)