Sitelet https://web.archive.org/web/20230718103617/https://github.com/sourcegraph/sourcegraph/pull/14589
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

Add homepage panel stats to pings #14589

Merged
merged 21 commits into from Oct 14, 2020
Merged

Add homepage panel stats to pings #14589

merged 21 commits into from Oct 14, 2020

Conversation

ebrodymoore
Copy link
Member

No description provided.

@ebrodymoore ebrodymoore marked this pull request as ready for review October 14, 2020 00:33
@ebrodymoore ebrodymoore requested a review from a team October 14, 2020 00:33

func GetHomepagePanels(ctx context.Context) (*types.HomepagePanels, error) {
const q = `
WITH sub AS (SELECT name, user_id FROM event_logs WHERE name LIKE '%Panel%' AND DATE_TRUNC('week', timestamp) = DATE_TRUNC('week', current_date))
Copy link
Member

Choose a reason for hiding this comment

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

Full text search with '%Panel%' is much slower than a prefix-only search in my experience. Is it possible that we have a common prefix of all events for homepage panels?

For example, HomepagePanels::RecentFilesPanelFileClicked, in that case, we only need to do WHERE name LIKE 'HomepagePanels::%'. cc @tsenart

Here is the query plan I got for running this query in prod DB:

                                                                             QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=590944.79..590944.90 rows=1 width=96) (actual time=1489.295..1489.296 rows=1 loops=1)
   ->  Gather  (cost=1000.00..590942.26 rows=23 width=24) (actual time=1433.922..1715.514 rows=520 loops=1)
         Workers Planned: 2
         Workers Launched: 2
         ->  Parallel Seq Scan on event_logs  (cost=0.00..589939.96 rows=10 width=24) (actual time=1431.128..1484.354 rows=173 loops=3)
               Filter: ((name ~~ '%Panel%'::text) AND (date_trunc('week'::text, "timestamp") = date_trunc('week'::text, (CURRENT_DATE)::timestamp with time zone)))
               Rows Removed by Filter: 3720315
 Planning Time: 0.347 ms
 Execution Time: 1716.090 ms
(9 rows)

Copy link
Contributor

Choose a reason for hiding this comment

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

I took the liberty to improve the query and the method that runs it :) Please take a look. The query plan now looks like this:

Subquery Scan on sub  (cost=2315.49..2315.62 rows=1 width=96) (actual time=24.003..24.003 rows=1 loops=1)
  ->  Aggregate  (cost=2315.49..2315.58 rows=1 width=136) (actual time=24.000..24.000 rows=1 loops=1)
        ->  Bitmap Heap Scan on event_logs  (cost=2126.86..2302.31 rows=155 width=24) (actual time=22.868..23.651 rows=545 loops=1)
              Recheck Cond: ((name = ANY ('{RecentFilesPanelFileClicked,RecentFilesPanelLoaded,RecentSearchesPanelSearchClicked,RecentSearchesPanelLoaded,RepositoriesPanelRepoFilterClicked,RepositoriesPanelLoaded,SavedSearchesPanelSearchClicked,SavedSearchesPanelLoaded,SavedSearchesPanelCreateButtonClicked,RecentFilesPanelFileClicked,RecentFilesPanelLoaded}'::text[])) AND ("timestamp" >= date_trunc('week'::text, (CURRENT_DATE)::timestamp with time zone)))
              Heap Blocks: exact=412
              ->  BitmapAnd  (cost=2126.86..2126.86 rows=155 width=0) (actual time=22.792..22.792 rows=0 loops=1)
                    ->  Bitmap Index Scan on event_logs_name  (cost=0.00..139.34 rows=9692 width=0) (actual time=0.592..0.592 rows=3569 loops=1)
                          Index Cond: (name = ANY ('{RecentFilesPanelFileClicked,RecentFilesPanelLoaded,RecentSearchesPanelSearchClicked,RecentSearchesPanelLoaded,RepositoriesPanelRepoFilterClicked,RepositoriesPanelLoaded,SavedSearchesPanelSearchClicked,SavedSearchesPanelLoaded,SavedSearchesPanelCreateButtonClicked,RecentFilesPanelFileClicked,RecentFilesPanelLoaded}'::text[]))
                    ->  Bitmap Index Scan on event_logs_timestamp  (cost=0.00..1987.19 rows=183500 width=0) (actual time=21.979..21.979 rows=363041 loops=1)
                          Index Cond: ("timestamp" >= date_trunc('week'::text, (CURRENT_DATE)::timestamp with time zone))
Planning Time: 0.271 ms
Execution Time: 24.108 ms

@codecov
Copy link

codecov bot commented Oct 14, 2020 •

Codecov Report

Merging #14589 into main will increase coverage by 0.07%.
The diff coverage is 4.00%.

@@            Coverage Diff             @@
##             main   #14589      +/-   ##
==========================================
+ Coverage   52.13%   52.21%   +0.07%     
==========================================
  Files        1558     1558              
  Lines       79322    79179     -143     
  Branches     7108     6948     -160     
==========================================
- Hits        41356    41340      -16     
+ Misses      34223    34102     -121     
+ Partials     3743     3737       -6     
Flag Coverage Δ
#go 52.51% <4.00%> (+0.10%) ⬆️
#integration 30.81% <ø> (ø)
#storybook 22.05% <ø> (-0.01%) ⬇️
#typescript 51.46% <ø> (+<0.01%) ⬆️
#unit 33.24% <ø> (+<0.01%) ⬆️
Impacted Files Coverage Δ
client/web/src/site-admin/SiteAdminPingsPage.tsx 0.00% <ø> (ø)
cmd/frontend/internal/app/updatecheck/client.go 0.00% <0.00%> (ø)
...md/frontend/internal/usagestats/homepage_panels.go 0.00% <0.00%> (ø)
cmd/frontend/internal/app/updatecheck/handler.go 42.32% <100.00%> (-0.41%) ⬇️
...nterprise/cmd/frontend/auth/httpheader/provider.go 0.00% <0.00%> (-20.00%) ⬇️
...prise/cmd/frontend/auth/httpheader/config_watch.go 83.33% <0.00%> (-16.67%) ⬇️
...eb/src/enterprise/codeintel/CodeIntelIndexPage.tsx 57.62% <0.00%> (-1.70%) ⬇️
.../internal/codeintel/resolvers/graphql/locations.go 85.56% <0.00%> (+4.12%) ⬆️

Copy link
Member

@unknwon unknwon left a comment

Choose a reason for hiding this comment

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

Thanks @tsenart !

@ebrodymoore ebrodymoore merged commit a3daa7b into main Oct 14, 2020
@ebrodymoore ebrodymoore deleted the ebm-panel-pings branch October 14, 2020 14:54
RecentRepositoriesClickedPercentage float64
SavedSearchesClickedPercentage float64
NewSavedSearchesClickedPercentage float64
TotalPanelViews float64
Copy link
Member

Choose a reason for hiding this comment

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

@ebrodymoore should this be a float64? What type is it in BigQuery? I assume an integer?

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually have them all as floats

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. Not a big deal, but generally I'd recommend using the best matched number types where possible. E.g. for counts, there will never be fractional values, so ints are a better fit (no worries about weird rounding issues, they take less space, they help users make assumptions about the data that is being held here, etc., but again, not a big deal).

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.

None yet

4 participants