Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add alertId parameter in get chained alert API and paginate associated alerts if alertId param is set. #1070

Closed
wants to merge 2 commits into from

Conversation

eirsep
Copy link
Member

@eirsep eirsep commented Aug 2, 2023

Get chained alert API will support filtering based on an alertId. The motivation is to fetch associated alerts with support for pagination. The size and sort params would apply to fetch associated alerts in this api when alert id is mentioned

…d alerts if alertId param is mentioned

Signed-off-by: Surya Sashank Nistala <[email protected]>
@codecov
Copy link

codecov bot commented Aug 2, 2023

Codecov Report

Merging #1070 (caf8f95) into 2.9 (3ad1365) will decrease coverage by 4.76%.
Report is 1 commits behind head on 2.9.
The diff coverage is 79.16%.

@@             Coverage Diff              @@
##                2.9    #1070      +/-   ##
============================================
- Coverage     72.75%   68.00%   -4.76%     
  Complexity      119      119              
============================================
  Files           160      160              
  Lines         10447    10467      +20     
  Branches       1572     1576       +4     
============================================
- Hits           7601     7118     -483     
- Misses         1952     2647     +695     
+ Partials        894      702     -192     
Files Changed Coverage Δ
...ting/transport/TransportGetWorkflowAlertsAction.kt 67.96% <77.77%> (+1.30%) ⬆️
...lerting/resthandler/RestGetWorkflowAlertsAction.kt 95.55% <83.33%> (-1.95%) ⬇️

... and 10 files with indirect coverage changes

val getAssociatedAlerts: Boolean = request.param("getAssociatedAlerts", "false").toBoolean()
val workflowIds = mutableListOf<String>()
if (workflowId.isNullOrEmpty() == false) {
workflowIds.add(workflowId)
}
val alertIds = mutableListOf<String>()
if (alertId.isNullOrEmpty() == false) {
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: use isNotEmpty() or isNotBlank()

Copy link
Member Author

Choose a reason for hiding this comment

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

alertId is of type String?

isNotEmpty() and isNotBlank() can be used only if it is not nullable. so the isNullOrEmpty() check takes care of it. There isn't a negated implementation of isNullOrEmpty

try {
val associatedAlertIds = mutableSetOf<String>()
alerts.forEach { associatedAlertIds.addAll(it.associatedAlertIds) }
if (associatedAlertIds.isEmpty()) return
val queryBuilder = QueryBuilders.boolQuery()
val searchRequest = SearchRequest(alertIndex)
// if chained alert id param is non-null, paginate the associated alerts.
if (getWorkflowAlertsRequest.alertIds.isNullOrEmpty() == false) {
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: use isNotEmpty() or isNotBlank()

Copy link
Member Author

Choose a reason for hiding this comment

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

this is a list

if (!tableProp.missing.isNullOrBlank()) {
sortBuilder.missing(tableProp.missing)
}
searchRequest.source().sort(sortBuilder).size(tableProp.size)
Copy link
Member

Choose a reason for hiding this comment

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

We dont take the from value. How are we paginating associated alerts?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed this.

Copy link
Member

@lezzago lezzago left a comment

Choose a reason for hiding this comment

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

Please make the PR first to main

@eirsep eirsep closed this Aug 2, 2023
@eirsep
Copy link
Member Author

eirsep commented Aug 2, 2023

Closing this PR

Will backport #1071 to 2.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants