diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 124a3cacd..8de499629 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -131,6 +131,7 @@ jobs: env: RUN_CONSUL_ENTERPRISE_TESTS: ${{env.RUN_CONSUL_ENTERPRISE_TESTS }} CONSUL_LICENSE: ${{ secrets.CONSUL_LICENSE }} + CONSUL_AGENT_CONFIG_PATH: ${{ github.workspace }}/Consul.Test/test_config.json - name: Upload Consul logs if: failure() uses: actions/upload-artifact@v3 diff --git a/Consul.Test/AgentTest.cs b/Consul.Test/AgentTest.cs index 1d95bd9cd..786770b6b 100644 --- a/Consul.Test/AgentTest.cs +++ b/Consul.Test/AgentTest.cs @@ -1,13 +1,12 @@ // ----------------------------------------------------------------------- -// -// Copyright 2015 PlayFab Inc. +// // Copyright 2020 G-Research Limited // -// Licensed under the Apache License, Version 2.0 (the "License"); +// Licensed under the Apache License, Version 2.0 (the "License"), // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -1014,5 +1013,35 @@ public async Task Agent_Metrics() Assert.NotNull(agentMetrics.Response.Points); Assert.NotNull(agentMetrics.Response.Samples); } + + [SkippableFact] + public async Task Agent_Reload() + { + var cutOffVersion = SemanticVersion.Parse("1.14.0"); + Skip.If(AgentVersion < cutOffVersion, $"Current version is {AgentVersion}, but `Agent_Reload` is only supported from Consul {cutOffVersion}"); + string configFile = Environment.GetEnvironmentVariable("CONSUL_AGENT_CONFIG_PATH"); + Skip.If(string.IsNullOrEmpty(configFile), "The CONSUL_AGENT_CONFIG_PATH environment variable was not set"); + var initialConfig = System.IO.File.ReadAllText(configFile); + var udpatedConfig = initialConfig.Replace("TRACE", "DEBUG"); + try + { + var agentDetails = await _client.Agent.Self(); + var agentLogLevel = agentDetails.Response["DebugConfig"]["Logging"]["LogLevel"]; + Assert.Equal("TRACE", agentLogLevel.Value); + System.IO.File.WriteAllText(configFile, udpatedConfig); + + await _client.Agent.Reload(); + agentDetails = await _client.Agent.Self(); + agentLogLevel = agentDetails.Response["DebugConfig"]["Logging"]["LogLevel"]; + Assert.Equal("DEBUG", agentLogLevel.Value); + + System.IO.File.WriteAllText(configFile, initialConfig); + await _client.Agent.Reload(); + } + finally + { + System.IO.File.WriteAllText(configFile, initialConfig); + } + } } } diff --git a/Consul.Test/Consul.Test.csproj b/Consul.Test/Consul.Test.csproj index 1e0af803d..3582171a0 100644 --- a/Consul.Test/Consul.Test.csproj +++ b/Consul.Test/Consul.Test.csproj @@ -1,4 +1,4 @@ - + net461;net5.0;net6.0;net7.0 diff --git a/Consul/Agent.cs b/Consul/Agent.cs index e5566df5d..a6de3f634 100644 --- a/Consul/Agent.cs +++ b/Consul/Agent.cs @@ -868,6 +868,17 @@ public Task Leave(string node, CancellationToken ct = default) /// Reload triggers a configuration reload for the agent we are connected to. /// /// An empty write result + public Task Reload(CancellationToken ct = default) + { + return _client.PutNothing("/v1/agent/reload").Execute(ct); + } + + /// + /// Reload triggers a configuration reload for the agent we are connected to. + /// + /// The node name to reload + /// An empty write result + [Obsolete] public Task Reload(string node, CancellationToken ct = default) { return _client.PutNothing("/v1/agent/reload").Execute(ct); diff --git a/Consul/Interfaces/IAgentEndpoint.cs b/Consul/Interfaces/IAgentEndpoint.cs index 264ba30a3..04a3db175 100644 --- a/Consul/Interfaces/IAgentEndpoint.cs +++ b/Consul/Interfaces/IAgentEndpoint.cs @@ -63,8 +63,10 @@ public interface IAgentEndpoint Task> GetLocalServiceHealthByID(string serviceID, QueryOptions q, CancellationToken ct = default); Task> GetLocalServiceHealthByID(string serviceID, CancellationToken ct = default); Task> GetAgentMetrics(CancellationToken ct = default); + Task Reload(CancellationToken ct = default); + [Obsolete] + Task Reload(string node, CancellationToken ct = default); Task> GetAgentHostInfo(CancellationToken ct = default); Task Leave(string node, CancellationToken ct = default); - Task Reload(string node, CancellationToken ct = default); } }