Skip to content

feat(api): add application statistics #2347

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

Merged

Conversation

Shreya-7
Copy link
Contributor

@Shreya-7 Shreya-7 commented Oct 28, 2022

resolves #2264

@Shreya-7 Shreya-7 force-pushed the issue-2264-add-application-statistics branch from 0ff7047 to 090ed9a Compare October 28, 2022 19:38
@Shreya-7
Copy link
Contributor Author

@nejch had a quick question. I've written a functional test for this functionality where I'm creating some entities (projects, groups, snippets, users, etc.) and then checking whether the statistics returned match or not (number of projects created = number from statistics).
However, this test keeps failing because there are a number of projects created in other functional tests that were not cleaned up, and hence those numbers are interfering with the test. Similarly for other entities.

I have two options here: either I go around modifying those tests to clean up any entities they create, or I do a count of created (and undeleted) entities and just modify my test accordingly.
I would definitely prefer the first one, since it makes my test independent of others -- what do you think?

@lmilbaum
Copy link

@nejch had a quick question. I've written a functional test for this functionality where I'm creating some entities (projects, groups, snippets, users, etc.) and then checking whether the statistics returned match or not (number of projects created = number from statistics). However, this test keeps failing because there are a number of projects created in other functional tests that were not cleaned up, and hence those numbers are interfering with the test. Similarly for other entities.

I have two options here: either I go around modifying those tests to clean up any entities they create, or I do a count of created (and undeleted) entities and just modify my test accordingly. I would definitely prefer the first one, since it makes my test independent of others -- what do you think?

Jumping in if I may. The fixture reset_gitlab can do the trick.

@Shreya-7 Shreya-7 marked this pull request as draft October 29, 2022 11:33
@Shreya-7
Copy link
Contributor Author

Jumping in if I may. The fixture reset_gitlab can do the trick.

Just what I was looking for, thanks!

@Shreya-7 Shreya-7 marked this pull request as ready for review October 29, 2022 17:52
@Shreya-7 Shreya-7 requested a review from lmilbaum October 29, 2022 17:52
@codecov-commenter
Copy link

codecov-commenter commented Oct 29, 2022

Codecov Report

Merging #2347 (6619835) into main (f04e8ba) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #2347   +/-   ##
=======================================
  Coverage   95.78%   95.79%           
=======================================
  Files          79       79           
  Lines        5249     5258    +9     
=======================================
+ Hits         5028     5037    +9     
  Misses        221      221           
Flag Coverage Δ
api_func_v4 83.41% <100.00%> (+0.02%) ⬆️
cli_func_v4 82.73% <88.88%> (+0.01%) ⬆️
unit 87.77% <100.00%> (+0.02%) ⬆️

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

Impacted Files Coverage Δ
gitlab/client.py 98.55% <100.00%> (+<0.01%) ⬆️
gitlab/v4/objects/statistics.py 100.00% <100.00%> (ø)

@nejch
Copy link
Member

nejch commented Oct 30, 2022

Sorry @Shreya-7 I was away on a long weekend and catching up a bit!

I have two options here: either I go around modifying those tests to clean up any entities they create, or I do a count of created (and undeleted) entities and just modify my test accordingly.
I would definitely prefer the first one, since it makes my test independent of others -- what do you think?

I would actually keep it even simpler than that, and only check that the attributes in the response can be successfully cast to an int but not actually assert on their values, that way we know the server response makes sense.

GitLab does a lot of creation and cleanup tasks asynchronously and I would not rely on absolute values here. We've actually tried to move away from that in some other tests - see #2118 for context.

That said, I see you've done a lot of work on getting reset_gitlab to behave. So we can keep that as it likely helps the testing in any case (in a separate commit maybe). WDYT?

@Shreya-7
Copy link
Contributor Author

I would actually keep it even simpler than that, and only check that the attributes in the response can be successfully cast to an int but not actually assert on their values, that way we know the server response makes sense.

This makes sense, let me try that!

That said, I see you've done a lot of work on getting reset_gitlab to behave. So we can keep that as it likely helps the testing in any case (in a separate commit maybe). WDYT?

So should I open a new PR for this fix? I'm fine with it going in with this one, since my test does use this function

Copy link
Member

@nejch nejch left a comment

Choose a reason for hiding this comment

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

@Shreya-7 up to you if you want this as a separate PR, I'm fine with it in here too! Just a few more nits from me here.

@Shreya-7 Shreya-7 requested review from nejch and removed request for lmilbaum October 31, 2022 18:17
@nejch nejch force-pushed the issue-2264-add-application-statistics branch from 56f11fa to 6fcf3b6 Compare November 1, 2022 08:59
Copy link
Member

@nejch nejch left a comment

Choose a reason for hiding this comment

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

Thanks for all the work here @Shreya-7! Hopefully next time it's less of a bumpy ride ;)

@nejch nejch merged commit 31ec146 into python-gitlab:main Nov 1, 2022
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.

Add application statistics
4 participants