Skip to content

Commit

Permalink
Merge pull request #1327 from kamon-io/scalafmt
Browse files Browse the repository at this point in the history
Added and applied scalafmt
  • Loading branch information
hughsimpson authored Mar 4, 2024
2 parents 13b3069 + db6527d commit 5327237
Show file tree
Hide file tree
Showing 389 changed files with 6,020 additions and 4,233 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Initial scalafmtAll was applied
022216d6b1ebe4dd0c00aef204625f7f3372fc90
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Test all the things

on: [push, pull_request]
on: [ push, pull_request ]

jobs:
ci:
Expand All @@ -18,3 +18,11 @@ jobs:
apps: sbt
- name: Test
run: sbt -v ";+core/test;+instrumentation/test;+reporters/test"
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: coursier/cache-action@v6
- name: Test
run: sbt -v "scalafmtCheckAll"

20 changes: 20 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version = "3.8.0"

runner.dialect = "scala213"

maxColumn = 120

align.preset = some

binPack.parentConstructors = source

docstrings.style = keep

indent.defnSite = 2

indentOperator.excludeRegex = "^.+$"
indentOperator.exemptScope = all

newlines {
source = keep
}
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 {

}
}
}
}
Loading

0 comments on commit 5327237

Please sign in to comment.