Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ case class SpliceMetricsFactory(
new ValidatorAppMetrics(
metricsFactoryProvider.generateMetricsFactory(metricsContext),
storageHistograms,
loggerFactory,
)
},
)
Expand All @@ -45,6 +46,7 @@ case class SpliceMetricsFactory(
new SvAppMetrics(
metricsFactoryProvider.generateMetricsFactory(metricsContext),
storageHistograms,
loggerFactory,
)
},
)
Expand All @@ -71,9 +73,9 @@ case class SpliceMetricsFactory(
new SplitwellAppMetrics(
metricsFactoryProvider.generateMetricsFactory(metricsContext),
storageHistograms,
loggerFactory,
)
},
)
}

}
11 changes: 10 additions & 1 deletion apps/common/frontend/src/api/scan/ScanClientContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ export const ScanClientProvider: React.FC<React.PropsWithChildren<ScanProps>> =
const client: openapi.ScanApi | undefined = useMemo(() => {
const configuration = openapi.createConfiguration({
baseServer: new openapi.ServerConfiguration(url, {}),
promiseMiddleware: [new OpenAPILoggingMiddleware('scan')],
promiseMiddleware: [
new OpenAPILoggingMiddleware('scan'),
{
pre: async context => {
context.setHeaderParam('x-source-ui', 'scan');
return context;
},
post: async context => context,
},
],
});

return new openapi.ScanApi(configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.daml.metrics.HealthMetrics
import com.daml.metrics.api.MetricHandle.LabeledMetricsFactory
import com.daml.metrics.api.{MetricName, MetricsContext}
import com.digitalasset.canton.environment.BaseMetrics
import com.digitalasset.canton.logging.NamedLoggerFactory
import com.digitalasset.canton.metrics.ActiveRequestsMetrics.GrpcServerMetricsX
import com.digitalasset.canton.metrics.{
DbStorageHistograms,
Expand All @@ -33,6 +34,7 @@ abstract class BaseSpliceMetrics(
nodeType: String,
override val openTelemetryMetricsFactory: LabeledMetricsFactory,
storageHistograms: DbStorageHistograms,
loggerFactory: NamedLoggerFactory,
) extends SpliceMetrics {

override val prefix = MetricName(nodeType)
Expand All @@ -48,7 +50,8 @@ abstract class BaseSpliceMetrics(
new DbStorageMetrics(storageHistograms, openTelemetryMetricsFactory)

override def httpServerMetrics: HttpServerMetrics = new HttpServerMetrics(
openTelemetryMetricsFactory
openTelemetryMetricsFactory,
loggerFactory,
)
override def httpClientMetrics: HttpClientMetrics = new HttpClientMetrics(
openTelemetryMetricsFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,29 @@ package org.lfdecentralizedtrust.splice.http
import com.daml.metrics.api.MetricHandle.LabeledMetricsFactory
import com.daml.metrics.api.MetricQualification.Latency
import com.daml.metrics.api.{MetricInfo, MetricName, MetricsContext}
import com.digitalasset.canton.logging.{NamedLoggerFactory, NamedLogging}
import com.digitalasset.canton.tracing.TraceContext
import org.apache.pekko.http.scaladsl.server.{Directive0, RouteResult}

import scala.util.{Failure, Success}

class HttpServerMetrics(metricsFactory: LabeledMetricsFactory) {
object HttpServerMetrics {
val customSourceUiHeader = "x-source-ui"
object LabelNames {
val Operation = "operation"
val Status = "status"
val StatusCode = "status_code"
val HttpService = "http_service"
val SourceUi = "source_ui"
}
}

class HttpServerMetrics(
metricsFactory: LabeledMetricsFactory,
override protected val loggerFactory: NamedLoggerFactory,
) extends NamedLogging {
import HttpServerMetrics.*
import HttpServerMetrics.LabelNames.*

private val prefix: MetricName = MetricName.Daml :+ "http"

Expand All @@ -20,8 +38,8 @@ class HttpServerMetrics(metricsFactory: LabeledMetricsFactory) {
summary = "Histogram for http request durations",
qualification = Latency,
labelsWithDescription = Map(
"operation" -> "Descriptor of the HTTP operation done, as per the OpenAPI spec",
"status" -> "Status of the HTTP request: completed, rejected, failure",
Operation -> "Descriptor of the HTTP operation done, as per the OpenAPI spec",
Status -> "Status of the HTTP request: completed, rejected, failure",
Comment on lines +41 to +42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the implications of this change? Do we need to adjust some dashboard?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no is just reusing strings

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, of course, missed that you also dropped the "", I thought you changed the label itself...

),
)
)
Expand All @@ -32,38 +50,53 @@ class HttpServerMetrics(metricsFactory: LabeledMetricsFactory) {
summary = "Count of in-flight http requests",
qualification = Latency,
labelsWithDescription = Map(
"operation" -> "Descriptor of the HTTP operation done, as per the OpenAPI spec"
Operation -> "Descriptor of the HTTP operation done, as per the OpenAPI spec"
),
)
)

// This directive is used to wrap HTTP routes with metrics collection.
// We need to pass the operation explicitly, which represents the OpenAPI operation ID.
def withMetrics(service: String)(operation: String): Directive0 = {
def withMetrics(service: String)(operation: String)(implicit tc: TraceContext): Directive0 = {
import org.apache.pekko.http.scaladsl.server.Directives.*
implicit val mc: MetricsContext =
MetricsContext("operation" -> operation, "http_service" -> service)

extractExecutionContext.flatMap { implicit ec =>
extractRequest.flatMap { _ =>
extractRequest.flatMap { req =>
val c = MetricsContext(Operation -> operation, HttpService -> service)
implicit val mc: MetricsContext = req.headers
.find(_.is(customSourceUiHeader)) // custom header added by the UI
.map { header =>
val sourceUi = header.value
logger.debug(
s"HTTP Request from UI($customSourceUiHeader: $sourceUi): service = $service, operation= $operation"
)
c.withExtraLabels(SourceUi -> sourceUi)
}
.getOrElse {
logger.debug(
s"HTTP Request no source UI header: service = $service, operation= $operation"
)
c
}

inFlightRequests.inc()
val timing = requestTiming.startAsync()
mapRouteResultFuture { resultFuture =>
resultFuture.map[RouteResult] {
case res @ RouteResult.Complete(response) =>
timing.stop()(
MetricsContext(
"status_code" -> response.status.intValue().toString,
"status" -> "completed",
StatusCode -> response.status.intValue().toString,
Status -> "completed",
)
)
res
case res @ RouteResult.Rejected(_) =>
timing.stop()(MetricsContext("status" -> "rejected"))
timing.stop()(MetricsContext(Status -> "rejected"))
res
} andThen {
case Failure(_) =>
timing.stop()(MetricsContext("status" -> "failure"))
timing.stop()(MetricsContext(Status -> "failure"))
inFlightRequests.dec()
case Success(_) =>
inFlightRequests.dec()
Expand Down
11 changes: 10 additions & 1 deletion apps/scan/frontend/src/api/TokenMetadataClientContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ export const TokenMetadataClientProvider: React.FC<React.PropsWithChildren<ScanC
const client: openapi.DefaultApi | undefined = useMemo(() => {
const configuration = openapi.createConfiguration({
baseServer: new openapi.ServerConfiguration(scanUrl, {}),
promiseMiddleware: [new OpenAPILoggingMiddleware('TokenMetadata')],
promiseMiddleware: [
new OpenAPILoggingMiddleware('TokenMetadata'),
{
pre: async context => {
context.setHeaderParam('x-source-ui', 'scan');
return context;
},
post: async context => context,
},
],
});

return new openapi.DefaultApi(configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ScanAppMetrics(
storageHistograms: DbStorageHistograms,
loggerFactory: NamedLoggerFactory,
timeouts: ProcessingTimeout,
) extends BaseSpliceMetrics("scan", metricsFactory, storageHistograms) {
) extends BaseSpliceMetrics("scan", metricsFactory, storageHistograms, loggerFactory) {
val dbScanStore = new DbScanStoreMetrics(metricsFactory, loggerFactory, timeouts)
val verdictIngestion = new ScanMediatorVerdictIngestionMetrics(metricsFactory)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.lfdecentralizedtrust.splice.splitwell.metrics

import com.daml.metrics.api.MetricHandle.LabeledMetricsFactory
import com.digitalasset.canton.logging.NamedLoggerFactory
import org.lfdecentralizedtrust.splice.BaseSpliceMetrics
import com.digitalasset.canton.metrics.DbStorageHistograms

Expand All @@ -14,4 +15,5 @@ import com.digitalasset.canton.metrics.DbStorageHistograms
class SplitwellAppMetrics(
metricsFactory: LabeledMetricsFactory,
storageHistograms: DbStorageHistograms,
) extends BaseSpliceMetrics("splitwell", metricsFactory, storageHistograms) {}
loggerFactory: NamedLoggerFactory,
) extends BaseSpliceMetrics("splitwell", metricsFactory, storageHistograms, loggerFactory) {}
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ class SvApp(
val errorHandler = new HttpErrorHandler(loggerFactory)
def buildOperation(service: String, operation: String) = {
metrics.httpServerMetrics
.withMetrics(service)(operation)
.withMetrics(service)(operation)(traceContext)
.tflatMap(_ => {
httpRateLimiter.withRateLimit(service)(operation).tflatMap { _ =>
config.parameters.customTimeouts.get(operation) match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.lfdecentralizedtrust.splice.sv.metrics

import com.daml.metrics.api.MetricHandle.LabeledMetricsFactory
import com.digitalasset.canton.logging.NamedLoggerFactory
import org.lfdecentralizedtrust.splice.BaseSpliceMetrics
import com.digitalasset.canton.metrics.DbStorageHistograms

Expand All @@ -14,4 +15,5 @@ import com.digitalasset.canton.metrics.DbStorageHistograms
class SvAppMetrics(
metricsFactory: LabeledMetricsFactory,
storageHistograms: DbStorageHistograms,
) extends BaseSpliceMetrics("sv", metricsFactory, storageHistograms) {}
loggerFactory: NamedLoggerFactory,
) extends BaseSpliceMetrics("sv", metricsFactory, storageHistograms, loggerFactory) {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.lfdecentralizedtrust.splice.validator.metrics

import com.daml.metrics.api.MetricHandle.LabeledMetricsFactory
import com.digitalasset.canton.logging.NamedLoggerFactory
import com.digitalasset.canton.metrics.DbStorageHistograms
import org.lfdecentralizedtrust.splice.BaseSpliceMetrics

Expand All @@ -12,4 +13,5 @@ import org.lfdecentralizedtrust.splice.BaseSpliceMetrics
class ValidatorAppMetrics(
metricsFactory: LabeledMetricsFactory,
storageHistograms: DbStorageHistograms,
) extends BaseSpliceMetrics("validator", metricsFactory, storageHistograms) {}
loggerFactory: NamedLoggerFactory,
) extends BaseSpliceMetrics("validator", metricsFactory, storageHistograms, loggerFactory) {}
2 changes: 1 addition & 1 deletion cluster/expected/infra/expected.json

Large diffs are not rendered by default.

Loading
Loading