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 (kamon-io#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 <hsimpson@rzsoftware.com>
  • Loading branch information
thyandrecardoso and hughsimpson committed Nov 7, 2023
1 parent b97db72 commit 096886b
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 096886b

Please sign in to comment.