diff options
author | Morten Tokle <mortent@vespa.ai> | 2024-04-03 12:48:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-03 12:48:39 +0200 |
commit | 70d8cd75b69c0c95546ee9177017317ed4485f8c (patch) | |
tree | 420016b8bdf57d7db5f61b83334441be48e6fea6 | |
parent | a009cdd704f427282c3c9ed3b70a7caf9d536c7e (diff) |
Handle proxy reloading properly (#30793)
-rw-r--r-- | container-disc/src/main/java/com/yahoo/container/jdisc/DataplaneProxyService.java | 18 | ||||
-rw-r--r-- | container-disc/src/test/java/com/yahoo/container/jdisc/DataplaneProxyServiceTest.java | 14 |
2 files changed, 17 insertions, 15 deletions
diff --git a/container-disc/src/main/java/com/yahoo/container/jdisc/DataplaneProxyService.java b/container-disc/src/main/java/com/yahoo/container/jdisc/DataplaneProxyService.java index d94244b0e47..e1a753ddf27 100644 --- a/container-disc/src/main/java/com/yahoo/container/jdisc/DataplaneProxyService.java +++ b/container-disc/src/main/java/com/yahoo/container/jdisc/DataplaneProxyService.java @@ -134,7 +134,7 @@ public class DataplaneProxyService extends AbstractComponent { } else { if (state == NginxState.RELOAD_REQUIRED) { try { - proxyCommands.reload(); + proxyCommands.reload(nginxConf); changeState(convergeTo); } catch (Exception e) { logger.log(Level.INFO, "Failed to reconfigure nginx, will retry."); @@ -148,7 +148,7 @@ public class DataplaneProxyService extends AbstractComponent { } else if (convergeTo == NginxState.STOPPED) { if (proxyCommands.isRunning()) { try { - proxyCommands.stop(); + proxyCommands.stop(nginxConf); } catch (Exception e) { logger.log(Level.INFO, "Failed to stop nginx, will retry"); logger.log(Level.FINE, "Exception from nginx stop", e); @@ -240,8 +240,8 @@ public class DataplaneProxyService extends AbstractComponent { public interface ProxyCommands { void start(Path configFile); - void stop(); - void reload(); + void stop(Path configFile); + void reload(Path configFile); boolean isRunning(); } @@ -264,11 +264,12 @@ public class DataplaneProxyService extends AbstractComponent { } @Override - public void stop() { + public void stop(Path configFile) { try { Process stopCommand = new ProcessBuilder().command( "nginx", - "-s", "stop" + "-s", "stop", + "-c", configFile.toString() ).start(); int exitCode = stopCommand.waitFor(); if (exitCode != 0) { @@ -281,11 +282,12 @@ public class DataplaneProxyService extends AbstractComponent { } @Override - public void reload() { + public void reload(Path configFile) { try { Process reloadCommand = new ProcessBuilder().command( "nginx", - "-s", "reload" + "-s", "reload", + "-c", configFile.toString() ).start(); int exitCode = reloadCommand.waitFor(); if (exitCode != 0) { diff --git a/container-disc/src/test/java/com/yahoo/container/jdisc/DataplaneProxyServiceTest.java b/container-disc/src/test/java/com/yahoo/container/jdisc/DataplaneProxyServiceTest.java index 719a6c0af85..47ff646918d 100644 --- a/container-disc/src/test/java/com/yahoo/container/jdisc/DataplaneProxyServiceTest.java +++ b/container-disc/src/test/java/com/yahoo/container/jdisc/DataplaneProxyServiceTest.java @@ -67,7 +67,7 @@ public class DataplaneProxyServiceTest { @Test public void retries_reload_errors() throws IOException { - Mockito.doThrow(new RuntimeException("IO error")).doNothing().when(proxyCommandsMock).reload(); + Mockito.doThrow(new RuntimeException("IO error")).doNothing().when(proxyCommandsMock).reload(any()); when(proxyCommandsMock.isRunning()).thenReturn(false); DataplaneProxyService service = dataplaneProxyService(proxyCommandsMock); @@ -83,7 +83,7 @@ public class DataplaneProxyServiceTest { assertEquals(DataplaneProxyService.NginxState.RELOAD_REQUIRED, service.state()); service.converge(); assertEquals(DataplaneProxyService.NginxState.RUNNING, service.state()); - verify(proxyCommandsMock, times(2)).reload(); + verify(proxyCommandsMock, times(2)).reload(any()); } @Test @@ -98,7 +98,7 @@ public class DataplaneProxyServiceTest { assertTrue(proxyCommands.isRunning()); // Simulate nginx process dying - proxyCommands.stop(); + proxyCommands.stop(null); assertFalse(proxyCommands.isRunning()); service.converge(); assertTrue(proxyCommands.isRunning()); @@ -136,7 +136,7 @@ public class DataplaneProxyServiceTest { reset(proxyCommandsMock); when(mockProxyCommands.isRunning()).thenReturn(true).thenReturn(false); - doThrow(new RuntimeException("Failed to stop proxy")).when(proxyCommandsMock).stop(); + doThrow(new RuntimeException("Failed to stop proxy")).when(proxyCommandsMock).stop(any()); Thread thread = new Thread(service::deconstruct);// deconstruct will block until nginx is stopped thread.start(); @@ -151,7 +151,7 @@ public class DataplaneProxyServiceTest { assertEquals(service.state(), DataplaneProxyService.NginxState.STOPPED); thread.join(); - verify(mockProxyCommands, times(1)).stop(); + verify(mockProxyCommands, times(1)).stop(any()); } private DataplaneProxyService dataplaneProxyService(DataplaneProxyService.ProxyCommands proxyCommands) throws IOException { @@ -190,12 +190,12 @@ public class DataplaneProxyServiceTest { } @Override - public void stop() { + public void stop(Path configFile) { running = false; } @Override - public void reload() { + public void reload(Path configFile) { } |