-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
110 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
components/proxy/src/main/java/com/hotels/styx/admin/handlers/UptimeHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
Copyright (C) 2013-2019 Expedia Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.hotels.styx.admin.handlers; | ||
|
||
import com.hotels.styx.api.Eventual; | ||
import com.hotels.styx.api.HttpInterceptor; | ||
import com.hotels.styx.api.HttpRequest; | ||
import com.hotels.styx.api.HttpResponse; | ||
import com.hotels.styx.api.MetricRegistry; | ||
import com.hotels.styx.api.WebServiceHandler; | ||
|
||
import static com.hotels.styx.api.HttpHeaderNames.CONTENT_TYPE; | ||
import static com.hotels.styx.api.HttpResponseStatus.OK; | ||
import static java.lang.String.format; | ||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
/** | ||
* Provides an uptime via admin interface. | ||
*/ | ||
public class UptimeHandler implements WebServiceHandler { | ||
private final MetricRegistry metricRegistry; | ||
|
||
public UptimeHandler(MetricRegistry metricRegistry) { | ||
this.metricRegistry = metricRegistry; | ||
} | ||
|
||
@Override | ||
public Eventual<HttpResponse> handle(HttpRequest request, HttpInterceptor.Context context) { | ||
Object uptime = metricRegistry.getGauges().get("jvm.uptime.formatted").getValue(); | ||
|
||
return Eventual.of(HttpResponse.response(OK) | ||
.disableCaching() | ||
.addHeader(CONTENT_TYPE, "application/json") | ||
.body(format("\"%s\"", uptime), UTF_8) | ||
.build()); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
system-tests/ft-suite/src/test/kotlin/com/hotels/styx/admin/AdminInterfaceSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.hotels.styx.admin | ||
|
||
import com.hotels.styx.support.StyxServerProvider | ||
import com.hotels.styx.support.adminRequest | ||
import io.kotlintest.Spec | ||
import io.kotlintest.matchers.string.shouldMatch | ||
import io.kotlintest.specs.FeatureSpec | ||
import java.nio.charset.StandardCharsets.UTF_8 | ||
|
||
class AdminInterfaceSpec : FeatureSpec() { | ||
val styxServer = StyxServerProvider( | ||
defaultConfig = """ | ||
--- | ||
proxy: | ||
connectors: | ||
http: | ||
port: 0 | ||
admin: | ||
connectors: | ||
http: | ||
port: 0 | ||
httpPipeline: | ||
type: StaticResponseHandler | ||
config: | ||
status: 200 | ||
""".trimIndent() | ||
) | ||
|
||
init { | ||
feature("Styx Server Admin Interface") { | ||
styxServer.restart() | ||
|
||
scenario("Uptime endpoint") { | ||
styxServer.adminRequest("/admin/uptime") | ||
.bodyAs(UTF_8) | ||
.shouldMatch("\"[0-9]{1,2}d [0-9]{1,2}h [0-9]{1,2}m\"".toRegex()) | ||
} | ||
} | ||
} | ||
|
||
override fun afterSpec(spec: Spec) { | ||
styxServer.stop() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters