Skip to content

Commit

Permalink
Merge pull request #48 from soramitsu/transfer_asset
Browse files Browse the repository at this point in the history
updated unsubscribe
  • Loading branch information
timofeevmd authored Feb 1, 2024
2 parents e138104 + ff67469 commit ce69c12
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 169 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,6 @@
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-android</artifactId>
<version>1.7.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_pushgateway</artifactId>
Expand Down
74 changes: 34 additions & 40 deletions src/main/kotlin/jp/co/soramitsu/load/TransferAssets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import io.gatling.javaapi.core.CoreDsl.*
import io.gatling.javaapi.core.ScenarioBuilder
import jp.co.soramitsu.iroha2.asAccountId
import jp.co.soramitsu.iroha2.asAssetId
import jp.co.soramitsu.iroha2.client.blockstream.BlockStreamStorage
import jp.co.soramitsu.iroha2.client.blockstream.BlockStreamSubscription
import jp.co.soramitsu.iroha2.generated.*
import jp.co.soramitsu.iroha2.asDomainId
import jp.co.soramitsu.load.TechicalScns.Iroha2SetUp
Expand Down Expand Up @@ -46,17 +44,15 @@ class TransferAssets : Wrench13() {
Session
}
.exec { Session ->
val iroha2Client = buildClient(SimulationConfig.simulation.configuration())
timer = CustomMetrics.subscriptionToBlockStreamTimer.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
Iroha2SetUp::class.simpleName
).startTimer()
try {
val idToSubscription: Pair<Iterable<BlockStreamStorage>, BlockStreamSubscription> =
iroha2Client.subscribeToBlockStream(1, 2)
subscription = idToSubscription.component2()
} finally {
runBlocking {
val iroha2Client = buildClient(SimulationConfig.simulation.configuration())
timer = CustomMetrics.subscriptionToBlockStreamTimer.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
Iroha2SetUp::class.simpleName
).startTimer()
val idToSubscription = iroha2Client.subscribeToBlockStream(1, 2)
val subscription = idToSubscription.second
timer.observeDuration()
CustomMetrics.subscriptionToBlockStreamCount.labels(
"gatling",
Expand All @@ -65,20 +61,18 @@ class TransferAssets : Wrench13() {
).inc()
sendMetricsToPrometheus(CustomMetrics.subscriptionToBlockStreamCount, "transaction")
sendMetricsToPrometheus(CustomMetrics.subscriptionToBlockStreamTimer, "transaction")
}
timer = CustomMetrics.transferAssetTimer.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
Iroha2SetUp::class.simpleName
).startTimer()
CustomMetrics.transferAssetCount.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
Iroha2SetUp::class.simpleName
).inc()
sendMetricsToPrometheus(CustomMetrics.transferAssetCount, "transaction")
try {
runBlocking {
timer = CustomMetrics.transferAssetTimer.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
Iroha2SetUp::class.simpleName
).startTimer()
CustomMetrics.transferAssetCount.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
Iroha2SetUp::class.simpleName
).inc()
sendMetricsToPrometheus(CustomMetrics.transferAssetCount, "transaction")
try {
iroha2Client.sendTransaction {
account(anotherDevAccountIdSender)
transferAsset(anotherDevAssetIdSender, 1, targetDevAccountIdReceiver)
Expand All @@ -89,20 +83,20 @@ class TransferAssets : Wrench13() {
pliers.healthCheck(true, "TransferAssets")
}
}
subscription.close()
subscription.stop()
} catch (ex: RuntimeException) {
CustomMetrics.transferAssetErrorCount.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
Iroha2SetUp::class.simpleName
).inc()
sendMetricsToPrometheus(CustomMetrics.transferAssetErrorCount, "transaction")
println("Something went wrong on TransferAssets scenario, problem with transfer asset transaction: " + ex.message)
pliers.healthCheck(false, "TransferAssets")
} finally {
timer.observeDuration()
sendMetricsToPrometheus(CustomMetrics.transferAssetTimer, "transaction")
}
} catch (ex: RuntimeException) {
CustomMetrics.transferAssetErrorCount.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
Iroha2SetUp::class.simpleName
).inc()
sendMetricsToPrometheus(CustomMetrics.transferAssetErrorCount, "transaction")
println("Something went wrong on TransferAssets scenario, problem with transfer asset transaction: " + ex.message)
pliers.healthCheck(false, "TransferAssets")
} finally {
timer.observeDuration()
sendMetricsToPrometheus(CustomMetrics.transferAssetTimer, "transaction")
}
Session
}
Expand Down
138 changes: 67 additions & 71 deletions src/main/kotlin/jp/co/soramitsu/load/TransferAssetsQuery.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,46 +49,46 @@ class TransferAssetsQuery : Wrench13() {
Session
}
.exec { Session ->
val iroha2Client = buildClient(SimulationConfig.simulation.configuration())
timer = CustomMetrics.findAssetsByAccountIdQueryTimer.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
TransferAssetsQuery::class.simpleName
).startTimer()
CustomMetrics.findAssetsByAccountIdQueryCount.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
TransferAssetsQuery::class.simpleName
).inc()
sendMetricsToPrometheus(CustomMetrics.findAssetsByAccountIdQueryCount, "query")
try {
runBlocking {
QueryBuilder.findAssetsByAccountId(anotherDevAccountIdSender)
.account(anotherDevAccountIdSender)
.buildSigned(anotherDevKeyPair)
.let { query ->
iroha2Client.sendQuery(query)
}
}
} catch (ex: RuntimeException) {
CustomMetrics.findAssetsByAccountIdQueryErrorCount.labels(
val iroha2Client = buildClient(SimulationConfig.simulation.configuration())
timer = CustomMetrics.findAssetsByAccountIdQueryTimer.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
TransferAssetsQuery::class.simpleName
).inc()
sendMetricsToPrometheus(CustomMetrics.findAssetsByAccountIdQueryErrorCount, "query")
println("Something went wrong on findAssetsByAccountIdQuery request, problem with find asset query: " + ex.message)
pliers.healthCheck(false, "TransferAssets")
} finally {
timer.observeDuration()
).startTimer()
CustomMetrics.findAssetsByAccountIdQueryCount.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
TransferAssetsQuery::class.simpleName
).inc()
sendMetricsToPrometheus(CustomMetrics.findAssetsByAccountIdQueryCount, "query")
sendMetricsToPrometheus(CustomMetrics.findAssetsByAccountIdQueryTimer, "query")
}
try {
runBlocking {
QueryBuilder.findAssetsByAccountId(anotherDevAccountIdSender)
.account(anotherDevAccountIdSender)
.buildSigned(anotherDevKeyPair)
.let { query ->
iroha2Client.sendQuery(query)
}
}
} catch (ex: RuntimeException) {
CustomMetrics.findAssetsByAccountIdQueryErrorCount.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
TransferAssetsQuery::class.simpleName
).inc()
sendMetricsToPrometheus(CustomMetrics.findAssetsByAccountIdQueryErrorCount, "query")
println("Something went wrong on findAssetsByAccountIdQuery request, problem with find asset query: " + ex.message)
pliers.healthCheck(false, "TransferAssets")
} finally {
timer.observeDuration()
CustomMetrics.findAssetsByAccountIdQueryCount.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
TransferAssetsQuery::class.simpleName
).inc()
sendMetricsToPrometheus(CustomMetrics.findAssetsByAccountIdQueryCount, "query")
sendMetricsToPrometheus(CustomMetrics.findAssetsByAccountIdQueryTimer, "query")
}
Session
}
.exec { Session ->
Expand Down Expand Up @@ -143,17 +143,15 @@ class TransferAssetsQuery : Wrench13() {
}.doIf { Session -> Session.getBoolean("condition") }
.then(
exec { Session ->
val iroha2Client = buildClient(SimulationConfig.simulation.configuration())
timer = CustomMetrics.subscriptionToBlockStreamTimer.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
TransferAssetsQuery::class.simpleName
).startTimer()
try {
val idToSubscription: Pair<Iterable<BlockStreamStorage>, BlockStreamSubscription> =
iroha2Client.subscribeToBlockStream(1, 2)
subscription = idToSubscription.component2()
} finally {
runBlocking {
val iroha2Client = buildClient(SimulationConfig.simulation.configuration())
timer = CustomMetrics.subscriptionToBlockStreamTimer.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
TransferAssetsQuery::class.simpleName
).startTimer()
val idToSubscription = iroha2Client.subscribeToBlockStream(1, 2)
val subscription = idToSubscription.second
timer.observeDuration()
CustomMetrics.subscriptionToBlockStreamCount.labels(
"gatling",
Expand All @@ -162,20 +160,18 @@ class TransferAssetsQuery : Wrench13() {
).inc()
sendMetricsToPrometheus(CustomMetrics.subscriptionToBlockStreamCount, "transaction")
sendMetricsToPrometheus(CustomMetrics.subscriptionToBlockStreamTimer, "transaction")
}
timer = CustomMetrics.transferAssetTimer.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
TransferAssetsQuery::class.simpleName
).startTimer()
CustomMetrics.transferAssetCount.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
TransferAssetsQuery::class.simpleName
).inc()
sendMetricsToPrometheus(CustomMetrics.transferAssetCount, "transaction")
try {
runBlocking {
timer = CustomMetrics.transferAssetTimer.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
TransferAssetsQuery::class.simpleName
).startTimer()
CustomMetrics.transferAssetCount.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
TransferAssetsQuery::class.simpleName
).inc()
sendMetricsToPrometheus(CustomMetrics.transferAssetCount, "transaction")
try {
iroha2Client.sendTransaction {
account(anotherDevAccountIdSender)
transferAsset(anotherDevAssetIdSender, 1, targetDevAccountIdReceiver)
Expand All @@ -186,23 +182,23 @@ class TransferAssetsQuery : Wrench13() {
pliers.healthCheck(true, "TransferAssets")
}
}
subscription.close()
subscription.stop()
} catch (ex: RuntimeException) {
CustomMetrics.transferAssetErrorCount.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
TransferAssetsQuery::class.simpleName
).inc()
sendMetricsToPrometheus(CustomMetrics.transferAssetErrorCount, "transaction")
println("Something went wrong on TransferAssets scenario, problem with transfer asset transaction: " + ex.message)
pliers.healthCheck(false, "TransferAssets")
} finally {
timer.observeDuration()
sendMetricsToPrometheus(CustomMetrics.transferAssetTimer, "transaction")
}
} catch (ex: RuntimeException) {
CustomMetrics.transferAssetErrorCount.labels(
"gatling",
System.getProperty("user.dir").substringAfterLast("/").substringAfterLast("\\"),
TransferAssetsQuery::class.simpleName
).inc()
sendMetricsToPrometheus(CustomMetrics.transferAssetErrorCount, "transaction")
println("Something went wrong on TransferAssets scenario, problem with transfer asset transaction: " + ex.message)
pliers.healthCheck(false, "TransferAssets")
} finally {
timer.observeDuration()
sendMetricsToPrometheus(CustomMetrics.transferAssetTimer, "transaction")
val newSession = Session.set("condition", false)
newSession
}
val newSession = Session.set("condition", false)
newSession
}
.exec { Session ->
val iroha2Client = buildClient(SimulationConfig.simulation.configuration())
Expand Down
Loading

0 comments on commit ce69c12

Please sign in to comment.