Skip to content

Conversation

@idastambuk
Copy link
Contributor

@idastambuk idastambuk commented Apr 12, 2024

Service Map feature: Add aggregations and query filters to use in service map queries

We're using some new aggregation types (openSeachQuery.aggs) and query filters (openSearchQuery.query) in requests for service map data to Open search.

Query filters are what Open Search will filter the documents by, before applying the aggregations to the filtered set.

Query filters:

  • MustNotFilters
  • ShouldFilters (functions as OR for conditions inside it)
  • Terms/Term filter (they must get marshaled differently depending on whether they have one or multiple values

Aggregations:

  • Script aggregation
  • Terms aggregation (different than Terms filter) aggregating by term (field) serviceName

Also:

  • tests
  • renamed MustQueryBuilder to FilterList, as this struct wasn't Must-specific

Note:

The Bool filters that we need to add in order to get the right stats for the service map are quite nested and look a bit messy. This is because filter, must _not, must... filters always need to be nested under the bool filter, so there's a lot of repetition in the nesting. Once we start using them, we will need to have a complex query that looks like this:

Screenshot 2024-04-15 at 11 17 24

What this PR does / why we need it:
Part of the service map feature

Special notes for your reviewer:
Not using them in main, but they will be used in subsequent PRs for Service map

@idastambuk idastambuk force-pushed the service-map-aggregations branch from e16ed29 to ad3c83a Compare April 15, 2024 09:15
@idastambuk idastambuk marked this pull request as ready for review April 15, 2024 09:50
@idastambuk idastambuk requested a review from a team as a code owner April 15, 2024 09:50
@idastambuk idastambuk requested review from iwysiu, kevinwcyu, njvrzm and sarahzinger and removed request for a team April 15, 2024 09:50
Copy link
Contributor

@iwysiu iwysiu left a comment

Choose a reason for hiding this comment

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

Nice! Some style nits

t.Key: {"value": t.Values[0]},
},
})
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove the else and just make this a return

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, but I feel like adding the else explicitly is more readable 🤔

Copy link
Contributor

@iwysiu iwysiu Apr 16, 2024

Choose a reason for hiding this comment

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

This is a short enough function that it doesn't really matter, but generally, the go style convention is to avoid having final returns in elses, and golint actually will format your code that way (though we don't have golint turned on in our repos). Basically the idea for readability is that your functions are always returning at the end with the general behavior as left justified as possible, with exceptions branching off with an if (splitting off into sub functions if really necessary).
(My old mentor's position was that you should never have an else in your go code ever, and while I'm not that extreme I do see his point that it ends up with a lot of different behavior paths that are easy to lose bugs in)
(Also If you want to read people talking about it on reddit here's a link, lol)

@idastambuk idastambuk merged commit 3d47837 into main Apr 16, 2024
@idastambuk idastambuk deleted the service-map-aggregations branch April 16, 2024 11:05
@katebrenner
Copy link
Contributor

fixes #371

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

5 participants