-
Notifications
You must be signed in to change notification settings - Fork 30
POL-293 Add paging to the history of a single policy #119
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
POL-293 Add paging to the history of a single policy #119
Conversation
Signed-off-by: Heiko W. Rupp <[email protected]>
limit = min(limit,200); | ||
int pageNum = pager.getOffset() / limit; | ||
|
||
String alerts = engine.findLastTriggered(policyId.toString(), false, pageNum, limit, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll need a "paginated response", e.g. to know the total number of elements to decide if "next page" button is disabled or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I am not sure yet how to get that from the engine
Something else to note, is that the UI would still need all the elements in the page for exporting (json/csv), should the UI consume all the pages to build this report? |
Some test, not sure if i'm wrongly fetching the second page Page 1 with 50 elements (limit=50 and offset=0) curl 'https://ci.foo.redhat.com:1337/api/policies/v1.0/policies/3f421b5c-babc-4cf4-9026-0b9083d5b1df/history/trigger?limit=50&offset=0' | jq ". | length"
50 Page 1 with 200 elements (limit=200 and offset=0) curl 'https://ci.foo.redhat.com:1337/api/policies/v1.0/policies/3f421b5c-babc-4cf4-9026-0b9083d5b1df/history/trigger?limit=200&offset=0' | jq ". | length"
200 but Page 2 with 50 elements (limit=50 and offset=50) curl 'https://ci.foo.redhat.com:1337/api/policies/v1.0/policies/3f421b5c-babc-4cf4-9026-0b9083d5b1df/history/trigger?limit=50&offset=50' | jq ". | length"
0 and Page 3 with 50 elements (limit=50 and offset=100) curl 'https://ci.foo.redhat.com:1337/api/policies/v1.0/policies/3f421b5c-babc-4cf4-9026-0b9083d5b1df/history/trigger?limit=50&offset=100' | jq ". | length"
50 From there, all the pages seems to yield correctly |
@burmanm maybe a bug from the engine? @GET
@Consumes("application/json")
String findLastTriggered(@QueryParam("triggerIds") String triggerIds,
@QueryParam("thin") boolean thin,
@QueryParam("page") int page,
@QueryParam("per_page") int per_page,
@HeaderParam("Hawkular-Tenant") String customerId); engine.findLastTriggered("the-id", false, 1, 50, "the-account") and the engine returns |
I updated the engine, and now I'm getting |
I don't see that |
Debugging the backend code, it looks like something changed on the engine, it is returning (for first page of 2 elements): [
{
"eventType":"ALERT",
"tenantId":"940527",
"id":"fe5a82ed-129c-4ce0-8e3b-63ab4aac045e-1591732136644-2243f530-f544-410b-bb4c-3d6090f65cc4",
"ctime":1591732136644,
"dataSource":"_none_",
"dataId":"fe5a82ed-129c-4ce0-8e3b-63ab4aac045e",
"category":"ALERT",
"text":"Fail if we are running on a x86_64 - We should be using arm.",
"trigger":{
"tenantId":"940527",
"id":"fe5a82ed-129c-4ce0-8e3b-63ab4aac045e",
"name":"Copy of Not arch x86_64",
"description":"Fail if we are running on a x86_64 - We should be using arm.",
"type":"STANDARD",
"eventType":"ALERT",
"eventCategory":null,
"eventText":null,
"severity":"MEDIUM",
"actions":[
{
"tenantId":"940527",
"actionPlugin":"email",
"actionId":"_managed-instance-email-35e48b6487d9568e"
}
],
"autoDisable":false,
"autoEnable":false,
"autoResolve":false,
"autoResolveAlerts":false,
"autoResolveMatch":"ALL",
"enabled":true,
"firingMatch":"ALL",
"source":"_none_"
},
"severity":"MEDIUM",
"status":"OPEN",
"lifecycle":[
{
"status":"OPEN",
"stime":1591732136644
}
]
},
{
"eventType":"ALERT",
"tenantId":"940527",
"id":"fe5a82ed-129c-4ce0-8e3b-63ab4aac045e-1591732136583-20d4a793-fa41-4321-9f6d-006e4d062cfc",
"ctime":1591732136583,
"dataSource":"_none_",
"dataId":"fe5a82ed-129c-4ce0-8e3b-63ab4aac045e",
"category":"ALERT",
"text":"Fail if we are running on a x86_64 - We should be using arm.",
"trigger":{
"tenantId":"940527",
"id":"fe5a82ed-129c-4ce0-8e3b-63ab4aac045e",
"name":"Copy of Not arch x86_64",
"description":"Fail if we are running on a x86_64 - We should be using arm.",
"type":"STANDARD",
"eventType":"ALERT",
"eventCategory":null,
"eventText":null,
"severity":"MEDIUM",
"actions":[
{
"tenantId":"940527",
"actionPlugin":"email",
"actionId":"_managed-instance-email-35e48b6487d9568e"
}
],
"autoDisable":false,
"autoEnable":false,
"autoResolve":false,
"autoResolveAlerts":false,
"autoResolveMatch":"ALL",
"enabled":true,
"firingMatch":"ALL",
"source":"_none_"
},
"severity":"MEDIUM",
"status":"OPEN",
"lifecycle":[
{
"status":"OPEN",
"stime":1591732136583
}
]
}
] and the backend query |
Well, the backend is now removing evalsets from alerts storage if that is set (in the application.properties), so searching them would be impossible. |
Ok, when setting |
What i said above (#119 (comment)) is still an issue. Using pages of 50 elements:
|
I think the UI would need to iterate over the pages. Sending with unlimited could be much too much data that is dealt with in one go. |
If there's export functionality, then it should probably just stream the data from engine? No point keeping any of this in memory elsewhere. |
Signed-off-by: Heiko W. Rupp <[email protected]>
Signed-off-by: Heiko W. Rupp <[email protected]>
@@ -782,26 +784,51 @@ public Response getPolicy(@PathParam("id") UUID policyId) { | |||
|
|||
@Operation(summary = "Retrieve the trigger history of a single policy") | |||
@APIResponse(responseCode = "200", description = "History could be retrieved", | |||
content = @Content (schema = @Schema(type = SchemaType.ARRAY, implementation = HistoryItem.class))) | |||
content = @Content (schema = @Schema(implementation = PagingUtils.PagedResponse.class)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a problem here, using this syntax removes the HistoryItem
from the openapi.json plus the PagedResponse
doesn't have any info about its contents.
I found the following [1] workaround:
// workaround for returning generic types: https://github.com/swagger-api/swagger-core/issues/498#issuecomment-74510379
// This class is used only for swagger return type
private static class PagedResponseOfHistoryItem extends PagingUtils.PagedResponse<HistoryItem> {
private List<HistoryItem> data;
private PagedResponseOfHistoryItem() {}
}
@Operation(summary = "Retrieve the trigger history of a single policy")
@APIResponse(responseCode = "200", description = "History could be retrieved",
content = @Content (schema = @Schema(implementation = PagedResponseOfHistoryItem.class)),
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about something similar, as I don't like the type-erasure.
Same for getPolicies
Change openapi types to not erase the inner type Signed-off-by: Heiko W. Rupp <[email protected]>
This depends now on RedHatInsights/policies-engine#82 |
Tested this PR, is working fine.
Already iterating over the pages when exporting. |
Signed-off-by: Heiko W. Rupp <[email protected]>
Signed-off-by: Heiko W. Rupp [email protected]