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

feat(pg-usage-data): Add cache to batch tracking data #4308

Merged
merged 4 commits into from
Jul 18, 2024
Merged

Conversation

gagantrivedi
Copy link
Member

@gagantrivedi gagantrivedi commented Jul 9, 2024

Thanks for submitting a PR! Please check the boxes below:

  • I have run pre-commit to check linting
  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

Add cache to batch usage tracking
fixes: #4241

How did you test this code?

Adds unit tests

@gagantrivedi gagantrivedi requested a review from a team as a code owner July 9, 2024 03:11
@gagantrivedi gagantrivedi requested review from zachaysan and removed request for a team July 9, 2024 03:11
Copy link

vercel bot commented Jul 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview Jul 16, 2024 1:50pm
flagsmith-frontend-preview ⬜️ Ignored (Inspect) Visit Preview Jul 16, 2024 1:50pm
flagsmith-frontend-staging ⬜️ Ignored (Inspect) Visit Preview Jul 16, 2024 1:50pm

@github-actions github-actions bot added feature New feature or request api Issue related to the REST API labels Jul 9, 2024
Copy link
Contributor

github-actions bot commented Jul 9, 2024

flagsmith-private-cloud image build and security scan finished ✨

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-private-cloud:pr-4308 Finished ✅ Results

Copy link
Contributor

github-actions bot commented Jul 9, 2024

flagsmith-frontend image build and security scan finished ✨

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-frontend:pr-4308 Finished ✅ Results

Copy link
Contributor

github-actions bot commented Jul 9, 2024

flagsmith image build and security scan finished ✨

Image Build Status Security report
ghcr.io/flagsmith/flagsmith:pr-4308 Finished ✅ Results

Copy link
Contributor

github-actions bot commented Jul 9, 2024

flagsmith-e2e image build finished ✨

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-4308 Finished ✅ Skipped

Copy link
Contributor

github-actions bot commented Jul 9, 2024

flagsmith-api image build and security scan finished ✨

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api:pr-4308 Finished ✅ Results

Copy link
Contributor

github-actions bot commented Jul 9, 2024

Uffizzi Ephemeral Environment Deploying

☁️ https://app.uffizzi.com/github.com/Flagsmith/flagsmith/pull/4308

⚙️ Updating now by workflow run 9958175504.

What is Uffizzi? Learn more!

Copy link

codecov bot commented Jul 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.78%. Comparing base (627370f) to head (bdb2321).
Report is 34 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4308      +/-   ##
==========================================
+ Coverage   96.60%   96.78%   +0.17%     
==========================================
  Files        1195     1162      -33     
  Lines       39099    38154     -945     
==========================================
- Hits        37773    36927     -846     
+ Misses       1326     1227      -99     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Jul 9, 2024
@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Jul 9, 2024
@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Jul 12, 2024
Copy link
Contributor

github-actions bot commented Jul 12, 2024

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-4308 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api-test:pr-4308 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api-test:pr-4308 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-4308 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-4308 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-frontend:pr-4308 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-4308 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-4308 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-4308 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-4308 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-4308 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-4308 Finished ✅ Results

@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Jul 12, 2024
frozen_time.tick(CACHE_FLUSH_INTERVAL + 1)

# Next, let's call flush
cache.flush()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we have this pattern elsewhere so we're probably just following that, but it's odd to me that we're calling flush directly here since I don't think any external calls are made to it. I think we should probably mark the flush method as private, and this test should only use the track_request method.

Copy link
Member Author

Choose a reason for hiding this comment

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

Although It's not being used, but I feel it makes the interface a bit more clean? Does that make sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm... maybe it does, yes, but the test feels a bit too 'internal' to me. It's not really testing the actual behaviour.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's a fair point! I have made it private

Copy link
Contributor

@zachaysan zachaysan left a comment

Choose a reason for hiding this comment

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

Overall looks good to me, just a bunch of typing suggestions.

path: str,
enum_resource_value: int,
settings: SettingsWrapper,
):
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Missing typing for return value

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

api/tests/unit/app_analytics/test_middleware.py Outdated Show resolved Hide resolved
Comment on lines 88 to 89
rf: RequestFactory, mocker: MockerFixture, settings: SettingsWrapper
):
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Missing typing for return value

from pytest_mock import MockerFixture


def test_api_usage_cache(mocker: MockerFixture):
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Missing typing for return value

@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Jul 16, 2024
@github-actions github-actions bot added feature New feature or request and removed feature New feature or request labels Jul 16, 2024
@gagantrivedi gagantrivedi added this pull request to the merge queue Jul 18, 2024
Merged via the queue into main with commit 117f72a Jul 18, 2024
33 checks passed
@gagantrivedi gagantrivedi deleted the fix/4241 branch July 18, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue related to the REST API feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Batch API usage raw write to reduce the load on database
3 participants