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

Added support for agent version #261

Merged
merged 6 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Consul.Test/AgentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,17 @@ public async Task Agent_HostInfo()
Assert.True(hostInfo.Response.CollectionTime > 0);
}

[SkippableFact]
public async Task Agent_Version()
{
var cutOffVersion = SemanticVersion.Parse("1.16.0");
Skip.If(AgentVersion < cutOffVersion, $"Current version is {AgentVersion}, but `Agent_Version` is only supported from Consul {cutOffVersion}");

var agentVersion = await _client.Agent.GetAgentVersion();
Assert.NotNull(agentVersion.Response.HumanVersion);
Assert.NotNull(agentVersion.Response.SHA);
}

[Fact]
public async Task Agent_Metrics()
{
Expand Down
19 changes: 19 additions & 0 deletions Consul/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,16 @@ public class LocalServiceHealth
public AgentCheck[] Checks { get; set; }
}

/// <summary>
/// AgentVersion represents the version information for the Consul agent
/// </summary>
public class AgentVersion
{
public string SHA { get; set; }
public DateTime BuildDate { get; set; }
public string HumanVersion { get; set; }
public string FIPS { get; set; }
}
/// <summary>
/// Log Level Enum
/// </summary>
Expand Down Expand Up @@ -1033,6 +1043,15 @@ public async Task<QueryResult<AgentHostInfo>> GetAgentHostInfo(CancellationToken
return await _client.Get<AgentHostInfo>($"v1/agent/host").Execute(ct).ConfigureAwait(false);
}
/// <summary>
/// GetAgentVersion returns the version of the agent
/// </summary>
/// <param name="ct"></param>
/// <returns>Version of the agent</returns>
public async Task<QueryResult<AgentVersion>> GetAgentVersion(CancellationToken ct = default)
{
return await _client.Get<AgentVersion>("/v1/agent/version").Execute(ct).ConfigureAwait(false);
}
/// <summary>
/// Log streamer
/// </summary>
public class LogStream : IEnumerable<Task<string>>, IDisposable
Expand Down
1 change: 1 addition & 0 deletions Consul/Interfaces/IAgentEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public interface IAgentEndpoint
Task<QueryResult<LocalServiceHealth>> GetLocalServiceHealthByID(string serviceID, QueryOptions q, CancellationToken ct = default);
Task<QueryResult<LocalServiceHealth>> GetLocalServiceHealthByID(string serviceID, CancellationToken ct = default);
Task<QueryResult<Metrics>> GetAgentMetrics(CancellationToken ct = default);
Task<QueryResult<AgentVersion>> GetAgentVersion(CancellationToken ct = default);
Task<WriteResult> Reload(CancellationToken ct = default);
[Obsolete]
Task<WriteResult> Reload(string node, CancellationToken ct = default);
Expand Down