Skip to content

Commit f3362ec

Browse files
authored
Merge branch 'main' into wip-periodic-client-discovery-refresh
2 parents fa493c6 + 7cf311f commit f3362ec

File tree

9 files changed

+55
-27
lines changed

9 files changed

+55
-27
lines changed

benchmark-java/build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ run / javaOptions ++= List("-Xms1g", "-Xmx1g", "-XX:+PrintGCDetails", "-XX:+Prin
99
// generate both client and server (default) in Java
1010
akkaGrpcGeneratedLanguages := Seq(AkkaGrpc.Java)
1111

12-
val grpcVersion = "1.60.0" // checked synced by VersionSyncCheckPlugin
12+
val grpcVersion = "1.60.2" // checked synced by VersionSyncCheckPlugin
1313

1414
val runtimeProject = ProjectRef(file("../"), "akka-grpc-runtime")
1515

gradle-plugin/src/main/groovy/akka/grpc/gradle/AkkaGrpcPluginExtension.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class AkkaGrpcPluginExtension {
99

1010
static final String PROTOC_PLUGIN_SCALA_VERSION = "2.12"
1111

12-
static final String GRPC_VERSION = "1.60.0" // checked synced by VersionSyncCheckPlugin
12+
static final String GRPC_VERSION = "1.60.2" // checked synced by VersionSyncCheckPlugin
1313

1414
static final String PLUGIN_CODE = 'com.lightbend.akka.grpc.gradle'
1515

plugin-tester-java/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<maven-exec-plugin.version>3.0.0</maven-exec-plugin.version>
1717
<akka.http.cors.version>1.1.0</akka.http.cors.version>
1818
<akka.version>2.9.1</akka.version>
19-
<grpc.version>1.60.0</grpc.version> <!-- checked synced by VersionSyncCheckPlugin -->
19+
<grpc.version>1.60.2</grpc.version> <!-- checked synced by VersionSyncCheckPlugin -->
2020
<project.encoding>UTF-8</project.encoding>
2121
<build-helper-maven-plugin>3.3.0</build-helper-maven-plugin>
2222
<protobuf-java.version>3.22.2</protobuf-java.version>

plugin-tester-scala/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<maven.compiler.release>11</maven.compiler.release>
1515
<akka.version>2.9.1</akka.version>
1616
<akka.http.cors.version>0.4.2</akka.http.cors.version>
17-
<grpc.version>1.60.0</grpc.version> <!-- checked synced by VersionSyncCheckPlugin -->
17+
<grpc.version>1.60.2</grpc.version> <!-- checked synced by VersionSyncCheckPlugin -->
1818
<project.encoding>UTF-8</project.encoding>
1919
</properties>
2020

project/Dependencies.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ object Dependencies {
2222
val akkaHttp = "10.6.0"
2323
val akkaHttpBinary = "10.6"
2424

25-
val grpc = "1.60.0" // checked synced by VersionSyncCheckPlugin
25+
val grpc = "1.60.2" // checked synced by VersionSyncCheckPlugin
2626

2727
// Even referenced explicitly in the sbt-plugin's sbt-tests
2828
// If changing this, remember to update protoc plugin version to align in
2929
// maven-plugin/src/main/maven/plugin.xml and akka.grpc.sbt.AkkaGrpcPlugin
3030
val googleProtobuf = "3.24.0" // checked synced by VersionSyncCheckPlugin
31-
val googleApi = "2.30.0"
31+
val googleApi = "2.34.0"
3232

3333
val scalaTest = "3.2.12"
3434

project/plugins.sbt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
enablePlugins(BuildInfoPlugin)
22

3-
val sbtProtocV = "1.0.6"
3+
val sbtProtocV = "1.0.7"
44

55
buildInfoKeys := Seq[BuildInfoKey]("sbtProtocVersion" -> sbtProtocV)
66

@@ -29,4 +29,4 @@ libraryDependencies += "org.eclipse.jgit" % "org.eclipse.jgit" % "5.13.3.2024011
2929
// scripted testing
3030
libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
3131

32-
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.14"
32+
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.15"

runtime/src/main/scala/akka/grpc/internal/AkkaHttpClientUtils.scala

+18-11
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import akka.annotation.InternalApi
1414
import akka.event.LoggingAdapter
1515
import akka.grpc.GrpcProtocol.GrpcProtocolReader
1616
import akka.grpc.{ GrpcClientSettings, GrpcResponseMetadata, GrpcSingleResponse, ProtobufSerializer }
17+
import akka.grpc.scaladsl.StringEntry
1718
import akka.http.scaladsl.model.HttpEntity.{ Chunk, Chunked, LastChunk, Strict }
1819
import akka.http.scaladsl.{ ClientTransport, ConnectionContext, Http }
19-
import akka.http.scaladsl.model.{ AttributeKey, HttpHeader, HttpRequest, HttpResponse, RequestResponseAssociation, Uri }
20+
import akka.http.scaladsl.model._
2021
import akka.http.scaladsl.settings.ClientConnectionSettings
2122
import akka.stream.{ Materializer, OverflowStrategy }
2223
import akka.stream.scaladsl.{ Keep, Sink, Source }
@@ -220,7 +221,11 @@ object AkkaHttpClientUtils {
220221
.watchTermination()((_, done) =>
221222
done.onComplete(_ => trailerPromise.trySuccess(immutable.Seq.empty)))
222223
case Strict(_, data) =>
223-
trailerPromise.success(immutable.Seq.empty)
224+
val rawTrailers = response.attribute(AttributeKeys.trailer).map(_.headers).getOrElse(Seq.empty)
225+
val trailers = rawTrailers.map(h => HttpHeader.parse(h._1, h._2)).collect {
226+
case HttpHeader.ParsingResult.Ok(header, _) => header
227+
}
228+
trailerPromise.success(trailers)
224229
Source.single[ByteString](data)
225230
case _ =>
226231
response.entity.discardBytes()
@@ -281,19 +286,21 @@ object AkkaHttpClientUtils {
281286
response: HttpResponse,
282287
trailers: Seq[HttpHeader]): StatusRuntimeException = {
283288
val allHeaders = response.headers ++ trailers
289+
val metadata: io.grpc.Metadata =
290+
new MetadataImpl(allHeaders.map(h => (h.name, StringEntry(h.value))).toList).toGoogleGrpcMetadata()
284291
allHeaders.find(_.name == "grpc-status").map(_.value) match {
285292
case None =>
286-
new StatusRuntimeException(
287-
mapHttpStatus(response)
288-
.withDescription("No grpc-status found")
289-
.augmentDescription(s"When calling rpc service: ${requestUri.toString()}"))
293+
val status = mapHttpStatus(response)
294+
.withDescription("No grpc-status found")
295+
.augmentDescription(s"When calling rpc service: ${requestUri.toString()}")
296+
new StatusRuntimeException(status, metadata)
290297
case Some(statusCode) =>
291298
val description = allHeaders.find(_.name == "grpc-message").map(_.value)
292-
new StatusRuntimeException(
293-
Status
294-
.fromCodeValue(statusCode.toInt)
295-
.withDescription(description.orNull)
296-
.augmentDescription(s"When calling rpc service: ${requestUri.toString()}"))
299+
val status = Status
300+
.fromCodeValue(statusCode.toInt)
301+
.withDescription(description.orNull)
302+
.augmentDescription(s"When calling rpc service: ${requestUri.toString()}")
303+
new StatusRuntimeException(status, metadata)
297304
}
298305
}
299306

runtime/src/test/scala/akka/grpc/internal/AkkaHttpClientUtilsSpec.scala

+26-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ package akka.grpc.internal
77
import scala.concurrent.Future
88
import scala.concurrent.duration._
99
import akka.actor.ActorSystem
10+
import akka.http.scaladsl.model._
1011
import akka.http.scaladsl.model.HttpEntity.Strict
11-
import akka.http.scaladsl.model.HttpResponse
1212
import akka.http.scaladsl.model.StatusCodes._
13-
import akka.http.scaladsl.model.Uri
1413
import akka.http.scaladsl.model.headers.RawHeader
1514
import akka.testkit.TestKit
1615
import akka.util.ByteString
17-
import io.grpc.{ Status, StatusRuntimeException }
16+
import io.grpc.{ Metadata, Status, StatusRuntimeException }
1817
import org.scalatest.concurrent.ScalaFutures
1918
import org.scalatest.matchers.should.Matchers
2019
import org.scalatest.time.Span
@@ -41,12 +40,35 @@ class AkkaHttpClientUtilsSpec extends TestKit(ActorSystem()) with AnyWordSpecLik
4140

4241
"map a strict 200 response with non-0 gRPC error code to a failed stream" in {
4342
val requestUri = Uri("https://example.com/GuestExeSample/GrpcHello")
43+
val responseHeaders = List(RawHeader("grpc-status", "9"), RawHeader("custom-key", "custom-value-in-header"))
44+
val response =
45+
Future.successful(HttpResponse(OK, responseHeaders, Strict(GrpcProtocolNative.contentType, ByteString.empty)))
46+
val source = AkkaHttpClientUtils.responseToSource(requestUri, response, null, false)
47+
48+
val failure = source.run().failed.futureValue
49+
failure.asInstanceOf[StatusRuntimeException].getStatus.getCode should be(Status.Code.FAILED_PRECONDITION)
50+
failure.asInstanceOf[StatusRuntimeException].getTrailers.get(key) should be("custom-value-in-header")
51+
}
52+
53+
"map a strict 200 response with non-0 gRPC error code with a trailer to a failed stream with trailer metadata" in {
54+
val requestUri = Uri("https://example.com/GuestExeSample/GrpcHello")
55+
val responseHeaders = List(RawHeader("grpc-status", "9"))
56+
val responseTrailers = Trailer(RawHeader("custom-key", "custom-trailer-value") :: Nil)
4457
val response = Future.successful(
45-
HttpResponse(OK, List(RawHeader("grpc-status", "9")), Strict(GrpcProtocolNative.contentType, ByteString.empty)))
58+
new HttpResponse(
59+
OK,
60+
responseHeaders,
61+
Map.empty[AttributeKey[_], Any].updated(AttributeKeys.trailer, responseTrailers),
62+
Strict(GrpcProtocolNative.contentType, ByteString.empty),
63+
HttpProtocols.`HTTP/1.1`))
4664
val source = AkkaHttpClientUtils.responseToSource(requestUri, response, null, false)
4765

4866
val failure = source.run().failed.futureValue
4967
failure.asInstanceOf[StatusRuntimeException].getStatus.getCode should be(Status.Code.FAILED_PRECONDITION)
68+
failure.asInstanceOf[StatusRuntimeException].getTrailers should not be null
69+
failure.asInstanceOf[StatusRuntimeException].getTrailers.get(key) should be("custom-trailer-value")
5070
}
71+
72+
lazy val key = Metadata.Key.of("custom-key", Metadata.ASCII_STRING_MARSHALLER)
5173
}
5274
}

sbt-plugin/src/sbt-test/gen-scala-server/00-interop/build.sbt

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ resolvers += "Akka library repository".at("https://repo.akka.io/maven")
44

55
organization := "com.lightbend.akka.grpc"
66

7-
val grpcVersion = "1.60.0" // checked synced by VersionSyncCheckPlugin
7+
val grpcVersion = "1.60.2" // checked synced by VersionSyncCheckPlugin
88

99
libraryDependencies ++= Seq(
1010
"io.grpc" % "grpc-interop-testing" % grpcVersion % "protobuf-src",
@@ -26,9 +26,8 @@ enablePlugins(AkkaGrpcPlugin)
2626
PB.generate / excludeFilter := new SimpleFileFilter((f: File) =>
2727
f.getAbsolutePath.endsWith("google/protobuf/descriptor.proto") ||
2828
f.getAbsolutePath.endsWith("google/protobuf/empty.proto") ||
29-
// grpc-interop pulls in proto files with unfulfilled transitive deps it seems, so skip them as well
30-
f.getParent.contains("envoy")
31-
)
29+
// grpc-interop pulls in proto files with unfulfilled transitive deps it seems, so skip them as well
30+
f.getParent.contains("envoy"))
3231

3332
//#sources-both
3433
// This is the default - both client and server

0 commit comments

Comments
 (0)