Skip to content

Commit

Permalink
Upgrades detekt version to 1.17.1 (opensearch-project#252)
Browse files Browse the repository at this point in the history
* Upgrades detekt version

Signed-off-by: Robert Downs <[email protected]>
  • Loading branch information
downsrob committed Jan 19, 2022
1 parent 3a3692d commit 989383a
Show file tree
Hide file tree
Showing 51 changed files with 89 additions and 73 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ buildscript {
classpath "org.opensearch.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.0.0-RC15"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.17.1"
classpath "org.jacoco:org.jacoco.agent:0.8.5"
}
}
Expand Down
16 changes: 14 additions & 2 deletions detekt.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
failFast: false

# TODO: Remove this before initial release, only for developmental purposes
build:
maxIssues: 10

exceptions:
TooGenericExceptionCaught:
active: false
SwallowedException: # Detekt fails to pick up the logger, and produces too many false positives for this rule
active: false

style:
ForbiddenComment:
active: false
MaxLineLength:
maxLineLength: 150
excludes: ['**/test/**']

complexity:
LargeClass:
excludes: ['**/test/**']
LongMethod:
excludes: ['**/test/**']
LongParameterList:
excludes: ['**/test/**']
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,15 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin
class GuiceHolder @Inject constructor(
remoteClusterService: TransportService
) : LifecycleComponent {
override fun close() {}
override fun close() { /* do nothing */ }
override fun lifecycleState(): Lifecycle.State? {
return null
}

override fun addLifecycleListener(listener: LifecycleListener) {}
override fun removeLifecycleListener(listener: LifecycleListener) {}
override fun start() {}
override fun stop() {}
override fun addLifecycleListener(listener: LifecycleListener) { /* do nothing */ }
override fun removeLifecycleListener(listener: LifecycleListener) { /* do nothing */ }
override fun start() { /* do nothing */ }
override fun stop() { /* do nothing */ }

companion object {
lateinit var remoteClusterService: RemoteClusterService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class IndexStateManagementHistory(
}

private fun getIndicesToDelete(clusterStateResponse: ClusterStateResponse): List<String> {
var indicesToDelete = mutableListOf<String>()
val indicesToDelete = mutableListOf<String>()
for (entry in clusterStateResponse.state.metadata.indices()) {
val indexMetaData = entry.value
val creationTime = indexMetaData.creationDate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

@file:Suppress("ReturnCount")
package org.opensearch.indexmanagement.indexstatemanagement

import kotlinx.coroutines.CoroutineName
Expand Down Expand Up @@ -98,7 +97,7 @@ import org.opensearch.threadpool.ThreadPool
* a user wants to update an existing [ManagedIndexConfig] to a new policy (or updated version of policy)
* then they must use the ChangePolicy API.
*/
@Suppress("TooManyFunctions")
@Suppress("TooManyFunctions", "ReturnCount", "NestedBlockDepth", "LongParameterList")
@OpenForTesting
class ManagedIndexCoordinator(
private val settings: Settings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package org.opensearch.indexmanagement.indexstatemanagement.model

import org.apache.logging.log4j.LogManager
import org.opensearch.common.io.stream.StreamInput
import org.opensearch.common.io.stream.StreamOutput
import org.opensearch.common.io.stream.Writeable
Expand All @@ -21,8 +20,6 @@ import java.io.IOException
import java.lang.IllegalArgumentException
import java.time.Instant

private val log = LogManager.getLogger(ISMTemplate::class.java)

data class ISMTemplate(
val indexPatterns: List<String>,
val priority: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ data class SweptManagedIndexConfig(
) {

companion object {
@Suppress("ComplexMethod")
@Suppress("ComplexMethod", "UnusedPrivateMember")
@JvmStatic
@Throws(IOException::class)
fun parse(xcp: XContentParser, id: String = NO_ID, seqNo: Long, primaryTerm: Long): SweptManagedIndexConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package org.opensearch.indexmanagement.indexstatemanagement.resthandler

import org.apache.logging.log4j.LogManager
import org.opensearch.client.node.NodeClient
import org.opensearch.common.Strings
import org.opensearch.common.xcontent.XContentParser.Token
Expand All @@ -26,8 +25,6 @@ import java.io.IOException

class RestChangePolicyAction : BaseRestHandler() {

private val log = LogManager.getLogger(javaClass)

override fun routes(): List<Route> {
return emptyList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package org.opensearch.indexmanagement.indexstatemanagement.resthandler

import org.apache.logging.log4j.LogManager
import org.opensearch.action.support.WriteRequest
import org.opensearch.client.node.NodeClient
import org.opensearch.cluster.service.ClusterService
Expand Down Expand Up @@ -36,8 +35,6 @@ import org.opensearch.rest.action.RestResponseListener
import java.io.IOException
import java.time.Instant

private val log = LogManager.getLogger(RestIndexPolicyAction::class.java)

class RestIndexPolicyAction(
settings: Settings,
val clusterService: ClusterService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package org.opensearch.indexmanagement.indexstatemanagement.resthandler

import org.apache.logging.log4j.LogManager
import org.opensearch.action.support.master.MasterNodeRequest.DEFAULT_MASTER_NODE_TIMEOUT
import org.opensearch.client.node.NodeClient
import org.opensearch.common.Strings
Expand All @@ -24,8 +23,6 @@ import org.opensearch.rest.action.RestToXContentListener

class RestRetryFailedManagedIndexAction : BaseRestHandler() {

private val log = LogManager.getLogger(javaClass)

override fun routes(): List<Route> {
return emptyList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.opensearch.indexmanagement.indexstatemanagement.ISMActionsParser
import java.util.concurrent.TimeUnit
import java.util.function.Function

@Suppress("UtilityClassWithPublicConstructor")
class LegacyOpenDistroManagedIndexSettings {
companion object {
const val DEFAULT_ISM_ENABLED = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.opensearch.common.settings.Setting
import org.opensearch.common.unit.TimeValue
import java.util.function.Function

@Suppress("UtilityClassWithPublicConstructor")
class ManagedIndexSettings {
companion object {
const val DEFAULT_ISM_ENABLED = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class WaitForRollupCompletionStep : Step(name) {
RollupMetadata.Status.STOPPED -> {
stepStatus = StepStatus.FAILED
hasRollupFailed = true
info = mapOf("message" to getJobFailedMessage(rollupJobId, indexName), "cause" to getJobStoppedMessage())
info = mapOf("message" to getJobFailedMessage(rollupJobId, indexName), "cause" to JOB_STOPPED_MESSAGE)
}
}
}
Expand Down Expand Up @@ -117,11 +117,11 @@ class WaitForRollupCompletionStep : Step(name) {

companion object {
const val name = "wait_for_rollup_completion"
const val JOB_STOPPED_MESSAGE = "Rollup job was stopped"
fun getFailedMessage(rollupJob: String, index: String) = "Failed to get the status of rollup job [$rollupJob] [index=$index]"
fun getJobProcessingMessage(rollupJob: String, index: String) = "Rollup job [$rollupJob] is still processing [index=$index]"
fun getJobCompletionMessage(rollupJob: String, index: String) = "Rollup job [$rollupJob] completed [index=$index]"
fun getJobFailedMessage(rollupJob: String, index: String) = "Rollup job [$rollupJob] failed [index=$index]"
fun getJobStoppedMessage() = "Rollup job was stopped"
fun getMissingRollupJobMessage(index: String) = "Rollup job was not found [index=$index]"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import java.time.Instant

private val log = LogManager.getLogger(TransportAddPolicyAction::class.java)

@Suppress("SpreadOperator", "ReturnCount")
@Suppress("SpreadOperator", "ReturnCount", "LongParameterList")
class TransportAddPolicyAction @Inject constructor(
val client: NodeClient,
transportService: TransportService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import org.opensearch.transport.TransportService

private val log = LogManager.getLogger(TransportIndexPolicyAction::class.java)

@Suppress("LongParameterList")
class TransportIndexPolicyAction @Inject constructor(
val client: NodeClient,
transportService: TransportService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class RefreshSearchAnalyzerResponse : BroadcastResponse {

// TODO: restrict it for testing
fun getSuccessfulRefreshDetails(): MutableMap<String, List<String>> {
var successfulRefreshDetails: MutableMap<String, List<String>> = HashMap()
var failedIndices = mutableSetOf<String>()
val successfulRefreshDetails: MutableMap<String, List<String>> = HashMap()
val failedIndices = mutableSetOf<String>()
for (failure in shardFailures) {
failedIndices.add(failure.index()!!)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class RollupIndexer(
try {
var requestsToRetry = convertResponseToRequests(rollup, internalComposite)
var stats = RollupStats(0, 0, requestsToRetry.size.toLong(), 0, 0)
var nonRetryableFailures = mutableListOf<BulkItemResponse>()
val nonRetryableFailures = mutableListOf<BulkItemResponse>()
if (requestsToRetry.isNotEmpty()) {
retryIngestPolicy.retry(logger, listOf(RestStatus.TOO_MANY_REQUESTS)) {
if (it.seconds >= (Rollup.ROLLUP_LOCK_DURATION_SECONDS / 2)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ExplainRollupResponse : ActionResponse, ToXContentObject {
idsToExplain = sin.let {
val idsToExplain = mutableMapOf<String, ExplainRollup?>()
val size = it.readVInt()
for (i in 0 until size) {
repeat(size) { _ ->
idsToExplain[it.readString()] = if (sin.readBoolean()) ExplainRollup(it) else null
}
idsToExplain.toMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.opensearch.tasks.Task
import org.opensearch.transport.TransportService

// TODO: Field and mappings validations of source and target index, i.e. reject a histogram agg on example_field if its not possible
@Suppress("LongParameterList")
class TransportIndexRollupAction @Inject constructor(
transportService: TransportService,
val client: Client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ data class ISMRollup(
dimensions = sin.let {
val dimensionsList = mutableListOf<Dimension>()
val size = it.readVInt()
for (i in 0 until size) {
repeat(size) { _ ->
val type = it.readEnum(Dimension.Type::class.java)
dimensionsList.add(
when (requireNotNull(type) { "Dimension type cannot be null" }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ data class Rollup(
dimensions = sin.let {
val dimensionsList = mutableListOf<Dimension>()
val size = it.readVInt()
for (i in 0 until size) {
repeat(size) { _ ->
val type = it.readEnum(Dimension.Type::class.java)
dimensionsList.add(
when (requireNotNull(type) { "Dimension type cannot be null" }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package org.opensearch.indexmanagement.rollup.model

import org.apache.logging.log4j.LogManager
import org.opensearch.common.io.stream.StreamInput
import org.opensearch.common.io.stream.StreamOutput
import org.opensearch.common.io.stream.Writeable
Expand All @@ -29,8 +28,6 @@ data class RollupMetrics(
val metrics: List<Metric>
) : ToXContentObject, Writeable {

private val logger = LogManager.getLogger(javaClass)

init {
require(metrics.size == metrics.distinctBy { it.type }.size) {
"Cannot have multiple metrics of the same type in a single rollup metric [$metrics]"
Expand All @@ -46,7 +43,7 @@ data class RollupMetrics(
metrics = sin.let {
val metricsList = mutableListOf<Metric>()
val size = it.readVInt()
for (i in 0 until size) {
repeat(size) { _ ->
val type = it.readEnum(Metric.Type::class.java)
metricsList.add(
when (requireNotNull(type) { "Metric type cannot be null" }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import org.opensearch.common.xcontent.XContentParser.Token
import org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken

class Average() : Metric(Type.AVERAGE) {

@Suppress("UnusedPrivateMember")
constructor(sin: StreamInput) : this()

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
return builder.startObject().startObject(Type.AVERAGE.type).endObject().endObject()
}

override fun writeTo(out: StreamOutput) {} // nothing to write
override fun writeTo(out: StreamOutput) { /* nothing to write */ }

override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import org.opensearch.common.xcontent.XContentParser.Token
import org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken

class Max() : Metric(Type.MAX) {
@Suppress("UnusedPrivateMember")
constructor(sin: StreamInput) : this()

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
return builder.startObject().startObject(Type.MAX.type).endObject().endObject()
}

override fun writeTo(out: StreamOutput) {} // nothing to write
override fun writeTo(out: StreamOutput) { /* nothing to write */ }

override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import org.opensearch.common.xcontent.XContentParser.Token
import org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken

class Min() : Metric(Type.MIN) {
@Suppress("UnusedPrivateMember")
constructor(sin: StreamInput) : this()

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
return builder.startObject().startObject(Type.MIN.type).endObject().endObject()
}

override fun writeTo(out: StreamOutput) {} // nothing to write
override fun writeTo(out: StreamOutput) { /* nothing to write */ }

override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import org.opensearch.common.xcontent.XContentParser.Token
import org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken

class Sum() : Metric(Type.SUM) {
@Suppress("UnusedPrivateMember")
constructor(sin: StreamInput) : this()

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
return builder.startObject().startObject(Type.SUM.type).endObject().endObject()
}

override fun writeTo(out: StreamOutput) {} // nothing to write
override fun writeTo(out: StreamOutput) { /* nothing to write */ }

override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import org.opensearch.common.xcontent.XContentParser.Token
import org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken

class ValueCount() : Metric(Type.VALUE_COUNT) {
@Suppress("UnusedPrivateMember")
constructor(sin: StreamInput) : this()

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
return builder.startObject().startObject(Type.VALUE_COUNT.type).endObject().endObject()
}

override fun writeTo(out: StreamOutput) {} // nothing to write
override fun writeTo(out: StreamOutput) { /* nothing to write */ }

override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.opensearch.indexmanagement.rollup.settings
import org.opensearch.common.settings.Setting
import org.opensearch.common.unit.TimeValue

@Suppress("UtilityClassWithPublicConstructor")
class LegacyOpenDistroRollupSettings {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.opensearch.indexmanagement.rollup.settings
import org.opensearch.common.settings.Setting
import org.opensearch.common.unit.TimeValue

@Suppress("UtilityClassWithPublicConstructor")
class RollupSettings {

companion object {
Expand Down
Loading

0 comments on commit 989383a

Please sign in to comment.