Skip to content

Commit 9513b3f

Browse files
committed
[SPARK-26118][WEB UI] Introducing spark.ui.requestHeaderSize for setting HTTP requestHeaderSize
Introducing spark.ui.requestHeaderSize for configuring Jetty's HTTP requestHeaderSize. This way long authorization field does not lead to HTTP 413. Manually with curl (which version must be at least 7.55). With the original default value (8k limit): ```bash $ ./sbin/start-history-server.sh starting org.apache.spark.deploy.history.HistoryServer, logging to /Users/attilapiros/github/spark/logs/spark-attilapiros-org.apache.spark.deploy.history.HistoryServer-1-apiros-MBP.lan.out $ echo -n "X-Custom-Header: " > cookie $ printf 'A%.0s' {1..9500} >> cookie $ curl -H cookie http://458apiros-MBP.lan:18080/ <h1>Bad Message 431</h1><pre>reason: Request Header Fields Too Large</pre> $ tail -1 /Users/attilapiros/github/spark/logs/spark-attilapiros-org.apache.spark.deploy.history.HistoryServer-1-apiros-MBP.lan.out 18/11/19 21:24:28 WARN HttpParser: Header is too large 8193>8192 ``` After: ```bash $ echo spark.ui.requestHeaderSize=10000 > history.properties $ ./sbin/start-history-server.sh --properties-file history.properties starting org.apache.spark.deploy.history.HistoryServer, logging to /Users/attilapiros/github/spark/logs/spark-attilapiros-org.apache.spark.deploy.history.HistoryServer-1-apiros-MBP.lan.out $ curl -H cookie http://458apiros-MBP.lan:18080/ <!DOCTYPE html><html> <head>... <link rel="shortcut icon" href="/static/spark-logo-77x50px-hd.png"></link> <title>History Server</title> </head> <body> ... ``` (cherry picked from commit ab61ddb)
1 parent 1d8a4a2 commit 9513b3f

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

core/src/main/scala/org/apache/spark/internal/config/package.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,11 @@ package object config {
312312
" service is disabled.")
313313
.bytesConf(ByteUnit.BYTE)
314314
.createWithDefault(Long.MaxValue)
315+
316+
private[spark] val UI_REQUEST_HEADER_SIZE =
317+
ConfigBuilder("spark.ui.requestHeaderSize")
318+
.doc("Value for HTTP request header size in bytes.")
319+
.bytesConf(ByteUnit.BYTE)
320+
.createWithDefaultString("8k")
321+
315322
}

core/src/main/scala/org/apache/spark/ui/JettyUtils.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import org.json4s.jackson.JsonMethods.{pretty, render}
4040

4141
import org.apache.spark.{SecurityManager, SparkConf, SSLOptions}
4242
import org.apache.spark.internal.Logging
43+
import org.apache.spark.internal.config._
4344
import org.apache.spark.util.Utils
4445

4546
/**
@@ -342,13 +343,15 @@ private[spark] object JettyUtils extends Logging {
342343

343344
(connector, connector.getLocalPort())
344345
}
346+
val httpConfig = new HttpConfiguration()
347+
httpConfig.setRequestHeaderSize(conf.get(UI_REQUEST_HEADER_SIZE).toInt)
345348

346349
// If SSL is configured, create the secure connector first.
347350
val securePort = sslOptions.createJettySslContextFactory().map { factory =>
348351
val securePort = sslOptions.port.getOrElse(if (port > 0) Utils.userPort(port, 400) else 0)
349352
val secureServerName = if (serverName.nonEmpty) s"$serverName (HTTPS)" else serverName
350353
val connectionFactories = AbstractConnectionFactory.getFactories(factory,
351-
new HttpConnectionFactory())
354+
new HttpConnectionFactory(httpConfig))
352355

353356
def sslConnect(currentPort: Int): (ServerConnector, Int) = {
354357
newConnector(connectionFactories, currentPort)
@@ -363,7 +366,7 @@ private[spark] object JettyUtils extends Logging {
363366

364367
// Bind the HTTP port.
365368
def httpConnect(currentPort: Int): (ServerConnector, Int) = {
366-
newConnector(Array(new HttpConnectionFactory()), currentPort)
369+
newConnector(Array(new HttpConnectionFactory(httpConfig)), currentPort)
367370
}
368371

369372
val (httpConnector, httpPort) = Utils.startServiceOnPort[ServerConnector](port, httpConnect,

docs/configuration.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,14 @@ Apart from these, the following properties are also available, and may be useful
801801
How many dead executors the Spark UI and status APIs remember before garbage collecting.
802802
</td>
803803
</tr>
804+
<tr>
805+
<td><code>spark.ui.requestHeaderSize</code></td>
806+
<td>8k</td>
807+
<td>
808+
The maximum allowed size for a HTTP request header, in bytes unless otherwise specified.
809+
This setting applies for the Spark History Server too.
810+
<td>
811+
</tr>
804812
</table>
805813

806814
### Compression and Serialization

0 commit comments

Comments
 (0)