Skip to content

Commit

Permalink
apply scalafmt to a few more files and ensure lint is against all lan…
Browse files Browse the repository at this point in the history
…guage versions
  • Loading branch information
hughsimpson committed Mar 4, 2024
1 parent 81f92aa commit 18cfff3
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ jobs:
- uses: actions/checkout@v1
- uses: coursier/cache-action@v6
- name: Test
run: sbt -v "scalafmtCheckAll"
run: sbt -v "+scalafmtCheckAll"

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import kanela.agent.libs.net.bytebuddy.matcher.ElementMatchers.isPublic

import scala.collection.immutable


class AkkaHttpServerInstrumentation extends InstrumentationBuilder {

/**
Expand Down Expand Up @@ -69,7 +68,10 @@ class AkkaHttpServerInstrumentation extends InstrumentationBuilder {
onType("akka.http.scaladsl.server.directives.FutureDirectives$class")
.intercept(method("onComplete"), classOf[ResolveOperationNameOnRouteInterceptor])

onTypes("akka.http.scaladsl.server.directives.OnSuccessMagnet$", "akka.http.scaladsl.server.directives.CompleteOrRecoverWithMagnet$")
onTypes(
"akka.http.scaladsl.server.directives.OnSuccessMagnet$",
"akka.http.scaladsl.server.directives.CompleteOrRecoverWithMagnet$"
)
.intercept(method("apply"), classOf[ResolveOperationNameOnRouteInterceptor])

onType("akka.http.scaladsl.server.directives.RouteDirectives$class")
Expand Down Expand Up @@ -97,12 +99,13 @@ trait HasMatchingContext {

object HasMatchingContext {

case class PathMatchingContext (
case class PathMatchingContext(
fullPath: String,
matched: Matched[_]
)

class Mixin(var matchingContext: Seq[PathMatchingContext], var defaultOperationName: String) extends HasMatchingContext {
class Mixin(var matchingContext: Seq[PathMatchingContext], var defaultOperationName: String)
extends HasMatchingContext {

override def setMatchingContext(matchingContext: Seq[PathMatchingContext]): Unit =
this.matchingContext = matchingContext
Expand Down Expand Up @@ -136,7 +139,9 @@ object ResolveOperationNameOnRouteInterceptor {
def complete[T](status: StatusCode, v: => T)(implicit m: ToEntityMarshaller[T]): StandardRoute =
StandardRoute(resolveOperationName(_).complete((status, v)))

def complete[T](status: StatusCode, headers: immutable.Seq[HttpHeader], v: => T)(implicit m: ToEntityMarshaller[T]): StandardRoute =
def complete[T](status: StatusCode, headers: immutable.Seq[HttpHeader], v: => T)(implicit
m: ToEntityMarshaller[T]
): StandardRoute =
complete((status, headers, v))

def redirect(@Argument(1) uri: Uri, @Argument(2) redirectionType: Redirection): StandardRoute =
Expand Down Expand Up @@ -185,18 +190,18 @@ object ResolveOperationNameOnRouteInterceptor {
Kamon.currentContext().get(LastAutomaticOperationNameEdit.Key).foreach(lastEdit => {
val currentSpan = Kamon.currentSpan()

if(lastEdit.allowAutomaticChanges) {
if(currentSpan.operationName() == lastEdit.operationName) {
val allMatches = requestContext.asInstanceOf[HasMatchingContext].matchingContext.reverse.map(singleMatch)
val operationName = allMatches.mkString("")
if (lastEdit.allowAutomaticChanges) {
if (currentSpan.operationName() == lastEdit.operationName) {
val allMatches = requestContext.asInstanceOf[HasMatchingContext].matchingContext.reverse.map(singleMatch)
val operationName = allMatches.mkString("")

if(operationName.nonEmpty) {
if (operationName.nonEmpty) {
currentSpan
.name(operationName)
.takeSamplingDecision()
.name(operationName)
.takeSamplingDecision()

lastEdit.operationName = operationName
}
lastEdit.operationName = operationName
}
} else {
lastEdit.allowAutomaticChanges = false
}
Expand All @@ -214,7 +219,7 @@ object ResolveOperationNameOnRouteInterceptor {
val consumedSegment = matching.fullPath.substring(0, consumedCount)

matching.matched.extractions match {
case () => //string segment matched
case () => // string segment matched
consumedSegment
case tuple: Product =>
val values = tuple.productIterator.toList map {
Expand Down Expand Up @@ -260,7 +265,9 @@ object RequestContextCopyInterceptor {
@RuntimeType
def copy(@This context: RequestContext, @SuperCall copyCall: Callable[RequestContext]): RequestContext = {
val copiedRequestContext = copyCall.call()
copiedRequestContext.asInstanceOf[HasMatchingContext].setMatchingContext(context.asInstanceOf[HasMatchingContext].matchingContext)
copiedRequestContext.asInstanceOf[HasMatchingContext].setMatchingContext(
context.asInstanceOf[HasMatchingContext].matchingContext
)
copiedRequestContext
}
}
Expand Down Expand Up @@ -288,8 +295,7 @@ object PathDirectivesRawPathPrefixInterceptor {
} flatMap {
case (ctx, Matched(rest, values)) =>
tprovide(values) & mapRequestContext(_ withUnmatchedPath rest) & mapRouteResult { routeResult =>

if(routeResult.isInstanceOf[Rejected])
if (routeResult.isInstanceOf[Rejected])
ctx.asInstanceOf[HasMatchingContext].popOneMatchingContext()

routeResult
Expand All @@ -300,7 +306,6 @@ object PathDirectivesRawPathPrefixInterceptor {
}
}


object Http2BlueprintInterceptor {

case class HandlerWithEndpoint(interface: String, port: Int, handler: HttpRequest => Future[HttpResponse])
Expand All @@ -310,8 +315,10 @@ object Http2BlueprintInterceptor {
}

@RuntimeType
def handleWithStreamIdHeader(@Argument(1) handler: HttpRequest => Future[HttpResponse],
@SuperCall zuper: Callable[Flow[HttpRequest, HttpResponse, NotUsed]]): Flow[HttpRequest, HttpResponse, NotUsed] = {
def handleWithStreamIdHeader(
@Argument(1) handler: HttpRequest => Future[HttpResponse],
@SuperCall zuper: Callable[Flow[HttpRequest, HttpResponse, NotUsed]]
): Flow[HttpRequest, HttpResponse, NotUsed] = {

handler match {
case HandlerWithEndpoint(interface, port, _) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kamon.instrumentation
package object executor {
type ScalaForkJoinPool = scala.concurrent.forkjoin.ForkJoinPool
type ScalaForkJoinPool = scala.concurrent.forkjoin.ForkJoinPool
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kamon.instrumentation
package object executor {
type ScalaForkJoinPool = java.util.concurrent.ForkJoinPool
type ScalaForkJoinPool = java.util.concurrent.ForkJoinPool
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package scala.annotation

import scala.annotation.meta._
final class static extends StaticAnnotation
final class static extends StaticAnnotation
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ object CallbackRunnableRunInstrumentation {
def enter(@Advice.This runnable: HasContext with HasTimestamp with InternalState): Scope = {
val timestamp = runnable.timestamp
val valueContext = runnable.valueBridge().asInstanceOf[HasContext].context
val context = if(valueContext.nonEmpty()) valueContext else runnable.context
val context = if (valueContext.nonEmpty()) valueContext else runnable.context

storeCurrentRunnableTimestamp(timestamp)
Kamon.storeContext(context)
Expand Down Expand Up @@ -127,4 +127,4 @@ object CopyCurrentContextToArgument {
@Advice.OnMethodEnter(suppress = classOf[Throwable])
def enter(@Advice.Argument(0) arg: Any): Unit =
arg.asInstanceOf[HasContext].setContext(Kamon.currentContext())
}
}

0 comments on commit 18cfff3

Please sign in to comment.