Skip to content

Commit

Permalink
Merge 1.1 fixes back to 1.x (opensearch-project#193)
Browse files Browse the repository at this point in the history
* Remove default integtest.sh. (opensearch-project#181)

Signed-off-by: dblock <dblock@dblock.org>

* Add valid search filters.

* Added this fix to release notes

Co-authored-by: Daniel Doubrovkine (dB.) <dblock@dblock.org>
Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
  • Loading branch information
2 people authored and AWSHurneyt committed Mar 30, 2022
1 parent ddc7708 commit 47ac56f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.opensearch.action.search.SearchResponse
import org.opensearch.alerting.AlertingPlugin
import org.opensearch.alerting.action.SearchMonitorAction
import org.opensearch.alerting.action.SearchMonitorRequest
import org.opensearch.alerting.alerts.AlertIndices.Companion.ALL_INDEX_PATTERN
import org.opensearch.alerting.core.model.ScheduledJob
import org.opensearch.alerting.core.model.ScheduledJob.Companion.SCHEDULED_JOBS_INDEX
import org.opensearch.alerting.model.Monitor
Expand Down Expand Up @@ -108,12 +109,18 @@ class RestSearchMonitorAction(
log.debug("${request.method()} ${AlertingPlugin.MONITOR_BASE_URI}/_search")

val index = request.param("index", SCHEDULED_JOBS_INDEX)
if (index != SCHEDULED_JOBS_INDEX && index != ALL_INDEX_PATTERN) {
throw IllegalArgumentException("Invalid index name.")
}

val searchSourceBuilder = SearchSourceBuilder()
searchSourceBuilder.parseXContent(request.contentOrSourceParamParser())
searchSourceBuilder.fetchSource(context(request))

val queryBuilder = QueryBuilders.boolQuery().must(searchSourceBuilder.query())
queryBuilder.filter(QueryBuilders.existsQuery(Monitor.MONITOR_TYPE))
if (index == SCHEDULED_JOBS_INDEX) {
queryBuilder.filter(QueryBuilders.existsQuery(Monitor.MONITOR_TYPE))
}

searchSourceBuilder.query(queryBuilder)
.seqNoAndPrimaryTerm(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,4 +942,22 @@ class MonitorRestApiIT : AlertingRestTestCase() {
val monitorHit = hit["_source"] as Map<String, Any>
assertEquals("Type is not monitor", monitorHit[Monitor.TYPE_FIELD], "monitor")
}

@Throws(Exception::class)
fun `test search monitor with alerting indices only`() {
// 1. search - must return error as invalid index is passed
val search = SearchSourceBuilder().query(QueryBuilders.matchAllQuery()).toString()
val params: MutableMap<String, String> = HashMap()
params["index"] = "data-logs"
try {
client().makeRequest(
"GET",
"$ALERTING_BASE_URI/_search",
params,
NStringEntity(search, ContentType.APPLICATION_JSON)
)
} catch (e: ResponseException) {
assertEquals("Unexpected status", RestStatus.BAD_REQUEST, e.response.restStatus())
}
}
}
77 changes: 0 additions & 77 deletions integtest.sh

This file was deleted.

3 changes: 2 additions & 1 deletion release-notes/opensearch-alerting.release-notes-1.1.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Compatible with OpenSearch 1.1.0
* Fix bug in paginating multiple bucket paths for Bucket-Level Monitor ([#163](https://github.com/opensearch-project/alerting/pull/163))
* Various bug fixes for Bucket-Level Alerting ([#164](https://github.com/opensearch-project/alerting/pull/164))
* Return only monitors for /monitors/_search ([#162](https://github.com/opensearch-project/alerting/pull/162))
* Add valid search filters ([#191](https://github.com/opensearch-project/alerting/pull/191))

### Infrastructure

Expand All @@ -42,4 +43,4 @@ Compatible with OpenSearch 1.1.0

### Refactoring

* Refactor MonitorRunner ([#143](https://github.com/opensearch-project/alerting/pull/143))
* Refactor MonitorRunner ([#143](https://github.com/opensearch-project/alerting/pull/143))

0 comments on commit 47ac56f

Please sign in to comment.