diff options
author | bjormel <bjormel@yahooinc.com> | 2023-10-26 13:59:28 +0000 |
---|---|---|
committer | bjormel <bjormel@yahooinc.com> | 2023-10-26 13:59:28 +0000 |
commit | 567be9a1f6353cec41c23bfd1fcd46b4b2a4d2d7 (patch) | |
tree | 4664a743e166a5e11aee7b9acd70ad8ee2617612 /routing-generator/src/main/java/com/yahoo/vespa/hosted/routing/nginx/Nginx.java | |
parent | e9058b555d4dfea2f6c872d9a677e8678b569569 (diff) | |
parent | bce3b8e926bf9da880172acbe1ba4b12d5e026d6 (diff) |
Merge branch 'master' into bjormel/aws-main-controllerbjormel/aws-main-controller
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)); |