Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsimpson committed Mar 2, 2024
1 parent a494d5a commit 022216d
Show file tree
Hide file tree
Showing 385 changed files with 5,988 additions and 4,232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ object Attacher {
*/
private def isKanelaLoaded(): Boolean = {
val isLoadedProperty = java.lang.Boolean.parseBoolean(System.getProperty("kanela.loaded"))
val hasKanelaClasses = try {
Class.forName("kanela.agent.Kanela", false, ClassLoader.getSystemClassLoader) != null
} catch {
case _: Throwable => false
}
val hasKanelaClasses =
try {
Class.forName("kanela.agent.Kanela", false, ClassLoader.getSystemClassLoader) != null
} catch {
case _: Throwable => false
}

hasKanelaClasses && isLoadedProperty
}
Expand All @@ -78,7 +79,6 @@ object Attacher {
.filter(cl => cl.getClass.getName == "org.springframework.boot.loader.LaunchedURLClassLoader")
}


/**
* Reloads the Kanela agent. This will cause all instrumentation definitions to be dropped and re-initialized.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class TagSetCreationBenchmark {
def createTagSetFromIndividualKeys(): TagSet = {
var tags = TagSet.Empty
tags = tags.withTag("http.method", "POST")
if(tagCount > 1) tags = tags.withTag("http.url", "http://localhost:8080/test")
if(tagCount > 2) tags = tags.withTag("http.status_code", 200L)
if(tagCount > 3) tags = tags.withTag("error", false)
if(tagCount > 4) tags = tags.withTag("userID", "abcdef")
if(tagCount > 5) tags = tags.withTag("correlationID", "0123456")
if (tagCount > 1) tags = tags.withTag("http.url", "http://localhost:8080/test")
if (tagCount > 2) tags = tags.withTag("http.status_code", 200L)
if (tagCount > 3) tags = tags.withTag("error", false)
if (tagCount > 4) tags = tags.withTag("userID", "abcdef")
if (tagCount > 5) tags = tags.withTag("correlationID", "0123456")

tags
}
Expand All @@ -47,11 +47,11 @@ class TagSetCreationBenchmark {
def createTagSetFromBuilder(): TagSet = {
val tags = TagSet.builder()
tags.add("http.method", "POST")
if(tagCount > 1) tags.add("http.url", "http://localhost:8080/test")
if(tagCount > 2) tags.add("http.status_code", 200L)
if(tagCount > 3) tags.add("error", false)
if(tagCount > 4) tags.add("userID", "abcdef")
if(tagCount > 5) tags.add("correlationID", "0123456")
if (tagCount > 1) tags.add("http.url", "http://localhost:8080/test")
if (tagCount > 2) tags.add("http.status_code", 200L)
if (tagCount > 3) tags.add("error", false)
if (tagCount > 4) tags.add("userID", "abcdef")
if (tagCount > 5) tags.add("correlationID", "0123456")

tags.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class TagSetLookupBenchmark {
.withTag("userID", "abcdef")
.withTag("correlationID", "0123456")


val builderLeft = builderTags()
val builderRight = builderTags()
val keyByKeyLeft = keyByKeyTags()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ class ThreadLocalStorageBenchmark {
val TestKey: Context.Key[Int] = Context.key("test-key", 0)
val ContextWithKey: Context = Context.of(TestKey, 43)

val CrossTLS: Storage = new CrossThreadLocal
val FTLS: Storage = new Storage.ThreadLocal

val CrossTLS: Storage = new CrossThreadLocal
val FTLS: Storage = new Storage.ThreadLocal

@Benchmark
@BenchmarkMode(Array(Mode.AverageTime))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ class InitialConfigLoadingSpec extends AnyWordSpec with Matchers with Eventually

"the initial config loading" should {
"fallback to using reference configuration only when application.conf files are malformed" in {
val process = Runtime.getRuntime.exec(createProcessWithConfig("kamon.KamonWithCustomConfig", "{This is a bad config}"))
val process =
Runtime.getRuntime.exec(createProcessWithConfig("kamon.KamonWithCustomConfig", "{This is a bad config}"))
val processOutputReader = new BufferedReader(new InputStreamReader(process.getInputStream()))

eventually(timeout(10 seconds)) {
val outputLine = processOutputReader.readLine()
outputLine shouldBe "All Good"
}

if(process.isAlive) {
if (process.isAlive) {
process.destroyForcibly().waitFor(5, TimeUnit.SECONDS)
}
}
Expand All @@ -50,4 +51,4 @@ object KamonWithCustomConfig extends App {
case Failure(_) => println("All Bad")
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class KamonLifecycleSpec extends AnyWordSpec with Matchers with Eventually {
}
}


def createProcessCommand(mainClass: String): String = {
System.getProperty("java.home") + File.separator + "bin" + File.separator + "java" +
" -cp " + System.getProperty("java.class.path") + " " + mainClass
Expand Down Expand Up @@ -95,7 +94,7 @@ object UsingKamonApisWithoutInit extends App {
.asScala
.filter(_.getName.startsWith("kamon"))

if(allKamonThreadNames.nonEmpty)
if (allKamonThreadNames.nonEmpty)
sys.error("Kamon shouldn't start or create threads until init is called")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ class UtilsOnConfigSpec extends AnyWordSpec with Matchers {

"the utils on config syntax" should {
"list all top level keys with a configuration" in {
config.getConfig("kamon.test").topLevelKeys should contain only("configuration-one", "config.two")
config.getConfig("kamon.test").topLevelKeys should contain only ("configuration-one", "config.two")
}

"create a map from top level keys to the inner configuration objects"in {
"create a map from top level keys to the inner configuration objects" in {
val extractedConfigurations = config.getConfig("kamon.test").configurations

extractedConfigurations.keys should contain only("configuration-one", "config.two")
extractedConfigurations("configuration-one").topLevelKeys should contain only("setting", "other-setting")
extractedConfigurations("config.two").topLevelKeys should contain only("setting")
extractedConfigurations.keys should contain only ("configuration-one", "config.two")
extractedConfigurations("configuration-one").topLevelKeys should contain only ("setting", "other-setting")
extractedConfigurations("config.two").topLevelKeys should contain only ("setting")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ class BinaryPropagationSpec extends AnyWordSpec with Matchers with OptionValues

"handle read failures in an entry reader" in {
val context = Context.of(
BinaryPropagationSpec.StringKey, "string-value",
BinaryPropagationSpec.FailStringKey, "fail-read"
BinaryPropagationSpec.StringKey,
"string-value",
BinaryPropagationSpec.FailStringKey,
"fail-read"
)
val writer = inspectableByteStreamWriter()
binaryPropagation.write(context, writer)
Expand All @@ -50,8 +52,10 @@ class BinaryPropagationSpec extends AnyWordSpec with Matchers with OptionValues

"handle write failures in an entry writer" in {
val context = Context.of(
BinaryPropagationSpec.StringKey, "string-value",
BinaryPropagationSpec.FailStringKey, "fail-write"
BinaryPropagationSpec.StringKey,
"string-value",
BinaryPropagationSpec.FailStringKey,
"fail-write"
)
val writer = inspectableByteStreamWriter()
binaryPropagation.write(context, writer)
Expand Down Expand Up @@ -120,8 +124,8 @@ class BinaryPropagationSpec extends AnyWordSpec with Matchers with OptionValues
|entries.outgoing.failString = "kamon.context.BinaryPropagationSpec$FailStringEntryCodec"
|
""".stripMargin
).withFallback(ConfigFactory.load().getConfig("kamon.propagation")))

).withFallback(ConfigFactory.load().getConfig("kamon.propagation"))
)

def inspectableByteStreamWriter() = new ByteArrayOutputStream(32) with ByteStreamWriter

Expand All @@ -138,14 +142,14 @@ object BinaryPropagationSpec {
override def read(medium: ByteStreamReader, context: Context): Context = {
val valueData = medium.readAll()

if(valueData.length > 0) {
if (valueData.length > 0) {
context.withEntry(StringKey, new String(valueData))
} else context
}

override def write(context: Context, medium: ByteStreamWriter): Unit = {
val value = context.get(StringKey)
if(value != null) {
if (value != null) {
medium.write(value.getBytes)
}
}
Expand All @@ -156,9 +160,9 @@ object BinaryPropagationSpec {
override def read(medium: ByteStreamReader, context: Context): Context = {
val valueData = medium.readAll()

if(valueData.length > 0) {
if (valueData.length > 0) {
val stringValue = new String(valueData)
if(stringValue == "fail-read") {
if (stringValue == "fail-read") {
sys.error("The fail string entry reader has triggered")
}

Expand All @@ -168,12 +172,12 @@ object BinaryPropagationSpec {

override def write(context: Context, medium: ByteStreamWriter): Unit = {
val value = context.get(FailStringKey)
if(value != null && value != "fail-write") {
if (value != null && value != "fail-write") {
medium.write(value.getBytes)
} else {
medium.write(42) // malformed data on purpose
sys.error("The fail string entry writer has triggered")
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,16 @@ class HttpPropagationSpec extends AnyWordSpec with Matchers with OptionValues {
context.getTag(plain("hello")) shouldBe "world"
context.getTag(option("correlation")).value shouldBe "1234"
context.getTag(option("unknown")) shouldBe empty
context.getTag(option("myLocalTag")) shouldBe empty //should be removed by the filter
context.getTag(option("privateMappedTag")) shouldBe empty //should be removed by the filter
context.getTag(option("myLocalTag")) shouldBe empty // should be removed by the filter
context.getTag(option("privateMappedTag")) shouldBe empty // should be removed by the filter
}
}


"writing to outgoing requests" should {
"at least write the upstream name when the context is empty" in {
val headers = mutable.Map.empty[String, String]
httpPropagation.write(Context.Empty, headerWriterFromMap(headers))
headers should contain only(
headers should contain only (
"x-content-tags" -> "upstream.name=kamon-application;"
)
}
Expand All @@ -92,7 +91,7 @@ class HttpPropagationSpec extends AnyWordSpec with Matchers with OptionValues {
)))

httpPropagation.write(context, headerWriterFromMap(headers))
headers should contain only(
headers should contain only (
"x-content-tags" -> "hello=world;upstream.name=kamon-application;",
"x-mapped-tag" -> "value"
)
Expand All @@ -101,29 +100,31 @@ class HttpPropagationSpec extends AnyWordSpec with Matchers with OptionValues {
"write context entries when available" in {
val headers = mutable.Map.empty[String, String]
val context = Context.of(
HttpPropagationSpec.StringKey, "out-we-go",
HttpPropagationSpec.IntegerKey, 42
HttpPropagationSpec.StringKey,
"out-we-go",
HttpPropagationSpec.IntegerKey,
42
)

httpPropagation.write(context, headerWriterFromMap(headers))
headers should contain only(
headers should contain only (
"x-content-tags" -> "upstream.name=kamon-application;",
"string-header" -> "out-we-go"
)
)
}

"not write filtered context tags" in {
val headers = mutable.Map.empty[String, String]
val context = Context.of(TagSet.from(Map(
"hello" -> "world",
"mappedTag" -> "value",
"privateHello" -> "world", //should be filtered
"privateMappedTag" -> "value", //should be filtered
"myLocalTag" -> "value" //should be filtered
"privateHello" -> "world", // should be filtered
"privateMappedTag" -> "value", // should be filtered
"myLocalTag" -> "value" // should be filtered
)))

httpPropagation.write(context, headerWriterFromMap(headers))
headers should contain only(
headers should contain only (
"x-content-tags" -> "hello=world;upstream.name=kamon-application;",
"x-mapped-tag" -> "value"
)
Expand All @@ -132,7 +133,6 @@ class HttpPropagationSpec extends AnyWordSpec with Matchers with OptionValues {
}
}


val httpPropagation = HttpPropagation.from(
ConfigFactory.parseString(
"""
Expand All @@ -150,12 +150,13 @@ class HttpPropagationSpec extends AnyWordSpec with Matchers with OptionValues {
|entries.outgoing.string = "kamon.context.HttpPropagationSpec$StringEntryCodec"
|
""".stripMargin
).withFallback(ConfigFactory.load().getConfig("kamon.propagation")), identifierScheme = "single")

).withFallback(ConfigFactory.load().getConfig("kamon.propagation")),
identifierScheme = "single"
)

def headerReaderFromMap(map: Map[String, String]): HttpPropagation.HeaderReader = new HttpPropagation.HeaderReader {
override def read(header: String): Option[String] = {
if(map.get("fail").nonEmpty)
if (map.get("fail").nonEmpty)
sys.error("failing on purpose")

map.get(header)
Expand All @@ -164,9 +165,10 @@ class HttpPropagationSpec extends AnyWordSpec with Matchers with OptionValues {
override def readAll(): Map[String, String] = map
}

def headerWriterFromMap(map: mutable.Map[String, String]): HttpPropagation.HeaderWriter = new HttpPropagation.HeaderWriter {
override def write(header: String, value: String): Unit = map.put(header, value)
}
def headerWriterFromMap(map: mutable.Map[String, String]): HttpPropagation.HeaderWriter =
new HttpPropagation.HeaderWriter {
override def write(header: String, value: String): Unit = map.put(header, value)
}
}

object HttpPropagationSpec {
Expand All @@ -175,7 +177,6 @@ object HttpPropagationSpec {
val IntegerKey = Context.key[Int]("integer", 0)
val OptionalKey = Context.key[Option[String]]("optional", None)


class StringEntryCodec extends EntryReader[HeaderReader] with EntryWriter[HeaderWriter] {
private val HeaderName = "string-header"

Expand All @@ -198,4 +199,4 @@ object HttpPropagationSpec {

}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

package kamon.context


import kamon.context.Storage.Scope
import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.ScalaFutures._
Expand Down Expand Up @@ -48,7 +47,7 @@ class ThreadLocalStorageSpec extends AnyWordSpec with Matchers with BeforeAndAft
TLS.current() shouldBe Context.Empty

val scope = TLS.store(ScopeWithKey)
TLS.current() shouldBe theSameInstanceAs(ScopeWithKey)
TLS.current() shouldBe theSameInstanceAs(ScopeWithKey)
scope.close()

TLS.current() shouldBe Context.Empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import kamon.metric.Counter.delta

class CounterSpec extends AnyWordSpec with Matchers with InstrumentInspection.Syntax with Eventually with InitAndStopKamonAfterAll {
class CounterSpec extends AnyWordSpec with Matchers with InstrumentInspection.Syntax with Eventually
with InitAndStopKamonAfterAll {

"a Counter" should {
"allow unit and bundled increments" in {
Expand Down Expand Up @@ -88,7 +89,8 @@ class CounterSpec extends AnyWordSpec with Matchers with InstrumentInspection.Sy
var last = numbers.head

override def get(): Long = synchronized {
if(remaining.isEmpty) last else {
if (remaining.isEmpty) last
else {
val head = remaining.head
remaining = remaining.tail
last = head
Expand Down
Loading

0 comments on commit 022216d

Please sign in to comment.