Skip to content

Commit

Permalink
KTOR log level can be set (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
arndey authored Nov 18, 2024
1 parent 558784f commit 1cd813f
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fun main(args: Array<String>): Unit = runBlocking {
"9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e",
)

val client = AdminIroha2Client(URL(peerUrl), URL(peerUrl), URL(telemetryUrl), log = true)
val client = AdminIroha2Client(URL(peerUrl), URL(peerUrl), URL(telemetryUrl))
val query = Query(client, admin, adminKeyPair)
query.findAllDomains()
.also { println("ALL DOMAINS: ${it.map { d -> d.id.asString() }}") }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jp.co.soramitsu.iroha2

import io.ktor.client.plugins.logging.LogLevel
import jp.co.soramitsu.iroha2.model.IrohaUrls
import kotlinx.coroutines.future.future

Expand All @@ -9,9 +10,9 @@ import kotlinx.coroutines.future.future
@Suppress("unused")
class AdminIroha2AsyncClient @JvmOverloads constructor(
urls: List<IrohaUrls>,
log: Boolean = false,
httpLogLevel: LogLevel = LogLevel.NONE,
credentials: String? = null,
) : AdminIroha2Client(urls, log, credentials) {
) : AdminIroha2Client(urls, httpLogLevel, credentials) {

/**
* Send health check request
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jp.co.soramitsu.iroha2

import io.ktor.client.call.body
import io.ktor.client.plugins.logging.LogLevel
import io.ktor.client.request.get
import io.ktor.client.request.setBody
import io.ktor.client.statement.HttpResponse
Expand All @@ -18,35 +19,35 @@ import java.net.URL
@Suppress("unused")
open class AdminIroha2Client(
urls: List<IrohaUrls>,
log: Boolean = false,
httpLogLevel: LogLevel = LogLevel.NONE,
credentials: String? = null,
private val balancingHealthCheck: Boolean = true,
) : Iroha2Client(urls, log, credentials) {
) : Iroha2Client(urls, httpLogLevel, credentials) {

constructor(
url: IrohaUrls,
log: Boolean = false,
httpLogLevel: LogLevel = LogLevel.NONE,
credentials: String? = null,
balancingHealthCheck: Boolean = true,
) : this(mutableListOf(url), log, credentials, balancingHealthCheck)
) : this(mutableListOf(url), httpLogLevel, credentials, balancingHealthCheck)

constructor(
apiUrl: URL,
telemetryUrl: URL,
peerUrl: URL,
log: Boolean = false,
httpLogLevel: LogLevel = LogLevel.NONE,
credentials: String? = null,
balancingHealthCheck: Boolean = true,
) : this(IrohaUrls(apiUrl, telemetryUrl, peerUrl), log, credentials, balancingHealthCheck)
) : this(IrohaUrls(apiUrl, telemetryUrl, peerUrl), httpLogLevel, credentials, balancingHealthCheck)

constructor(
apiUrl: String,
telemetryUrl: String,
peerUrl: String,
log: Boolean = false,
httpLogLevel: LogLevel = LogLevel.NONE,
credentials: String? = null,
balancingHealthCheck: Boolean = true,
) : this(URL(apiUrl), URL(telemetryUrl), URL(peerUrl), log, credentials, balancingHealthCheck)
) : this(URL(apiUrl), URL(telemetryUrl), URL(peerUrl), httpLogLevel, credentials, balancingHealthCheck)

/**
* Send metrics request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ class DeserializerTest {
val block = JSON_SERDE.convertValue(node, RawGenesisBlock::class.java)

assert(block.transactions.isNotEmpty())
// genesis.json has 12 instructions ("isi")
// Register -> NewDomain
// Register -> NewAccount (2)
// Register -> NewAssetDefinition
// Grant -> PermissionToken (2)
// Mint -> AssetId (2)
// Register -> Trigger (4)
assert(block.transactions.flatten().size == 12)

val genesis = Genesis(block)
val newJson = removeWhiteSpaceAndReplacePubKey(genesis.asJson())
Expand Down Expand Up @@ -93,7 +85,8 @@ class DeserializerTest {

private fun removeWhiteSpaceAndReplacePubKey(json: String): String {
val regex = "(\"ed01)+\\w+\"".toRegex()
return json.replace(System.getProperty("line.separator"), "")
return json
.replace(System.getProperty("line.separator"), "")
.replace(" ", "")
.replace(regex, "publicKey")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jp.co.soramitsu.iroha2.client

import io.ktor.client.plugins.logging.LogLevel
import jp.co.soramitsu.iroha2.generated.SignedTransaction
import jp.co.soramitsu.iroha2.model.IrohaUrls
import jp.co.soramitsu.iroha2.query.QueryAndExtractor
Expand All @@ -14,11 +15,11 @@ import java.util.concurrent.CompletableFuture
@Suppress("unused")
class Iroha2AsyncClient @JvmOverloads constructor(
urls: List<IrohaUrls>,
log: Boolean = false,
httpLogLevel: LogLevel = LogLevel.NONE,
credentials: String? = null,
eventReadTimeoutInMills: Long = 250,
eventReadMaxAttempts: Int = 10,
) : Iroha2Client(urls, log, credentials, eventReadTimeoutInMills, eventReadMaxAttempts) {
) : Iroha2Client(urls, httpLogLevel, credentials, eventReadTimeoutInMills, eventReadMaxAttempts) {

/**
* Send a request to Iroha2 and extract payload.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import io.ktor.client.plugins.auth.Auth
import io.ktor.client.plugins.auth.providers.BasicAuthCredentials
import io.ktor.client.plugins.auth.providers.basic
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.plugins.logging.LogLevel
import io.ktor.client.plugins.logging.Logging
import io.ktor.client.plugins.websocket.WebSockets
import io.ktor.client.plugins.websocket.webSocket
Expand Down Expand Up @@ -83,7 +84,7 @@ import kotlin.coroutines.CoroutineContext
@Suppress("unused")
open class Iroha2Client(
open val urls: List<IrohaUrls>,
open val log: Boolean = false,
open val httpLogLevel: LogLevel = LogLevel.NONE,
open val credentials: String? = null,
open val eventReadTimeoutInMills: Long = 250,
open val eventReadMaxAttempts: Int = 10,
Expand All @@ -92,23 +93,23 @@ open class Iroha2Client(

constructor(
url: IrohaUrls,
log: Boolean = false,
httpLogLevel: LogLevel = LogLevel.NONE,
credentials: String? = null,
eventReadTimeoutInMills: Long = 250,
eventReadMaxAttempts: Int = 10,
) : this(mutableListOf(url), log, credentials, eventReadTimeoutInMills, eventReadMaxAttempts)
) : this(mutableListOf(url), httpLogLevel, credentials, eventReadTimeoutInMills, eventReadMaxAttempts)

constructor(
apiUrl: URL,
telemetryUrl: URL,
peerUrl: URL,
log: Boolean = false,
httpLogLevel: LogLevel = LogLevel.NONE,
credentials: String? = null,
eventReadTimeoutInMills: Long = 250,
eventReadMaxAttempts: Int = 10,
) : this(
IrohaUrls(apiUrl, telemetryUrl, peerUrl),
log,
httpLogLevel,
credentials,
eventReadTimeoutInMills,
eventReadMaxAttempts,
Expand All @@ -118,15 +119,15 @@ open class Iroha2Client(
apiUrl: String,
telemetryUrl: String,
peerUrl: String,
log: Boolean = true,
httpLogLevel: LogLevel = LogLevel.NONE,
credentials: String? = null,
eventReadTimeoutInMills: Long = 250,
eventReadMaxAttempts: Int = 10,
) : this(
URL(apiUrl),
URL(telemetryUrl),
URL(peerUrl),
log,
httpLogLevel,
credentials,
eventReadTimeoutInMills,
eventReadMaxAttempts,
Expand All @@ -150,8 +151,8 @@ open class Iroha2Client(
open val client by lazy {
HttpClient(CIO) {
expectSuccess = true
if (log) {
install(Logging)
install(Logging) {
level = httpLogLevel
}
install(WebSockets)
install(ContentNegotiation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ExampleTest {
this.genesis = DefaultGenesis::class.createInstance()
}.also { it.start() }

val client = Iroha2Client(container.getApiUrl(), container.getTelemetryUrl(), container.getP2pUrl(), true)
val client = Iroha2Client(container.getApiUrl(), container.getTelemetryUrl(), container.getP2pUrl())

val domainId = "new_domain_name".asDomainId()
client.sendTransaction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class GenesisTest : IrohaTest<Iroha2Client>() {
this.genesisPath = path
}.also { it.start() }

val client = Iroha2Client(container.getApiUrl(), container.getTelemetryUrl(), container.getP2pUrl(), true)
val client = Iroha2Client(container.getApiUrl(), container.getTelemetryUrl(), container.getP2pUrl())
client.checkAliceAndBobExists()
}

Expand Down

0 comments on commit 1cd813f

Please sign in to comment.