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: add prometheus instrumentation to requests, db accesses, and models #202

Merged
merged 12 commits into from
Nov 6, 2023

Conversation

matt-codecov
Copy link
Contributor

@matt-codecov matt-codecov commented Oct 19, 2023

uses django-prometheus to instrument a bunch of metrics in django. there are quite a lot

if django is running on localhost:8000, metrics will be served at localhost:8001/monitoring/metrics. it will listen on a range from 8001-8020 for when gunicorn is running multiple worker processes that collect metrics separately. so i guess poll the whole range, though i think today prod only runs two workers

when gunicorn runs django in multiple worker processes, we need to use prometheus's multiprocess mode. dev just runs a single worker, but prod runs 2 and enterprise runs a configurable number. so:

  • in prod, assign a default value for the $PROMETHEUS_MULTIPROC_DIR env var ($HOME/.prometheus)
  • in enterprise, assign a default value for the $PROMETHEUS_MULTIPROC_DIR env var _if using more than 1 worker process ($HOME/.prometheus`)
  • in dev, prod, and enterprise, clear/recreate the $PROMETHEUS_MULTIPROC_DIR directory on startup if it's set

if $PROMETHEUS_MULTIPROC_DIR is set, django-prometheus will automatically use the multiprocessing registry and no extra configuration is needed.

some of the key metrics that this generates:

  • API hits, labelled by view
  • API responses, labeled by view, http method, and status code
  • counters for insert/update/delete for models including commit, upload, report, repository...

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@codecov-staging
Copy link

codecov-staging bot commented Oct 19, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@codecov-qa
Copy link

codecov-qa bot commented Oct 19, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (6434b23) 95.67% compared to head (5b4d4ce) 95.66%.

❗ Current head 5b4d4ce differs from pull request most recent head 31f1d0d. Consider uploading reports for the commit 31f1d0d to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #202      +/-   ##
==========================================
- Coverage   95.67%   95.66%   -0.01%     
==========================================
  Files         604      603       -1     
  Lines       15458    15446      -12     
==========================================
- Hits        14789    14777      -12     
  Misses        669      669              
Flag Coverage Δ
unit 95.66% <100.00%> (-0.01%) ⬇️
unit-latest-uploader 95.66% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@codecov-public-qa
Copy link

codecov-public-qa bot commented Oct 19, 2023

Codecov Report

❗ No coverage uploaded for pull request base (main@6434b23). Click here to learn what that means.
The diff coverage is 100.00%.

❗ Current head d8cbbeb differs from pull request most recent head 31f1d0d. Consider uploading reports for the commit 31f1d0d to get more accurate results

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #202   +/-   ##
=======================================
  Coverage        ?   95.66%           
=======================================
  Files           ?      602           
  Lines           ?    15437           
  Branches        ?        0           
=======================================
  Hits            ?    14768           
  Misses          ?      669           
  Partials        ?        0           
Flag Coverage Δ
unit 95.66% <100.00%> (?)
unit-latest-uploader 95.66% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
billing/models.py 100.00% <100.00%> (ø)
codecov/settings_base.py 85.39% <100.00%> (ø)
codecov/urls.py 100.00% <ø> (ø)
codecov_auth/models.py 98.87% <100.00%> (ø)
compare/models.py 100.00% <100.00%> (ø)
core/models.py 94.57% <100.00%> (ø)
labelanalysis/models.py 100.00% <100.00%> (ø)
legacy_migrations/models.py 100.00% <100.00%> (ø)
profiling/models.py 95.45% <100.00%> (ø)
reports/models.py 96.26% <100.00%> (ø)
... and 2 more

Impacted file tree graph

@codecov
Copy link

codecov bot commented Oct 19, 2023

Codecov Report

Merging #202 (31f1d0d) into main (6434b23) will increase coverage by 0.01%.
Report is 1 commits behind head on main.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##            main    #202     +/-   ##
=======================================
+ Coverage   95.57   95.58   +0.01     
=======================================
  Files        718     718             
  Lines      15864   15875     +11     
=======================================
+ Hits       15162   15173     +11     
  Misses       702     702             
Flag Coverage Δ
unit 95.67% <100.00%> (+<0.01%) ⬆️
unit-latest-uploader 95.67% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
billing/models.py 100.00% <100.00%> (ø)
codecov/settings_base.py 88.33% <100.00%> (+0.06%) ⬆️
codecov/urls.py 100.00% <ø> (ø)
codecov_auth/models.py 98.87% <100.00%> (+<0.01%) ⬆️
compare/models.py 100.00% <100.00%> (ø)
core/models.py 94.57% <100.00%> (+0.02%) ⬆️
labelanalysis/models.py 100.00% <100.00%> (ø)
legacy_migrations/models.py 100.00% <100.00%> (ø)
profiling/models.py 95.45% <100.00%> (+0.21%) ⬆️
reports/models.py 96.26% <100.00%> (+0.03%) ⬆️
... and 2 more

@codecov-test
Copy link

Welcome to Codecov 🎉

Once merged to your default branch, Codecov will compare your coverage reports and display the results in this comment.

Thanks for integrating Codecov - We've got you covered ☂️

codecov/urls.py Show resolved Hide resolved
dev.sh Show resolved Hide resolved
@matt-codecov
Copy link
Contributor Author

@matt-codecov matt-codecov merged commit 28d93eb into main Nov 6, 2023
11 of 12 checks passed
@matt-codecov matt-codecov deleted the matt/add-prometheus-instrumentation branch November 6, 2023 20:59
trent-codecov added a commit that referenced this pull request Nov 14, 2023
* Test ats run (#229)

* Test ats run

* Test ats run

* Test ats run

* Test ats run

* Test ats run

* Test ats run

* Test ats run

* Test ats run

* feat: Emit sync repo message to Shelter on repo update (#215)

* feat: add prometheus instrumentation to requests, db accesses, and models (#202)

* feat: add prometheus instrumentation to requests, db accesses, and models

* switch to multiprocessing mode

* add nullchecking for gunicorn worker/pid

* only call multiprocess.mark_process_dead if prometheus multiprocess is enabled

* add comment about public prometheus route

---------

Co-authored-by: Trent Schmidt <trent@codecov.io>

* fix: make GraphQL types matches nullability with django models (#220)


Audit all the GraphQL API types to make sure that the nullabilitity (nullable or not nullable) matches that of the database columns (via Django ORM).

* feat: Add index on pulls (repoid, id) (#217)

* feat: Add index on pulls (repoid, id)

* Fix migration conflict

* Fix XSS vulnerability by removing ref_type from Response (#211)

* fix: available plans for users while trialing (#731) (#230)


Fix a bug where a user while trialing does not have Team plans available to upgrade to.
This happens because while trialing we set plan_user_count to 1000 while trialing, so we will check plan_activated_users while user is trialing.

* fix: Skip login if GitHub OAuth does not return access_token (#236)

* Send github oauth access token expiry with cookie (#237)

* initial commit

* remove method

* lint

* sort imports

* reintroduce variable

* Update small badge (#238)

* chore: Moves the small badge mask over to leave space for 100% while still looking good with 2 digits

* fix small badge expected svg util

* fix small badge tests

* fix: Upgrade Django version to fix security vulnerabilities (#239)


Fixes Django security vulnerabilities by updating to the fix version:

Django Denial-of-service in django.utils.text.Truncator
Django potential denial of service vulnerability in UsernameField on Windows
Django Denial of service vulnerability in django.utils.encoding.uri_to_iri

* feat: Modify billing for Team plan (#637) (#225)


- When signing up to a new paid plan, it will have Team plan choice, and checks for plan user limit.
- Also update limit from 1000 to 2500 and refactor a variable name
- Add isPublic option to measurements filter
- Change marketing name of Pro Team to Pro

* fix: Handle Shelter storage paths in upload download handler (#234)

* fix: Handle shetler storage paths in upload download handler

* fix: Handle shetler storage paths in upload download handler

* Add test for shelter storage path

* Updating workflows (#242)

* Fix urllib and opentelemetry-instrumentation dependencies (#213)

* Update urllib3 dependency
* Fix opentelementry-instrumentation dependency

Fixes: codecov/internal-issues#103
Fixes: codecov/internal-issues#104

Signed-off-by: joseph-sentry <joseph.sawaya@sentry.io>

* Make migration info log less confusing (#221)

Clearly state whether migrations failed or succeded.

Co-authored-by: Trent Schmidt <trent@codecov.io>

* Use alpine 3.18

---------

Signed-off-by: joseph-sentry <joseph.sawaya@sentry.io>
Co-authored-by: scott-codecov <scott@codecov.io>
Co-authored-by: matt-codecov <137832199+matt-codecov@users.noreply.github.com>
Co-authored-by: JerrySentry <142266253+JerrySentry@users.noreply.github.com>
Co-authored-by: joseph-sentry <136376984+joseph-sentry@users.noreply.github.com>
Co-authored-by: Rohit Vinnakota <148245014+rohitvinnakota-codecov@users.noreply.github.com>
Co-authored-by: Terry <87824812+terry-codecov@users.noreply.github.com>
Co-authored-by: Andreas Bergmeier <51448674+AndreasBergmeier6176@users.noreply.github.com>
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