Manual license sync doesn't work after initial sync for a day
Problem
Once a license has been synced (through manual or automation) on a given day, no additional manual syncing works until the next report day. This happens because the seat link sync request from the SM instance is sent with a timestamp using the current time. In other words, each sync request will have a unique timestamp
in the request. A date
param is also included in the payload which is derived from the date of the timestamp
here.
In CustomersDot, the SeatLinkCreateService
is responsible for processing the sync request. It is supposed to look up an existing LicenseSeatLink
record using timestamp
if present (which it would be on newer versions of EE), otherwise it uses the date
param. However, since the timestamp is different from the earlier sync, instead of finding/using the existing LicenseSeatLink
record for that report date, the service initializes a new one. When it attempts to save the record, it fails due to the validation on report_date
which verifies uniqueness scoped to order_id
and self_managed_instance_activation_id
.
Proposal
This service should be updated to allow multiple syncs in a report day. After discussing options with the team, we've agreed to the following plan as mentioned here.
-
Update the SeatLinkCreateService
to find or createLicenseSeatLink
records usingself_managed_instance_activation
, in addition to the existing fields (report_timestamp|date
andzuora_subscription_name
)- Created separate issue for this: #3184 (closed)
- MR: https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/3344 (Verified)
-
Update the CreateReconciliationService
to only update an existing reconciliation record if the newuser_count
is greater than the previoususer_count
(code reference). -
When a new seat link record is received, if the report_timestamp
is not included in the request, set it toreport_date 03:00 UTC
. -
Populate all existing rows where report_timestamp is NULL
to setreport_timestamp
toreport_date 03:00 UTC
. Set DB constraint forreport_timestamp
tonull: false
. Removereport_timestamp
method fromLicenseSeatLink
model. -
Modify the 2 unique indices to use report_timestamp
instead ofreport_date
.
In #3240 (closed), we will look at removing report_date
from license_seat_links
as it should no longer be needed.