-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
work around bug in EC2 query serialization when using DescribeInstances
- Loading branch information
Showing
6 changed files
with
134 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.dwolla.aws.ec2 | ||
|
||
import cats.tagless.aop.* | ||
import cats.* | ||
import com.amazonaws.ec2.* | ||
import natchez.* | ||
import com.dwolla.aws.TraceableValueInstances.given | ||
|
||
private def traceableAdvice[A: TraceableValue](name: String, a: A): Aspect.Advice[Eval, TraceableValue] = | ||
Aspect.Advice.byValue[TraceableValue, A](name, a) | ||
|
||
given Aspect[EC2, TraceableValue, TraceableValue] = new Aspect[EC2, TraceableValue, TraceableValue] { | ||
override def weave[F[_]](af: EC2[F]): EC2[[A] =>> Aspect.Weave[F, TraceableValue, TraceableValue, A]] = | ||
new EC2[[A] =>> Aspect.Weave[F, TraceableValue, TraceableValue, A]] { | ||
override def describeInstances(dryRun: Boolean, | ||
filters: Option[List[Filter]], | ||
instanceIds: Option[List[InstanceId]], | ||
nextToken: Option[String]): Aspect.Weave[F, TraceableValue, TraceableValue, DescribeInstancesResult] = | ||
Aspect.Weave[F, TraceableValue, TraceableValue, DescribeInstancesResult]( | ||
"EC2", | ||
List(List( | ||
traceableAdvice("dryRun", dryRun), | ||
traceableAdvice("filters", filters), | ||
traceableAdvice("instanceIds", instanceIds), | ||
traceableAdvice("nextToken", nextToken), | ||
)), | ||
Aspect.Advice("describeInstances", af.describeInstances(dryRun, filters, instanceIds, nextToken)) | ||
) | ||
} | ||
|
||
override def mapK[F[_], G[_]](af: EC2[F]) | ||
(fk: F ~> G): EC2[G] = | ||
new EC2[G] { | ||
override def describeInstances(dryRun: Boolean, | ||
filters: Option[List[Filter]], | ||
instanceIds: Option[List[InstanceId]], | ||
nextToken: Option[String]): G[DescribeInstancesResult] = | ||
fk(af.describeInstances(dryRun, filters, instanceIds, nextToken)) | ||
} | ||
} |
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
75 changes: 75 additions & 0 deletions
75
registrator-health-check/src/test/scala/com/dwolla/autoscaling/ecs/registrator/TestApp.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,75 @@ | ||
package com.dwolla.autoscaling.ecs.registrator | ||
|
||
import cats.* | ||
import cats.effect.* | ||
import cats.effect.std.Console | ||
import cats.mtl.Local | ||
import cats.syntax.all.* | ||
import com.amazonaws.ec2.* | ||
import com.dwolla.aws.ec2.{*, given} | ||
import com.dwolla.tracing.mtl.LocalSpan | ||
import com.dwolla.tracing.syntax.* | ||
import com.dwolla.tracing.{DwollaEnvironment, OpenTelemetryAtDwolla} | ||
import natchez.Span | ||
import natchez.mtl.given | ||
import org.http4s.* | ||
import org.http4s.client.{Client, middleware} | ||
import org.http4s.ember.client.EmberClientBuilder | ||
import org.typelevel.log4cats.* | ||
import smithy4s.aws.* | ||
import smithy4s.aws.kernel.AwsRegion | ||
|
||
object TestApp extends ResourceApp.Simple { | ||
private val id = InstanceId("i-04d30e1ebb1109aa2") | ||
override def run: Resource[IO, Unit] = | ||
OpenTelemetryAtDwolla[IO]("ecs-autoscaling-scale-out-hook", DwollaEnvironment.Local) | ||
.flatMap(_.root("EC2 Test App")) | ||
.evalMap(LocalSpan(_)) | ||
.flatMap { case given Local[IO, Span[IO]] => | ||
given LoggerFactory[IO] = new ConsoleLogger[IO] | ||
|
||
EmberClientBuilder.default[IO].build | ||
.map(middleware.Logger(true, true, logAction = (IO.println(_: String)).some)) | ||
.flatMap(AwsEnvironment.default(_, AwsRegion.US_WEST_2)) | ||
.flatMap(AwsClient(EC2, _)) | ||
.map(_.traceWithInputsAndOutputs) | ||
.map(Ec2Alg(_)) | ||
.evalTap(_ => IO.println("using client via Ec2Alg")) | ||
.evalTap(_.getTagsForInstance(id) >>= IO.println) | ||
.void | ||
} | ||
|
||
} | ||
|
||
class ConsoleLogger[F[_] : Applicative : Console] extends LoggerFactory[F] { | ||
override def getLoggerFromName(name: String): SelfAwareStructuredLogger[F] = | ||
new SelfAwareStructuredLogger[F] { | ||
override def isTraceEnabled: F[Boolean] = true.pure[F] | ||
override def isDebugEnabled: F[Boolean] = true.pure[F] | ||
override def isInfoEnabled: F[Boolean] = true.pure[F] | ||
override def isWarnEnabled: F[Boolean] = true.pure[F] | ||
override def isErrorEnabled: F[Boolean] = true.pure[F] | ||
override def trace(ctx: Map[String, String])(msg: => String): F[Unit] = Console[F].println(msg) | ||
override def trace(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] = Console[F].println(msg) | ||
override def debug(ctx: Map[String, String])(msg: => String): F[Unit] = Console[F].println(msg) | ||
override def debug(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] = Console[F].println(msg) | ||
override def info(ctx: Map[String, String])(msg: => String): F[Unit] = Console[F].println(msg) | ||
override def info(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] = Console[F].println(msg) | ||
override def warn(ctx: Map[String, String])(msg: => String): F[Unit] = Console[F].println(msg) | ||
override def warn(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] = Console[F].println(msg) | ||
override def error(ctx: Map[String, String])(msg: => String): F[Unit] = Console[F].println(msg) | ||
override def error(ctx: Map[String, String], t: Throwable)(msg: => String): F[Unit] = Console[F].println(msg) | ||
override def error(t: Throwable)(message: => String): F[Unit] = Console[F].println(message) | ||
override def warn(t: Throwable)(message: => String): F[Unit] = Console[F].println(message) | ||
override def info(t: Throwable)(message: => String): F[Unit] = Console[F].println(message) | ||
override def debug(t: Throwable)(message: => String): F[Unit] = Console[F].println(message) | ||
override def trace(t: Throwable)(message: => String): F[Unit] = Console[F].println(message) | ||
override def error(message: => String): F[Unit] = Console[F].println(message) | ||
override def warn(message: => String): F[Unit] = Console[F].println(message) | ||
override def info(message: => String): F[Unit] = Console[F].println(message) | ||
override def debug(message: => String): F[Unit] = Console[F].println(message) | ||
override def trace(message: => String): F[Unit] = Console[F].println(message) | ||
} | ||
override def fromName(name: String): F[SelfAwareStructuredLogger[F]] = | ||
getLoggerFromName(name).pure[F] | ||
} |
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