Skip to content

Commit eab2cc3

Browse files
committed
Adapt for breaking change in Consul v1.7.14.8
1 parent 23c04f3 commit eab2cc3

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

src/Discovery/src/Consul/ConsulDiscoveryClient.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using Consul;
6+
using Consul.Filtering;
67
using Microsoft.Extensions.Logging;
78
using Microsoft.Extensions.Logging.Abstractions;
89
using Microsoft.Extensions.Options;
@@ -130,7 +131,7 @@ public async Task<IList<IServiceInstance>> GetAllInstancesAsync(QueryOptions que
130131

131132
if (options.Enabled)
132133
{
133-
ISet<string> serviceIds = await GetServiceIdsAsync(queryOptions, cancellationToken);
134+
ISet<string> serviceIds = await GetServiceIdsAsync(null, null, queryOptions, cancellationToken);
134135

135136
foreach (string serviceId in serviceIds)
136137
{
@@ -144,22 +145,28 @@ public async Task<IList<IServiceInstance>> GetAllInstancesAsync(QueryOptions que
144145
/// <inheritdoc />
145146
public Task<ISet<string>> GetServiceIdsAsync(CancellationToken cancellationToken)
146147
{
147-
return GetServiceIdsAsync(QueryOptions.Default, cancellationToken);
148+
return GetServiceIdsAsync(null, null, QueryOptions.Default, cancellationToken);
148149
}
149150

150151
/// <summary>
151152
/// Gets all registered service IDs from the Consul catalog.
152153
/// </summary>
154+
/// <param name="dataCenter">
155+
/// Specifies the datacenter to query.
156+
/// </param>
157+
/// <param name="filter">
158+
/// Specifies the expression used to filter the queries results prior to returning the data.
159+
/// </param>
153160
/// <param name="queryOptions">
154-
/// Any Consul query options to use.
161+
/// Options to parameterize the Consul query.
155162
/// </param>
156163
/// <param name="cancellationToken">
157164
/// The token to monitor for cancellation requests.
158165
/// </param>
159166
/// <returns>
160167
/// The list of service IDs.
161168
/// </returns>
162-
public async Task<ISet<string>> GetServiceIdsAsync(QueryOptions queryOptions, CancellationToken cancellationToken)
169+
public async Task<ISet<string>> GetServiceIdsAsync(string? dataCenter, Filter? filter, QueryOptions queryOptions, CancellationToken cancellationToken)
163170
{
164171
ArgumentNullException.ThrowIfNull(queryOptions);
165172

@@ -170,7 +177,7 @@ public async Task<ISet<string>> GetServiceIdsAsync(QueryOptions queryOptions, Ca
170177
return new HashSet<string>();
171178
}
172179

173-
QueryResult<Dictionary<string, string[]>> result = await _client.Catalog.Services(queryOptions, cancellationToken);
180+
QueryResult<Dictionary<string, string[]>> result = await _client.Catalog.Services(dataCenter, filter, queryOptions, cancellationToken);
174181
return result.Response.Keys.ToHashSet();
175182
}
176183

src/Discovery/src/Consul/ConsulHealthContributor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ internal Task<string> GetLeaderStatusAsync(CancellationToken cancellationToken)
6767

6868
internal async Task<Dictionary<string, string[]>> GetCatalogServicesAsync(CancellationToken cancellationToken)
6969
{
70-
QueryResult<Dictionary<string, string[]>> result = await _client.Catalog.Services(QueryOptions.Default, cancellationToken);
70+
QueryResult<Dictionary<string, string[]>> result = await _client.Catalog.Services(cancellationToken);
7171
return result.Response;
7272
}
7373
}

src/Discovery/src/Consul/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Steeltoe.Discovery.Consul.ConsulDiscoveryClient.GetAllInstancesAsync(Consul.Quer
104104
Steeltoe.Discovery.Consul.ConsulDiscoveryClient.GetInstancesAsync(string! serviceId, Consul.QueryOptions! queryOptions, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.Collections.Generic.IList<Steeltoe.Common.Discovery.IServiceInstance!>!>!
105105
Steeltoe.Discovery.Consul.ConsulDiscoveryClient.GetInstancesAsync(string! serviceId, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.Collections.Generic.IList<Steeltoe.Common.Discovery.IServiceInstance!>!>!
106106
Steeltoe.Discovery.Consul.ConsulDiscoveryClient.GetLocalServiceInstance() -> Steeltoe.Common.Discovery.IServiceInstance?
107-
Steeltoe.Discovery.Consul.ConsulDiscoveryClient.GetServiceIdsAsync(Consul.QueryOptions! queryOptions, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.Collections.Generic.ISet<string!>!>!
107+
Steeltoe.Discovery.Consul.ConsulDiscoveryClient.GetServiceIdsAsync(string? dataCenter, Consul.Filtering.Filter? filter, Consul.QueryOptions! queryOptions, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.Collections.Generic.ISet<string!>!>!
108108
Steeltoe.Discovery.Consul.ConsulDiscoveryClient.GetServiceIdsAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.Collections.Generic.ISet<string!>!>!
109109
Steeltoe.Discovery.Consul.ConsulDiscoveryClient.ShutdownAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
110110
Steeltoe.Discovery.Consul.ConsulServiceCollectionExtensions

src/Discovery/test/Consul.Test/Discovery/ConsulDiscoveryClientTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ public async Task GetServicesAsync_ReturnsExpected()
124124
};
125125

126126
var catalogMoq = new Mock<ICatalogEndpoint>();
127-
catalogMoq.Setup(endpoint => endpoint.Services(QueryOptions.Default, It.IsAny<CancellationToken>())).Returns(Task.FromResult(queryResult));
127+
catalogMoq.Setup(endpoint => endpoint.Services(null, null, QueryOptions.Default, It.IsAny<CancellationToken>())).Returns(Task.FromResult(queryResult));
128128

129129
var clientMoq = new Mock<IConsulClient>();
130130
clientMoq.Setup(client => client.Catalog).Returns(catalogMoq.Object);
131131

132132
TestOptionsMonitor<ConsulDiscoveryOptions> optionsMonitor = TestOptionsMonitor.Create(options);
133133
var discoveryClient = new ConsulDiscoveryClient(clientMoq.Object, optionsMonitor, NullLoggerFactory.Instance);
134-
ISet<string> serviceIds = await discoveryClient.GetServiceIdsAsync(QueryOptions.Default, TestContext.Current.CancellationToken);
134+
ISet<string> serviceIds = await discoveryClient.GetServiceIdsAsync(TestContext.Current.CancellationToken);
135135

136136
serviceIds.Should().HaveCount(2);
137137
serviceIds.Should().Contain("foo");
@@ -196,7 +196,7 @@ public async Task GetAllInstances_ReturnsExpected()
196196
};
197197

198198
var catalogMoq = new Mock<ICatalogEndpoint>();
199-
catalogMoq.Setup(endpoint => endpoint.Services(QueryOptions.Default, It.IsAny<CancellationToken>())).Returns(Task.FromResult(queryResult1));
199+
catalogMoq.Setup(endpoint => endpoint.Services(null, null, QueryOptions.Default, It.IsAny<CancellationToken>())).Returns(Task.FromResult(queryResult1));
200200

201201
var clientMoq = new Mock<IConsulClient>();
202202
clientMoq.Setup(client => client.Catalog).Returns(catalogMoq.Object);

src/Discovery/test/Consul.Test/Discovery/ConsulHealthContributorTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public async Task GetCatalogServicesAsync_ReturnsExpected()
5050
};
5151

5252
var catalogMoq = new Mock<ICatalogEndpoint>();
53-
catalogMoq.Setup(endpoint => endpoint.Services(QueryOptions.Default, It.IsAny<CancellationToken>())).Returns(Task.FromResult(queryResult));
53+
catalogMoq.Setup(endpoint => endpoint.Services(It.IsAny<CancellationToken>())).Returns(Task.FromResult(queryResult));
5454

5555
var clientMoq = new Mock<IConsulClient>();
5656
clientMoq.Setup(client => client.Catalog).Returns(catalogMoq.Object);
@@ -89,7 +89,7 @@ public async Task Health_ReturnsExpected()
8989
statusMoq.Setup(endpoint => endpoint.Leader(It.IsAny<CancellationToken>())).Returns(Task.FromResult("the-status"));
9090

9191
var catalogMoq = new Mock<ICatalogEndpoint>();
92-
catalogMoq.Setup(endpoint => endpoint.Services(QueryOptions.Default, It.IsAny<CancellationToken>())).Returns(Task.FromResult(queryResult));
92+
catalogMoq.Setup(endpoint => endpoint.Services(It.IsAny<CancellationToken>())).Returns(Task.FromResult(queryResult));
9393

9494
var clientMoq = new Mock<IConsulClient>();
9595
clientMoq.Setup(client => client.Status).Returns(statusMoq.Object);

0 commit comments

Comments
 (0)