Skip to content

insights: Background process to check for a license and freeze/unfreeze insights

Warren Gifford requested to merge insights/freeze into main

Created by: CristinaBirkel

Closes: https://github.com/sourcegraph/sourcegraph/issues/32189

Description

This PR adds a new background process called checkAndEnforceLicense . It checks for the existence of a Code Insights license, and either freezes or unfreezes insights based on if the customer has a license or not.

I did the "freeze" operation in two steps because it seemed simpler. I'm also ignoring insight_view_grants because I believe they're not applicable here, but let me know if you disagree!

The license check requires this environment variable to be set locally and on cloud, and this comment says it isn't needed elsewhere, but I am a bit concerned about not knowing how to test for this on other environments.

Test plan

To test this locally:

  1. Your local environment probably has a dev license by default, which has the feature code-insights included. To check this you can query for:
query {
  enterpriseLicenseHasFeature(feature:"code-insights")
}
  1. To generate a new license without the code-insights feature, run this from your sourcegraph folder:
go run ./enterprise/internal/license/generate-license.go -private-key ../dev-private/enterprise/dev/test-license-generation-key.pem -tags=starter -users=10 -expires=8784h

(Change the tag to dev to get a dev license as needed.) 3. Then copy-paste this license into dev-private/site-config.json under licenseKey. This will persist it to your local environment when you start it up. 4. Start up sourcegraph locally and verify that it freezes your insights as expected! It should keep up to 2 global insights unfrozen, and freeze the rest. 5. Swap in the dev license, and run the service again. Then verify that it unfreezes everything.

Note to self: k8s does not have a license with code-insights so I will need to get a valid one there so that the feature doesn't get turned off (though would be a great way to test this out.)

Merge request reports

Loading