insights: Migrate InsightOrgVisible and InsightTimeIntervals pings to backend
Created by: CristinaBirkel
Closes https://github.com/sourcegraph/sourcegraph/issues/24481
Note: Wait to merge this until after https://github.com/sourcegraph/sourcegraph/pull/27473
Description
The InsightOrgVisible
ping and the InsightTimeIntervals
ping used to be calculated by parsing the settings. With this PR they are now calculated by querying the database.
I also did a bit of refactoring, which I hope makes this easier to extend in the future:
- Broke
insight_ping_emitter.go
into 2 files: one with the functions that collect/format the aggregates and the other with the emitter itself. - Simplified the
emit
function by breaking out separate functions for each thing we want to emit.
Side note: I'm sorry the diff is so hard to read. I probably should have done the refactor in a separate commit.
Testing Steps
I tested this by running the SQL queries against my local database and then verifying that the pings showed the correct values here: https://sourcegraph.test:3443/site-admin/pings
I also tested out the edge case where the InsightTimeIntervals
get regrouped due to there being some kind of overlap (for example, 30 days vs 1 month.)