Fix health container numbers and pagination numbers #725
Fix health container numbers and pagination numbers #725
Conversation
d6bb91d
to
1decd4c
Compare
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.
Looks good @arbulu89! Thanks for addressing this!
There's a couple of little comments, tho! eheh 😄 Nothing major.
Keep this in mind: If you rebase on main
, the hosts_overview.js
test should fail, as the behavior changed.
Specifically this one should show health status of the first 10 visible hosts
, so the test needs to be updated, and the feature
file too 😄
As an extra reminder for future discussions: I am wondering whether we are doing too much things in our controllers and if the application might need some refactor as we go further refining requirements.
Yes. I'm aware of this divergence in the recently added tests, and I'm working on them. Thank you for the reminder though. |
Great! If you are experiencing randomic failures during |
By the way, do you prefer guys if I rebase already existing e2e and add the updates here, or a new PR with that? There won't be that many changes in cypress, so maybe we can put them all together here. |
I think the test needs to be updated in this PR, otherwise e2e will fail and pipeline won't proceed 🤔 |
1decd4c
to
057902b
Compare
@nelsonkopliku Changes applied, main branch rebased and e2e test adapted! |
057902b
to
e69fbba
Compare
return | ||
} | ||
pagination := NewPagination(count, pageNumber, pageSize) | ||
pagination := NewPagination(len(clusterListAll), pageNumber, pageSize) |
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 would instead introduce another health count service method that gives as an output the health counts directly, and the delegate that to the service instead of loading again the whole list in the controller, and use the count method for the pagination lenght.
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.
But what would this improve? In order to get the health numbers, we need to get all the clusters with the applied filters and get the health data.
We could create other service method, but it would do exactly the same as far as I see. I don't know any way to save any query to the database.
It might look cleaner, yes. But the code efficiency and in fact almost all the code would be the same.
Or am I missing something?
PD: And we cannot use the currently existing GetCount
method, as we need to get the count with the filtered values, which at the end, would require to use the same sql where conditions we have now. Does it make sense to complicate the code yet more?
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.
PD2: The unique way I see to reduce this to a unique call is to do the pagination within the code instead of using sql conditions
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.
It might look cleaner, yes. But the code efficiency and in fact almost all the code would be the same.
Or am I missing something?
If I am not mistaken, I think that to get the health status we don't need a "select *" query that also does various preload (e.g. Tags) but just the IDs of the clusters (a select id + pluck) should be enough to be used in the check service GetAggregatedChecksResultByCluster(cluster.ID)
PD: And we cannot use the currently existing GetCount method, as we need to get the count with the filtered values, which at the end, would require to use the same sql where conditions we have now.
By abstracting the filtering to a new method we can shape a GetCount with the filters, I don't think this would complicate the code a lot.
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.
No, the get the health we need to preload the tags, as we need to filter them. And we would need to get the id
, name
, cluster_type
and sid
. And we would need to get the checks results too. So the unique difference would to we discard only the number of hosts and the number of resources
hContainer := NewHostsHealthContainer(hostList) | ||
pagination := NewPagination(len(hostListAll), pageNumber, pageSize) | ||
|
||
hContainer := NewHostsHealthContainer(hostListAll) |
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.
Same as for the cluster comment, we fetch the list twice, while we just need the health count. I understand that queries are to be done to aggregate the data in the service anyway, but fetching the whole list with preloaded data seems overkill. It also helps with clarity in the controller which I feel is doing too much stuff ATM.
if err != nil { | ||
_ = c.Error(err) | ||
return | ||
} | ||
|
||
count, err := sapSystemsService.GetDatabasesCount() | ||
filterTags, err := sapSystemsService.GetAllDatabasesTags() |
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.
Same as above, I don't think we need to do the whole table fetching.
@arbulu89 thanks for addressing this! I have some doubts about how we fetch the paginated / non-paginated list twice in the contoller, since it seems that we can delegate some stuff to the service and maybe improve the fact that we load the whole preloaded list twice. |
Ah great stuff! Hope you did't encounter too many quirks 😅 I also took a look at the |
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.
For me it's a green light as long as the discussion with @fabriziosestito is sorted out.
In that regards, here's my two cents:
I think we all agree that we need to discuss about the codebase and code design itself, related also to the domain we're modeling.
So whatever we do here now, it might be anyway subject of change again, so let's do just the good enough.
const selectedOption = `#bs-select-1-${index}` | ||
cy.get(selectedOption).click() | ||
cy.wait('@filterByHealthStatus').then(() => { | ||
expectedHostsWithThisHealth == 0 && cy.get('.table.eos-table').contains('There are currently no records to be shown') | ||
expectedHostsWithThisHealth > 0 && cy.get('.tn-hostname').its('length').should('eq', expectedHostsWithThisHealth) | ||
cy.get('.pagination-count').should('contain', `${expectedHostsWithThisHealth} items`) |
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.
As a suggestion for the future:
This could be a custom cy
command https://docs.cypress.io/api/cypress-api/custom-commands, and we can think of it as a custom assertion for pagination.
Something along these lines:
Cypress.Commands.add('paginationShouldMatch', (itemsCount) => {
cy.get('.pagination-count').should('contain', `${itemsCount} items`)
cy.get('.page-item').its('length').should('eq', Math.ceil(itemsCount/100)+2)
})
which then becomes accessible as
cy.paginationShouldMatch(expectedHostsWithThisHealth)
cy.paginationShouldMatch(expectedRelatedHosts)
cy.paginationShouldMatch(expectedTaggedHosts)
in the different variants.
Look, don't bother changing it now, as I understand it wouldn't add much value right now 😄
Just wanted to share the cypress concept of custom command that might become more and more useful as we go.
Hey @fabriziosestito , |
@arbulu89 sorry thought i did it already, now it is green |
In order to improve the code structure, I have moved some structs to models