Skip to content
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

feat(monkeys): Write CC version in logs and allow to skip warmup [WPB-6784] #2529

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion monkeys/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ tasks.startScripts {
dependsOn(serverScripts)
}

tasks.jar {
manifest {
attributes["CC-Version"] = libs.coreCrypto.get().version
}
}

sourceSets {
val main by getting {

dependencies {
implementation(project(":network"))
implementation(project(":cryptography"))
Expand Down
6 changes: 3 additions & 3 deletions monkeys/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@
"passwordForUsers",
"domain",
"authUser",
"authPassword",
"userCount"
"authPassword"
],
"properties": {
"api": {
Expand Down Expand Up @@ -196,7 +195,8 @@
},
"userCount": {
"description": "How many users should be created in this team",
"type": "integer"
"type": "integer",
"default": 10
},
"2FAEnabled": {
"description": "Does this server require 2FA authentication?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import co.touchlab.kermit.LogWriter
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.types.enum
import com.wire.kalium.logger.KaliumLogLevel
Expand Down Expand Up @@ -60,6 +61,7 @@ import sun.misc.SignalHandler
import java.io.File
import java.util.Optional
import java.util.concurrent.atomic.AtomicBoolean
import java.util.jar.Manifest
import kotlin.coroutines.cancellation.CancellationException

fun CoroutineScope.stopIM() {
Expand All @@ -70,6 +72,7 @@ fun CoroutineScope.stopIM() {

class MonkeyApplication : CliktCommand(allowMultipleSubcommands = true) {
private val dataFilePath by argument(help = "path to the test data file")
private val skipWarmup by option("-s", "--skip-warmup", help = "Should the warmup be skipped?").flag()
private val logLevel by option("-l", "--log-level", help = "log level").enum<KaliumLogLevel>().default(KaliumLogLevel.INFO)
private val logOutputFile by option("-f", "--log-file", help = "output file for logs")
private val monkeysLogOutputFile by option("-m", "--monkeys-log-file", help = "output file for monkey logs")
Expand Down Expand Up @@ -102,7 +105,7 @@ class MonkeyApplication : CliktCommand(allowMultipleSubcommands = true) {
}
}.start(false).stopServerOnCancellation()

logger.i("Initializing Infinite Monkeys")
logger.i("Initializing Infinite Monkeys - CC: ${getCCVersion()}")
val testData = TestDataImporter.importFromFile(dataFilePath)
val eventProcessor = when (testData.eventStorage) {
is com.wire.kalium.monkeys.model.EventStorage.FileStorage -> FileStorage(testData.eventStorage)
Expand Down Expand Up @@ -151,8 +154,10 @@ class MonkeyApplication : CliktCommand(allowMultipleSubcommands = true) {
// the first one creates the preset groups and logs everyone in so keypackages are created
val eventChannel = Channel<Event>(Channel.UNLIMITED)
if (index == 0) {
logger.i("Creating initial key packages for clients (logging everyone in and out). This can take a while...")
monkeyPool.warmUp(coreLogic)
if (!this.skipWarmup) {
logger.i("Creating initial key packages for clients (logging everyone in and out). This can take a while...")
monkeyPool.warmUp(coreLogic)
}
logger.i("Creating prefixed groups")
testData.conversationDistribution.forEach { (prefix, config) ->
ConversationPool.createPrefixedConversations(
Expand All @@ -173,5 +178,16 @@ class MonkeyApplication : CliktCommand(allowMultipleSubcommands = true) {
companion object {
val HOME_DIRECTORY: String = homeDirectory()
val isActive = AtomicBoolean(true)

fun getCCVersion(): String {
this::class.java.classLoader?.getResources("META-INF/MANIFEST.MF")?.asIterator()?.forEach { url ->
url.openStream().use {
val manifest = Manifest(it)
if (manifest.mainAttributes.getValue("CC-Version") != null)
return manifest.mainAttributes.getValue("CC-Version")
}
}
return "Not-Found"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ data class BackendConfig(
@SerialName("teamName") val teamName: String,
@SerialName("authUser") val authUser: String,
@SerialName("authPassword") val authPassword: String,
@SerialName("userCount") val userCount: ULong,
@SerialName("userCount") val userCount: ULong = 10u,
@SerialName("2FAEnabled") val secondFactorAuth: Boolean = false,
@SerialName("dumpUsers") val dumpUsers: Boolean = false,
@SerialName("presetTeam") val presetTeam: TeamConfig? = null
Expand Down
Loading