-
-
Notifications
You must be signed in to change notification settings - Fork 933
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
Track downloads statistics on timescaledb #4979
Open
jonatas
wants to merge
16
commits into
rubygems:master
Choose a base branch
from
jonatas:setup-downloads-on-timescaledb
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jonatas
changed the title
setup downloads on timescaledb
Setup downloads on timescaledb
Aug 23, 2024
jonatas
force-pushed
the
setup-downloads-on-timescaledb
branch
from
December 19, 2024 20:40
23f058c
to
11dfd76
Compare
jonatas
changed the title
Setup downloads on timescaledb
Track downloads statistics on timescaledb
Dec 20, 2024
jonatas
force-pushed
the
setup-downloads-on-timescaledb
branch
from
December 20, 2024 17:24
11dfd76
to
eb6fcc7
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4979 +/- ##
===========================================
- Coverage 97.13% 20.19% -76.95%
===========================================
Files 457 465 +8
Lines 9567 11693 +2126
===========================================
- Hits 9293 2361 -6932
- Misses 274 9332 +9058 ☔ View full report in Codecov by Sentry. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It's second part of #4642.
Add the downloads and log_downloads table to the timescaledb database.
The actual code makes a duplication of
LogTicket
and alsoFastlyLogDownloadProcessor
mimics the previous processor. I think we can live with both until we build the trust and guarantee all statistics are working as expected.TODO
How it works
Check the final download class:
To use raw data, you can query directly from Download:
It's already faster than a regular table because
Download
is a hypertable and uses partitions. So, it can use a Parallel scan to counter faster on each partition.The macro:
It will automatically map each scope into all time frames using hierarchical continuous aggregates, which means it will reuse minute data for hourly data. I originally introduced all boilerplates here and later migrated to the timescaledb gem. You can even see I wrote a blog post inspired by this challenge.
With that, you can also query the aggregated data by timeframe using the nested generated classes done by the continuous_aggregates macro:
How to test it
We have a maintenance task that will copy the actual LogTickets to be processed again by the Timescaledb. It will feed the
LogDownloads
table and then be processed by Timescaledb directly in the database.To process and see it in action directly from the command line, you can parse a log file
In my example, the output to insert 6175 records in a single transaction:
Migrating data
A maintenance task can be executed to import the actual data from LogTicket.
I haven't tested because I don't have access to production data, so this step needs to be validated.
Refreshing continuous aggregates
By default, the refresh will be done in the background. After the backfill, we'll need a single refresh in the continuous aggregates, which can also be useful for testing.
Here's a shortcut to refresh all at once: