Skip to content

Commit

Permalink
Use ConfigUtil.splitPath to build environment tag keys from a config …
Browse files Browse the repository at this point in the history
…path (#1303)

* = kamon-core: add tests that fail using tags with special chars

* = kamon-core: Use ConfigUtil.splitPath to build a tag key from a config path

* = kamon-core: Improve spec examples and formatting

---------

Co-authored-by: hughsimpson <[email protected]>
  • Loading branch information
thyandrecardoso and hughsimpson committed Oct 27, 2023
1 parent 8fd9f24 commit a8bef44
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ class EnvironmentTagsSpec extends AnyWordSpec with Matchers {
| some {
| tag {
| inside = example
| "@inside" = value
| }
| }
|
| "defined-using-quotes" = value
|
| "\"tag-with-quotes\"" = value
|
| "@tag-with-special-chars" = value
| }
|}
""".stripMargin
Expand Down Expand Up @@ -80,6 +87,19 @@ class EnvironmentTagsSpec extends AnyWordSpec with Matchers {
tags("env") shouldBe "staging"
tags("region") shouldBe "asia-1"

tags.toMap shouldBe Map(
"@tag-with-special-chars" -> "value",
"env" -> "staging",
"host" -> "my-hostname",
"instance" -> "my-instance-name",
"k8s.namespace.name" -> "production",
"region" -> "asia-1",
"service" -> "environment-spec",
"some.tag.@inside" -> "value",
"some.tag.inside" -> "example",
"defined-using-quotes" -> "value",
"\"tag-with-quotes\"" -> "value"
)
}

"remove excluded tags" in {
Expand All @@ -105,7 +125,16 @@ class EnvironmentTagsSpec extends AnyWordSpec with Matchers {
|include-service = no
|include-host = no
|include-instance = no
|exclude = [ "region", "env", "k8s.namespace.name", "some.tag.inside" ]
|exclude = [
| "region",
| "env",
| "k8s.namespace.name",
| "some.tag.inside",
| "some.tag.@inside",
| "defined-using-quotes",
| "@tag-with-special-chars",
| "\"tag-with-quotes\""
|]
""".stripMargin)

val tags = EnvironmentTags.from(testEnv, config)
Expand Down
4 changes: 2 additions & 2 deletions core/kamon-core/src/main/scala/kamon/status/Environment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package status

import java.net.InetAddress
import java.util.concurrent.ThreadLocalRandom
import com.typesafe.config.Config
import com.typesafe.config.{Config, ConfigUtil}
import kamon.tag.TagSet
import kamon.util.HexCodec
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -83,7 +83,7 @@ object Environment {
tagsConfig.entrySet()
.iterator()
.asScala
.map { e => e.getKey -> e.getValue.unwrapped().toString }
.map { e => ConfigUtil.splitPath(e.getKey).asScala.mkString(".") -> e.getValue.unwrapped().toString }
.toMap
)
}
Expand Down

0 comments on commit a8bef44

Please sign in to comment.