Skip to content

Commit

Permalink
Merge pull request #54 from craigatk/counters
Browse files Browse the repository at this point in the history
(feature) Adding counters for successful and failed results processing
  • Loading branch information
craigatk authored Apr 7, 2020
2 parents 9eafe69 + fa3ff0f commit 880989f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class GroupedTestResultsService(

private val coroutineScope = CoroutineScope(Dispatchers.IO)

private val resultsProcessSuccessCounter = metricRegistry.counter("grouped_results_process_success")
private val resultsProcessFailureCounter = metricRegistry.counter("grouped_results_process_failure")

suspend fun persistTestResultsAsync(groupedResultsBlob: String): PublicId {
val publicId = randomPublicId()
val timer = metricRegistry.timer("persist_grouped_results")
Expand All @@ -41,9 +44,12 @@ class GroupedTestResultsService(
testRunRepository.saveGroupedTestRun(publicId, groupedResults)

testResultsProcessingService.updateResultsProcessingStatus(publicId, ResultsProcessingStatus.SUCCESS)

resultsProcessSuccessCounter.increment()
} catch (e: Exception) {
val errorMessage = "Error persisting test results: ${e.message}"
handleException(publicId, groupedResultsBlob, errorMessage, e)
resultsProcessFailureCounter.increment()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ fun Route.results(
authService: AuthService,
metricRegistry: MeterRegistry
) {
val groupedResultsSuccessCounter = metricRegistry.counter("routes_grouped_results_success")

post("/results") {
if (!authService.isAuthValid(call.request.header(AuthConfig.PublishToken))) {
call.respond(HttpStatusCode.Unauthorized)
Expand All @@ -60,6 +62,7 @@ fun Route.results(

if (groupedResultsBlob.isNotBlank()) {
val publicId = groupedTestResultsService.persistTestResultsAsync(groupedResultsBlob)
groupedResultsSuccessCounter.increment()

call.respond(HttpStatusCode.OK, SaveResultsResponse(publicId.id, "/tests/${publicId.id}"))
} else {
Expand Down

0 comments on commit 880989f

Please sign in to comment.