forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sandbox: Capture timing metrics for API server calls. (digital-asset#…
…5145) * sandbox: Capture timing metrics for API server calls. `timer` is a superset of `meter`, so this doesn't lose any existing behavior; just adds new behavior. CHANGELOG_BEGIN - [Ledger API Server] Added timing metrics for all GRPC endpoints. CHANGELOG_END * sandbox: Rename SandboxClientResource to GrpcClientResource. * sample-service: Clean up warnings. * sandbox: Add tests for MetricsInterceptor. * sandbox: Split the API metrics interceptor from the naming. * sandbox: Use `MetricRegistry.name` instead of string interpolation. * rs-grpc-akka: Restrict the test library to the DAML workspace. Co-Authored-By: Stefano Baghino <43749967+stefanobaghino-da@users.noreply.github.com> Co-authored-by: Stefano Baghino <43749967+stefanobaghino-da@users.noreply.github.com>
- Loading branch information
1 parent
2c0627c
commit bfe27d2
Showing
14 changed files
with
286 additions
and
131 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
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
51 changes: 51 additions & 0 deletions
51
ledger/sandbox/src/main/scala/com/digitalasset/platform/apiserver/MetricsNaming.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,51 @@ | ||
// Copyright (c) 2020 The DAML Authors. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.digitalasset.platform.apiserver | ||
|
||
import com.codahale.metrics.MetricRegistry | ||
|
||
object MetricsNaming { | ||
|
||
private[this] val capitalization = "[A-Z]+".r | ||
private[this] val startWordCapitalization = "^[A-Z]+".r | ||
private[this] val endWordAcronym = "[A-Z]{2,}$".r | ||
|
||
private[this] val snakifyWholeWord = (s: String) => if (s.forall(_.isUpper)) s.toLowerCase else s | ||
|
||
private[this] val snakify = (s: String) => | ||
capitalization.findAllMatchIn(s).foldRight(s) { (m, r) => | ||
val s = m.toString | ||
if (s.length == 1) r.patch(m.start, s"_${s.toLowerCase}", 1) | ||
else r.patch(m.start, s"_${s.init.toLowerCase}_${s.last.toLower}", s.length) | ||
} | ||
|
||
private[this] val snakifyStart = (s: String) => | ||
startWordCapitalization.findFirstIn(s).fold(s) { m => | ||
s.patch( | ||
0, | ||
if (m.length == 1) m.toLowerCase else m.init.toLowerCase, | ||
math.max(m.length - 1, 1)) | ||
} | ||
|
||
private[this] val snakifyEnd = (s: String) => | ||
endWordAcronym.findFirstIn(s).fold(s) { m => | ||
s.patch(s.length - m.length, s"_${m.toLowerCase}", m.length) | ||
} | ||
|
||
// Turns a camelCased string into a snake_cased one | ||
private[apiserver] val camelCaseToSnakeCase: String => String = | ||
snakifyWholeWord andThen snakifyStart andThen snakifyEnd andThen snakify | ||
|
||
// assert(fullServiceName("org.example.SomeService/someMethod") == "daml.lapi.some_service.some_method") | ||
private[apiserver] def nameFor(fullMethodName: String): String = { | ||
val serviceAndMethodName = fullMethodName.split('/') | ||
assert( | ||
serviceAndMethodName.length == 2, | ||
s"Expected service and method names separated by '/', got '$fullMethodName'") | ||
val serviceName = camelCaseToSnakeCase(serviceAndMethodName(0).split('.').last) | ||
val methodName = camelCaseToSnakeCase(serviceAndMethodName(1)) | ||
MetricRegistry.name("daml", "lapi", serviceName, methodName) | ||
} | ||
|
||
} |
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
Oops, something went wrong.