Skip to content

Commit ed3518c

Browse files
Read LAN Coordinates for a specific node (G-Research#314)
1 parent 280ccfa commit ed3518c

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

Consul.Test/BaseFixture.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class BaseFixture : IAsyncLifetime
2222
c.Address = TestHelper.HttpUri;
2323
});
2424

25-
var timeout = TimeSpan.FromSeconds(15);
25+
var timeout = TimeSpan.FromSeconds(60);
2626
var cancelToken = new CancellationTokenSource(timeout).Token;
2727
Exception exception = null;
2828
var firstIteration = true;
@@ -67,6 +67,9 @@ public class BaseFixture : IAsyncLifetime
6767
// Workaround for https://github.com/hashicorp/consul/issues/15061
6868
await client.Agent.GetAgentMetrics();
6969

70+
if ((await client.Coordinate.Nodes()).Response.Length == 0)
71+
continue;
72+
7073
break;
7174
}
7275
catch (OperationCanceledException)

Consul.Test/CoordinateTest.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,29 @@ public async Task Coordinate_GetNodes()
4949
// get an error. - from offical API.
5050
Assert.NotNull(nodes);
5151
}
52+
53+
[Fact]
54+
public async Task Coordinate_GetNode()
55+
{
56+
var info = await _client.Agent.Self();
57+
var nodesResult = await _client.Coordinate.Nodes();
58+
59+
Assert.NotNull(nodesResult);
60+
Assert.NotEmpty(nodesResult.Response);
61+
62+
var nodes = nodesResult.Response;
63+
64+
var firstNode = nodes[0];
65+
66+
var nodeDetailsResult = await _client.Coordinate.Node(firstNode.Node);
67+
68+
Assert.NotNull(nodeDetailsResult);
69+
Assert.NotEmpty(nodeDetailsResult.Response);
70+
71+
var nodeDetails = nodeDetailsResult.Response;
72+
73+
Assert.IsType<CoordinateEntry[]>(nodeDetails);
74+
Assert.NotEmpty(nodeDetails);
75+
}
5276
}
5377
}
61 MB
Binary file not shown.

Consul/Coordinate.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,23 @@ public Task<QueryResult<CoordinateEntry[]>> Nodes(QueryOptions q, CancellationTo
8888
{
8989
return _client.Get<CoordinateEntry[]>(string.Format("/v1/coordinate/nodes"), q).Execute(ct);
9090
}
91+
92+
/// <summary>
93+
/// Node returns the coordinates of a given node in the LAN pool.
94+
/// </summary>
95+
/// <param name="node">The node to query</param>"
96+
/// <param name="ct">The cancellation token</param>"
97+
/// <param name="q">Customized query options</param>"
98+
/// <remarks>Node is used to return the coordinates of a given node in the LAN pool.</returns>
99+
public Task<QueryResult<CoordinateEntry[]>> Node(string node, QueryOptions q, CancellationToken ct = default)
100+
{
101+
return _client.Get<CoordinateEntry[]>(string.Format("/v1/coordinate/node/{0}", node), q).Execute(ct);
102+
}
103+
104+
public Task<QueryResult<CoordinateEntry[]>> Node(string node, CancellationToken ct = default)
105+
{
106+
return Node(node, QueryOptions.Default, ct);
107+
}
91108
}
92109

93110
public partial class ConsulClient : IConsulClient

Consul/Interfaces/ICoordinateEndpoint.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public interface ICoordinateEndpoint
2929
{
3030
Task<QueryResult<CoordinateDatacenterMap[]>> Datacenters(CancellationToken ct = default);
3131
Task<QueryResult<CoordinateEntry[]>> Nodes(CancellationToken ct = default);
32+
Task<QueryResult<CoordinateEntry[]>> Node(string node, QueryOptions q, CancellationToken ct = default);
33+
Task<QueryResult<CoordinateEntry[]>> Node(string node, CancellationToken ct = default);
3234
Task<QueryResult<CoordinateEntry[]>> Nodes(QueryOptions q, CancellationToken ct = default);
3335
}
3436
}

0 commit comments

Comments
 (0)