-
-
Notifications
You must be signed in to change notification settings - Fork 416
Support for manual transaction logging #853
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
Open
aliab
wants to merge
9
commits into
ChuckerTeam:main
Choose a base branch
from
aliab:support_for_manual_transaction
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
45e5ecd
add ManualHttpTransaction.kt to wrap over HttpTransaction entity. thiβ¦
aliab f191019
add saveTransaction method to ChuckerCollector.kt. ManualHttpTransactβ¦
aliab aacefb8
add default null value for ManualHttpTransaction.kt to instantiate itβ¦
aliab 085716f
add chucker collector as an argument to make it available as an exterβ¦
aliab b9344f6
add sample manual transaction to demonstrate how it is working
aliab 08245bc
add manual transaction task to all current task
aliab 25a92d5
Update CHANGELOG.md and add manual transaction to the unrelased part
aliab 509ed8f
update api files to match new api changes
aliab a8ef44d
merge with develp
aliab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
library-no-op/src/main/kotlin/com/chuckerteam/chucker/api/entity/ManualHttpTransaction.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package com.chuckerteam.chucker.api.entity | ||
|
|
||
| /** | ||
| * No-op implementation. | ||
| */ | ||
| public data class ManualHttpTransaction( | ||
| public var requestDate: Long? = null, | ||
| public var responseDate: Long? = null, | ||
| public var tookMs: Long? = null, | ||
| public var protocol: String? = null, | ||
| public var method: String? = null, | ||
| public var url: String? = null, | ||
| public var host: String? = null, | ||
| public var path: String? = null, | ||
| public var scheme: String? = null, | ||
| public var responseTlsVersion: String? = null, | ||
| public var responseCipherSuite: String? = null, | ||
| public var requestPayloadSize: Long? = null, | ||
| public var requestContentType: String? = null, | ||
| public var requestHeaders: String? = null, | ||
| public var requestHeadersSize: Long? = null, | ||
| public var requestBody: String? = null, | ||
| public var isRequestBodyEncoded: Boolean = false, | ||
| public var responseCode: Int? = null, | ||
| public var responseMessage: String? = null, | ||
| public var error: String? = null, | ||
| public var responsePayloadSize: Long? = null, | ||
| public var responseContentType: String? = null, | ||
| public var responseHeaders: String? = null, | ||
| public var responseHeadersSize: Long? = null, | ||
| public var responseBody: String? = null, | ||
| public var isResponseBodyEncoded: Boolean = false, | ||
| public var responseImageData: ByteArray? = null | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
library/src/main/kotlin/com/chuckerteam/chucker/api/entity/ManualHttpTransaction.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package com.chuckerteam.chucker.api.entity | ||
|
|
||
| import com.chuckerteam.chucker.internal.data.entity.HttpTransaction | ||
|
|
||
| /** | ||
| * Represent Manual Http transaction that developer want to populate as an custom http transaction | ||
| */ | ||
| public data class ManualHttpTransaction( | ||
| public var requestDate: Long? = null, | ||
| public var responseDate: Long? = null, | ||
| public var tookMs: Long? = null, | ||
| public var protocol: String? = null, | ||
| public var method: String? = null, | ||
| public var url: String? = null, | ||
| public var host: String? = null, | ||
| public var path: String? = null, | ||
| public var scheme: String? = null, | ||
| public var responseTlsVersion: String? = null, | ||
| public var responseCipherSuite: String? = null, | ||
| public var requestPayloadSize: Long? = null, | ||
| public var requestContentType: String? = null, | ||
| public var requestHeaders: String? = null, | ||
| public var requestHeadersSize: Long? = null, | ||
| public var requestBody: String? = null, | ||
| public var isRequestBodyEncoded: Boolean = false, | ||
| public var responseCode: Int? = null, | ||
| public var responseMessage: String? = null, | ||
| public var error: String? = null, | ||
| public var responsePayloadSize: Long? = null, | ||
| public var responseContentType: String? = null, | ||
| public var responseHeaders: String? = null, | ||
| public var responseHeadersSize: Long? = null, | ||
| public var responseBody: String? = null, | ||
| public var isResponseBodyEncoded: Boolean = false, | ||
| public var responseImageData: ByteArray? = null | ||
| ) { | ||
|
|
||
| /** | ||
| * this will convert this class to HttpTransaction to be able to save it on database as a real | ||
| * transaction. | ||
| */ | ||
| internal fun convertToHttpTransaction(): HttpTransaction { | ||
| return HttpTransaction( | ||
| 0, | ||
| requestDate, | ||
| responseDate, | ||
| tookMs, | ||
| protocol, | ||
| method, | ||
| url, | ||
| host, | ||
| path, | ||
| scheme, | ||
| responseTlsVersion, | ||
| responseCipherSuite, | ||
| requestPayloadSize, | ||
| requestContentType, | ||
| requestHeaders, | ||
| requestHeadersSize, | ||
| requestBody, | ||
| isRequestBodyEncoded, | ||
| responseCode, | ||
| responseMessage, | ||
| error, | ||
| responsePayloadSize, | ||
| responseContentType, | ||
| responseHeaders, | ||
| responseHeadersSize, | ||
| responseBody, | ||
| isResponseBodyEncoded, | ||
| responseImageData | ||
| ) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
sample/src/main/kotlin/com/chuckerteam/chucker/sample/ManualTransactionTask.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package com.chuckerteam.chucker.sample | ||
|
|
||
| import com.chuckerteam.chucker.api.ChuckerCollector | ||
| import com.chuckerteam.chucker.api.entity.ManualHttpTransaction | ||
|
|
||
| class ManualTransactionTask( | ||
| private val chuckerCollector: ChuckerCollector | ||
| ) : HttpTask { | ||
|
|
||
| override fun run() { | ||
| val responseBody = "Some Custom response body!" | ||
| chuckerCollector.saveTransaction( | ||
| transaction = ManualHttpTransaction( | ||
| requestDate = System.currentTimeMillis(), | ||
| responseDate = System.currentTimeMillis(), | ||
| protocol = "CustomProtocol", | ||
| method = "Custom Method", | ||
| responseContentType = "text/html; charset=UTF-8", | ||
| requestContentType = "text/html; charset=UTF-8", | ||
| scheme = "http", | ||
| isResponseBodyEncoded = false, | ||
| tookMs = 1000, | ||
| responseCode = 200, | ||
| responseMessage = "OK", | ||
| responseBody = responseBody, | ||
| isRequestBodyEncoded = false, | ||
| responsePayloadSize = responseBody.toByteArray().size.toLong(), | ||
| host = "Custom HOST", | ||
| url = "http://customUrl.com/", | ||
| path = "/custom", | ||
| ) | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why do we need another class here?
Uh oh!
There was an error while loading. Please reload this page.
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.
I didn't want to move the
HttpTransactionclass to the API package or expose it to the developer. I could use a builder pattern to build transaction objects or create a method with a bunch of args in theChuckerCollectorclass.But both of these mentioned approaches have their downsides regarding logging the data. In this implemented approach, to log a transaction's start and end information, the developer no longer needs to store the data in a separate data store and can create the model and fill it in during transactions. In the end, the developer can save the object in the chucker.