Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Commit edd6766

Browse files
Opendistro 1.3
* Revert "Adding new type of input for Monitors - HttpInput (#82)" This reverts commit c2004f7.
1 parent c72a267 commit edd6766

File tree

12 files changed

+13
-601
lines changed

12 files changed

+13
-601
lines changed

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ Please see our [documentation](https://opendistro.github.io/for-elasticsearch-do
2727
1. Check out this package from version control.
2828
1. Launch Intellij IDEA, choose **Import Project**, and select the `settings.gradle` file in the root of this package.
2929
1. To build from the command line, set `JAVA_HOME` to point to a JDK >= 12 before running `./gradlew`.
30-
- Unix System
31-
1. `export JAVA_HOME=jdk-install-dir`: Replace `jdk-install-dir` by the JAVA_HOME directory of your system.
32-
1. `export PATH=$JAVA_HOME/bin:$PATH`
33-
34-
- Windows System
35-
1. Find **My Computers** from file directory, right click and select **properties**.
36-
1. Select the **Advanced** tab, select **Environment variables**.
37-
1. Edit **JAVA_HOME** to path of where JDK software is installed.
3830

3931

4032
## Build

alerting/build.gradle

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ configurations.all {
4949
force "commons-logging:commons-logging:${versions.commonslogging}"
5050
force "org.apache.httpcomponents:httpcore:${versions.httpcore}"
5151
force "commons-codec:commons-codec:${versions.commonscodec}"
52-
force "commons-collections:commons-collections:3.2.2"
53-
force "org.apache.httpcomponents:httpcore-nio:4.4.11"
54-
force "org.apache.httpcomponents:httpclient:4.5.7"
55-
52+
5653
// This is required because kotlin coroutines core-1.1.1 still requires kotin stdlib 1.3.20 and we're using 1.3.21
5754
force "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}"
5855
force "org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin_version}"
@@ -61,7 +58,6 @@ configurations.all {
6158

6259
dependencies {
6360
compileOnly "org.elasticsearch.plugin:elasticsearch-scripting-painless-spi:${versions.elasticsearch}"
64-
compile "org.apache.httpcomponents:httpasyncclient:4.1.4"
6561

6662
// Elasticsearch Nanny state
6763
compile "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}"

alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/AlertingPlugin.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import com.amazon.opendistroforelasticsearch.alerting.core.JobSweeper
1919
import com.amazon.opendistroforelasticsearch.alerting.core.ScheduledJobIndices
2020
import com.amazon.opendistroforelasticsearch.alerting.core.action.node.ScheduledJobsStatsAction
2121
import com.amazon.opendistroforelasticsearch.alerting.core.action.node.ScheduledJobsStatsTransportAction
22-
import com.amazon.opendistroforelasticsearch.alerting.core.model.HttpInput
2322
import com.amazon.opendistroforelasticsearch.alerting.core.model.ScheduledJob
2423
import com.amazon.opendistroforelasticsearch.alerting.core.model.SearchInput
2524
import com.amazon.opendistroforelasticsearch.alerting.core.resthandler.RestScheduledJobStatsHandler
@@ -119,7 +118,7 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, P
119118
}
120119

121120
override fun getNamedXContent(): List<NamedXContentRegistry.Entry> {
122-
return listOf(Monitor.XCONTENT_REGISTRY, SearchInput.XCONTENT_REGISTRY, HttpInput.XCONTENT_REGISTRY)
121+
return listOf(Monitor.XCONTENT_REGISTRY, SearchInput.XCONTENT_REGISTRY)
123122
}
124123

125124
override fun createComponents(

alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/MonitorRunner.kt

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ package com.amazon.opendistroforelasticsearch.alerting
1818
import com.amazon.opendistroforelasticsearch.alerting.alerts.AlertError
1919
import com.amazon.opendistroforelasticsearch.alerting.alerts.AlertIndices
2020
import com.amazon.opendistroforelasticsearch.alerting.alerts.moveAlerts
21-
import com.amazon.opendistroforelasticsearch.alerting.client.HttpInputClient
2221
import com.amazon.opendistroforelasticsearch.alerting.core.JobRunner
23-
import com.amazon.opendistroforelasticsearch.alerting.core.httpapi.suspendUntil
24-
import com.amazon.opendistroforelasticsearch.alerting.core.httpapi.toGetRequest
25-
import com.amazon.opendistroforelasticsearch.alerting.core.httpapi.toMap
26-
import com.amazon.opendistroforelasticsearch.alerting.core.model.HttpInput
2722
import com.amazon.opendistroforelasticsearch.alerting.core.model.ScheduledJob
2823
import com.amazon.opendistroforelasticsearch.alerting.core.model.ScheduledJob.Companion.SCHEDULED_JOBS_INDEX
2924
import com.amazon.opendistroforelasticsearch.alerting.core.model.SearchInput
@@ -56,14 +51,13 @@ import com.amazon.opendistroforelasticsearch.alerting.settings.AlertingSettings.
5651
import com.amazon.opendistroforelasticsearch.alerting.settings.AlertingSettings.Companion.MOVE_ALERTS_BACKOFF_COUNT
5752
import com.amazon.opendistroforelasticsearch.alerting.settings.AlertingSettings.Companion.MOVE_ALERTS_BACKOFF_MILLIS
5853
import com.amazon.opendistroforelasticsearch.alerting.util.IndexUtils
54+
import org.apache.logging.log4j.LogManager
5955
import kotlinx.coroutines.CoroutineScope
6056
import kotlinx.coroutines.Dispatchers
6157
import kotlinx.coroutines.Job
6258
import kotlinx.coroutines.SupervisorJob
6359
import kotlinx.coroutines.launch
6460
import kotlinx.coroutines.withContext
65-
import org.apache.http.HttpResponse
66-
import org.apache.logging.log4j.LogManager
6761
import org.elasticsearch.ExceptionsHelper
6862
import org.elasticsearch.action.DocWriteRequest
6963
import org.elasticsearch.action.bulk.BackoffPolicy
@@ -111,7 +105,7 @@ class MonitorRunner(
111105
) : JobRunner, CoroutineScope, AbstractLifecycleComponent() {
112106

113107
private val logger = LogManager.getLogger(MonitorRunner::class.java)
114-
private var httpClient: HttpInputClient
108+
115109
private lateinit var runnerSupervisor: Job
116110
override val coroutineContext: CoroutineContext
117111
get() = Dispatchers.Default + runnerSupervisor
@@ -128,17 +122,14 @@ class MonitorRunner(
128122
clusterService.clusterSettings.addSettingsUpdateConsumer(MOVE_ALERTS_BACKOFF_MILLIS, MOVE_ALERTS_BACKOFF_COUNT) {
129123
millis, count -> moveAlertsRetryPolicy = BackoffPolicy.exponentialBackoff(millis, count)
130124
}
131-
httpClient = HttpInputClient()
132125
}
133126

134127
override fun doStart() {
135128
runnerSupervisor = SupervisorJob()
136-
httpClient.client.start()
137129
}
138130

139131
override fun doStop() {
140132
runnerSupervisor.cancel()
141-
httpClient.client.close()
142133
}
143134

144135
override fun doClose() { }
@@ -301,29 +292,6 @@ class MonitorRunner(
301292
val searchResponse: SearchResponse = client.suspendUntil { client.search(searchRequest, it) }
302293
results += searchResponse.convertToMap()
303294
}
304-
is HttpInput -> {
305-
val response: HttpResponse = httpClient.client.suspendUntil {
306-
httpClient.client.execute(input.toGetRequest(), it)
307-
}
308-
// Make sure response content length is not larger than 100MB
309-
val contentLengthHeader = response.getFirstHeader("Content-Length").value
310-
311-
// Use content-length header to check size. If content-length header does not exist, set Alert in Error state.
312-
if (contentLengthHeader != null) {
313-
logger.debug("Content length is $contentLengthHeader")
314-
val contentLength = contentLengthHeader.toInt()
315-
if (contentLength > httpClient.MAX_CONTENT_LENGTH) {
316-
throw Exception("Response content size: $contentLength, is larger than ${httpClient.MAX_CONTENT_LENGTH}.")
317-
}
318-
} else {
319-
logger.debug("Content-length header does not exist, set alert to error state.")
320-
throw IllegalArgumentException("Response does not contain content-length header.")
321-
}
322-
323-
results += withContext(Dispatchers.IO) {
324-
response.toMap()
325-
}
326-
}
327295
else -> {
328296
throw IllegalArgumentException("Unsupported input type: ${input.name()}.")
329297
}

alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/client/HttpInputClient.kt

Lines changed: 0 additions & 57 deletions
This file was deleted.

alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestIndexMonitorAction.kt

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,23 @@
1414
*/
1515
package com.amazon.opendistroforelasticsearch.alerting.resthandler
1616

17-
import com.amazon.opendistroforelasticsearch.alerting.AlertingPlugin
1817
import com.amazon.opendistroforelasticsearch.alerting.core.ScheduledJobIndices
19-
import com.amazon.opendistroforelasticsearch.alerting.core.httpapi.toConstructedUrl
20-
import com.amazon.opendistroforelasticsearch.alerting.core.model.HttpInput
2118
import com.amazon.opendistroforelasticsearch.alerting.core.model.ScheduledJob
2219
import com.amazon.opendistroforelasticsearch.alerting.core.model.ScheduledJob.Companion.SCHEDULED_JOBS_INDEX
2320
import com.amazon.opendistroforelasticsearch.alerting.model.Monitor
2421
import com.amazon.opendistroforelasticsearch.alerting.settings.AlertingSettings.Companion.ALERTING_MAX_MONITORS
2522
import com.amazon.opendistroforelasticsearch.alerting.settings.AlertingSettings.Companion.INDEX_TIMEOUT
26-
import com.amazon.opendistroforelasticsearch.alerting.settings.AlertingSettings.Companion.MAX_ACTION_THROTTLE_VALUE
2723
import com.amazon.opendistroforelasticsearch.alerting.settings.AlertingSettings.Companion.REQUEST_TIMEOUT
24+
import com.amazon.opendistroforelasticsearch.alerting.util.REFRESH
25+
import com.amazon.opendistroforelasticsearch.alerting.util._ID
26+
import com.amazon.opendistroforelasticsearch.alerting.util._VERSION
27+
import com.amazon.opendistroforelasticsearch.alerting.AlertingPlugin
28+
import com.amazon.opendistroforelasticsearch.alerting.settings.AlertingSettings.Companion.MAX_ACTION_THROTTLE_VALUE
2829
import com.amazon.opendistroforelasticsearch.alerting.util.IF_PRIMARY_TERM
2930
import com.amazon.opendistroforelasticsearch.alerting.util.IF_SEQ_NO
3031
import com.amazon.opendistroforelasticsearch.alerting.util.IndexUtils
31-
import com.amazon.opendistroforelasticsearch.alerting.util.REFRESH
32-
import com.amazon.opendistroforelasticsearch.alerting.util._ID
3332
import com.amazon.opendistroforelasticsearch.alerting.util._PRIMARY_TERM
3433
import com.amazon.opendistroforelasticsearch.alerting.util._SEQ_NO
35-
import com.amazon.opendistroforelasticsearch.alerting.util._VERSION
3634
import org.apache.logging.log4j.LogManager
3735
import org.elasticsearch.action.ActionListener
3836
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse
@@ -78,7 +76,7 @@ private val log = LogManager.getLogger(RestIndexMonitorAction::class.java)
7876
* Rest handlers to create and update monitors.
7977
*/
8078
class RestIndexMonitorAction(
81-
val settings: Settings,
79+
settings: Settings,
8280
controller: RestController,
8381
jobIndices: ScheduledJobIndices,
8482
clusterService: ClusterService
@@ -161,7 +159,6 @@ class RestIndexMonitorAction(
161159
*/
162160
private fun prepareMonitorIndexing() {
163161
validateActionThrottle(newMonitor, maxActionThrottle, TimeValue.timeValueMinutes(1))
164-
validateLocalPort(newMonitor, settings.get("http.port").toInt())
165162
if (channel.request().method() == PUT) return updateMonitor()
166163
val query = QueryBuilders.boolQuery().filter(QueryBuilders.termQuery("${Monitor.MONITOR_TYPE}.type", Monitor.MONITOR_TYPE))
167164
val searchSource = SearchSourceBuilder().query(query).timeout(requestTimeout)
@@ -183,23 +180,6 @@ class RestIndexMonitorAction(
183180
}
184181
}
185182

186-
/**
187-
* This function checks whether the [Monitor] has an [HttpInput] with localhost. If so, make sure the port is same as specified in settings.
188-
*/
189-
private fun validateLocalPort(monitor: Monitor, settingsPort: Int) {
190-
for (input in monitor.inputs) {
191-
if (input is HttpInput) {
192-
val constructedUrl = input.toConstructedUrl()
193-
// Make sure that when host is "localhost", only port number specified in settings is allowed.
194-
if (constructedUrl.host == "localhost") {
195-
require(constructedUrl.port == settingsPort) {
196-
"Host: ${constructedUrl.host} is restricted to port $settingsPort."
197-
}
198-
}
199-
}
200-
}
201-
}
202-
203183
/**
204184
* After searching for all existing monitors we validate the system can support another monitor to be created.
205185
*/

0 commit comments

Comments
 (0)