diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/AlertingPlugin.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/AlertingPlugin.kt index 2d08994c..f24fb57c 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/AlertingPlugin.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/AlertingPlugin.kt @@ -103,15 +103,15 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, P indexNameExpressionResolver: IndexNameExpressionResolver?, nodesInCluster: Supplier ): List { - return listOf(RestGetMonitorAction(settings, restController), - RestDeleteMonitorAction(settings, restController), + return listOf(RestGetMonitorAction(restController), + RestDeleteMonitorAction(restController), RestIndexMonitorAction(settings, restController, scheduledJobIndices, clusterService), - RestSearchMonitorAction(settings, restController), + RestSearchMonitorAction(restController), RestExecuteMonitorAction(settings, restController, runner), - RestAcknowledgeAlertAction(settings, restController), - RestScheduledJobStatsHandler(settings, restController, "_alerting"), + RestAcknowledgeAlertAction(restController), + RestScheduledJobStatsHandler(restController, "_alerting"), RestIndexDestinationAction(settings, restController, scheduledJobIndices, clusterService), - RestDeleteDestinationAction(settings, restController)) + RestDeleteDestinationAction(restController)) } override fun getActions(): List> { diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/alerts/AlertMover.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/alerts/AlertMover.kt index a1af6949..52a330c0 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/alerts/AlertMover.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/alerts/AlertMover.kt @@ -70,7 +70,7 @@ suspend fun moveAlerts(client: Client, monitorId: String, monitor: Monitor? = nu val response: SearchResponse = client.suspendUntil { search(activeAlertsRequest, it) } // If no alerts are found, simply return - if (response.hits.totalHits.value == 0L) return + if (response.hits.totalHits?.value == 0L) return val indexRequests = response.hits.map { hit -> IndexRequest(AlertIndices.HISTORY_WRITE_INDEX) .routing(monitorId) diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestAcknowledgeAlertAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestAcknowledgeAlertAction.kt index b26c3b83..527f4f00 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestAcknowledgeAlertAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestAcknowledgeAlertAction.kt @@ -35,7 +35,6 @@ import org.elasticsearch.action.support.WriteRequest import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.action.update.UpdateRequest import org.elasticsearch.client.node.NodeClient -import org.elasticsearch.common.settings.Settings import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.common.xcontent.XContentBuilder import org.elasticsearch.common.xcontent.XContentFactory @@ -63,7 +62,7 @@ private val log: Logger = LogManager.getLogger(RestAcknowledgeAlertAction::class * The user provides the monitorID to which these alerts pertain and in the content of the request provides * the ids to the alerts he would like to acknowledge. */ -class RestAcknowledgeAlertAction(settings: Settings, controller: RestController) : BaseRestHandler(settings) { +class RestAcknowledgeAlertAction(controller: RestController) : BaseRestHandler() { init { // Acknowledge alerts diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestDeleteDestinationAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestDeleteDestinationAction.kt index af2bd453..d5b294b1 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestDeleteDestinationAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestDeleteDestinationAction.kt @@ -21,7 +21,6 @@ import com.amazon.opendistroforelasticsearch.alerting.util.REFRESH import org.elasticsearch.action.delete.DeleteRequest import org.elasticsearch.action.support.WriteRequest import org.elasticsearch.client.node.NodeClient -import org.elasticsearch.common.settings.Settings import org.elasticsearch.rest.BaseRestHandler import org.elasticsearch.rest.BaseRestHandler.RestChannelConsumer import org.elasticsearch.rest.RestController @@ -32,7 +31,7 @@ import java.io.IOException /** * This class consists of the REST handler to delete destination. */ -class RestDeleteDestinationAction(settings: Settings, controller: RestController) : BaseRestHandler(settings) { +class RestDeleteDestinationAction(controller: RestController) : BaseRestHandler() { init { controller.registerHandler(RestRequest.Method.DELETE, "${AlertingPlugin.DESTINATION_BASE_URI}/{destinationID}", this) diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestDeleteMonitorAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestDeleteMonitorAction.kt index 4eb66b21..254d38c8 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestDeleteMonitorAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestDeleteMonitorAction.kt @@ -21,7 +21,6 @@ import com.amazon.opendistroforelasticsearch.alerting.AlertingPlugin import org.elasticsearch.action.delete.DeleteRequest import org.elasticsearch.action.support.WriteRequest.RefreshPolicy import org.elasticsearch.client.node.NodeClient -import org.elasticsearch.common.settings.Settings import org.elasticsearch.rest.BaseRestHandler import org.elasticsearch.rest.BaseRestHandler.RestChannelConsumer import org.elasticsearch.rest.RestController @@ -35,8 +34,8 @@ import java.io.IOException * When a monitor is deleted, all alerts are moved to the [Alert.State.DELETED] state and moved to the alert history index. * If this process fails the monitor is not deleted. */ -class RestDeleteMonitorAction(settings: Settings, controller: RestController) : - BaseRestHandler(settings) { +class RestDeleteMonitorAction(controller: RestController) : + BaseRestHandler() { init { controller.registerHandler(DELETE, "${AlertingPlugin.MONITOR_BASE_URI}/{monitorID}", this) // Delete a monitor diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestExecuteMonitorAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestExecuteMonitorAction.kt index c38a0ff5..367a6841 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestExecuteMonitorAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestExecuteMonitorAction.kt @@ -50,7 +50,7 @@ class RestExecuteMonitorAction( val settings: Settings, restController: RestController, private val runner: MonitorRunner -) : BaseRestHandler(settings) { +) : BaseRestHandler() { init { restController.registerHandler(POST, "${AlertingPlugin.MONITOR_BASE_URI}/{monitorID}/_execute", this) diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestGetMonitorAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestGetMonitorAction.kt index 93faf888..1cd65508 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestGetMonitorAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestGetMonitorAction.kt @@ -25,7 +25,6 @@ import com.amazon.opendistroforelasticsearch.alerting.util._SEQ_NO import org.elasticsearch.action.get.GetRequest import org.elasticsearch.action.get.GetResponse import org.elasticsearch.client.node.NodeClient -import org.elasticsearch.common.settings.Settings import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.common.xcontent.XContentHelper import org.elasticsearch.common.xcontent.XContentType @@ -46,7 +45,7 @@ import org.elasticsearch.search.fetch.subphase.FetchSourceContext /** * This class consists of the REST handler to retrieve a monitor . */ -class RestGetMonitorAction(settings: Settings, controller: RestController) : BaseRestHandler(settings) { +class RestGetMonitorAction(controller: RestController) : BaseRestHandler() { init { // Get a specific monitor diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexDestinationAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexDestinationAction.kt index bfaeb043..81893c44 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexDestinationAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexDestinationAction.kt @@ -66,7 +66,7 @@ class RestIndexDestinationAction( controller: RestController, jobIndices: ScheduledJobIndices, clusterService: ClusterService -) : BaseRestHandler(settings) { +) : BaseRestHandler() { private var scheduledJobIndices: ScheduledJobIndices private val clusterService: ClusterService @Volatile private var indexTimeout = INDEX_TIMEOUT.get(settings) diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexMonitorAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexMonitorAction.kt index 8f109c4d..f8e4af12 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexMonitorAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexMonitorAction.kt @@ -82,7 +82,7 @@ class RestIndexMonitorAction( controller: RestController, jobIndices: ScheduledJobIndices, clusterService: ClusterService -) : BaseRestHandler(settings) { +) : BaseRestHandler() { private var scheduledJobIndices: ScheduledJobIndices private val clusterService: ClusterService diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestSearchMonitorAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestSearchMonitorAction.kt index 1b364bdf..d5c7116e 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestSearchMonitorAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestSearchMonitorAction.kt @@ -23,7 +23,6 @@ import org.elasticsearch.action.search.SearchRequest import org.elasticsearch.action.search.SearchResponse import org.elasticsearch.client.node.NodeClient import org.elasticsearch.common.bytes.BytesReference -import org.elasticsearch.common.settings.Settings import org.elasticsearch.common.xcontent.LoggingDeprecationHandler import org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS import org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder @@ -46,7 +45,7 @@ import java.io.IOException /** * Rest handlers to search for monitors. */ -class RestSearchMonitorAction(settings: Settings, controller: RestController) : BaseRestHandler(settings) { +class RestSearchMonitorAction(controller: RestController) : BaseRestHandler() { init { // Search for monitors controller.registerHandler(POST, "${AlertingPlugin.MONITOR_BASE_URI}/_search", this) diff --git a/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/DestinationRestApiIT.kt b/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/DestinationRestApiIT.kt index b3c64d53..2b0fbbde 100644 --- a/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/DestinationRestApiIT.kt +++ b/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/DestinationRestApiIT.kt @@ -28,7 +28,7 @@ import org.elasticsearch.test.junit.annotations.TestLogging import org.junit.Assert import java.time.Instant -@TestLogging("level:DEBUG") +@TestLogging("level:DEBUG", reason = "Debug for tests.") @Suppress("UNCHECKED_CAST") class DestinationRestApiIT : AlertingRestTestCase() { diff --git a/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/MonitorRestApiIT.kt b/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/MonitorRestApiIT.kt index 151e1107..24038a30 100644 --- a/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/MonitorRestApiIT.kt +++ b/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/MonitorRestApiIT.kt @@ -51,7 +51,7 @@ import java.time.ZoneId import java.time.temporal.ChronoUnit import org.elasticsearch.common.unit.TimeValue -@TestLogging("level:DEBUG") +@TestLogging("level:DEBUG", reason = "Debug for tests.") @Suppress("UNCHECKED_CAST") class MonitorRestApiIT : AlertingRestTestCase() { diff --git a/build-tools/merged-coverage.gradle b/build-tools/merged-coverage.gradle index 59339492..f47d0156 100644 --- a/build-tools/merged-coverage.gradle +++ b/build-tools/merged-coverage.gradle @@ -16,7 +16,7 @@ allprojects { plugins.withId('jacoco') { // 0.8.2 doesn't show missing coverage of Kotlin generated methods. Remove once this becomes gradle's default - jacoco.toolVersion = '0.8.2' + jacoco.toolVersion = '0.8.5' tasks.withType(Test) { jacoco { append = false } } diff --git a/build.gradle b/build.gradle index be844308..d98bb1f8 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { apply from: 'build-tools/repositories.gradle' ext { - es_version = '7.3.2' + es_version = '7.4.2' kotlin_version = '1.3.21' } diff --git a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobStats.kt b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobStats.kt index 1a0a3e67..373cf296 100644 --- a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobStats.kt +++ b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobStats.kt @@ -44,7 +44,7 @@ class ScheduledJobStats : BaseNodeResponse, ToXContentFragment { var jobSweeperMetrics: JobSweeperMetrics? = null var jobInfos: Array? = null - constructor() + constructor(si: StreamInput): super(si) constructor( node: DiscoveryNode, @@ -59,18 +59,7 @@ class ScheduledJobStats : BaseNodeResponse, ToXContentFragment { companion object { @JvmStatic - fun readScheduledJobStatus(si: StreamInput): ScheduledJobStats { - val scheduledJobStatus = ScheduledJobStats() - scheduledJobStatus.readFrom(si) - return scheduledJobStatus - } - } - - override fun readFrom(si: StreamInput) { - super.readFrom(si) - this.status = si.readEnum(ScheduleStatus::class.java) - this.jobSweeperMetrics = si.readOptionalWriteable { JobSweeperMetrics(si) } - this.jobInfos = si.readOptionalArray({ JobSchedulerMetrics(si) }, { arrayOfNulls(it) }) + fun readScheduledJobStatus(si: StreamInput) = ScheduledJobStats(si) } override fun writeTo(out: StreamOutput) { diff --git a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsAction.kt b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsAction.kt index 9d189288..99177b1f 100644 --- a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsAction.kt +++ b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsAction.kt @@ -24,8 +24,7 @@ class ScheduledJobsStatsAction : ActionType(NAME, re const val NAME = "cluster:admin/opendistro/_scheduled_jobs/stats" val reader = Writeable.Reader { - val response = ScheduledJobsStatsResponse() - response.readFrom(it) + val response = ScheduledJobsStatsResponse(it) response } } diff --git a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsRequest.kt b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsRequest.kt index 67dbe082..6626cdc9 100644 --- a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsRequest.kt +++ b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsRequest.kt @@ -28,15 +28,11 @@ class ScheduledJobsStatsRequest : BaseNodesRequest { var jobSchedulingMetrics: Boolean = true var jobsInfo: Boolean = true - constructor() - constructor(nodeIds: Array) : super(*nodeIds) - - @Throws(IOException::class) - override fun readFrom(si: StreamInput) { - super.readFrom(si) + constructor(si: StreamInput): super(si) { jobSchedulingMetrics = si.readBoolean() jobsInfo = si.readBoolean() } + constructor(nodeIds: Array) : super(*nodeIds) @Throws(IOException::class) override fun writeTo(out: StreamOutput) { diff --git a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsRequestBuilder.kt b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsRequestBuilder.kt deleted file mode 100644 index 44022b98..00000000 --- a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsRequestBuilder.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.opendistroforelasticsearch.alerting.core.action.node - -import org.elasticsearch.action.support.nodes.NodesOperationRequestBuilder -import org.elasticsearch.client.ElasticsearchClient - -class ScheduledJobsStatsRequestBuilder( - client: ElasticsearchClient, - action: ScheduledJobsStatsAction -) : - NodesOperationRequestBuilder< - ScheduledJobsStatsRequest, - ScheduledJobsStatsResponse, - ScheduledJobsStatsRequestBuilder> - (client, action, ScheduledJobsStatsRequest()) diff --git a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsResponse.kt b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsResponse.kt index e07ca323..fae31d4d 100644 --- a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsResponse.kt +++ b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsResponse.kt @@ -35,7 +35,8 @@ class ScheduledJobsStatsResponse : BaseNodesResponse, ToXCont private var indexExists: Boolean? = null private var indexHealth: ClusterIndexHealth? = null - constructor() + constructor(si: StreamInput): super(si) + constructor( clusterName: ClusterName, nodeResponses: List, @@ -53,7 +54,7 @@ class ScheduledJobsStatsResponse : BaseNodesResponse, ToXCont out: StreamOutput, nodes: MutableList ) { - out.writeStreamableList(nodes) + out.writeList(nodes) } override fun readNodesFrom(si: StreamInput): MutableList { diff --git a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsTransportAction.kt b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsTransportAction.kt index b100fb8c..bdeca9c4 100644 --- a/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsTransportAction.kt +++ b/core/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/core/action/node/ScheduledJobsStatsTransportAction.kt @@ -58,8 +58,8 @@ class ScheduledJobsStatsTransportAction : TransportNodesAction