Details
-
Story
-
Resolution: Unresolved
-
Minor
-
None
-
None
-
None
-
False
-
-
False
-
ANSTRAT-137 - Insights reports for Partners (metric collection)
Description
As a collection author, I would like to know how many times my collection has been downloaded.
Models
Create a CollectionVersionDownload model that tracks downloads by client. client and collection_version keys should be unique together:
Fields:
- collection_version: FK to collection version
- client: string. "pulp", "ansible-galaxy", or "other".
- count: int
This model should subclass BaseModel from pulpcore.
Note: Collection version downloads are tracked in a separate table instead of adding them as a field on the CollectionVersion model itself because CollectionVersion is immutable. Download counts don't need to be preserved during sync and import/export operations, so they can be stored separately from the content they're connected to.
Views
On artifact download endpoint:
- check request user-agent
- if pulp: client = pulp
- if ansible galaxy: client = ansible-galaxy
- if anything else: client = other
- get or create new download count object with collection version and client.
- Increase count by 1
Serializers
CollectionVersion and Collection serializers:
Add download_count field.
"download_count": [ {"client": "pulp", "downloads": 0} {"client": "ansible-galaxy", "downloads": 0} {"client": "other", "downloads": 0} ]
On the collection serializer, the download counts should be the sum of all the collection versions. So if a collection has two versions with 3 and 5 downloads from the pulp client, the collection serializer would return 8 downloads.
Add last_downloaded field that returns the time that the object was last downloaded:
"last_downloaded": "2022-04-22T16:36:58.249615Z"