summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorten Tokle <mortent@verizonmedia.com>2020-01-28 09:10:02 +0100
committerGitHub <noreply@github.com>2020-01-28 09:10:02 +0100
commit42d8547ea0e10831faf332bf65b58c3d573b30d8 (patch)
tree42511d1c759e727b9e21d2769278b841a044c587
parent078152580843854f3b7c4cdc9164b207c33204fc (diff)
parentd7ccee6444d6577ba0756e002a87b2fc0bb1d55a (diff)
Merge pull request #11971 from vespa-engine/hmusum/stop-generating-lb-serviconfig-for-tester-apps-if-feature-flag-is-enabled
Do not generate lb-services config for tester app in all cases
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/model/LbServicesProducer.java27
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/model/LbServicesProducerTest.java35
2 files changed, 50 insertions, 12 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/model/LbServicesProducer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/model/LbServicesProducer.java
index d88fae0a8ef..b648280020f 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/model/LbServicesProducer.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/model/LbServicesProducer.java
@@ -9,6 +9,7 @@ import com.yahoo.config.model.api.ServiceInfo;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.TenantName;
import com.yahoo.config.provision.Zone;
+import com.yahoo.config.provision.zone.ZoneId;
import com.yahoo.vespa.flags.BooleanFlag;
import com.yahoo.vespa.flags.FetchVector;
import com.yahoo.vespa.flags.FlagSource;
@@ -36,11 +37,13 @@ public class LbServicesProducer implements LbServicesConfig.Producer {
private final Map<TenantName, Set<ApplicationInfo>> models;
private final Zone zone;
private final BooleanFlag use4443Upstream;
+ private final BooleanFlag generateConfigForTesterApplications;
public LbServicesProducer(Map<TenantName, Set<ApplicationInfo>> models, Zone zone, FlagSource flagSource) {
this.models = models;
this.zone = zone;
this.use4443Upstream = Flags.USE_4443_UPSTREAM.bindTo(flagSource);
+ this.generateConfigForTesterApplications = Flags.GENERATE_ROUTING_CONFIG_FOR_TESTER_APPLICATIONS.bindTo(flagSource);
}
@Override
@@ -56,10 +59,18 @@ public class LbServicesProducer implements LbServicesConfig.Producer {
LbServicesConfig.Tenants.Builder tb = new LbServicesConfig.Tenants.Builder();
apps.stream()
.sorted(Comparator.comparing(ApplicationInfo::getApplicationId))
+ .filter(applicationInfo -> generateRoutingConfig(applicationInfo.getApplicationId()))
.forEach(applicationInfo -> tb.applications(createLbAppIdKey(applicationInfo.getApplicationId()), getAppConfig(applicationInfo)));
return tb;
}
+ private boolean generateRoutingConfig(ApplicationId applicationId) {
+ if (!applicationId.instance().isTester()) return true;
+ return generateConfigForTesterApplications.with(FetchVector.Dimension.ZONE_ID,
+ ZoneId.from(zone.environment().value(), zone.region().value()).value())
+ .value();
+ }
+
private String createLbAppIdKey(ApplicationId applicationId) {
return applicationId.application().value() + ":" + zone.environment().value() + ":" + zone.region().value() + ":" + applicationId.instance().value();
}
@@ -92,10 +103,7 @@ public class LbServicesProducer implements LbServicesConfig.Producer {
private LbServicesConfig.Tenants.Applications.Hosts.Builder getHostsConfig(HostInfo hostInfo) {
LbServicesConfig.Tenants.Applications.Hosts.Builder hb = new LbServicesConfig.Tenants.Applications.Hosts.Builder();
hb.hostname(hostInfo.getHostname());
- hostInfo.getServices().stream()
- .forEach(serviceInfo -> {
- hb.services(serviceInfo.getServiceName(), getServiceConfig(serviceInfo));
- });
+ hostInfo.getServices().forEach(serviceInfo -> hb.services(serviceInfo.getServiceName(), getServiceConfig(serviceInfo)));
return hb;
}
@@ -114,12 +122,11 @@ public class LbServicesProducer implements LbServicesConfig.Producer {
filter(prop -> !"".equals(prop)).sorted((a, b) -> a.compareTo(b)).collect(Collectors.toList()))
.endpointaliases(endpointAliases)
.index(Integer.parseInt(serviceInfo.getProperty("index").orElse("999999")));
- serviceInfo.getPorts().stream()
- .forEach(portInfo -> {
- LbServicesConfig.Tenants.Applications.Hosts.Services.Ports.Builder pb = new LbServicesConfig.Tenants.Applications.Hosts.Services.Ports.Builder()
- .number(portInfo.getPort())
- .tags(Joiner.on(" ").join(portInfo.getTags()));
- sb.ports(pb);
+ serviceInfo.getPorts().forEach(portInfo -> {
+ LbServicesConfig.Tenants.Applications.Hosts.Services.Ports.Builder pb = new LbServicesConfig.Tenants.Applications.Hosts.Services.Ports.Builder()
+ .number(portInfo.getPort())
+ .tags(Joiner.on(" ").join(portInfo.getTags()));
+ sb.ports(pb);
});
return sb;
}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/model/LbServicesProducerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/model/LbServicesProducerTest.java
index 9a7cb72804f..614ebdf8e47 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/model/LbServicesProducerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/model/LbServicesProducerTest.java
@@ -16,6 +16,7 @@ import com.yahoo.config.provision.RegionName;
import com.yahoo.config.provision.TenantName;
import com.yahoo.config.provision.Zone;
import com.yahoo.vespa.config.ConfigPayload;
+import com.yahoo.vespa.flags.Flags;
import com.yahoo.vespa.flags.InMemoryFlagSource;
import com.yahoo.vespa.model.VespaModel;
import org.junit.Test;
@@ -38,6 +39,8 @@ import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;
@@ -53,7 +56,7 @@ public class LbServicesProducerTest {
private static final Set<ContainerEndpoint> endpoints = Set.of(
new ContainerEndpoint("mydisc", List.of("rotation-1", "rotation-2"))
);
- private final InMemoryFlagSource flagSource = new InMemoryFlagSource();
+ private InMemoryFlagSource flagSource;
private final boolean useGlobalServiceId;
@Parameterized.Parameters
@@ -63,6 +66,7 @@ public class LbServicesProducerTest {
public LbServicesProducerTest(boolean useGlobalServiceId) {
this.useGlobalServiceId = useGlobalServiceId;
+ this.flagSource = new InMemoryFlagSource().withBooleanFlag(Flags.GENERATE_ROUTING_CONFIG_FOR_TESTER_APPLICATIONS.id(), true);
}
@Test
@@ -141,6 +145,33 @@ public class LbServicesProducerTest {
assertThat("Missing endpoints in list: " + services.endpointaliases(), services.endpointaliases(), containsInAnyOrder("foo1.bar1.com", "foo2.bar2.com", rotation1, rotation2));
}
+
+ @Test
+ public void testRoutingConfigForTesterApplication() throws IOException, SAXException {
+ flagSource = new InMemoryFlagSource().withBooleanFlag(Flags.GENERATE_ROUTING_CONFIG_FOR_TESTER_APPLICATIONS.id(), false);
+ assumeFalse(useGlobalServiceId);
+
+ Map<TenantName, Set<ApplicationInfo>> testModel = createTestModel(new DeployState.Builder());
+ LbServicesConfig conf = getLbServicesConfig(Zone.defaultZone(), testModel);
+ LbServicesConfig.Tenants.Applications.Hosts.Services services = conf.tenants("foo").applications("foo:prod:default:default").hosts("foo.foo.yahoo.com").services(QRSERVER.serviceName);
+ assertThat(services.servicealiases().size(), is(1));
+ assertThat(services.endpointaliases().size(), is(2));
+
+ // No config for tester application
+ assertNull(getLbServicesConfig(Zone.defaultZone(), testModel)
+ .tenants("foo")
+ .applications("baz:prod:default:custom-t"));
+
+ // When flag is to true routing config should be generated for tester app
+ flagSource = new InMemoryFlagSource().withBooleanFlag(Flags.GENERATE_ROUTING_CONFIG_FOR_TESTER_APPLICATIONS.id(), true);
+ testModel = createTestModel(new DeployState.Builder());
+ conf = getLbServicesConfig(Zone.defaultZone(), testModel);
+ assertNotNull(conf);
+ services = conf.tenants("foo").applications("baz:prod:default:custom-t").hosts("foo.baz.yahoo.com").services(QRSERVER.serviceName);
+ assertThat(services.servicealiases().size(), is(1));
+ assertThat(services.endpointaliases().size(), is(2));
+ }
+
private Map<TenantName, Set<ApplicationInfo>> randomizeApplications(Map<TenantName, Set<ApplicationInfo>> testModel, int seed) {
Map<TenantName, Set<ApplicationInfo>> randomizedApplications = new LinkedHashMap<>();
List<TenantName> keys = new ArrayList<>(testModel.keySet());
@@ -166,7 +197,7 @@ public class LbServicesProducerTest {
Set<ApplicationInfo> aMap = new LinkedHashSet<>();
ApplicationId fooApp = new ApplicationId.Builder().tenant(tenant).applicationName("foo").build();
ApplicationId barApp = new ApplicationId.Builder().tenant(tenant).applicationName("bar").build();
- ApplicationId bazApp = new ApplicationId.Builder().tenant(tenant).applicationName("baz").build();
+ ApplicationId bazApp = new ApplicationId.Builder().tenant(tenant).applicationName("baz").instanceName("custom-t").build(); // tester app
aMap.add(createApplication(fooApp, deploystateBuilder));
aMap.add(createApplication(barApp, deploystateBuilder));
aMap.add(createApplication(bazApp, deploystateBuilder));