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

Add getDestinations and getAlerts API #260

Merged
merged 17 commits into from
Sep 30, 2020
Merged

Add getDestinations and getAlerts API #260

merged 17 commits into from
Sep 30, 2020

Conversation

lezzago
Copy link
Contributor

@lezzago lezzago commented Sep 28, 2020

Issue #, if available:
#215
Description of changes:
#215

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@lezzago lezzago changed the title Ashisagr dev Add getDestinations and getAlerts API Sep 28, 2020
@lezzago lezzago closed this Sep 28, 2020
@lezzago lezzago reopened this Sep 28, 2020
@lezzago lezzago marked this pull request as ready for review September 28, 2020 21:13
@lezzago lezzago self-assigned this Sep 28, 2020
@codecov
Copy link

codecov bot commented Sep 28, 2020

Codecov Report

Merging #260 into master will increase coverage by 1.04%.
The diff coverage is 93.15%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #260      +/-   ##
============================================
+ Coverage     79.34%   80.39%   +1.04%     
- Complexity      197      199       +2     
============================================
  Files           138      149      +11     
  Lines          4522     4810     +288     
  Branches        614      635      +21     
============================================
+ Hits           3588     3867     +279     
- Misses          596      597       +1     
- Partials        338      346       +8     
Impacted Files Coverage Δ Complexity Δ
...orelasticsearch/alerting/action/GetAlertsAction.kt 66.66% <66.66%> (ø) 0.00 <0.00> (?)
...ticsearch/alerting/action/GetDestinationsAction.kt 66.66% <66.66%> (ø) 0.00 <0.00> (?)
...erting/transport/TransportGetDestinationsAction.kt 86.53% <86.53%> (ø) 0.00 <0.00> (?)
...rch/alerting/transport/TransportGetAlertsAction.kt 86.66% <86.66%> (ø) 0.00 <0.00> (?)
...icsearch/alerting/model/destination/Destination.kt 73.88% <87.50%> (+3.95%) 0.00 <0.00> (ø)
...elasticsearch/alerting/action/GetAlertsResponse.kt 93.33% <93.33%> (ø) 0.00 <0.00> (?)
.../alerting/resthandler/RestGetDestinationsAction.kt 93.93% <93.93%> (ø) 0.00 <0.00> (?)
...ndistroforelasticsearch/alerting/AlertingPlugin.kt 91.48% <100.00%> (+0.37%) 0.00 <0.00> (ø)
...relasticsearch/alerting/action/GetAlertsRequest.kt 100.00% <100.00%> (ø) 0.00 <0.00> (?)
...icsearch/alerting/action/GetDestinationsRequest.kt 100.00% <100.00%> (ø) 0.00 <0.00> (?)
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 39a13d3...841a942. Read the comment docs.

Copy link
Contributor

@skkosuri-amzn skkosuri-amzn left a comment

Choose a reason for hiding this comment

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

Added my comments.

@@ -185,6 +185,21 @@ class MonitorRunner(
}

suspend fun runMonitor(monitor: Monitor, periodStart: Instant, periodEnd: Instant, dryrun: Boolean = false): MonitorRunResult {
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you picked inject roles changes. Do we need this change for getDest, getAlerts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed. I accidentally picked it up

@@ -121,9 +121,9 @@ data class Alert(

companion object {

const val ALERT_ID_FIELD = "id"
const val ALERT_ID_FIELD = "alert_id"
Copy link
Contributor

Choose a reason for hiding this comment

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

Whats the reason behind changing the name from id to alert_id ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to insert the same string into alert_mapping.json. In the file, there is monitor_id and trigger_id, so I wanted to follow the same format and ensure it is clear what the id is for.

type = sin.readEnum(DestinationType::class.java),
name = sin.readString(),
user = if (sin.readBoolean()) {
User(sin)
User.readFrom(sin)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you over wrote my change ;) . User(sin)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I cherry picked changes, it looked like it was changed to User.readFrom(sin). Just changed it back

return listOf(
// Get a specific destination
RestHandler.Route(RestRequest.Method.GET, "${AlertingPlugin.DESTINATION_BASE_URI}/{destinationID}"),
RestHandler.Route(RestRequest.Method.GET, "${AlertingPlugin.DESTINATION_BASE_URI}/all")
Copy link
Contributor

Choose a reason for hiding this comment

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

is all a standard REST way? Cant we leave GET /destinations/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that out. Meant to change it to something better later on after testing.

log.debug("${request.method()} ${AlertingPlugin.MONITOR_BASE_URI}/_search")

val index = request.param("index", SCHEDULED_JOBS_INDEX)

Copy link
Contributor

Choose a reason for hiding this comment

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

How this change is related to GET /destinations GET /alerts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had included it because it was needed for the security changes. I will remove this change since it is already included in ur PR.

@@ -135,7 +135,7 @@ class DestinationTests : ESTestCase() {
}

fun `test slack destination create using stream`() {
val chimeDest = Destination("2345", 1L, 2, DestinationType.SLACK, "TestSlackDest",
val chimeDest = Destination("2345", 1L, 2, 1, 1, DestinationType.SLACK, "TestSlackDest",

Choose a reason for hiding this comment

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

The variable is a little inaccurate, including the one for "custom webhook" in below test, but looks like it's a change in a past PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for pointing that out. I fixed them

Choose a reason for hiding this comment

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

Thank you 👍

skkosuri-amzn
skkosuri-amzn previously approved these changes Sep 29, 2020
ftianli-amzn
ftianli-amzn previously approved these changes Sep 29, 2020
@lezzago lezzago dismissed stale reviews from ftianli-amzn and skkosuri-amzn via 841a942 September 30, 2020 00:19
@lezzago lezzago merged commit 01269ec into master Sep 30, 2020
@lezzago lezzago deleted the ashisagr-dev branch December 4, 2020 20:39
tlfeng pushed a commit that referenced this pull request Feb 6, 2021
* Add getDestination(s) rest api

* remove security context for GetDestinations api

* replaces try-finally with use for all auto-closables

* add getAlerts API

* minor cleanup to get-alerts

* fix sorting and pagination. Also allow searchMonitor to search in other indexes

* fix sorting, searching, and filtering

* add opendistro to GetDestinations action name

* Cleanup code and add unit and integ tests

* cleanup some of the read streaminput code

* cleanup code more

* cleanup tests

* fix unit test

* remove extra stuff

* fix mappings

* fix test names

Co-authored-by: skkosuri-amzn <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants