Skip to content

Commit

Permalink
Set ErrorInfo metadata flag for definite_answer [KVL-1005] (#10583)
Browse files Browse the repository at this point in the history
* Set ErrorInfo metadata flag for definite_answer, which is propagated from the completion status

CHANGELOG_BEGIN
ledger-api-client - Propagate definite_answer as metadata in the GRPC response for submit/submitAndWait
CHANGELOG_END

* Keep alphabetical order for bazel build files

* Add test for inclusion of metadata

* Formatting
  • Loading branch information
nicu-da authored Aug 16, 2021
1 parent 147e8f2 commit cc37bc3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
4 changes: 4 additions & 0 deletions ledger/ledger-api-client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ da_scala_library(
"//ledger/ledger-api-auth-client",
"//ledger/ledger-api-common",
"//ledger/ledger-api-domain",
"//ledger/ledger-grpc",
"//ledger/ledger-resources",
"//ledger/metrics",
"//libs-scala/concurrent",
Expand Down Expand Up @@ -84,8 +85,11 @@ da_scala_test_suite(
"//ledger-api/rs-grpc-bridge",
"//ledger-api/testing-utils",
"//ledger/caching",
"//ledger/ledger-grpc",
"//ledger/metrics",
"//libs-scala/concurrent",
"@maven//:com_google_api_grpc_proto_google_common_protos",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:io_dropwizard_metrics_metrics_core",
"@maven//:org_mockito_mockito_core",
"@maven//:org_reactivestreams_reactive_streams",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.daml.ledger.client.services.commands.tracker

import com.daml.ledger.api.v1.completion.Completion
import com.daml.ledger.grpc.GrpcStatuses
import com.google.protobuf.Any
import com.google.rpc
import com.google.rpc.status.{Status => StatusProto}
Expand All @@ -20,7 +21,11 @@ object CompletionResponse {
def metadata: Map[String, String] = Map.empty
}
final case class NotOkResponse(commandId: String, grpcStatus: StatusProto)
extends CompletionFailure
extends CompletionFailure {
override def metadata: Map[String, String] = Map(
GrpcStatuses.DefiniteAnswerKey -> GrpcStatuses.isDefiniteAnswer(grpcStatus).toString
)
}
final case class TimeoutResponse(commandId: String) extends CompletionFailure
final case class NoStatusInResponse(commandId: String) extends CompletionFailure

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
package com.daml.ledger.client.services.commands.tracker

import com.daml.ledger.api.v1.completion.Completion
import com.daml.ledger.client.services.commands.tracker.CompletionResponse.{
NoStatusInResponse,
NotOkResponse,
QueueCompletionFailure,
QueueSubmitFailure,
TimeoutResponse,
}
import com.daml.ledger.client.services.commands.tracker.CompletionResponse._
import com.daml.ledger.grpc.GrpcStatuses
import com.google.protobuf.any.Any
import com.google.rpc.error_details.ErrorInfo
import com.google.rpc.{ErrorInfo => JavaErrorInfo}
import com.google.rpc.status.Status
import io.grpc
import io.grpc.Status.Code
import io.grpc.Status.Code.OK
import io.grpc.protobuf
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

Expand Down Expand Up @@ -83,6 +81,30 @@ class CompletionResponseTest extends AnyWordSpec with Matchers {
exception.getStatus.getCode shouldBe Code.RESOURCE_EXHAUSTED
}

"include metadata for status not ok" in {
val errorInfo = ErrorInfo(
metadata = Map(GrpcStatuses.DefiniteAnswerKey -> "true")
)
val exception = CompletionResponse.toException(
QueueCompletionFailure(
NotOkResponse(
commandId,
Status(
Code.CANCELLED.value(),
details = Seq(
Any.pack(
errorInfo
)
),
),
)
)
)
val status = protobuf.StatusProto.fromThrowable(exception)
val packedErrorInfo = status.getDetails(0).unpack(classOf[JavaErrorInfo])
packedErrorInfo.getMetadataOrThrow(GrpcStatuses.DefiniteAnswerKey) shouldEqual "true"
}

}
}
}

0 comments on commit cc37bc3

Please sign in to comment.