-
Notifications
You must be signed in to change notification settings - Fork 6
health dashboards: remove path templatization logic #9
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
Changes from 3 commits
2ec38a4
b0fc159
0e5afc6
b76db75
c4243c9
3ab216d
e216756
4289ece
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
|
||
package io.bitdrift.capture.network | ||
|
||
import io.bitdrift.capture.CaptureJniLibrary | ||
import io.bitdrift.capture.InternalFieldsMap | ||
import io.bitdrift.capture.events.span.SpanField | ||
import io.bitdrift.capture.providers.FieldValue | ||
|
@@ -36,60 +35,75 @@ data class HttpResponseInfo @JvmOverloads constructor( | |
) { | ||
internal val name: String = "HTTPResponse" | ||
|
||
// Lazy since the creation of the `HTTPResponseInfo` can happen before the logger is initialized | ||
// and trying to call a native `CaptureJniLibrary.normalizeUrlPath` method before the `Capture` | ||
// library is loaded leads to unsatisfied linking error. | ||
internal val fields: InternalFieldsMap by lazy { | ||
val fields = buildMap { | ||
put(SpanField.Key.TYPE, FieldValue.StringField(SpanField.Value.TYPE_END)) | ||
put(SpanField.Key.DURATION, FieldValue.StringField(durationMs.toString())) | ||
put(SpanField.Key.RESULT, FieldValue.StringField(response.result.name.lowercase())) | ||
putOptional("_status_code", response.statusCode) | ||
putOptional("_error_type", response.error) { it::javaClass.get().simpleName } | ||
putOptional("_error_message", response.error) { it.message.orEmpty() } | ||
putOptional(HttpFieldKey.HOST, response.host) | ||
putOptional(HttpFieldKey.PATH, response.path?.value) | ||
putOptional(HttpFieldKey.QUERY, response.query) | ||
internal val fields: InternalFieldsMap = | ||
run { | ||
val fields = buildMap { | ||
this.put(SpanField.Key.TYPE, FieldValue.StringField(SpanField.Value.TYPE_END)) | ||
this.put( | ||
SpanField.Key.DURATION, | ||
FieldValue.StringField(durationMs.toString()), | ||
) | ||
this.put( | ||
SpanField.Key.RESULT, | ||
FieldValue.StringField(response.result.name.lowercase()), | ||
) | ||
putOptional("_status_code", response.statusCode) | ||
putOptional( | ||
"_error_type", | ||
response.error, | ||
) { it::javaClass.get().simpleName } | ||
putOptional( | ||
"_error_message", | ||
response.error, | ||
) { it.message.orEmpty() } | ||
putOptional(HttpFieldKey.HOST, response.host) | ||
putOptional(HttpFieldKey.PATH, response.path?.value) | ||
putOptional(HttpFieldKey.QUERY, response.query) | ||
|
||
response.path?.let { | ||
val requestPathTemplate = if (request.path?.value == it.value) { | ||
// If the path between request and response did not change and an explicit path | ||
// template was provided as part of a request use it as path template on a response. | ||
request.path.template | ||
} else { | ||
null | ||
} | ||
response.path?.let { | ||
val requestPathTemplate = | ||
if (request.path?.value == it.value) { | ||
// If the path between request and response did not change and an explicit path | ||
// template was provided as part of a request use it as path template on a response. | ||
request.path.template | ||
} else { | ||
null | ||
} | ||
|
||
@Suppress("SwallowedException") | ||
val normalized: String? = requestPathTemplate?.let { it } | ||
?: it.template?.let { it } | ||
?: try { | ||
CaptureJniLibrary.normalizeUrlPath(it.value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's great to be able to get rid of this call |
||
} catch (e: Throwable) { | ||
null | ||
} | ||
@Suppress("SwallowedException") | ||
val normalized: String? = requestPathTemplate?.let { it } | ||
?: it.template?.let { it } | ||
|
||
putOptional(HttpFieldKey.PATH_TEMPLATE, normalized) | ||
} | ||
putOptional(HttpFieldKey.PATH_TEMPLATE, normalized) | ||
} | ||
|
||
metrics?.let { | ||
put("_request_body_bytes_sent_count", FieldValue.StringField(it.requestBodyBytesSentCount.toString())) | ||
put("_response_body_bytes_received_count", FieldValue.StringField(it.responseBodyBytesReceivedCount.toString())) | ||
put("_request_headers_bytes_count", FieldValue.StringField(it.requestHeadersBytesCount.toString())) | ||
put("_response_headers_bytes_count", FieldValue.StringField(it.responseHeadersBytesCount.toString())) | ||
putOptional("_dns_resolution_duration_ms", it.dnsResolutionDurationMs) | ||
metrics?.let<HttpRequestMetrics, Unit> { | ||
this.put( | ||
"_request_body_bytes_sent_count", | ||
FieldValue.StringField(it.requestBodyBytesSentCount.toString()), | ||
) | ||
this.put( | ||
"_response_body_bytes_received_count", | ||
FieldValue.StringField(it.responseBodyBytesReceivedCount.toString()), | ||
) | ||
this.put( | ||
"_request_headers_bytes_count", | ||
FieldValue.StringField(it.requestHeadersBytesCount.toString()), | ||
) | ||
this.put( | ||
"_response_headers_bytes_count", | ||
FieldValue.StringField(it.responseHeadersBytesCount.toString()), | ||
) | ||
putOptional("_dns_resolution_duration_ms", it.dnsResolutionDurationMs) | ||
} | ||
} | ||
// If the path between request and response did not change and an explicit path | ||
// template was provided as part of a request use it as path template on a response. | ||
Augustyniak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
extraFields.toFields() + request.commonFields + fields | ||
} | ||
|
||
extraFields.toFields() + request.commonFields + fields | ||
} | ||
|
||
// Lazy since the creation of the `HTTPResponseInfo` can happen before the logger is initialized | ||
// and trying to call a native `CaptureJniLibrary.normalizeUrlPath` method before the `Capture` | ||
// library is loaded leads to unsatisfied linking error. | ||
internal val matchingFields: InternalFieldsMap by lazy { | ||
internal val matchingFields: InternalFieldsMap = | ||
request.fields.mapKeys { "_request.${it.key}" } + | ||
request.matchingFields.mapKeys { "_request.${it.key}" } + | ||
response.headers?.let { HTTPHeaders.normalizeHeaders(it) }.toFields() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,7 +125,6 @@ class CaptureLoggerTest { | |
"_host" to "api.bitdrift.io", | ||
"_method" to "GET", | ||
"_path" to "/my_path/12345", | ||
"_path_template" to "/my_path/<id>", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we now remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not this particular test, it starts a test server and does depend on some native code. I removed |
||
"_query" to "my=query", | ||
"_span_id" to spanId.toString(), | ||
"_span_name" to "_http", | ||
|
@@ -164,7 +163,6 @@ class CaptureLoggerTest { | |
"_host" to "api.bitdrift.io", | ||
"_method" to "GET", | ||
"_path" to "/my_path/12345", | ||
"_path_template" to "/my_path/<id>", | ||
"_query" to "my=query", | ||
"_span_id" to spanId.toString(), | ||
"_span_name" to "_http", | ||
|
@@ -181,7 +179,6 @@ class CaptureLoggerTest { | |
"_request._host" to "api.bitdrift.io", | ||
"_request._method" to "GET", | ||
"_request._path" to "/my_path/12345", | ||
"_request._path_template" to "/my_path/<id>", | ||
"_request._span_id" to spanId.toString(), | ||
"_request._span_name" to "_http", | ||
"_request._span_type" to "start", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code is very hard to reason about, can you add some comments about what you're trying to achieve here?