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

Read LAN Coordinates for a specific node #314

Merged

Conversation

JocelynVelarde
Copy link
Contributor

Changes made

  1. Added GET /v1/coordinate/node/+node into Coordinate.cs
  2. Included new endpoints into ICoordinateEndpoint.cs
  3. Added test CoordinateTest.cs

Issue ticket number and link

Refers to issue #313

Copy link
Contributor

@marcin-krystianc marcin-krystianc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are failing to compile (because of missing query options parameter).
Please note also that the 'Node' endpoint returns an array (https://developer.hashicorp.com/consul/api-docs/v1.9.x/coordinate#sample-response-2), instead of a single object.
I'm not sure how to handle it. It seems unlikely that there will be more than one entry in the result, but since the endpoint returns an array we probably should use an array in the result as well.

@@ -29,6 +29,7 @@ public interface ICoordinateEndpoint
{
Task<QueryResult<CoordinateDatacenterMap[]>> Datacenters(CancellationToken ct = default);
Task<QueryResult<CoordinateEntry[]>> Nodes(CancellationToken ct = default);
Task<QueryResult<CoordinateEntry>> Node(string node, QueryOptions q, CancellationToken ct = default);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two overloads of Nodes endpoint (with and without QueryOptions q parameter).
We can Apply the same pattern for the new Node endpoint`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure noted! Already fixed 🚀

@JocelynVelarde
Copy link
Contributor Author

Tests are failing to compile (because of missing query options parameter). Please note also that the 'Node' endpoint returns an array (https://developer.hashicorp.com/consul/api-docs/v1.9.x/coordinate#sample-response-2), instead of a single object. I'm not sure how to handle it. It seems unlikely that there will be more than one entry in the result, but since the endpoint returns an array we probably should use an array in the result as well.

I already fixed this on the recent commit, let me know if it needs further adjustments :)

@marcin-krystianc
Copy link
Contributor

Tests are failing to compile (because of missing query options parameter). Please note also that the 'Node' endpoint returns an array (https://developer.hashicorp.com/consul/api-docs/v1.9.x/coordinate#sample-response-2), instead of a single object. I'm not sure how to handle it. It seems unlikely that there will be more than one entry in the result, but since the endpoint returns an array we probably should use an array in the result as well.

I already fixed this on the recent commit, let me know if it needs further adjustments :)

I've run the CI and there are some compilation issues. Please have a look.

@marcin-krystianc
Copy link
Contributor

Hi @JocelynVelarde,

there is a problem with the coordinates endpoint, which returns empty responses for some time after starting the consul agent (e.g. https://github.com/G-Research/consuldotnet/actions/runs/8692709325/job/23862884528).
We can fix this by bumping the wait time and adding another check in the Base Fixture class:
image

@JocelynVelarde
Copy link
Contributor Author

Hi @JocelynVelarde,

there is a problem with the coordinates endpoint, which returns empty responses for some time after starting the consul agent (e.g. https://github.com/G-Research/consuldotnet/actions/runs/8692709325/job/23862884528).

We can fix this by bumping the wait time and adding another check in the Base Fixture class:

image

Alright noted! Is there any way I can test the endpoint locally (making the request) so I can check the output before submitting for review?

@marcin-krystianc
Copy link
Contributor

Alright noted! Is there any way I can test the endpoint locally (making the request) so I can check the output before submitting for review?

Sure thing, there is a description how to to start local agent for tests -> https://consuldot.net/docs/getting-started/setting-up-server

@JocelynVelarde
Copy link
Contributor Author

Alright noted! Is there any way I can test the endpoint locally (making the request) so I can check the output before submitting for review?

Sure thing, there is a description how to to start local agent for tests -> https://consuldot.net/docs/getting-started/setting-up-server

Yeaaa! That's how I started running tests yesterday, so on the CLI I have to write the fetch request?


public Task<QueryResult<CoordinateEntry[]>> Node(string node, CancellationToken ct = default)
{
return _client.Get<CoordinateEntry[]>(string.Format("/v1/coordinate/node/{0}", node)).Execute(ct);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be replaced with:

Suggested change
return _client.Get<CoordinateEntry[]>(string.Format("/v1/coordinate/node/{0}", node)).Execute(ct);
return Node(node, QueryOptions.Default, ct);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright done

@@ -67,6 +67,10 @@ public class BaseFixture : IAsyncLifetime
// Workaround for https://github.com/hashicorp/consul/issues/15061
await client.Agent.GetAgentMetrics();

/*var nodesResponse = await client.Coordinate.Nodes();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it commented out by mistake?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh let me activate it again


[Fact]
public async Task Coordinate_GetNode()
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous version of the test was better, we did actually use a real node name in the query before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that with the node name I was receiving errors in the base fixture class

Copy link
Contributor

@marcin-krystianc marcin-krystianc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good. Just one final remark about removing unnecessary code.

Comment on lines 76 to 80

// Additional assertions can be added based on the expected properties of each node
// For example, if you expect certain properties like node name, ID, etc. to be present in each node detail
// Assert.NotNull(nodeDetails[0].PropertyName);
// Assert.Equal(expectedValue, nodeDetails[0].PropertyName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove that unnecessary lines:

Suggested change
// Additional assertions can be added based on the expected properties of each node
// For example, if you expect certain properties like node name, ID, etc. to be present in each node detail
// Assert.NotNull(nodeDetails[0].PropertyName);
// Assert.Equal(expectedValue, nodeDetails[0].PropertyName);

Copy link
Contributor

@marcin-krystianc marcin-krystianc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it is perfect, thank you!
I need to sort out macOS CI failures before merging it.

@marcin-krystianc marcin-krystianc merged commit ed3518c into G-Research:master Apr 29, 2024
227 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants