-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Smithy4s Kinesis Client #36
Conversation
@kubukoz per our convo, I tried setting up a client using smithy4s, but ran into a few weird bugs with the build. Mostly, I've been dealing with using a subset of scala versions in the smithy project as smithy4s is only publishing Scala 2.13/Scala 3 artifacts, so I am poorly attempting to use sbt-projectmatrix as well. But also, I ran into this when compiling on scala 2.13 versions:
|
project/Kinesis4CatsPlugin.scala
Outdated
) | ||
}) | ||
} | ||
|
||
final implicit class Kinesi4catsProjectOps(private val p: Project) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi: typo in class name
Never seen that before I think... perhaps @Baccata will have more insight. I know there was talk of removing the rules engine traits from the model before loading, and in general smithy4s will eventually make it easier to use AWS specs. disneystreaming/smithy4s#674 (comment) and that general thread may have more useful context |
I ran that in sbt as Additionally it'd be great to minimize any issue you encounter with smithy4s, as your build is pretty big and there could be multiple things at play |
if you do manage to hit this again, can you try with a local snapshot of smithy4s from the |
Thanks for looking into it @kubukoz ! I'll be out of pocket today but I'll see if I can get this PR cleaned up and reproduce the same. And yes, I'll try the new version as well! |
@etspaceman don't bother trying a snapshot, it does fix the bug you're currently encountering but another unrelated bug was introduce which leads the generated code for the |
Here's a fix to the newly introduced bug I'm talking about : disneystreaming/smithy4s#789 |
OK PR is cleaned up with clean reproduce, you should be able to get this via doing
|
I can't see it with just
Updating to a local snapshot of disneystreaming/smithy4s#789 seems to make it work. |
.scalafix.conf
Outdated
@@ -1,4 +1,4 @@ | |||
rules = [DisableSyntax, NoValInForComprehension, ProcedureSyntax, OrganizeImports] | |||
rules = [DisableSyntax, NoValInForComprehension, OrganizeImports] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sbt-projectmatrix added the impact of having scalafmt/scalafix operations run for each project inside of the matrix, including scala 3. These updates allow us to run it on scala 3.
"com.amazonaws.kinesis" | ||
) | ||
) | ||
.jvmPlatform(last2ScalaVersions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brought in sbt-projectmatrix to work through having a subset of scala versions supported here (Smithy4s AWS does not have a 2.12 offering)
@@ -140,7 +140,7 @@ object DockerComposePlugin extends AutoPlugin { | |||
configuration: Configuration, | |||
build: Boolean, | |||
projects: List[Project] | |||
): Seq[Setting[_]] = | |||
): Seq[Setting[_]] = inConfig(configuration)( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes the integration tests always targeting the functional test file...
@@ -186,6 +186,17 @@ object Kinesis4CatsPlugin extends AutoPlugin { | |||
Test / testOptions ++= { | |||
List(Tests.Argument(MUnitFramework, "+l")) | |||
}, | |||
scalacOptions ++= { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import kinesis4cats.smithy4s.client.KinesisClient | ||
import kinesis4cats.smithy4s.client.middleware._ | ||
|
||
object LocalstackKinesisClient { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation here is almost identical to the KinesisClient, except it adds an additional middleware to proxy the request, as well as uses some mock credentials.
val http4sResponseLogEncoder: LogEncoder[Response[F]] | ||
) | ||
|
||
def apply[F[_]]( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very simple implementation. Basically the provided generated client from Smithy4s with some middleware to add standard logging.
|
||
import kinesis4cats.logging.LogContext | ||
|
||
object RequestLogger { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly copied this from http4s. The http4s implementation records the requests and responses as a part of the message. This one will encode them as a part of the context, per the structured logging desires.
`trait`.toShapeId() == LengthTrait.ID && | ||
shape.toShapeId() == metricsNameListShapeId | ||
) { | ||
LengthTrait.builder().min(0).max(7).build() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually this is 1-7. Set to 0-7
IntegerShape | ||
.builder() | ||
.id( | ||
ShapeId.fromParts("com.amazonaws.kinesis", "NonNegativeIntegerObject") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Counterpart to PositiveIntegerObject
`trait`.toShapeId() == LengthTrait.ID && | ||
shape.toShapeId() == metricsNameListShapeId | ||
) { | ||
LengthTrait.builder().min(0).max(7).build() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty responses are possible, this seems to be a bug w/ the smithy file
`trait` | ||
.asInstanceOf[DocumentationTrait] // scalafix:ok | ||
.getValue() | ||
.replace("ListStreamConsumersInput$NextToken", "NextToken") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dollar sign is not valid for scaladoc, so we replace it here.
`trait` | ||
.asInstanceOf[DocumentationTrait] // scalafix:ok | ||
.getValue() | ||
.replace("ListShardsInput$NextToken", "NextToken") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (memberName == "FailedRecordCount") | ||
MemberShape | ||
.builder() | ||
.target(nonNegativeIntegerObjectShape.getId()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FailedRecordCount can be 0. This is a bug with smithy
Changes Introduced
Introduces a Smithy4s Kinesis Client implementation, bundled with logs and localstack support. Important decisions:
Applicable linked issues
#17 #16
Checklist (check all that apply)