From 0c55dc92a3bf889c67fac1ca855e6e33e1994904 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Mon, 9 Oct 2023 09:44:29 +0200 Subject: Update copyright --- .../test/java/com/yahoo/vespa/hosted/routing/RoutingGeneratorTest.java | 2 +- .../src/test/java/com/yahoo/vespa/hosted/routing/RoutingTableTest.java | 2 +- .../src/test/java/com/yahoo/vespa/hosted/routing/TestUtil.java | 2 +- .../test/java/com/yahoo/vespa/hosted/routing/mock/HealthStatusMock.java | 2 +- .../test/java/com/yahoo/vespa/hosted/routing/mock/HttpClientMock.java | 2 +- .../java/com/yahoo/vespa/hosted/routing/mock/RoutingStatusMock.java | 2 +- .../com/yahoo/vespa/hosted/routing/nginx/NginxHealthClientTest.java | 2 +- .../com/yahoo/vespa/hosted/routing/nginx/NginxMetricsReporterTest.java | 2 +- .../src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxTest.java | 2 +- .../java/com/yahoo/vespa/hosted/routing/restapi/AkamaiHandlerTest.java | 2 +- .../com/yahoo/vespa/hosted/routing/status/RoutingStatusClientTest.java | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) (limited to 'routing-generator/src/test/java/com') diff --git a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/RoutingGeneratorTest.java b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/RoutingGeneratorTest.java index 543a3b0a4e8..c8343a97d76 100644 --- a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/RoutingGeneratorTest.java +++ b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/RoutingGeneratorTest.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; import com.yahoo.cloud.config.LbServicesConfig; diff --git a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/RoutingTableTest.java b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/RoutingTableTest.java index 7fd88d85401..decafb1614c 100644 --- a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/RoutingTableTest.java +++ b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/RoutingTableTest.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; import com.yahoo.config.provision.ApplicationId; diff --git a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/TestUtil.java b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/TestUtil.java index ac2db906825..e13d890211d 100644 --- a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/TestUtil.java +++ b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/TestUtil.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; import com.yahoo.cloud.config.LbServicesConfig; diff --git a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/mock/HealthStatusMock.java b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/mock/HealthStatusMock.java index 66aff350b8b..74282842724 100644 --- a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/mock/HealthStatusMock.java +++ b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/mock/HealthStatusMock.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.mock; import com.yahoo.vespa.hosted.routing.status.HealthStatus; diff --git a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/mock/HttpClientMock.java b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/mock/HttpClientMock.java index 025eac90b8d..b323c1bf646 100644 --- a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/mock/HttpClientMock.java +++ b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/mock/HttpClientMock.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.mock; import com.yahoo.yolean.Exceptions; diff --git a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/mock/RoutingStatusMock.java b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/mock/RoutingStatusMock.java index 931627cd7c4..c229ab7a1d4 100644 --- a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/mock/RoutingStatusMock.java +++ b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/mock/RoutingStatusMock.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.mock; import com.yahoo.vespa.hosted.routing.status.RoutingStatus; diff --git a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxHealthClientTest.java b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxHealthClientTest.java index 24b5301d55b..c70569eb60c 100644 --- a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxHealthClientTest.java +++ b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxHealthClientTest.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.vespa.hosted.routing.mock.HttpClientMock; diff --git a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxMetricsReporterTest.java b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxMetricsReporterTest.java index eea3724e7e9..f337d636e44 100644 --- a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxMetricsReporterTest.java +++ b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxMetricsReporterTest.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.google.common.jimfs.Jimfs; diff --git a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxTest.java b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxTest.java index fb21d153ded..b84bec10d58 100644 --- a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxTest.java +++ b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxTest.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.google.common.jimfs.Jimfs; diff --git a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/restapi/AkamaiHandlerTest.java b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/restapi/AkamaiHandlerTest.java index 2814fcff8f7..4496a8d578b 100644 --- a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/restapi/AkamaiHandlerTest.java +++ b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/restapi/AkamaiHandlerTest.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.restapi; import com.yahoo.config.provision.ApplicationId; diff --git a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/status/RoutingStatusClientTest.java b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/status/RoutingStatusClientTest.java index 2e923292280..cacce3f9791 100644 --- a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/status/RoutingStatusClientTest.java +++ b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/status/RoutingStatusClientTest.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.status; import com.yahoo.vespa.hosted.routing.mock.HttpClientMock; -- cgit v1.2.3 From cb0937a18a18f5874f3376750bbf2477f4f94547 Mon Sep 17 00:00:00 2001 From: Andreas Eriksen Date: Tue, 10 Oct 2023 13:18:07 +0200 Subject: andreer/add routing config diff to vespa log (#28838) --- .../vespa/hosted/routing/RoutingGenerator.java | 8 +++++--- .../yahoo/vespa/hosted/routing/nginx/Nginx.java | 14 ++++++++++++-- .../vespa/hosted/routing/nginx/NginxTest.java | 22 ++++++++++++++++++++-- 3 files changed, 37 insertions(+), 7 deletions(-) (limited to 'routing-generator/src/test/java/com') diff --git a/routing-generator/src/main/java/com/yahoo/vespa/hosted/routing/RoutingGenerator.java b/routing-generator/src/main/java/com/yahoo/vespa/hosted/routing/RoutingGenerator.java index df646ab5525..f86ccc3df18 100644 --- a/routing-generator/src/main/java/com/yahoo/vespa/hosted/routing/RoutingGenerator.java +++ b/routing-generator/src/main/java/com/yahoo/vespa/hosted/routing/RoutingGenerator.java @@ -1,6 +1,8 @@ // 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; +import ai.vespa.cloud.Environment; +import ai.vespa.cloud.SystemInfo; import com.yahoo.cloud.config.LbServicesConfig; import com.yahoo.component.AbstractComponent; import com.yahoo.component.annotation.Inject; @@ -29,7 +31,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiConsumer; import java.util.logging.Level; import java.util.logging.Logger; @@ -61,13 +62,14 @@ public class RoutingGenerator extends AbstractComponent { private volatile RoutingTable routingTable = null; @Inject - public RoutingGenerator(ZoneConfig zoneConfig, RoutingStatus routingStatus, Metric metric) { + public RoutingGenerator(ZoneConfig zoneConfig, RoutingStatus routingStatus, Metric metric, SystemInfo systemInfo) { this(new ConfigSourceSet(zoneConfig.configserver()), new Nginx(FileSystems.getDefault(), new ProcessExecuter(), Sleeper.DEFAULT, Clock.systemUTC(), routingStatus, - metric), + metric, + systemInfo.zone().environment() == Environment.prod), Clock.systemUTC()); } 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 c8dc3638f5b..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 @@ -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 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)); diff --git a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxTest.java b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxTest.java index b84bec10d58..3e88fecd222 100644 --- a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxTest.java +++ b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxTest.java @@ -27,7 +27,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -38,6 +37,8 @@ import static org.junit.Assert.fail; */ public class NginxTest { + private static final String diffCommand = "diff -U1 /opt/vespa/var/vespa-hosted/routing/nginxl4.conf /opt/vespa/var/vespa-hosted/routing/nginxl4.conf.tmp"; + @Test public void load_routing_table() { NginxTester tester = new NginxTester(); @@ -93,6 +94,7 @@ public class NginxTest { .assertLoadedConfig(true) .assertConfigContents("nginx-updated.conf") .assertTemporaryConfigRemoved(true) + .assertProducedDiff() .assertRotatedFiles("nginxl4.conf-2022-01-01-15:00:00.000") .assertMetric(Nginx.CONFIG_RELOADS_METRIC, 2) .assertMetric(Nginx.OK_CONFIG_RELOADS_METRIC, 2); @@ -102,6 +104,7 @@ public class NginxTest { tester.load(table0); tester.clock.advance(Duration.ofDays(4).plusSeconds(1)); tester.load(table1) + .assertProducedDiff() .assertRotatedFiles("nginxl4.conf-2022-01-04-15:00:00.000", "nginxl4.conf-2022-01-08-15:00:01.000"); tester.clock.advance(Duration.ofDays(4)); @@ -116,7 +119,7 @@ public class NginxTest { private final RoutingStatusMock routingStatus = new RoutingStatusMock(); private final ProcessExecuterMock processExecuter = new ProcessExecuterMock(); private final MockMetric metric = new MockMetric(); - private final Nginx nginx = new Nginx(fileSystem, processExecuter, Sleeper.NOOP, clock, routingStatus, metric); + private final Nginx nginx = new Nginx(fileSystem, processExecuter, Sleeper.NOOP, clock, routingStatus, metric, true); public NginxTester load(RoutingTable table) { processExecuter.clearHistory(); @@ -158,6 +161,12 @@ public class NginxTest { return this; } + + public NginxTester assertProducedDiff() { + assertTrue(processExecuter.history.contains(diffCommand)); + return this; + } + public NginxTester assertLoadedConfig(boolean loaded) { String reloadCommand = "/usr/bin/sudo /opt/vespa/bin/vespa-reload-nginx"; if (loaded) { @@ -198,6 +207,15 @@ public class NginxTest { history.add(command); int exitCode = 0; String out = ""; + if(command.equals(diffCommand)) + return new Pair<>(1, """ + --- /opt/vespa/var/vespa-hosted/routing/nginxl4.conf 2023-10-09 05:28:09.815315000 +0000 + +++ /opt/vespa/var/vespa-hosted/routing/nginxl4.conf.tmp 2023-10-09 05:28:27.223030000 +0000 + @@ -45,7 +45,6 @@ + server 123.example.com:4443; + - server 456.example.com:4443; + server 789.example.com:4443;"""); + if (++currentFailCount <= wantedFailCount) { exitCode = 1; out = "failing to unit test"; -- cgit v1.2.3