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: Add new output style to print smaller output #1375

Merged
merged 6 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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: 7 additions & 0 deletions docs/logging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Logs in Flank

1. Log level depends on the output style.
1. ```Simple, multi``` and ```verbose``` output style prints logs from ```SIMPLE``` and ```DETAILED``` levels.
1. ```Compact``` style prints log only from ```SIMPLE``` level.
1. If you want a print message for all output styles uses ```log``` or ```logLn``` with only ```message``` parameter.
1. If you want print message more detailed message use ```log``` or ```logLn``` and set ```level``` to ```OutputLogLevel.DETAILED```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to update the # output-style: single section in the user facing docs & example yaml files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Docs and yaml examples updated.

2 changes: 1 addition & 1 deletion flank-scripts/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ shadowJar.apply {
}
}
// <breaking change>.<feature added>.<fix/minor change>
version = "1.1.4"
version = "1.1.5"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to update this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I check it one more time and it's fine with 1.1.4. I revert it and we check on CI.

group = "com.github.flank"

application {
Expand Down
7 changes: 4 additions & 3 deletions test_runner/src/main/kotlin/ftl/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ftl.cli.firebase.test.IPBlocksCommand
import ftl.cli.firebase.test.IosCommand
import ftl.cli.firebase.test.NetworkProfilesCommand
import ftl.cli.firebase.test.ProvidedSoftwareCommand
import ftl.log.logLn
import ftl.log.setDebugLogging
import ftl.util.readRevision
import ftl.util.readVersion
Expand Down Expand Up @@ -53,9 +54,9 @@ class Main : Runnable {
// Flank must invoke exitProcess to exit cleanly.
// https://github.com/bugsnag/bugsnag-java/issues/151
withGlobalExceptionHandling {
println("version: " + readVersion())
println("revision: " + readRevision())
println()
logLn("version: " + readVersion())
logLn("revision: " + readRevision())
logLn()
CommandLine(Main()).execute(*args)
}
}
Expand Down
3 changes: 2 additions & 1 deletion test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ftl.environment.common.asPrintableTable
import ftl.environment.getLocaleDescription
import ftl.gc.GcTesting
import ftl.http.executeWithRetry
import ftl.log.logLn

/**
* Contains lists of possible Android device and version ids, as well as checks
Expand Down Expand Up @@ -77,7 +78,7 @@ object AndroidCatalog {
val form = deviceCatalog(projectId).models
.find { it.id.equals(modelId, ignoreCase = true) }?.form
?: DeviceType.PHYSICAL.name.also {
println("Unable to find device type for $modelId. PHYSICAL used as fallback in cost calculations")
logLn("Unable to find device type for $modelId. PHYSICAL used as fallback in cost calculations")
}

return form.equals(DeviceType.VIRTUAL.name, ignoreCase = true)
Expand Down
9 changes: 5 additions & 4 deletions test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import ftl.config.credential
import ftl.config.defaultCredentialPath
import ftl.gc.GcStorage
import ftl.gc.GcToolResults
import ftl.log.logLn
import ftl.reports.xml.model.JUnitTestResult
import ftl.run.exception.FlankConfigurationError
import ftl.run.exception.FlankGeneralError
Expand Down Expand Up @@ -171,7 +172,7 @@ object ArgsHelper {
.build()
)
} catch (e: Exception) {
println("Warning: Failed to make bucket for $projectId\nCause: ${e.message}")
logLn("Warning: Failed to make bucket for $projectId\nCause: ${e.message}")
}

return bucket
Expand All @@ -187,8 +188,8 @@ object ArgsHelper {
GenericJson::class.java
)["project_id"] as String
} catch (e: Exception) {
println("Parsing $defaultCredentialPath failed:")
println(e.printStackTrace())
logLn("Parsing $defaultCredentialPath failed:")
logLn(e.printStackTrace())
}

return null
Expand All @@ -211,7 +212,7 @@ object ArgsHelper {
val envName = matcher.group(1)
val envValue: String? = System.getenv(envName)
if (envValue == null) {
println("WARNING: $envName not found")
logLn("WARNING: $envName not found")
}
matcher.appendReplacement(buffer, envValue ?: "")
}
Expand Down
8 changes: 8 additions & 0 deletions test_runner/src/main/kotlin/ftl/args/IArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ftl.args
import ftl.args.yml.Type
import ftl.config.Device
import ftl.config.common.CommonFlankConfig.Companion.defaultLocalResultsDir
import ftl.log.OutputLogLevel
import ftl.run.status.OutputStyle
import ftl.util.timeoutToMils

Expand Down Expand Up @@ -82,3 +83,10 @@ interface IArgs {
val validArgs: Map<String, List<String>>
}
}

val IArgs.logLevel
get() = if (outputStyle == OutputStyle.Compact) OutputLogLevel.SIMPLE else OutputLogLevel.DETAILED

fun IArgs.setLogLevel() = also {
ftl.log.setLogLevel(logLevel)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO setSomething needs some parameter, so I would suggest to rename it to setupLogLevel

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

9 changes: 5 additions & 4 deletions test_runner/src/main/kotlin/ftl/args/ValidateAndroidArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ftl.android.UnsupportedVersionId
import ftl.args.yml.Type
import ftl.config.containsPhysicalDevices
import ftl.config.containsVirtualDevices
import ftl.log.logLn
import ftl.run.exception.FlankConfigurationError
import ftl.run.exception.FlankGeneralError
import ftl.run.exception.IncompatibleTestDimensionError
Expand Down Expand Up @@ -146,7 +147,7 @@ private fun AndroidArgs.assertMaxTestShardsByDeviceType() =
}

private fun AndroidArgs.assertDevicesShards() {
if (inVirtualRange && !inPhysicalRange) println("Physical devices configured, but max-test-shards limit set to $maxTestShards, for physical devices range is ${IArgs.AVAILABLE_PHYSICAL_SHARD_COUNT_RANGE.first} to ${IArgs.AVAILABLE_PHYSICAL_SHARD_COUNT_RANGE.last}, you additionally have configured virtual devices. In this case, the physical limit will be decreased to: ${IArgs.AVAILABLE_PHYSICAL_SHARD_COUNT_RANGE.last}")
if (inVirtualRange && !inPhysicalRange) logLn("Physical devices configured, but max-test-shards limit set to $maxTestShards, for physical devices range is ${IArgs.AVAILABLE_PHYSICAL_SHARD_COUNT_RANGE.first} to ${IArgs.AVAILABLE_PHYSICAL_SHARD_COUNT_RANGE.last}, you additionally have configured virtual devices. In this case, the physical limit will be decreased to: ${IArgs.AVAILABLE_PHYSICAL_SHARD_COUNT_RANGE.last}")
else if (!inVirtualRange && !inPhysicalRange) throwMaxTestShardsLimitExceeded()
}

Expand Down Expand Up @@ -217,15 +218,15 @@ private fun AndroidArgs.assertOtherFiles() {

private fun AndroidArgs.checkEnvironmentVariables() {
if (environmentVariables.isNotEmpty() && directoriesToPull.isEmpty())
println("WARNING: environment-variables set but directories-to-pull is empty, this will result in the coverage file not downloading to the bucket.")
logLn("WARNING: environment-variables set but directories-to-pull is empty, this will result in the coverage file not downloading to the bucket.")
}

private fun AndroidArgs.checkFilesToDownload() {
if (filesToDownload.isNotEmpty() && directoriesToPull.isEmpty())
println("WARNING: files-to-download is set but directories-to-pull is empty, the coverage file may fail to download into the bucket.")
logLn("WARNING: files-to-download is set but directories-to-pull is empty, the coverage file may fail to download into the bucket.")
}

private fun AndroidArgs.checkNumUniformShards() {
if ((numUniformShards ?: 0) > 0 && disableSharding)
println("WARNING: disable-sharding is enabled with num-uniform-shards = $numUniformShards, Flank will ignore num-uniform-shards and disable sharding.")
logLn("WARNING: disable-sharding is enabled with num-uniform-shards = $numUniformShards, Flank will ignore num-uniform-shards and disable sharding.")
}
5 changes: 3 additions & 2 deletions test_runner/src/main/kotlin/ftl/args/ValidateCommonArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ftl.config.Device
import ftl.config.FtlConstants
import ftl.config.defaultCredentialPath
import ftl.gc.GcStorage
import ftl.log.logLn
import ftl.reports.FullJUnitReport
import ftl.reports.JUnitReport
import ftl.run.exception.FlankConfigurationError
Expand Down Expand Up @@ -72,10 +73,10 @@ private fun CommonArgs.assertSmartFlankGcsPath() = with(smartFlankGcsPath) {

fun IArgs.checkResultsDirUnique() {
if (useLegacyJUnitResult && GcStorage.exist(resultsBucket, resultsDir))
println("WARNING: Google cloud storage result directory should be unique, otherwise results from multiple test matrices will be overwritten or intermingled\n")
logLn("WARNING: Google cloud storage result directory should be unique, otherwise results from multiple test matrices will be overwritten or intermingled\n")
}

fun IArgs.checkDisableSharding() {
if (disableSharding && maxTestShards > 0)
println("WARNING: disable-sharding enabled with max-test-shards = $maxTestShards, Flank will ignore max-test-shard and disable sharding.")
logLn("WARNING: disable-sharding enabled with max-test-shards = $maxTestShards, Flank will ignore max-test-shard and disable sharding.")
}
5 changes: 3 additions & 2 deletions test_runner/src/main/kotlin/ftl/args/yml/YamlDeprecated.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.node.MissingNode
import com.fasterxml.jackson.databind.node.ObjectNode
import com.google.common.annotations.VisibleForTesting
import ftl.args.ArgsHelper.yamlMapper
import ftl.log.logLn
import ftl.util.loadFile
import ftl.run.exception.FlankConfigurationError
import ftl.run.exception.FlankGeneralError
Expand Down Expand Up @@ -116,7 +117,7 @@ object YamlDeprecated {
private fun validate(key: Key, keyValue: JsonNode): Transform? {
transforms.forEach {
if (it.old == key) {
println("${it.level}: `${it.old.parent}: ${it.old.name}:` renamed to `${it.new.parent}: ${it.new.name}:`")
logLn("${it.level}: `${it.old.parent}: ${it.old.name}:` renamed to `${it.new.parent}: ${it.new.name}:`")
return Transform(keyValue, it)
}
}
Expand All @@ -132,7 +133,7 @@ object YamlDeprecated {
val (errorDetected, string) = modify(loadFile(yamlPath))

Files.write(yamlPath, string.toByteArray())
println("\nUpdated ${yamlPath.fileName} file")
logLn("\nUpdated ${yamlPath.fileName} file")

return errorDetected
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ package ftl.cli.firebase.test

import ftl.args.yml.YamlDeprecated
import ftl.args.yml.fixDevices
import ftl.log.logLn
import ftl.run.exception.YmlValidationError
import java.nio.file.Path

fun processValidation(validationResult: String, shouldFix: Boolean, ymlPath: Path) {
when {
validationResult.isBlank() -> println("Valid yml file")
validationResult.isBlank() -> logLn("Valid yml file")
!shouldFix -> {
println(validationResult)
logLn(validationResult)
throw YmlValidationError("Invalid yml file, use --fix for automatically fix yml")
}
else -> {
println(validationResult)
println("Trying to fix yml file")
logLn(validationResult)
logLn("Trying to fix yml file")
if (YamlDeprecated.modify(ymlPath)) {
throw YmlValidationError("Invalid yml file, unable to fix yml file")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ftl.cli.firebase.test.android

import ftl.args.AndroidArgs
import ftl.args.setLogLevel
import ftl.args.validate
import ftl.cli.firebase.test.CommonRunCommand
import ftl.config.FtlConstants
Expand Down Expand Up @@ -45,6 +46,7 @@ class AndroidRunCommand : CommonRunCommand(), Runnable {
}

AndroidArgs.load(Paths.get(configPath), cli = this).validate().run {
setLogLevel()
runBlocking {
if (dumpShards) dumpShards()
else newTestRun()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ftl.config.FtlConstants
import ftl.environment.ipBlocksListAsTable
import ftl.environment.networkConfigurationAsTable
import ftl.environment.providedSoftwareAsTable
import ftl.log.logLn
import picocli.CommandLine
import java.nio.file.Paths

Expand All @@ -28,13 +29,13 @@ import java.nio.file.Paths
class AndroidTestEnvironmentCommand : Runnable {
override fun run() {
val projectId = AndroidArgs.loadOrDefault(Paths.get(configPath)).project
println(devicesCatalogAsTable(projectId))
println(supportedVersionsAsTable(projectId))
println(localesAsTable(projectId))
println(providedSoftwareAsTable())
println(networkConfigurationAsTable())
println(supportedOrientationsAsTable(projectId))
println(ipBlocksListAsTable())
logLn(devicesCatalogAsTable(projectId))
logLn(supportedVersionsAsTable(projectId))
logLn(localesAsTable(projectId))
logLn(providedSoftwareAsTable())
logLn(networkConfigurationAsTable())
logLn(supportedOrientationsAsTable(projectId))
logLn(ipBlocksListAsTable())
}

@CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.android.configuration
import ftl.android.AndroidCatalog.getLocaleDescription
import ftl.args.AndroidArgs
import ftl.config.FtlConstants
import ftl.log.log
import ftl.run.exception.FlankConfigurationError
import picocli.CommandLine
import java.nio.file.Paths
Expand All @@ -20,7 +21,7 @@ import java.nio.file.Paths
class AndroidLocalesDescribeCommand : Runnable {
override fun run() {
if (locale.isBlank()) throw FlankConfigurationError("Argument LOCALE must be specified.")
print(getLocaleDescription(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, locale))
log(getLocaleDescription(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, locale))
}

@CommandLine.Parameters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.android.configuration
import ftl.android.AndroidCatalog
import ftl.args.AndroidArgs
import ftl.config.FtlConstants
import ftl.log.logLn
import picocli.CommandLine
import java.nio.file.Paths

Expand All @@ -19,7 +20,7 @@ import java.nio.file.Paths
)
class AndroidLocalesListCommand : Runnable {
override fun run() {
println(AndroidCatalog.localesAsTable(projectId = AndroidArgs.loadOrDefault(Paths.get(configPath)).project))
logLn(AndroidCatalog.localesAsTable(projectId = AndroidArgs.loadOrDefault(Paths.get(configPath)).project))
}

@CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.android.models
import ftl.android.AndroidCatalog
import ftl.args.AndroidArgs
import ftl.config.FtlConstants
import ftl.log.logLn
import ftl.run.exception.FlankConfigurationError
import picocli.CommandLine
import java.nio.file.Paths
Expand All @@ -20,7 +21,7 @@ import java.nio.file.Paths
class AndroidModelDescribeCommand : Runnable {
override fun run() {
if (modelId.isBlank()) throw FlankConfigurationError("Argument MODEL_ID must be specified.")
println(AndroidCatalog.describeModel(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, modelId))
logLn(AndroidCatalog.describeModel(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, modelId))
}

@CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.android.models
import ftl.android.AndroidCatalog
import ftl.args.AndroidArgs
import ftl.config.FtlConstants
import ftl.log.logLn
import picocli.CommandLine
import java.nio.file.Paths

Expand All @@ -19,7 +20,7 @@ import java.nio.file.Paths
)
class AndroidModelsListCommand : Runnable {
override fun run() {
println(AndroidCatalog.devicesCatalogAsTable(AndroidArgs.loadOrDefault(Paths.get(configPath)).project))
logLn(AndroidCatalog.devicesCatalogAsTable(AndroidArgs.loadOrDefault(Paths.get(configPath)).project))
}

@CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.android.orientations
import ftl.android.AndroidCatalog
import ftl.args.AndroidArgs
import ftl.config.FtlConstants
import ftl.log.logLn
import picocli.CommandLine
import java.nio.file.Paths

Expand All @@ -19,7 +20,7 @@ import java.nio.file.Paths
)
class AndroidOrientationsListCommand : Runnable {
override fun run() {
println(AndroidCatalog.supportedOrientationsAsTable(AndroidArgs.loadOrDefault(Paths.get(configPath)).project))
logLn(AndroidCatalog.supportedOrientationsAsTable(AndroidArgs.loadOrDefault(Paths.get(configPath)).project))
}

@CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.android.versions
import ftl.android.AndroidCatalog
import ftl.args.AndroidArgs
import ftl.config.FtlConstants
import ftl.log.logLn
import ftl.run.exception.FlankConfigurationError
import picocli.CommandLine
import java.nio.file.Paths
Expand All @@ -21,7 +22,7 @@ import java.nio.file.Paths
class AndroidVersionsDescribeCommand : Runnable {
override fun run() {
if (versionId.isBlank()) throw FlankConfigurationError("Argument VERSION_ID must be specified.")
println(AndroidCatalog.describeSoftwareVersion(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, versionId))
logLn(AndroidCatalog.describeSoftwareVersion(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, versionId))
}

@CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.android.versions
import ftl.android.AndroidCatalog.supportedVersionsAsTable
import ftl.args.AndroidArgs
import ftl.config.FtlConstants
import ftl.log.logLn
import picocli.CommandLine
import java.nio.file.Paths

Expand All @@ -19,7 +20,7 @@ import java.nio.file.Paths
)
class AndroidVersionsListCommand : Runnable {
override fun run() {
println(supportedVersionsAsTable(AndroidArgs.loadOrDefault(Paths.get(configPath)).project))
logLn(supportedVersionsAsTable(AndroidArgs.loadOrDefault(Paths.get(configPath)).project))
}

@CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ftl.cli.firebase.test.ios

import ftl.args.IosArgs
import ftl.args.setLogLevel
import ftl.args.validate
import ftl.cli.firebase.test.CommonRunCommand
import ftl.config.FtlConstants
Expand Down Expand Up @@ -45,6 +46,7 @@ class IosRunCommand : CommonRunCommand(), Runnable {
}

IosArgs.load(Paths.get(configPath), cli = this).validate().run {
setLogLevel()
if (dumpShards) dumpShards()
else runBlocking { newTestRun() }
}
Expand Down
Loading