Skip to content

Log campaigns contributors and users counts, track additional events

Administrator requested to merge mrn/campaigns-mau into main

Created by: mrnugget

Short version: this adds the necessary data to implement the proposal in RFC 318.

But that depends on what @ebrodymoore says and whether these numbers can be grouped by month/week on the receiving end or whether we need to do that here.

Reviewers: I want to get some feedback on whether (a) this data is enough to make RFC 318 work (I need @malomarrec and @ebrodymoore to answer this) and (b) whether the queries make sense (I need @sourcegraph/campaigns to answer this one).


Details

This PR adds a few more events to the event_logs:

  • CampaignCreated when the CreateCampaign GraphQL mutation has been used (which means src-cli and web UI interactions are tracked)
  • CampaignCreatedOrUpdated when the ApplyCampaign GraphQL mutation has been used to create or update a campaign (same as above)
  • CampaignDeleted when a campaign has been deleted
  • CampaignClosed when a campaign has been closed

It then uses these newly-tracked events to track three additional numbers to the campaigns usagestats:

  • ActionChangesetsUnpublishedCount, the number of unpublished changesets in the database
  • ContributorsCount, the number of unique users that have logged a "contributor event", see code
  • UsersCount, the number of unique users that have logged a "contributor" or a "user" event, see code

With these changes, the updated CampaignsUsageStatistics look like this (see the diff/code for comments):

type CampaignsUsageStatistics struct {
	// OLD
	ViewCampaignApplyPageCount int32
	ViewCampaignDetailsPageAfterCreateCount int32
	ViewCampaignDetailsPageAfterUpdateCount int32
	CampaignsCount int32
	CampaignsClosedCount int32
	CampaignSpecsCreatedCount int32
	ChangesetSpecsCreatedCount int32
	ActionChangesetsCount int32
	ActionChangesetsDiffStatAddedSum int32
	ActionChangesetsDiffStatChangedSum int32
	ActionChangesetsDiffStatDeletedSum int32
	ActionChangesetsMergedCount int32
	ActionChangesetsMergedDiffStatAddedSum int32
	ActionChangesetsMergedDiffStatChangedSum int32
	ActionChangesetsMergedDiffStatDeletedSum int32
	ManualChangesetsCount int32
	ManualChangesetsMergedCount int32

	// 
	// NEW NEW NEW NEW
	// 
	// ActionChangesetsUnpublishedCount is the number of changesets in the
	// database that have not been published but belong to a campaign.
	// This number *could* go down, since it's not
	// based on event logs, but so far (Nov 2020) we never cleaned up
	// changesets in the database.
	ActionChangesetsUnpublishedCount int32

	// ContributorsCount is the count of unique users that have logged a
	// "contributing" campaigns event, such as "CampaignCreated".
	//
	// See `contributorsEvents` in `GetCampaignsUsageStatistics` for a full list
	// of events.
	ContributorsCount int64

	// UsersCount is the count of unique users that have logged a
	// "using" campaigns event, such as "ViewCampaignsListPage" and also "CampaignCreated".
	//
	// See `contributorsEvents` in `GetCampaignsUsageStatistics` for a full
	// list of events.
	UsersCount int64
}

Merge request reports

Loading