Merge ~ilasc/launchpad:add-repack-stats-api into launchpad:master

Proposed by Ioana Lasc
Status: Merged
Approved by: Ioana Lasc
Approved revision: 5b56401f928b9826cc81dd1e00d0d757de243595
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~ilasc/launchpad:add-repack-stats-api
Merge into: launchpad:master
Diff against target: 72 lines (+50/-0)
2 files modified
lib/lp/code/interfaces/gitrepository.py (+17/-0)
lib/lp/code/model/tests/test_gitrepository.py (+33/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+399851@code.launchpad.net

Commit message

Add API to see repack stats for one repo

Description of the change

I think the quickest and less computationally expensive way for us to have some visibility into repack data for a repository at the moment is an API.

The proposed endpoint might not be optimal but I figured proposing an attempt via code might be the easiest way for us to start discussing / refining a reasonable approach to this.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

We could do this, but the attributes in question are just simple ints/datetimes and they aren't secret. Any reason not to just export them as read-only attributes on IGitRepository?

review: Needs Information
1ee7e3c... by Ioana Lasc

Expose repack data as read-only

Revision history for this message
Ioana Lasc (ilasc) wrote :

Agreed they could just be exposed on the interface as read-only attributes, done.

Revision history for this message
Colin Watson (cjwatson) wrote :

Thanks for the update! A few minor nits, but otherwise LGTM - go ahead and land this once you've fixed these.

review: Approve
5b56401... by Ioana Lasc

Make repack stats not required on interface

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/lib/lp/code/interfaces/gitrepository.py b/lib/lp/code/interfaces/gitrepository.py
index 365f082..5374fb7 100644
--- a/lib/lp/code/interfaces/gitrepository.py
+++ b/lib/lp/code/interfaces/gitrepository.py
@@ -216,6 +216,23 @@ class IGitRepositoryView(IHasRecipes):
216 shortened_path = Attribute(216 shortened_path = Attribute(
217 "The shortest reasonable version of the path to this repository.")217 "The shortest reasonable version of the path to this repository.")
218218
219 pack_count = exported(Int(
220 title=_("Pack count"), readonly=True, required=False,
221 description=_("The number of packs for this repository.")))
222
223 loose_object_count = exported(Int(
224 title=_("Loose object count"), readonly=True, required=False,
225 description=_("The number of loose objects for this repository.")))
226
227 date_last_repacked = exported(Datetime(
228 title=_("Date last repacked"), readonly=True, required=False,
229 description=_("The date that this repository was last repacked.")))
230
231 date_last_scanned = exported(Datetime(
232 title=_("Date last scanned"), readonly=True, required=False,
233 description=_("The date when pack statistics were last updated "
234 "for this repository.")))
235
219 def getClonedFrom():236 def getClonedFrom():
220 """Returns from which repository the given repo is a clone from."""237 """Returns from which repository the given repo is a clone from."""
221238
diff --git a/lib/lp/code/model/tests/test_gitrepository.py b/lib/lp/code/model/tests/test_gitrepository.py
index bdf636b..6cec839 100644
--- a/lib/lp/code/model/tests/test_gitrepository.py
+++ b/lib/lp/code/model/tests/test_gitrepository.py
@@ -3900,6 +3900,39 @@ class TestGitRepositoryWebservice(TestCaseWithFactory):
3900 hosting_fixture.repackRepository.calls)3900 hosting_fixture.repackRepository.calls)
3901 self.assertEqual(1, hosting_fixture.repackRepository.call_count)3901 self.assertEqual(1, hosting_fixture.repackRepository.call_count)
39023902
3903 def test_repack_data(self):
3904 owner_db = self.factory.makePerson(name="person")
3905 project_db = self.factory.makeProduct(name="project")
3906 repository_db = self.factory.makeGitRepository(
3907 owner=owner_db, target=project_db, name="repository")
3908 webservice = webservice_for_person(
3909 repository_db.owner, permission=OAuthPermission.READ_PUBLIC)
3910 webservice.default_api_version = "devel"
3911 with person_logged_in(ANONYMOUS):
3912 repository_url = api_url(repository_db)
3913 repository = webservice.get(repository_url).jsonBody()
3914 self.assertThat(repository, ContainsDict({
3915 'loose_object_count': Is(None),
3916 'pack_count': Is(None),
3917 'date_last_repacked': Is(None),
3918 'date_last_scanned': Is(None),
3919 }))
3920
3921 repository_db = removeSecurityProxy(repository_db)
3922 repository_db.loose_object_count = 45
3923 repository_db.pack_count = 523
3924 repository_db.date_last_repacked = UTC_NOW
3925 repository_db.date_last_scanned = UTC_NOW
3926
3927 repository = webservice.get(repository_url).jsonBody()
3928
3929 self.assertThat(repository, ContainsDict({
3930 'loose_object_count': Equals(45),
3931 'pack_count': Equals(523),
3932 'date_last_repacked': Equals(UTC_NOW),
3933 'date_last_scanned': Equals(UTC_NOW),
3934 }))
3935
3903 def test_urls(self):3936 def test_urls(self):
3904 owner_db = self.factory.makePerson(name="person")3937 owner_db = self.factory.makePerson(name="person")
3905 project_db = self.factory.makeProduct(name="project")3938 project_db = self.factory.makeProduct(name="project")

Subscribers

People subscribed via source and target branches

to status/vote changes: