-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Empty GRPC Metering Report Service [DPP-856] (#12515)
* With mock metering service * Reformat changelog_begin changelog_end * Include nanos in generation time * Update with review comments * Update service count
- Loading branch information
1 parent
4d26f08
commit cbb4986
Showing
7 changed files
with
119 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
38 changes: 38 additions & 0 deletions
38
.../scala/com/digitalasset/ledger/api/auth/services/MeteringReportServiceAuthorization.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,38 @@ | ||
// 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.auth.services | ||
|
||
import com.daml.ledger.api.auth.Authorizer | ||
import com.daml.ledger.api.v1.admin.metering_report_service.MeteringReportServiceGrpc.MeteringReportService | ||
import com.daml.ledger.api.v1.admin.metering_report_service.{ | ||
GetMeteringReportRequest, | ||
GetMeteringReportResponse, | ||
MeteringReportServiceGrpc, | ||
} | ||
import com.daml.platform.api.grpc.GrpcApiService | ||
import com.daml.platform.server.api.ProxyCloseable | ||
import io.grpc.ServerServiceDefinition | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
private[daml] final class MeteringReportServiceAuthorization( | ||
protected val service: MeteringReportService with AutoCloseable, | ||
private val authorizer: Authorizer, | ||
)(implicit executionContext: ExecutionContext) | ||
extends MeteringReportService | ||
with ProxyCloseable | ||
with GrpcApiService { | ||
|
||
override def getMeteringReport( | ||
request: GetMeteringReportRequest | ||
): Future[GetMeteringReportResponse] = { | ||
authorizer.requireAdminClaims(service.getMeteringReport)(request) | ||
} | ||
|
||
override def bindService(): ServerServiceDefinition = | ||
MeteringReportServiceGrpc.bindService(this, executionContext) | ||
|
||
override def close(): Unit = service.close() | ||
|
||
} |
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
47 changes: 47 additions & 0 deletions
47
...integration-api/src/main/scala/platform/apiserver/services/ApiMeteringReportService.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,47 @@ | ||
// Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.platform.apiserver.services | ||
|
||
import com.daml.ledger.api.v1.admin.metering_report_service.MeteringReportServiceGrpc.MeteringReportService | ||
import com.daml.ledger.api.v1.admin.metering_report_service._ | ||
import com.daml.logging.{ContextualizedLogger, LoggingContext} | ||
import com.daml.platform.api.grpc.GrpcApiService | ||
import io.grpc.ServerServiceDefinition | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
private[apiserver] final class ApiMeteringReportService()(implicit | ||
executionContext: ExecutionContext, | ||
loggingContext: LoggingContext, | ||
) extends MeteringReportService | ||
with GrpcApiService { | ||
|
||
private implicit val logger: ContextualizedLogger = ContextualizedLogger.get(this.getClass) | ||
|
||
override def bindService(): ServerServiceDefinition = | ||
MeteringReportServiceGrpc.bindService(this, executionContext) | ||
|
||
override def close(): Unit = () | ||
|
||
override def getMeteringReport( | ||
request: GetMeteringReportRequest | ||
): Future[GetMeteringReportResponse] = { | ||
logger.info(s"Received metering report request: $request") | ||
val now = java.time.Instant.now() | ||
val generationTime = | ||
com.google.protobuf.timestamp.Timestamp.of(now.getEpochSecond, now.getNano) | ||
val participantReport = ParticipantMeteringReport( | ||
participantId = "participant1", | ||
request.to.orElse(Some(generationTime)), | ||
Seq( | ||
ApplicationMeteringReport("app1", 100), | ||
ApplicationMeteringReport("app2", 200), | ||
), | ||
) | ||
val response = | ||
GetMeteringReportResponse(Some(request), Some(participantReport), Some(generationTime)) | ||
Future.successful(response).andThen(logger.logErrorsOnCall[GetMeteringReportResponse]) | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
ledger/sandbox-classic/src/test/suite/scala/platform/sandbox/auth/MeteringReportAuthIT.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,22 @@ | ||
// Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml | ||
package platform.sandbox.auth | ||
|
||
import com.daml.ledger.api.v1.admin.metering_report_service.{ | ||
GetMeteringReportRequest, | ||
MeteringReportServiceGrpc, | ||
} | ||
|
||
import scala.concurrent.Future | ||
|
||
final class MeteringReportAuthIT extends AdminServiceCallAuthTests { | ||
|
||
override def serviceCallName: String = "MeteringReportService#GetMeteringReport" | ||
|
||
override def serviceCallWithToken(token: Option[String]): Future[Any] = | ||
stub(MeteringReportServiceGrpc.stub(channel), token) | ||
.getMeteringReport(GetMeteringReportRequest(None, None)) | ||
|
||
} |
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