Add redis counter for manifest delete events
What does this MR do and why?
Closes #382568 (closed)
In !112539 (closed), we learned that the container_registry
does not send in an actor for manifest delete events. There is still some work done for the actor to be sent so we discussed and pivoted to a solution for now.
In this MR, we implement the new plan to count the manifest delete events using a simple Redis counter without attributing it to any user.
How to set up and validate locally
- Test that the ContainerRegistryEventCounter is registered:
pry(main)> Gitlab::UsageDataCounters::ContainerRegistryEventCounter.totals
=> {:container_registry_events_i_container_registry_delete_manifest=>0}
- Call the endpoint
The counters are increased when
container_registry
calls the endpoint. We can test the counters by simulating a call to the endpoint.
To be able to curl without any tokens,
- open
api/container_registry_event.rb
and - comment out the line
before { authenticate_registry_notification! }
curl -d '{
"events": [
{
"id": "a582a0f3-e620-43e6-8e98-ff850fc9d984",
"timestamp": "2023-01-25T14:45:54.17327+11:00",
"action": "delete",
"target": {
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"size": 528,
"digest": "sha256:af06af3514c44a964d3b905b498cf6493db8f1cde7c10e078213a89c87308ba0",
"repository": "group-a/project-a",
"length": 528,
"url": "http://registry.test:5000/v2/root/test/manifests/sha256:af06af3514c44a964d3b905b498cf6493db8f1cde7c10e078213a89c87308ba0"
},
"request": {
"id": "8ef8d69b-f957-45ab-ba2c-9153291f47b6",
"addr": "172.16.123.1:56969",
"host": "registry.test:5000",
"method": "PUT",
"useragent": "docker/20.10.18 go/go1.18.6 git-commit/e42327a6d3c55ceda3bd5475be7aae6036d02db3 kernel/5.15.68-0-virt os/linux arch/arm64 UpstreamClient(Docker-Client/20.10.22 \\(darwin\\))"
},
"actor": {
"name": "root",
"user_type": "personal_access_token"
},
"source": {
"addr": "127.0.0.1:5000",
"instanceID": "45681f21-a006-42f2-ab7c-4cc37d8906b4"
}
}
]
}' -H "Content-Type: application/vnd.docker.distribution.events.v1+json" -X POST 'http://gdk.test:3000/api/v4/container_registry_event/events'
- Test that the counter has been incremented
[4] pry(main)> Gitlab::UsageDataCounters::ContainerRegistryEventCounter.totals
=> {:container_registry_events_i_container_registry_delete_manifest=>1}
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #382568 (closed) Related to !112539 (closed)
Edited by Adie (she/her)