If you are running history server and Yarn on the same node, then it is suggested to set the address to yarn.resourcemanager.hostname}:18080. You can do it as follows:
val sc = new SparkContext(new SparkConf())
./bin/spark-submit <all your existing options> --spark.yarn.historyServer.address=yarn.resourcemanager.hostname}:18080