diff options
Diffstat (limited to 'routing-generator/src/main/java/com/yahoo/vespa/hosted/routing/nginx/Nginx.java')
-rw-r--r-- | routing-generator/src/main/java/com/yahoo/vespa/hosted/routing/nginx/Nginx.java | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/routing-generator/src/main/java/com/yahoo/vespa/hosted/routing/nginx/Nginx.java b/routing-generator/src/main/java/com/yahoo/vespa/hosted/routing/nginx/Nginx.java index b197bff7a51..b6a4cc98038 100644 --- a/routing-generator/src/main/java/com/yahoo/vespa/hosted/routing/nginx/Nginx.java +++ b/routing-generator/src/main/java/com/yahoo/vespa/hosted/routing/nginx/Nginx.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.routing.nginx; import com.yahoo.collections.Pair; @@ -48,16 +48,18 @@ public class Nginx implements Router { private final Clock clock; private final RoutingStatus routingStatus; private final Metric metric; + private final boolean outputRoutingDiff; private final Object monitor = new Object(); - public Nginx(FileSystem fileSystem, ProcessExecuter processExecuter, Sleeper sleeper, Clock clock, RoutingStatus routingStatus, Metric metric) { + public Nginx(FileSystem fileSystem, ProcessExecuter processExecuter, Sleeper sleeper, Clock clock, RoutingStatus routingStatus, Metric metric, boolean outputRoutingDiff) { this.fileSystem = Objects.requireNonNull(fileSystem); this.processExecuter = Objects.requireNonNull(processExecuter); this.sleeper = Objects.requireNonNull(sleeper); this.clock = Objects.requireNonNull(clock); this.routingStatus = Objects.requireNonNull(routingStatus); this.metric = Objects.requireNonNull(metric); + this.outputRoutingDiff = outputRoutingDiff; } @Override @@ -89,6 +91,7 @@ public class Nginx implements Router { private void loadConfig(int upstreamCount) throws IOException { Path configPath = NginxPath.config.in(fileSystem); Path tempConfigPath = NginxPath.temporaryConfig.in(fileSystem); + String routingDiff = ""; try { String currentConfig = Files.readString(configPath); String newConfig = Files.readString(tempConfigPath); @@ -96,6 +99,8 @@ public class Nginx implements Router { Files.deleteIfExists(tempConfigPath); return; } + if(outputRoutingDiff) + routingDiff = " with diff:\n" + getDiff(configPath, tempConfigPath); Path rotatedConfig = NginxPath.config.rotatedIn(fileSystem, clock.instant()); atomicCopy(configPath, rotatedConfig); } catch (NoSuchFileException ignored) { @@ -104,12 +109,17 @@ public class Nginx implements Router { Files.move(tempConfigPath, configPath, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); metric.add(CONFIG_RELOADS_METRIC, 1, null); // Retry reload. Same rationale for retrying as in testConfig() - LOG.info("Loading new configuration file from " + configPath); + LOG.info("Loading new configuration file from " + configPath + routingDiff); retryingExec("/usr/bin/sudo /opt/vespa/bin/vespa-reload-nginx"); metric.add(OK_CONFIG_RELOADS_METRIC, 1, null); metric.set(GENERATED_UPSTREAMS_METRIC, upstreamCount, null); } + private String getDiff(Path configPath, Path tempConfigPath) throws IOException { + Pair<Integer, String> executed = processExecuter.exec("diff -U1 " + configPath + " " + tempConfigPath); + return executed.getSecond(); + } + /** Remove old config files */ private void gcConfig() throws IOException { Instant oneWeekAgo = clock.instant().minus(Duration.ofDays(7)); |