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

Add actions to create, execute, get monitors api #240

Merged
merged 4 commits into from
Aug 26, 2020
Merged

Conversation

skkosuri-amzn
Copy link
Contributor

Issue #, if available:
#232
Description of changes:
This to add actions to create/modify , execute, get monitor.

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

@codecov
Copy link

codecov bot commented Aug 20, 2020

Codecov Report

Merging #240 into master will increase coverage by 1.28%.
The diff coverage is 82.84%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #240      +/-   ##
============================================
+ Coverage     77.51%   78.79%   +1.28%     
  Complexity      164      164              
============================================
  Files            75       91      +16     
  Lines          2948     3249     +301     
  Branches        442      458      +16     
============================================
+ Hits           2285     2560     +275     
- Misses          433      446      +13     
- Partials        230      243      +13     
Impacted Files Coverage Δ Complexity Δ
...alerting/transport/TransportSearchMonitorAction.kt 57.14% <ø> (ø) 0.00 <0.00> (ø)
...lerting/transport/TransportExecuteMonitorAction.kt 64.51% <64.51%> (ø) 0.00 <0.00> (?)
.../alerting/transport/TransportIndexMonitorAction.kt 66.08% <66.08%> (ø) 0.00 <0.00> (?)
...sticsearch/alerting/action/ExecuteMonitorAction.kt 66.66% <66.66%> (ø) 0.00 <0.00> (?)
...relasticsearch/alerting/action/GetMonitorAction.kt 66.66% <66.66%> (ø) 0.00 <0.00> (?)
...lasticsearch/alerting/action/IndexMonitorAction.kt 66.66% <66.66%> (ø) 0.00 <0.00> (?)
...orelasticsearch/alerting/model/MonitorRunResult.kt 85.12% <75.00%> (+1.36%) 0.00 <0.00> (ø)
...ch/alerting/transport/TransportGetMonitorAction.kt 85.00% <85.00%> (ø) 0.00 <0.00> (?)
...lasticsearch/alerting/action/GetMonitorResponse.kt 92.50% <92.50%> (ø) 0.00 <0.00> (?)
...sticsearch/alerting/action/IndexMonitorResponse.kt 94.11% <94.11%> (ø) 0.00 <0.00> (?)
... and 37 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 4119ef1...fb873f6. Read the comment docs.

sin.readEnum(RestStatus::class.java), // RestStatus
if (sin.readBoolean()) {
Monitor.readFrom(sin) // monitor
} else null
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This response is used for GET or HEAD request. With HEAD request we wont have monitor object in response. This checks if monitor is present. Also refer to writeTo
if (monitor != null) { out.writeBoolean(true) monitor?.writeTo(out) } else { out.writeBoolean(false) }

Copy link
Contributor

Choose a reason for hiding this comment

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

Misread the code, just realized that this is inside a constructor call. Makes sense why this is done

ElasticsearchStatusException("Can't find monitor with id: ${response.id}", RestStatus.NOT_FOUND)
)
}
if (!response.isSourceEmpty) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This statement was not there before in the RestExecuteMonitorAction.kt file. Is this fixing a bug that was there before?

Copy link
Contributor Author

@skkosuri-amzn skkosuri-amzn Aug 26, 2020

Choose a reason for hiding this comment

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

Good catch. I added this extra check here to be extra safe. We were doing that in RestGetMonitorAction

Comment on lines +82 to +87
init {
clusterService.clusterSettings.addSettingsUpdateConsumer(ALERTING_MAX_MONITORS) { maxMonitors = it }
clusterService.clusterSettings.addSettingsUpdateConsumer(REQUEST_TIMEOUT) { requestTimeout = it }
clusterService.clusterSettings.addSettingsUpdateConsumer(INDEX_TIMEOUT) { indexTimeout = it }
clusterService.clusterSettings.addSettingsUpdateConsumer(MAX_ACTION_THROTTLE_VALUE) { maxActionThrottle = it }
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this need to be set if it is done in RestIndexMonitorAction.kt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I missed to remove this from RestIndexMonitorAction. Will fix it.

req.writeTo(out)
val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes)
val newReq = ExecuteMonitorRequest(sin)
assertNull(newReq.monitorId)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please compare this with the original monitorId

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this test the monitorId is null, so left this to check assertNull. Added a new check below to compare monitor.

Comment on lines 49 to 54
Monitor(
"123",
0L, "test-monitor", true, cronSchedule, Instant.now(),
Instant.now(), 0, mutableListOf(), mutableListOf(), mutableMapOf()

))
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix formatting so it is consistent for the input attributes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed formatting.

Comment on lines 35 to 40
Monitor(
"123",
0L, "test-monitor", true, cronSchedule, Instant.now(),
Instant.now(), 0, mutableListOf(), mutableListOf(), mutableMapOf()

))
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix formatting so it is consistent for the input attributes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed formatting.

@skkosuri-amzn skkosuri-amzn merged commit 7320bc6 into master Aug 26, 2020
@bowenlan-amzn bowenlan-amzn added the enhancement New feature or request label Sep 8, 2020
@qreshi qreshi deleted the monitor-apis branch December 19, 2020 00:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants