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 user agent to prom metrics #404

Merged
merged 4 commits into from
Feb 20, 2024

Conversation

daniel-codecov
Copy link
Contributor

@daniel-codecov daniel-codecov commented Feb 16, 2024

Purpose/Motivation

This change adds the User-Agent http header to our prometheus metrics that we expose so that we can have a better understanding of where traffic comes from for our API. We can visualize the data via Grafana by the different User-Agents and it could give us insights in how our users use the codecov cli, uploader, etc..

What does this PR do?

  • subclass the provided django_prometheus middlewares, but add the additional label when appropriate
  • add unit tests to ensure functionality

Notes to Reviewer

You can view the exposed metrics at http://localhost:8000/monitoring/metrics, but I wasn't able to try querying in Grafana. Do we need to deploy to staging to test that?

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 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 Feb 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (21c3d75) 96.09% compared to head (3332852) 96.10%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #404   +/-   ##
=======================================
  Coverage   96.09%   96.10%           
=======================================
  Files         637      637           
  Lines       16654    16671   +17     
=======================================
+ Hits        16004    16021   +17     
  Misses        650      650           
Flag Coverage Δ
unit 96.10% <100.00%> (+<0.01%) ⬆️
unit-latest-uploader 96.10% <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.

Copy link

codecov-public-qa bot commented Feb 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (21c3d75) 96.09% compared to head (3332852) 96.10%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #404   +/-   ##
=======================================
  Coverage   96.09%   96.10%           
=======================================
  Files         637      637           
  Lines       16654    16671   +17     
=======================================
+ Hits        16004    16021   +17     
  Misses        650      650           
Flag Coverage Δ
unit 96.10% <100.00%> (+<0.01%) ⬆️
unit-latest-uploader 96.10% <100.00%> (+<0.01%) ⬆️

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

Files Coverage Δ
codecov/settings_base.py 85.71% <ø> (ø)
core/middleware.py 100.00% <100.00%> (ø)

Impacted file tree graph

Copy link

codecov bot commented Feb 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (21c3d75) 95.80% compared to head (6d80dec) 95.80%.

❗ Current head 6d80dec differs from pull request most recent head 3332852. Consider uploading reports for the commit 3332852 to get more accurate results

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #404   +/-   ##
=====================================
  Coverage   95.80   95.80           
=====================================
  Files        757     757           
  Lines      17264   17253   -11     
=====================================
- Hits       16539   16528   -11     
  Misses       725     725           
Flag Coverage Δ
unit 96.10% <100.00%> (+<0.01%) ⬆️
unit-latest-uploader 96.10% <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.

@daniel-codecov daniel-codecov changed the title cccccbgktviciclleucfituikfikjdtbftfltjrtnnlcDaniel/add user agent to prom metrics Daniel/add user agent to prom metrics Feb 16, 2024
Copy link
Contributor

@matt-codecov matt-codecov left a comment

Choose a reason for hiding this comment

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

awesome work, thanks a ton!

codecov-api automatically deploys when you merge to main so we should wait until monday to merge this in case something goes wrong. wouldn't want to make anyone work late on a friday

also might be a good idea to push to staging first and click around to see if anything crashes. and if there's a staging instance of grafana we can test it end-to-end with a dashboard too

core/middleware.py Show resolved Hide resolved
core/middleware.py Show resolved Hide resolved
core/tests/test_middleware.py Show resolved Hide resolved
@daniel-codecov daniel-codecov changed the title Daniel/add user agent to prom metrics feat: add user agent to prom metrics Feb 20, 2024
@daniel-codecov daniel-codecov force-pushed the daniel/add-user-agent-to-prom-metrics branch 3 times, most recently from bf08a59 to 6d80dec Compare February 20, 2024 21:16
@daniel-codecov daniel-codecov force-pushed the daniel/add-user-agent-to-prom-metrics branch from 6d80dec to 3332852 Compare February 20, 2024 21:21
@matt-codecov matt-codecov merged commit 1db5bd6 into main Feb 20, 2024
20 checks passed
@matt-codecov matt-codecov deleted the daniel/add-user-agent-to-prom-metrics branch February 20, 2024 21:41
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

2 participants