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

Enable Detekt #522

Merged
merged 2 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 reports-scheduler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ buildscript {
classpath "${opensearch_group}.gradle:build-tools:${opensearch_version}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_version}"
classpath "org.jetbrains.kotlin:kotlin-allopen:${kotlin_version}"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.22.0-RC2"
classpath "org.jacoco:org.jacoco.agent:0.8.5"
}
}
Expand All @@ -56,6 +57,7 @@ apply plugin: 'idea'
apply plugin: 'opensearch.opensearchplugin'
apply plugin: 'opensearch.pluginzip'
apply plugin: 'opensearch.testclusters'
apply plugin: 'io.gitlab.arturbosch.detekt'
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'org.jetbrains.kotlin.plugin.allopen'

Expand Down Expand Up @@ -105,6 +107,11 @@ configurations {
testRuntime
}

detekt {
config = files("detekt.yml")
buildUponDefaultConfig = true
}

configurations.testCompile {
exclude module: "securemock"
}
Expand Down
5 changes: 5 additions & 0 deletions reports-scheduler/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ style:
ReturnCount:
active: true
max: 10
complexity:
LongMethod:
threshold: 120
NestedBlockDepth:
threshold: 5
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ internal object ReportDefinitionsIndex {
const val REPORT_DEFINITIONS_INDEX_NAME = ".opendistro-reports-definitions"
private const val REPORT_DEFINITIONS_MAPPING_FILE_NAME = "report-definitions-mapping.yml"
private const val REPORT_DEFINITIONS_SETTINGS_FILE_NAME = "report-definitions-settings.yml"
private const val MAPPING_TYPE = "_doc"

private lateinit var client: Client
private lateinit var clusterService: ClusterService
Expand Down Expand Up @@ -75,10 +74,12 @@ internal object ReportDefinitionsIndex {
log.info("$LOG_PREFIX:Index $REPORT_DEFINITIONS_INDEX_NAME creation Acknowledged")
} else {
Metrics.REPORT_DEFINITION_CREATE_SYSTEM_ERROR.counter.increment()
throw IllegalStateException("$LOG_PREFIX:Index $REPORT_DEFINITIONS_INDEX_NAME creation not Acknowledged")
error("$LOG_PREFIX:Index $REPORT_DEFINITIONS_INDEX_NAME creation not Acknowledged")
}
} catch (exception: ResourceAlreadyExistsException) {
log.warn("message: ${exception.message}")
} catch (exception: Exception) {
if (exception !is ResourceAlreadyExistsException && exception.cause !is ResourceAlreadyExistsException) {
if (exception.cause !is ResourceAlreadyExistsException) {
Metrics.REPORT_DEFINITION_CREATE_SYSTEM_ERROR.counter.increment()
throw exception
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ internal object ReportInstancesIndex {
private const val REPORT_INSTANCES_INDEX_NAME = ".opendistro-reports-instances"
private const val REPORT_INSTANCES_MAPPING_FILE_NAME = "report-instances-mapping.yml"
private const val REPORT_INSTANCES_SETTINGS_FILE_NAME = "report-instances-settings.yml"
private const val MAPPING_TYPE = "_doc"

private lateinit var client: Client
private lateinit var clusterService: ClusterService
Expand Down Expand Up @@ -74,10 +73,12 @@ internal object ReportInstancesIndex {
if (response.isAcknowledged) {
log.info("$LOG_PREFIX:Index $REPORT_INSTANCES_INDEX_NAME creation Acknowledged")
} else {
throw IllegalStateException("$LOG_PREFIX:Index $REPORT_INSTANCES_INDEX_NAME creation not Acknowledged")
error("$LOG_PREFIX:Index $REPORT_INSTANCES_INDEX_NAME creation not Acknowledged")
}
} catch (exception: ResourceAlreadyExistsException) {
log.warn("message: ${exception.message}")
} catch (exception: Exception) {
if (exception !is ResourceAlreadyExistsException && exception.cause !is ResourceAlreadyExistsException) {
if (exception.cause !is ResourceAlreadyExistsException) {
throw exception
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ internal data class ReportDefinition(
val configIds: List<String>
) : ToXContentObject {
internal companion object {
private const val DELIVERY_FORMAT_TAG = "deliveryFormat"
private const val TITLE_TAG = "title"
private const val TEXT_DESCRIPTION_TAG = "textDescription"
private const val HTML_DESCRIPTION_TAG = "htmlDescription"
Expand All @@ -382,7 +381,6 @@ internal data class ReportDefinition(
* @return created Delivery object
*/
fun parse(parser: XContentParser): Delivery {
var recipients: List<String> = listOf()
var title: String? = null
var textDescription: String? = null
var htmlDescription: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ internal object SecurityAccess {
return try {
AccessController.doPrivileged(operation)
} catch (e: PrivilegedActionException) {
throw (e.cause as Exception?)!!
var exception = e
throw (exception.cause as Exception?)!!
Copy link
Member

Choose a reason for hiding this comment

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

why this change? if it's variable naming maybe change to } catch (exception: PrivilegedActionException) {

Copy link
Contributor Author

@rupal-bq rupal-bq Oct 28, 2022

Choose a reason for hiding this comment

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

Build was failing with SwallowedException here.
This rule reports all instances where exceptions are caught and not correctly passed (e.g. as a cause) into a newly thrown exception.

Copy link
Member

Choose a reason for hiding this comment

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

you can use suppress @Suppress("SwallowedException")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

kk. Thanks. added suppress.

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ internal object PluginSettings {
try {
settings = Settings.builder().loadFromPath(defaultSettingYmlFile).build()
} catch (exception: IOException) {
log.warn("$LOG_PREFIX:Failed to load ${defaultSettingYmlFile.toAbsolutePath()}")
log.warn("$LOG_PREFIX:Failed to load ${defaultSettingYmlFile.toAbsolutePath()} message:${exception.message}")
}
}
// Initialize the settings values to default values
Expand Down

This file was deleted.