Skip to content

Commit 80c431b

Browse files
committed
Beautify
1 parent 1fe0597 commit 80c431b

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

src/main/resources/dashboard.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ <h3>🚦 Traffic data (last 100 requests)</h3>
259259
}
260260

261261
const items = circuitBreakers.map(cb => {
262-
const lastFailure = cb.lastFailure
263-
? new Date(cb.lastFailure).toLocaleString()
262+
const closedSince = cb.closedSince
263+
? new Date(cb.closedSince).toLocaleString()
264264
: '-';
265265

266266
return `
@@ -270,7 +270,7 @@ <h3>🚦 Traffic data (last 100 requests)</h3>
270270
<span class="cb-status ${cb.state.toLowerCase()}">${cb.state}</span>
271271
</div>
272272
<div class="cb-metrics">
273-
<span>Last Failure: ${lastFailure}</span>
273+
<span>Closed since: ${closedSince}</span>
274274
</div>
275275
</div>
276276
`;

src/main/scala/akkahttp/ReverseProxy.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ import scala.util.{Failure, Success}
3737
* - CircuitBreaker per target server to avoid overload
3838
* - HTTP Header `X-Correlation-ID` for tracing (only for Mode.local)
3939
* - HTTP Header `X-Content-Hash` as an example of an on-the-fly processing scenario
40-
* - [[ReverseProxyMonitor]]
40+
* - Visualize traffic with [[ReverseProxyMonitor]]
4141
*
42-
* Mode.local:
42+
* Mode.local (default):
4343
* HTTP client(s) --> ReverseProxy --> local target server(s)
4444
*
4545
* Mode.remote:
@@ -51,7 +51,7 @@ import scala.util.{Failure, Success}
5151
* e.g. for mode Local adjust [[responseCodes]]
5252
* - On top of the built-in client, you may also try other clients, see below
5353
* - This PoC may not scale well, because the 'round robin' implementation
54-
* with `requestCounter` means shared state
54+
* with [[requestCounter]] means shared state
5555
*
5656
* Gatling client: [[ReverseProxySimulation]]
5757
*
@@ -105,8 +105,8 @@ object ReverseProxy extends App {
105105

106106
// Switch mode to let ReverseProxy forward client requests to local/remote target server(s)
107107
// Note that the remote servers can not interpret the X-Correlation-ID header
108-
val mode = Mode.remote
109-
clients(nbrOfClients = 10, requestsPerClient = 10, mode)
108+
val mode = Mode.local
109+
clients(nbrOfClients = 10, requestsPerClient = 100, mode)
110110
ReverseProxyMonitor.initializeWebUI(system, services(mode))
111111

112112
sys.addShutdownHook {

src/main/scala/akkahttp/ReverseProxyMonitor.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ object ReverseProxyMonitor {
6363
private case class CircuitBreakerStatus(
6464
target: String,
6565
state: String,
66-
lastFailure: Option[Long]
66+
closedSince: Option[Long]
6767
)
6868

6969
private case class ProxyStats(
@@ -116,7 +116,7 @@ object ReverseProxyMonitor {
116116
binding
117117
}
118118

119-
def browserClient() = {
119+
def browserClient(): AnyVal = {
120120
val os = System.getProperty("os.name").toLowerCase
121121
if (os == "mac os x") Process(s"open http://127.0.0.1:9000").!
122122
else if (os.startsWith("windows")) Seq("cmd", "/c", s"start http://127.0.0.1:9000").!
@@ -163,7 +163,7 @@ object ReverseProxyMonitor {
163163
val circuitBreakerStatus = CircuitBreakerStatus(
164164
target = target,
165165
state = state,
166-
lastFailure = if (state.equals("OPENED")) Some(Instant.now().toEpochMilli) else None
166+
closedSince = if (state.equals("CLOSED")) Some(Instant.now().toEpochMilli) else None
167167
)
168168
circuitBreakerStates.put(target, circuitBreakerStatus)
169169
logger.info(s"Circuit breaker for: $target changed to: $state")
@@ -206,8 +206,6 @@ object ReverseProxyMonitor {
206206
avgResponseTime = avgResponseTime,
207207
circuitBreakers = circuitBreakerStates.values().asScala.toList
208208
)
209-
210-
211209
}
212210

213211
private def createRoutes(): Route = {
@@ -217,8 +215,7 @@ object ReverseProxyMonitor {
217215
path("traffic") {
218216
get {
219217
complete {
220-
val recent = trafficHistory.asScala.takeRight(100).toList
221-
recent.asJson.noSpaces
218+
trafficHistory.asScala.takeRight(100).toList.asJson.noSpaces
222219
}
223220
}
224221
} ~

0 commit comments

Comments
 (0)