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

feat(services): add aggregations #268

Merged
merged 3 commits into from
Oct 8, 2024
Merged

Conversation

MR2011
Copy link
Collaborator

@MR2011 MR2011 commented Sep 27, 2024

Description

This PR adds the following two aggregations for services:

  • Count of ComponentInstances
  • Count of IssueMatches

What type of PR is this? (check all applicable)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation Update
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🤖 Build
  • 🔁 CI
  • 📦 Chore (Release)
  • ⏩ Revert

Related Tickets & Documents

Added tests?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help
  • Separate ticket for tests # (issue/pr)

Tests:

  • E2E testing metadata (aggregation)
  • App testing ListServices with aggregation
  • DB testing individual aggregation functions

Added to documentation?

  • 📜 README.md
  • 🤝 Documentation pages updated
  • 🙅 no documentation needed
  • (if applicable) generated OpenAPI docs for CRD changes

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

internal/app/service/service_handler.go Show resolved Hide resolved
internal/app/service/service_handler_test.go Show resolved Hide resolved
Comment on lines 439 to 493
When("Getting Services with Aggregations", Label("GetServicesWithAggregations"), func() {
BeforeEach(func() {
_ = seeder.SeedDbWithNFakeData(10)
})
Context("and and we have 10 elements in the database", func() {
It("returns the services with componentInstance count", func() {
entriesWithAggregations, err := db.GetServicesWithComponentInstanceCount(nil)

By("throwing no error", func() {
Expect(err).To(BeNil())
})

By("returning some aggregations", func() {
for _, entryWithAggregations := range entriesWithAggregations {
Expect(entryWithAggregations).NotTo(
BeEquivalentTo(entity.ServiceAggregations{}))
}
})
})
It("returns correct aggregation values", func() {
//Should be filled with a check for each aggregation value,
// this is currently skipped due to the complexity of the test implementation
// as we would need to implement for each of the aggregations a manual aggregation
// based on the seederCollection.
//
// This tests should therefore only get implemented in case we encourage errors in this area to test against
// possible regressions
})
})
Context("and and we have 10 elements in the database", func() {
It("returns the services with issueMatch count", func() {
entriesWithAggregations, err := db.GetServicesWithIssueMatchCount(nil)

By("throwing no error", func() {
Expect(err).To(BeNil())
})

By("returning some aggregations", func() {
for _, entryWithAggregations := range entriesWithAggregations {
Expect(entryWithAggregations).NotTo(
BeEquivalentTo(entity.ServiceAggregations{}))
}
})
})
It("returns correct aggregation values", func() {
//Should be filled with a check for each aggregation value,
// this is currently skipped due to the complexity of the test implementation
// as we would need to implement for each of the aggregations a manual aggregation
// based on the seederCollection.
//
// This tests should therefore only get implemented in case we encourage errors in this area to test against
// possible regressions
})
})
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't we need a test then here that is checking that for 0 counts the service is still listed?

So I'm expecting 10 services even though they might not all have a count > 0.

Copy link
Collaborator

@drochow drochow left a comment

Choose a reason for hiding this comment

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

I still think we might can create 2 services (without anything) and we would expect them to come back no?

@drochow
Copy link
Collaborator

drochow commented Oct 8, 2024

@MR2011 Am I missing something? I think its just about calling:

seeder.SeedServices(10)

in a test and check then if also the 0 count services are returned (if no filter is applied)

@MR2011
Copy link
Collaborator Author

MR2011 commented Oct 8, 2024

@MR2011 Am I missing something? I think its just about calling:

seeder.SeedServices(10)

in a test and check then if also the 0 count services are returned (if no filter is applied)
That's tested here

Context("and the database contains service without aggregations", func() {
BeforeEach(func() {
newServiceRow := test.NewFakeService()
newService := newServiceRow.AsService()
db.CreateService(&newService)
})
It("returns the services with componentInstance count", func() {
entriesWithAggregations, err := db.GetServicesWithComponentInstanceCount(nil)
By("throwing no error", func() {
Expect(err).To(BeNil())
})
By("returning some aggregations", func() {
for _, entryWithAggregations := range entriesWithAggregations {
Expect(entryWithAggregations).NotTo(
BeEquivalentTo(entity.ServiceAggregations{}))
Expect(entryWithAggregations.ServiceAggregations.ComponentInstances).To(BeEquivalentTo(0))
Expect(entryWithAggregations.ServiceAggregations.IssueMatches).To(BeEquivalentTo(0))
}
})
By("returning all services", func() {
Expect(len(entriesWithAggregations)).To(BeEquivalentTo(1))
})
})
})

@MR2011 MR2011 merged commit 876df98 into main Oct 8, 2024
7 checks passed
@MR2011 MR2011 deleted the mr2011/issue_249/service_aggregations branch October 8, 2024 09:16
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.

feat(service): Service List View Aggregation Query
2 participants