blob: 6a2d9685a33147a1747ed43c68458189b1c0bd56 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.http;
import com.yahoo.component.ComponentId;
import com.yahoo.component.ComponentSpecification;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.jdisc.http.ServerConfig;
import com.yahoo.osgi.provider.model.ComponentModel;
import com.yahoo.vespa.model.container.ApplicationContainerCluster;
import com.yahoo.vespa.model.container.ContainerCluster;
import com.yahoo.vespa.model.container.component.SimpleComponent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
/**
* @author Einar M R Rosenvinge
* @author bjorncs
*/
public class JettyHttpServer extends SimpleComponent implements ServerConfig.Producer {
private final ContainerCluster<?> cluster;
private volatile boolean isHostedVespa;
private final List<ConnectorFactory> connectorFactories = new ArrayList<>();
private final SortedSet<String> ignoredUserAgentsList = new TreeSet<>();
public JettyHttpServer(String componentId, ContainerCluster<?> cluster, DeployState deployState) {
super(new ComponentModel(componentId, com.yahoo.jdisc.http.server.jetty.JettyHttpServer.class.getName(), null));
this.isHostedVespa = deployState.isHosted();
this.cluster = cluster;
final FilterBindingsProviderComponent filterBindingsProviderComponent = new FilterBindingsProviderComponent(componentId);
addChild(filterBindingsProviderComponent);
inject(filterBindingsProviderComponent);
for (String agent : deployState.featureFlags().ignoredHttpUserAgents()) {
addIgnoredUserAgent(agent);
}
}
public void setHostedVespa(boolean isHostedVespa) { this.isHostedVespa = isHostedVespa; }
public void addConnector(ConnectorFactory connectorFactory) {
connectorFactories.add(connectorFactory);
addChild(connectorFactory);
}
public List<ConnectorFactory> getConnectorFactories() {
return Collections.unmodifiableList(connectorFactories);
}
public void addIgnoredUserAgent(String userAgent) {
ignoredUserAgentsList.add(userAgent);
}
@Override
public void getConfig(ServerConfig.Builder builder) {
builder.metric(new ServerConfig.Metric.Builder()
.monitoringHandlerPaths(List.of("/state/v1", "/status.html", "/metrics/v2"))
.ignoredUserAgents(ignoredUserAgentsList)
.searchHandlerPaths(List.of("/search"))
);
if (isHostedVespa) {
// Proxy-protocol v1/v2 is used in hosted Vespa for remote address/port
builder.accessLog(new ServerConfig.AccessLog.Builder()
.remoteAddressHeaders(List.of())
.remotePortHeaders(List.of()));
// Enable connection log hosted Vespa
builder.connectionLog(new ServerConfig.ConnectionLog.Builder().enabled(true));
} else {
builder.accessLog(new ServerConfig.AccessLog.Builder()
.remoteAddressHeaders(List.of("x-forwarded-for"))
.remotePortHeaders(List.of("X-Forwarded-Port")));
}
configureJettyThreadpool(builder);
builder.stopTimeout(300);
}
private void configureJettyThreadpool(ServerConfig.Builder builder) {
if (cluster == null) return;
if (cluster instanceof ApplicationContainerCluster) {
builder.minWorkerThreads(-1).maxWorkerThreads(-1);
} else {
builder.minWorkerThreads(4).maxWorkerThreads(4);
}
}
static ComponentModel providerComponentModel(String parentId, String className) {
final ComponentSpecification classNameSpec = new ComponentSpecification(
className);
return new ComponentModel(new BundleInstantiationSpecification(
classNameSpec.nestInNamespace(new ComponentId(parentId)),
classNameSpec,
null));
}
public static final class FilterBindingsProviderComponent extends SimpleComponent {
public FilterBindingsProviderComponent(String parentId) {
super(providerComponentModel(parentId, "com.yahoo.container.jdisc.FilterBindingsProvider"));
}
}
}
|