-
Notifications
You must be signed in to change notification settings - Fork 5
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
Usage API: breakdownBy=creatorId #183
Usage API: breakdownBy=creatorId #183
Conversation
…o remove unused grouping fields (time interval, creator id). Fixed UsageWithTimestamp that did not return the time interval
… from string format to unix timestamp to match the views query (it didnt work at all previously)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall, but requesting changes due to the breaking changes to the API
usage/bigquery.go
Outdated
bqRows, err := doBigQuery[UsageSummaryRow](bq, ctx, sql, args) | ||
if err != nil { | ||
return nil, fmt.Errorf("bigquery error: %w", err) | ||
} else if len(bqRows) > 1 { | ||
return nil, fmt.Errorf("internal error, query returned %d rows", len(bqRows)) | ||
} else if len(bqRows) > maxBigQueryResultRows { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have a separate check for when we have breakdown vs when we don't? When we don't have any breakdown there should be only 1 result, so it'd be an error to have more results
usage/client.go
Outdated
@@ -30,25 +46,70 @@ func NewClient(opts ClientOptions) (*Client, error) { | |||
return &Client{opts, lp, bigquery}, nil | |||
} | |||
|
|||
func (c *Client) QuerySummary(ctx context.Context, userID string, creatorID string, spec QuerySpec) (*UsageSummaryRow, error) { | |||
summary, err := c.bigquery.QueryUsageSummary(ctx, userID, creatorID, spec) | |||
func (c *Client) QuerySummary(ctx context.Context, userID string, spec QuerySpec) ([]Metric, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change from *UsageSummaryRow
to []Metric
is another breaking change. If a client was calling this API before and parsing the response as an object, it will now explode cause it's getting an array.
My suggestion is to build on top of the QuerySummary
vs QuerySummaryWithTimestep
separation, given the latter already returns an array. So, instead of changing every response to be an array, we could change QuerySummaryWithTimestep
to be QuerySummaryWithBreakdown
instead and update the check here to also call the breakdown version when len(breakdownBy) > 0
. And then we leave the no-breakdown version still returning an object not to break any existing integrations. WDYT?
Turns out that the explicit parameter on the functions was never used, they were actually grabbed from the spec.Filters.CreatorID which makes more sense. This actually fixes the userId function by removing the redundant argument and using only the filters one.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #183 +/- ##
===================================================
- Coverage 29.25926% 28.99628% -0.26298%
===================================================
Files 4 5 +1
Lines 270 269 -1
===================================================
- Hits 79 78 -1
Misses 180 180
Partials 11 11
Continue to review full report in Codecov by Sentry.
|
Test Queries
I used Trovo's api key