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.
Add grpc server interceptor with golden metrics [PLEN-9] (digital-ass…
- Loading branch information
Showing
16 changed files
with
721 additions
and
108 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
50 changes: 50 additions & 0 deletions
50
.../src/main/scala/com/digitalasset/ledger/api/testing/utils/TestingServerInterceptors.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,50 @@ | ||
// Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.ledger.api.testing.utils | ||
|
||
import java.net.{InetAddress, InetSocketAddress} | ||
|
||
import com.daml.ledger.resources.{ResourceContext, ResourceOwner, Resource => LedgerResource} | ||
import io.grpc.netty.{NettyChannelBuilder, NettyServerBuilder} | ||
import io.grpc.{BindableService, Channel, Server, ServerInterceptor} | ||
|
||
import scala.concurrent.Future | ||
import scala.concurrent.duration.DurationInt | ||
|
||
object TestingServerInterceptors { | ||
|
||
def channelOwner( | ||
interceptor: ServerInterceptor, | ||
service: BindableService, | ||
): ResourceOwner[Channel] = { | ||
for { | ||
server <- serverOwner(interceptor, service) | ||
channel <- ResourceOwner.forChannel( | ||
NettyChannelBuilder | ||
.forAddress(new InetSocketAddress(InetAddress.getLoopbackAddress, server.getPort)) | ||
.usePlaintext(), | ||
shutdownTimeout = 5.seconds, | ||
) | ||
} yield channel | ||
} | ||
|
||
def serverOwner( | ||
interceptor: ServerInterceptor, | ||
service: BindableService, | ||
): ResourceOwner[Server] = | ||
new ResourceOwner[Server] { | ||
def acquire()(implicit context: ResourceContext): LedgerResource[Server] = | ||
LedgerResource(Future { | ||
val server = | ||
NettyServerBuilder | ||
.forAddress(new InetSocketAddress(InetAddress.getLoopbackAddress, 0)) | ||
.directExecutor() | ||
.intercept(interceptor) | ||
.addService(service) | ||
.build() | ||
server.start() | ||
server | ||
})(server => Future(server.shutdown().awaitTermination())) | ||
} | ||
} |
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
Oops, something went wrong.