Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ConfigUtil.splitPath to build environment tag keys from a config path #1303

Merged
merged 4 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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