Skip to content

Commit ff150c9

Browse files
committed
add blocking route test
1 parent 53a2921 commit ff150c9

File tree

1 file changed

+112
-89
lines changed

1 file changed

+112
-89
lines changed

instrumentation/kamon-armeria/src/test/scala/kamon/instrumentation/armeria/server/ArmeriaHttpServerTracingSpec.scala

Lines changed: 112 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -47,114 +47,97 @@ class ArmeriaHttpServerTracingSpec extends WordSpec
4747

4848
val webClient = newWebClient(protocol,port)
4949

50-
s"The Armeria $protocol server" should {
51-
52-
"create a server Span when receiving requests" in {
53-
val target = s"$protocol://$interface:$port/$usersEndpoint"
54-
val expected = "/users"
55-
56-
val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, usersEndpoint))
57-
webClient.execute(request)
58-
59-
eventually(timeout(3 seconds)) {
60-
val span = testSpanReporter().nextSpan().value
61-
span.operationName shouldBe expected
62-
span.tags.get(plain("http.url")) shouldBe target
63-
span.metricTags.get(plain("component")) shouldBe "armeria.http.server"
64-
span.metricTags.get(plain("http.method")) shouldBe "GET"
65-
span.metricTags.get(plainLong("http.status_code")) shouldBe 200L
66-
}
67-
}
50+
s"The Armeria $protocol server" when {
6851

69-
"set operation name with unhandled" when {
70-
"request path doesn't exists" in {
71-
val target = s"$protocol://$interface:$port/$pathNotFoundEndpoint"
72-
val expected = "unhandled"
52+
"Non blocking route" should {
7353

74-
val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, pathNotFoundEndpoint))
75-
webClient.execute(request)
54+
"create a server Span when receiving requests" in {
55+
val target = s"$protocol://$interface:$port/$usersEndpoint"
56+
val expected = "/users"
57+
58+
val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, usersEndpoint))
59+
webClient.execute(request)
7660

7761
eventually(timeout(3 seconds)) {
7862
val span = testSpanReporter().nextSpan().value
7963
span.operationName shouldBe expected
8064
span.tags.get(plain("http.url")) shouldBe target
8165
span.metricTags.get(plain("component")) shouldBe "armeria.http.server"
8266
span.metricTags.get(plain("http.method")) shouldBe "GET"
83-
span.metricTags.get(plainBoolean("error")) shouldBe false
84-
span.metricTags.get(plainLong("http.status_code")) shouldBe 404
67+
span.metricTags.get(plainLong("http.status_code")) shouldBe 200L
8568
}
8669
}
87-
}
8870

89-
"set operation name with path + http method" when {
90-
"resource doesn't exist" in {
91-
val target = s"$protocol://$interface:$port/$usersEndpoint/not-found"
92-
val expected = "/users/{}"
71+
"set operation name with unhandled" when {
72+
"request path doesn't exists" in {
73+
val target = s"$protocol://$interface:$port/$pathNotFoundEndpoint"
74+
val expected = "unhandled"
75+
76+
val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, pathNotFoundEndpoint))
77+
webClient.execute(request)
78+
79+
eventually(timeout(3 seconds)) {
80+
val span = testSpanReporter().nextSpan().value
81+
span.operationName shouldBe expected
82+
span.tags.get(plain("http.url")) shouldBe target
83+
span.metricTags.get(plain("component")) shouldBe "armeria.http.server"
84+
span.metricTags.get(plain("http.method")) shouldBe "GET"
85+
span.metricTags.get(plainBoolean("error")) shouldBe false
86+
span.metricTags.get(plainLong("http.status_code")) shouldBe 404
87+
}
88+
}
89+
}
9390

94-
val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, s"$usersEndpoint/not-found"))
95-
webClient.execute(request)
91+
"set operation name with path + http method" when {
92+
"resource doesn't exist" in {
93+
val target = s"$protocol://$interface:$port/$usersEndpoint/not-found"
94+
val expected = "/users/{}"
95+
96+
val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, s"$usersEndpoint/not-found"))
97+
webClient.execute(request)
98+
99+
eventually(timeout(3 seconds)) {
100+
val span = testSpanReporter().nextSpan().value
101+
span.operationName shouldBe expected
102+
span.tags.get(plain("http.url")) shouldBe target
103+
span.metricTags.get(plain("component")) shouldBe "armeria.http.server"
104+
span.metricTags.get(plain("http.method")) shouldBe "GET"
105+
span.metricTags.get(plainBoolean("error")) shouldBe false
106+
span.metricTags.get(plainLong("http.status_code")) shouldBe 404
107+
}
108+
}
109+
}
110+
111+
"not include path variables names" in {
112+
val expected = "/users/{}/accounts/{}"
113+
114+
val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, userAccountEndpoint))
115+
webClient.execute(request)
96116

97117
eventually(timeout(3 seconds)) {
98118
val span = testSpanReporter().nextSpan().value
99119
span.operationName shouldBe expected
100-
span.tags.get(plain("http.url")) shouldBe target
101-
span.metricTags.get(plain("component")) shouldBe "armeria.http.server"
102-
span.metricTags.get(plain("http.method")) shouldBe "GET"
103-
span.metricTags.get(plainBoolean("error")) shouldBe false
104-
span.metricTags.get(plainLong("http.status_code")) shouldBe 404
105120
}
106121
}
107-
}
108-
109-
"not include path variables names" in {
110-
val expected = "/users/{}/accounts/{}"
111-
112-
val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, userAccountEndpoint))
113-
webClient.execute(request)
114122

115-
eventually(timeout(3 seconds)) {
116-
val span = testSpanReporter().nextSpan().value
117-
span.operationName shouldBe expected
118-
}
119-
}
123+
"not fail when request url contains special regexp chars" in {
124+
val expected = "/users/{}/accounts/{}"
120125

121-
"not fail when request url contains special regexp chars" in {
122-
val expected = "/users/{}/accounts/{}"
126+
val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, s"$userAccountEndpoint**"))
127+
val response = webClient.execute(request).aggregate().get()
123128

124-
val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, s"$userAccountEndpoint**"))
125-
val response = webClient.execute(request).aggregate().get()
126-
127-
eventually(timeout(3 seconds)) {
128-
val span = testSpanReporter().nextSpan().value
129-
span.operationName shouldBe expected
130-
response.status().code() shouldBe 200
131-
}
132-
}
133-
134-
"mark spans as failed when request fails" in {
135-
val target = s"$protocol://$interface:$port/$usersEndpoint/error"
136-
val expected = "/users/{}"
137-
138-
val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, s"$usersEndpoint/error"))
139-
webClient.execute(request)
140-
141-
eventually(timeout(3 seconds)) {
142-
val span = testSpanReporter().nextSpan().value
143-
span.operationName shouldBe expected
144-
span.tags.get(plain("http.url")) shouldBe target
145-
span.metricTags.get(plain("component")) shouldBe "armeria.http.server"
146-
span.metricTags.get(plain("http.method")) shouldBe "GET"
147-
span.metricTags.get(plainBoolean("error")) shouldBe true
148-
span.metricTags.get(plainLong("http.status_code")) shouldBe 500
129+
eventually(timeout(3 seconds)) {
130+
val span = testSpanReporter().nextSpan().value
131+
span.operationName shouldBe expected
132+
response.status().code() shouldBe 200
133+
}
149134
}
150-
}
151135

152-
"return a redirect status code" when {
153-
"a request to /docs is redirected to /docs/" in {
154-
val target = s"$protocol://$interface:$port/$docsEndpoint"
155-
val expected = s"/docs"
136+
"mark spans as failed when request fails" in {
137+
val target = s"$protocol://$interface:$port/$usersEndpoint/error"
138+
val expected = "/users/{}"
156139

157-
val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, docsEndpoint))
140+
val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, s"$usersEndpoint/error"))
158141
webClient.execute(request)
159142

160143
eventually(timeout(3 seconds)) {
@@ -163,17 +146,57 @@ class ArmeriaHttpServerTracingSpec extends WordSpec
163146
span.tags.get(plain("http.url")) shouldBe target
164147
span.metricTags.get(plain("component")) shouldBe "armeria.http.server"
165148
span.metricTags.get(plain("http.method")) shouldBe "GET"
166-
span.metricTags.get(plainLong("http.status_code")) shouldBe 307L
149+
span.metricTags.get(plainBoolean("error")) shouldBe true
150+
span.metricTags.get(plainLong("http.status_code")) shouldBe 500
151+
}
152+
}
153+
154+
"return a redirect status code" when {
155+
"a request to /docs is redirected to /docs/" in {
156+
val target = s"$protocol://$interface:$port/$docsEndpoint"
157+
val expected = s"/docs"
158+
159+
val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, docsEndpoint))
160+
webClient.execute(request)
161+
162+
eventually(timeout(3 seconds)) {
163+
val span = testSpanReporter().nextSpan().value
164+
span.operationName shouldBe expected
165+
span.tags.get(plain("http.url")) shouldBe target
166+
span.metricTags.get(plain("component")) shouldBe "armeria.http.server"
167+
span.metricTags.get(plain("http.method")) shouldBe "GET"
168+
span.metricTags.get(plainLong("http.status_code")) shouldBe 307L
169+
}
170+
}
171+
}
172+
173+
"return a ok status code " when {
174+
"a request to /docs/ is done" in {
175+
val target = s"$protocol://$interface:$port/$docsEndpoint/"
176+
val expected = s"/docs"
177+
178+
val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, s"$docsEndpoint/"))
179+
webClient.execute(request)
180+
181+
eventually(timeout(3 seconds)) {
182+
val span = testSpanReporter().nextSpan().value
183+
span.operationName shouldBe expected
184+
span.tags.get(plain("http.url")) shouldBe target
185+
span.metricTags.get(plain("component")) shouldBe "armeria.http.server"
186+
span.metricTags.get(plain("http.method")) shouldBe "GET"
187+
span.metricTags.get(plainLong("http.status_code")) shouldBe 200L
188+
}
167189
}
168190
}
169191
}
170192

171-
"return a ok status code " when {
172-
"a request to /docs/ is done" in {
173-
val target = s"$protocol://$interface:$port/$docsEndpoint/"
174-
val expected = s"/docs"
193+
"Blocking route" should {
194+
195+
"create a server Span when receiving requests" in {
196+
val target = s"$protocol://$interface:$port/$usersBlockingEndpoint"
197+
val expected = "/users-blocking"
175198

176-
val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, s"$docsEndpoint/"))
199+
val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, usersBlockingEndpoint))
177200
webClient.execute(request)
178201

179202
eventually(timeout(3 seconds)) {

0 commit comments

Comments
 (0)