1
1
package kamon .datadog
2
2
3
3
import java .time .Instant
4
-
5
4
import kamon .Kamon
6
5
import kamon .metric .Distribution .Percentile
7
6
import kamon .metric ._
8
7
import kamon .module .ModuleFactory
9
8
import kamon .tag .TagSet
10
9
import kamon .testkit .Reconfigure
11
10
import okhttp3 .mockwebserver .MockResponse
11
+ import okio .{Buffer , InflaterSource , Okio }
12
12
import org .scalatest .Matchers
13
13
import play .api .libs .json .Json
14
14
15
+ import java .util .zip .Inflater
15
16
import scala .concurrent .ExecutionContext
16
17
17
18
class DatadogAPIReporterSpec extends AbstractHttpReporter with Matchers with Reconfigure {
@@ -20,10 +21,45 @@ class DatadogAPIReporterSpec extends AbstractHttpReporter with Matchers with Rec
20
21
val reporter = new DatadogAPIReporterFactory ().create(ModuleFactory .Settings (Kamon .config(), ExecutionContext .global))
21
22
val now = Instant .ofEpochMilli(1523395554 )
22
23
24
+ " sends metrics - compressed" in {
25
+ val baseUrl = mockResponse(" /test" , new MockResponse ().setStatus(" HTTP/1.1 200 OK" ))
26
+ applyConfig(" kamon.datadog.api.api-url = \" " + baseUrl + " \" " )
27
+ applyConfig(" kamon.datadog.api.api-key = \" dummy\" " )
28
+ applyConfig(" kamon.datadog.api.compression = true" )
29
+ reporter.reconfigure(Kamon .config())
30
+
31
+ reporter.reportPeriodSnapshot(
32
+ PeriodSnapshot .apply(
33
+ now.minusMillis(1000 ),
34
+ now,
35
+ MetricSnapshot .ofValues[Long ](
36
+ " test.counter" ,
37
+ " test" ,
38
+ Metric .Settings .ForValueInstrument (MeasurementUnit .none, java.time.Duration .ZERO ),
39
+ Instrument .Snapshot .apply(TagSet .of(" tag1" , " value1" ), 0L ) :: Nil
40
+ ) :: Nil ,
41
+ Nil ,
42
+ Nil ,
43
+ Nil ,
44
+ Nil
45
+ )
46
+ )
47
+
48
+ val request = server.takeRequest()
49
+
50
+ val decompressedBody = Okio .buffer(new InflaterSource (request.getBody.buffer(), new Inflater ())).readByteString().utf8()
51
+
52
+ Json .parse(decompressedBody) shouldEqual Json
53
+ .parse(
54
+ """ {"series":[{"metric":"test.counter","interval":1,"points":[[1523394,0]],"type":"count","host":"test","tags":["env:staging","service:kamon-application","tag1:value1"]}]}"""
55
+ )
56
+ }
57
+
23
58
" sends counter metrics" in {
24
59
val baseUrl = mockResponse(" /test" , new MockResponse ().setStatus(" HTTP/1.1 200 OK" ))
25
60
applyConfig(" kamon.datadog.api.api-url = \" " + baseUrl + " \" " )
26
61
applyConfig(" kamon.datadog.api.api-key = \" dummy\" " )
62
+ applyConfig(" kamon.datadog.api.compression = false" )
27
63
reporter.reconfigure(Kamon .config())
28
64
29
65
reporter.reportPeriodSnapshot(
@@ -56,6 +92,7 @@ class DatadogAPIReporterSpec extends AbstractHttpReporter with Matchers with Rec
56
92
val baseUrl = mockResponse(" /test" , new MockResponse ().setStatus(" HTTP/1.1 200 OK" ))
57
93
applyConfig(" kamon.datadog.api.api-url = \" " + baseUrl + " \" " )
58
94
applyConfig(" kamon.datadog.api.api-key = \" dummy\" " )
95
+ applyConfig(" kamon.datadog.api.compression = false" )
59
96
reporter.reconfigure(Kamon .config())
60
97
61
98
val distribution = new Distribution {
0 commit comments