Skip to content
This repository was archived by the owner on Mar 29, 2020. It is now read-only.

Commit c7a594e

Browse files
ivantopoFalmarri
authored andcommitted
document and reorganize reference settings (#1)
1 parent 273868b commit c7a594e

File tree

7 files changed

+79
-77
lines changed

7 files changed

+79
-77
lines changed

src/main/resources/reference.conf

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,52 @@ kamon {
1616

1717
# Max packet size for UDP metrics data sent to Datadog.
1818
max-packet-size = 1024 bytes
19-
2019
measurement-formatter = "default"
21-
2220
packetbuffer = "default"
23-
2421
}
2522

2623
#
27-
# Settings relevant to the DatadogAPIReporter
24+
# Settings relevant to the DatadogSpanReporter
2825
#
29-
http {
26+
trace {
3027

31-
api-url = "https://app.datadoghq.com/api/v1/series"
32-
33-
34-
# Datadog API key to use to send metrics to datadog directly over HTTPS.
35-
# If this is not set, metrics are sent as statsd packets over UDP to dogstatsd.
36-
api-key = ""
28+
# Default to agent URL (https://docs.datadoghq.com/api/?lang=python#tracing)
29+
api-url = "http://localhost:8126/v0.4/traces"
3730

38-
using-agent = false
31+
# FQCN of the "kamon.datadog.KamonDataDogTranslator" implementation that will convert Kamon Spans into Datadog
32+
# Spans, or "defult" to use the built-in translator.
33+
translator = "default"
3934

35+
# HTTP client timeout settings:
36+
# - connect-timeout: how long to wait for an HTTP connection to establish before failing the request.
37+
# - read-timeout: how long to wait for a read IO operation to complete before failing the request.
38+
# - write-timeout: how long to wait for a write IO operation to complete before failing the request.
39+
#
4040
connect-timeout = 5 seconds
4141
read-timeout = 5 seconds
42-
request-timeout = 5 seconds
42+
write-timeout = 5 seconds
4343
}
4444

45-
4645
#
47-
# Settings relevant to the DatadogSpanReporter
46+
# Settings relevant to the DatadogAPIReporter
4847
#
49-
trace.http {
50-
51-
# Default to agent URL (https://docs.datadoghq.com/api/?lang=python#tracing)
52-
api-url = "http://localhost:8126/v0.4/traces"
53-
54-
api-key = ${kamon.datadog.http.api-key}
48+
api {
5549

56-
using-agent = true
50+
# API endpoint to which metrics time series data will be posted.
51+
api-url = "https://app.datadoghq.com/api/v1/series"
5752

58-
connect-timeout = ${kamon.datadog.http.connect-timeout}
59-
read-timeout = ${kamon.datadog.http.read-timeout}
60-
request-timeout = ${kamon.datadog.http.request-timeout}
53+
# Datadog API key to use to send metrics to Datadog directly over HTTPS. The API key will be combined with the
54+
# API URL to get the complete endpoint use for posting time series to Datadog.
55+
api-key = ""
6156

62-
translator = "default"
57+
# HTTP client timeout settings:
58+
# - connect-timeout: how long to wait for an HTTP connection to establish before failing the request.
59+
# - read-timeout: how long to wait for a read IO operation to complete before failing the request.
60+
# - write-timeout: how long to wait for a write IO operation to complete before failing the request.
61+
#
62+
connect-timeout = 5 seconds
63+
read-timeout = 5 seconds
64+
write-timeout = 5 seconds
6365
}
6466

6567

@@ -84,8 +86,6 @@ kamon {
8486
excludes = []
8587
}
8688
}
87-
88-
8989
}
9090

9191
modules {
@@ -96,19 +96,20 @@ kamon {
9696
factory = "kamon.datadog.DatadogAgentReporterFactory"
9797
}
9898

99+
datadog-trace-agent {
100+
enabled = true
101+
name = "DatadogSpanReporter"
102+
description = "Datadog Span reporter"
103+
factory = "kamon.datadog.DatadogSpanReporterFactory"
104+
}
105+
99106
datadog-api {
100107
enabled = false
101108
name = "DatadogHttp"
102109
description = "Datadog HTTP reporter"
103110
factory = "kamon.datadog.DatadogAPIReporterFactory"
104111
}
105-
106-
datadog-span-reporter {
107-
enabled = true
108-
name = "DatadogSpanReporter"
109-
description = "Datadog Span reporter"
110-
factory = "kamon.datadog.DatadogSpanReporterFactory"
111-
}
112112
}
113-
114113
}
114+
115+

src/main/scala/kamon/datadog/DatadogAPIReporter.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import scala.util.{ Failure, Success }
3737
class DatadogAPIReporterFactory extends ModuleFactory {
3838
override def create(settings: ModuleFactory.Settings): DatadogAPIReporter = {
3939
val config = DatadogAPIReporter.readConfiguration(settings.config)
40-
new DatadogAPIReporter(config, new HttpClient(config.httpConfig))
40+
new DatadogAPIReporter(config, new HttpClient(config.httpConfig, usingAgent = false))
4141
}
4242
}
4343

@@ -59,7 +59,7 @@ class DatadogAPIReporter(@volatile private var configuration: Configuration, @vo
5959
override def reconfigure(config: Config): Unit = {
6060
val newConfiguration = readConfiguration(config)
6161
configuration = newConfiguration
62-
httpClient = new HttpClient(configuration.httpConfig)
62+
httpClient = new HttpClient(configuration.httpConfig, usingAgent = false)
6363
}
6464

6565
override def reportPeriodSnapshot(snapshot: PeriodSnapshot): Unit = {
@@ -158,7 +158,7 @@ private object DatadogAPIReporter {
158158
def readConfiguration(config: Config): Configuration = {
159159
val datadogConfig = config.getConfig("kamon.datadog")
160160
Configuration(
161-
datadogConfig.getConfig("http"),
161+
datadogConfig.getConfig("api"),
162162
timeUnit = readTimeUnit(datadogConfig.getString("time-unit")),
163163
informationUnit = readInformationUnit(datadogConfig.getString("information-unit")),
164164
// Remove the "host" tag since it gets added to the datadog payload separately

src/main/scala/kamon/datadog/DatadogAgentReporter.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ object DatadogAgentReporter {
196196
}
197197
}
198198

199-
private def fitsOnBuffer(data: String): Boolean = (buffer.length + data.length) <= maxPacketSizeInBytes
199+
private def fitsOnBuffer(data: String): Boolean =
200+
(buffer.length + data.length) <= maxPacketSizeInBytes
200201

201202
private def flushToUDP(data: String): Unit = {
202203
val channel = DatagramChannel.open()

src/main/scala/kamon/datadog/DatadogSpanReporter.scala

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import java.time.Duration
44

55
import com.typesafe.config.Config
66
import kamon.trace.Span
7-
import kamon.{ClassLoading, Kamon}
7+
import kamon.{ ClassLoading, Kamon }
88
import kamon.datadog.DatadogSpanReporter.Configuration
9-
import kamon.module.{ModuleFactory, SpanReporter}
10-
import kamon.tag.{Lookups, Tag, TagSet}
11-
import kamon.util.{EnvironmentTags, Filter}
9+
import kamon.module.{ ModuleFactory, SpanReporter }
10+
import kamon.tag.{ Lookups, Tag, TagSet }
11+
import kamon.util.{ EnvironmentTags, Filter }
1212
import org.slf4j.LoggerFactory
13-
import play.api.libs.json.{JsObject, Json}
13+
import play.api.libs.json.{ JsObject, Json }
1414

1515
trait KamonDataDogTranslator {
1616
def translate(span: Span.Finished, additionalTags: TagSet, tagFilter: Filter): DdSpan
@@ -22,9 +22,10 @@ object KamonDataDogTranslatorDefault extends KamonDataDogTranslator {
2222
val spanId = BigInt(span.id.string, 16)
2323

2424
val parentId = if (span.parentId.isEmpty) None else Some(BigInt(span.parentId.string, 16))
25-
26-
val name = span.tags.get(Lookups.option("component"))
25+
val name = span.metricTags
26+
.get(Lookups.option("component"))
2727
.getOrElse("kamon.trace")
28+
2829
val resource = span.operationName
2930
val service = Kamon.environment.service
3031
val from = span.from
@@ -34,7 +35,7 @@ object KamonDataDogTranslatorDefault extends KamonDataDogTranslator {
3435
val tags = (span.tags.all() ++ span.metricTags.all() ++ additionalTags.all()).map { t =>
3536
t.key -> Tag.unwrapValue(t).toString
3637
}
37-
val meta = (marks ++ tags).filterKeys(tagFilter.accept(_))
38+
val meta = (marks ++ tags).filterKeys(tagFilter.accept(_)).toMap
3839
new DdSpan(traceId, spanId, parentId, name, resource, service, "custom", start, duration, meta, span.hasError)
3940

4041
}
@@ -45,11 +46,11 @@ object DatadogSpanReporter {
4546
case class Configuration(
4647
translator: KamonDataDogTranslator,
4748
httpClient: HttpClient,
48-
tagFilter: Filter,
49-
envTags: TagSet
49+
tagFilter: Filter,
50+
envTags: TagSet
5051
)
5152

52-
private[kamon] val httpConfigPath = "kamon.datadog.trace.http"
53+
private[kamon] val httpConfigPath = "kamon.datadog.trace"
5354

5455
private[kamon] def getTranslator(config: Config): KamonDataDogTranslator = {
5556
config.getConfig(httpConfigPath).getString("translator") match {
@@ -62,9 +63,9 @@ object DatadogSpanReporter {
6263

6364
Configuration(
6465
getTranslator(config),
65-
new HttpClient(config.getConfig(DatadogSpanReporter.httpConfigPath)),
66+
new HttpClient(config.getConfig(DatadogSpanReporter.httpConfigPath), usingAgent = true),
6667
Kamon.filter("kamon.datadog.environment-tags.filter"),
67-
EnvironmentTags.from(Kamon.environment, config.getConfig("kamon.datadog.environment-tags")).without("service"),
68+
EnvironmentTags.from(Kamon.environment, config.getConfig("kamon.datadog.environment-tags")).without("service")
6869
)
6970
}
7071
}

src/main/scala/kamon/datadog/package.scala

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@ package object datadog {
2121
}
2222
}
2323

24-
private[datadog] case class HttpClient(apiUrl: String, apiKey: String, usingAgent: Boolean, connectTimeout: Duration, readTimeout: Duration, requestTimeout: Duration) {
24+
private[datadog] case class HttpClient(apiUrl: String, apiKey: Option[String], usingAgent: Boolean, connectTimeout: Duration,
25+
readTimeout: Duration, writeTimeout: Duration) {
2526

2627
val httpClient: OkHttpClient = createHttpClient()
2728

28-
def this(config: Config) = {
29+
def this(config: Config, usingAgent: Boolean) = {
2930
this(
3031
config.getString("api-url"),
31-
config.getString("api-key"),
32-
config.getBoolean("using-agent"),
32+
if (usingAgent) None else Some(config.getString("api-key")),
33+
usingAgent,
3334
config.getDuration("connect-timeout"),
3435
config.getDuration("read-timeout"),
35-
config.getDuration("request-timeout")
36+
config.getDuration("write-timeout")
3637
)
3738
}
3839

@@ -42,11 +43,9 @@ package object datadog {
4243

4344
def doMethodWithBody(method: String, contentType: String, contentBody: Array[Byte]): Try[String] = {
4445
val body = RequestBody.create(MediaType.parse(contentType), contentBody)
45-
val url = usingAgent match {
46-
case true => apiUrl
47-
case false => apiUrl + "?api_key=" + apiKey
48-
}
46+
val url = apiUrl + apiKey.map(key => "?api_key=" + key).getOrElse("")
4947
val request = new Request.Builder().url(url).method(method, body).build
48+
5049
doRequest(request) match {
5150
case Success(response) =>
5251
val responseBody = response.body().string()
@@ -86,7 +85,7 @@ package object datadog {
8685
new OkHttpClient.Builder()
8786
.connectTimeout(connectTimeout.toMillis, TimeUnit.MILLISECONDS)
8887
.readTimeout(readTimeout.toMillis, TimeUnit.MILLISECONDS)
89-
.writeTimeout(requestTimeout.toMillis, TimeUnit.MILLISECONDS)
88+
.writeTimeout(writeTimeout.toMillis, TimeUnit.MILLISECONDS)
9089
.retryOnConnectionFailure(false)
9190
.build()
9291
}

src/test/scala/kamon/datadog/DatadogAPIReporterSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class DatadogAPIReporterSpec extends AbstractHttpReporter with Matchers with Rec
2121

2222
"sends counter metrics" in {
2323
val baseUrl = mockResponse("/test", new MockResponse().setStatus("HTTP/1.1 200 OK"))
24-
applyConfig("kamon.datadog.http.api-url = \"" + baseUrl + "\"")
25-
applyConfig("kamon.datadog.http.api-key = \"dummy\"")
24+
applyConfig("kamon.datadog.api.api-url = \"" + baseUrl + "\"")
25+
applyConfig("kamon.datadog.api.api-key = \"dummy\"")
2626

2727
reporter.reconfigure(Kamon.config())
2828

src/test/scala/kamon/datadog/DatadogSpanReporterSpec.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package kamon.datadog
22

3-
import java.time.{Duration, Instant}
3+
import java.time.{ Duration, Instant }
44
import java.util.concurrent.TimeUnit
55

66
import kamon.Kamon
@@ -59,30 +59,30 @@ trait TestData {
5959
"duration" -> JsNumber(duration.getSeconds * 1000000000 + duration.getNano),
6060
"name" -> "kamon.trace",
6161
"meta" -> Json.obj(
62-
"env" -> "staging",
62+
"env" -> "staging"
6363
),
6464
"error" -> 0,
6565
"type" -> "custom",
6666
"start" -> JsNumber(from.getEpochNano),
6767
"metrics" -> JsObject(Seq(
68-
"_sampling_priority_v1" -> JsNumber(1)
68+
"_sampling_priority_v1" -> JsNumber(1)
6969
))
7070
)
7171

7272
val spanWithoutParentId = span.copy(parentId = Identifier.Empty)
7373
val jsonWithoutParentId = json - "parent_id"
7474

75-
val spanWithError = span.copy(tags = TagSet.of("error", true), hasError=true)
75+
val spanWithError = span.copy(tags = TagSet.of("error", true), hasError = true)
7676

7777
val jsonWithError = json ++ Json.obj(
7878
"meta" -> Json.obj(
7979
"error" -> "true",
80-
"env" -> "staging",
80+
"env" -> "staging"
8181
),
8282
"error" -> 1
8383
)
8484

85-
val spanWithTags = span.copy(tags =
85+
val spanWithTags = span.copy(metricTags =
8686
TagSet.from(
8787
Map(
8888
"string" -> "value",
@@ -104,7 +104,7 @@ trait TestData {
104104
"false" -> "false",
105105
"number" -> randomNumber.toString,
106106
"component" -> "custom.component",
107-
"env" -> "staging",
107+
"env" -> "staging"
108108
)
109109
)
110110

@@ -115,7 +115,7 @@ trait TestData {
115115
val jsonWithMarks = json ++ Json.obj(
116116
"meta" -> Json.obj(
117117
"from" -> JsString(from.getEpochNano.toString),
118-
"env" -> JsString("staging")
118+
"env" -> JsString("staging")
119119
)
120120
)
121121

@@ -144,8 +144,8 @@ trait TestData {
144144
"span with meta and marks" -> (Seq(spanWithTagsAndMarks), Json.arr(Json.arr(jsonWithTagsAndMarks))),
145145
"span with error" -> (Seq(spanWithError), Json.arr(Json.arr(jsonWithError))),
146146

147-
"multiple spans with same trace" -> (Seq(span, spanWithTags), Json.arr(Json.arr(json, jsonWithTags))),
148-
// "multiple spans with two traces" -> (Seq(span, spanWithTags, otherTraceSpan, span), Json.arr(Json.arr(json, jsonWithTags, json), Json.arr(otherTraceJson)))
147+
"multiple spans with same trace" -> (Seq(span, spanWithTags), Json.arr(Json.arr(json, jsonWithTags)))
148+
// "multiple spans with two traces" -> (Seq(span, spanWithTags, otherTraceSpan, span), Json.arr(Json.arr(json, jsonWithTags, json), Json.arr(otherTraceJson)))
149149
)
150150
}
151151

@@ -165,7 +165,7 @@ class DatadogSpanReporterSpec extends AbstractHttpReporter with Matchers with Re
165165

166166
val baseUrl = mockResponse("/test", new MockResponse().setStatus("HTTP/1.1 200 OK").setBody("OK"))
167167

168-
applyConfig("kamon.datadog.trace.http.api-url = \"" + baseUrl + "\"")
168+
applyConfig("kamon.datadog.trace.api-url = \"" + baseUrl + "\"")
169169
reporter.reconfigure(Kamon.config())
170170
reporter.reportSpans(spans)
171171
val request = server.takeRequest()
@@ -186,7 +186,7 @@ class DatadogSpanReporterSpec extends AbstractHttpReporter with Matchers with Re
186186

187187
s"ignore error responses" in {
188188
val baseUrl = mockResponse("/test", new MockResponse().setStatus("HTTP/1.1 500 Internal Server Error"))
189-
applyConfig("kamon.datadog.trace.http.api-url = \"" + baseUrl + "\"")
189+
applyConfig("kamon.datadog.trace.api-url = \"" + baseUrl + "\"")
190190
reporter.reconfigure(Kamon.config())
191191
reporter.reportSpans(firstSpan)
192192
server.takeRequest()

0 commit comments

Comments
 (0)