-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* DAS 92 add put (#280) Co-authored-by: Augustinas Markevicius <[email protected]> Co-authored-by: Piotr Perzyna <[email protected]> * DAS 92 add put 2 (#283) Co-authored-by: Augustinas Markevicius <[email protected]> Co-authored-by: Piotr Perzyna <[email protected]> * Improve deployment (#284) * update github action * cleanup * DAS 92 add put 2 (#286) Co-authored-by: Augustinas Markevicius <[email protected]> Co-authored-by: Piotr Perzyna <[email protected]> * Update README.md (#287) * DAS 98 - Add Prometheus metrics. (#294) * add region to aws cli (#296) * Updated to sbt 1.3.13 (#301) * Updated to sbt 1.3.13 * Fixed a test * fix one test * Update v26.routes Hide the /metrics route for now. Co-authored-by: Ty <[email protected]> Co-authored-by: Augustinas Markevicius <[email protected]> Co-authored-by: Piotr Perzyna <[email protected]>
- Loading branch information
1 parent
749efe9
commit ad379e0
Showing
12 changed files
with
161 additions
and
10 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
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
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,10 @@ | ||
package org.hatdex.hat.filters | ||
|
||
import javax.inject.Inject | ||
import com.github.stijndehaes.playprometheusfilters.filters.{ StatusAndRouteLatencyFilter, StatusCounterFilter } | ||
import play.api.http.DefaultHttpFilters | ||
|
||
class PrometheusFilters @Inject() ( | ||
statusCounterFilter: StatusCounterFilter, | ||
statusAndRouteLatencyFilter: StatusAndRouteLatencyFilter) | ||
extends DefaultHttpFilters(statusCounterFilter, statusAndRouteLatencyFilter) |
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 |
---|---|---|
|
@@ -163,3 +163,4 @@ include "she.conf" | |
include "phata.conf" | ||
|
||
include "regions.conf" | ||
|
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
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
129 changes: 129 additions & 0 deletions
129
hat/test/org/hatdex/hat/filters/PrometheusFiltersSpec.scala
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,129 @@ | ||
// This is set as it is to access the private members of the filters to test them. | ||
package com.github.stijndehaes.playprometheusfilters.filters | ||
|
||
/* Test cases based on the archived project: https://github.com/stijndehaes/play-prometheus-filters */ | ||
|
||
import org.specs2.mock.Mockito | ||
import play.api.test.{ FakeRequest, PlaySpecification } | ||
import akka.actor.ActorSystem | ||
import akka.stream.ActorMaterializer | ||
import play.api.mvc._ | ||
import play.api.test.Helpers._ | ||
import play.api.test._ | ||
import play.api.routing.Router | ||
import io.prometheus.client.CollectorRegistry | ||
import play.api.libs.typedmap.TypedMap | ||
import play.api.routing.HandlerDef | ||
import play.api.mvc.{ AbstractController, ControllerComponents } | ||
import javax.inject.Inject | ||
import scala.collection.JavaConverters._ | ||
|
||
class PrometheusFiltersSpec extends PlaySpecification with Mockito { | ||
implicit val system = ActorSystem() | ||
implicit val executor = system.dispatcher | ||
implicit val materializer = ActorMaterializer() | ||
|
||
sequential | ||
|
||
"LatencyFilter" should { | ||
"Measure the latency" in { | ||
val promFilter: LatencyFilter = new LatencyFilter(mock[CollectorRegistry]) | ||
val fakeRequest = FakeRequest() | ||
val action = new MockController(stubControllerComponents()).ok | ||
|
||
await(promFilter(action)(fakeRequest).run()) | ||
|
||
val metrics = promFilter.requestLatency.collect() | ||
metrics must have size 1 | ||
val samples = metrics.get(0).samples | ||
|
||
val countSample = samples.get(samples.size() - 2) | ||
countSample.value mustEqual 1.0 | ||
countSample.labelValues must have size 0 | ||
} | ||
} | ||
|
||
"StatusAndRouteLatencyFilter" should { | ||
"Measure the latency and status" in { | ||
val expectedLabelCount: Long = 5 | ||
val expectedMethod = "test" | ||
val expectedStatus: String = "200" | ||
val expectedControllerName = "promController" | ||
val expectedPath = "/path" | ||
val expectedVerb = "GET" | ||
val listOfMatches = java.util.Arrays.asList(expectedMethod, expectedStatus, expectedControllerName, expectedPath, expectedVerb) | ||
|
||
|
||
val promFilter = new StatusAndRouteLatencyFilter(mock[CollectorRegistry]) | ||
val fakeRequest = FakeRequest().withAttrs( | ||
TypedMap( | ||
Router.Attrs.HandlerDef -> HandlerDef(null, | ||
null, | ||
expectedControllerName, | ||
expectedMethod, | ||
null, | ||
expectedVerb, | ||
expectedPath, | ||
null, | ||
null | ||
) | ||
) | ||
) | ||
|
||
val action = | ||
new MockController(stubControllerComponents()).ok | ||
|
||
await(promFilter(action)(fakeRequest).run()) | ||
|
||
val metrics = promFilter.requestLatency.collect() | ||
metrics must have size 1 | ||
val samples = metrics.get(0).samples | ||
val countSample = samples.get(samples.size() - 2) | ||
|
||
countSample.value mustEqual 1.0 | ||
countSample.labelValues.size mustEqual expectedLabelCount | ||
countSample.labelValues mustEqual listOfMatches | ||
} | ||
} | ||
|
||
"StatusCounterFilter" should { | ||
"Count the requests with status" in { | ||
val promFilter = new StatusCounterFilter(mock[CollectorRegistry]) | ||
val fakeRequest = FakeRequest() | ||
val actionOK = new MockController(stubControllerComponents()).ok | ||
val actionError = new MockController(stubControllerComponents()).error | ||
|
||
val bothRequests = for { | ||
ok <- promFilter(actionOK)(fakeRequest).run() | ||
ko <- promFilter(actionError)(fakeRequest).run() | ||
} yield (ok, ko) | ||
|
||
await(bothRequests) | ||
|
||
val metrics = promFilter.requestCounter.collect() | ||
metrics.size mustEqual 1 | ||
val samplesOk = metrics.get(0).samples.get(0) | ||
val samplesError = metrics.get(0).samples.get(1) | ||
|
||
samplesOk.value mustEqual 1.0 | ||
samplesOk.labelValues.size mustEqual 1 | ||
samplesOk.labelValues.get(0) mustEqual "200" | ||
|
||
samplesError.value mustEqual 1.0 | ||
samplesError.labelValues.size mustEqual 1 | ||
samplesError.labelValues.get(0) mustEqual "404" | ||
} | ||
} | ||
} | ||
|
||
class MockController @Inject() (cc: ControllerComponents) extends AbstractController(cc) { | ||
def ok = | ||
Action { | ||
Ok("ok") | ||
} | ||
|
||
def error = | ||
Action { | ||
NotFound("error") | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,4 @@ | |
# 2 / 2017 | ||
# | ||
|
||
sbt.version=1.3.8 | ||
sbt.version=1.3.13 |