Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

feat/enterprise-portal: subscriptions.ListEnterpriseSubscriptionLicenses#62932

Merged
bobheadxi merged 5 commits into
mainfrom
05-27-feat_enterprise-portal_subscriptions.listenterprisesubscriptionlicenses
May 28, 2024
Merged

feat/enterprise-portal: subscriptions.ListEnterpriseSubscriptionLicenses#62932
bobheadxi merged 5 commits into
mainfrom
05-27-feat_enterprise-portal_subscriptions.listenterprisesubscriptionlicenses

Conversation

@bobheadxi

@bobheadxi bobheadxi commented May 27, 2024

Copy link
Copy Markdown
Member

This PR implements the DB and RPC layer for the subscriptions.ListEnterpriseSubscriptionLicenses RPC proposed in https://github.com/sourcegraph/sourcegraph/pull/62263. Previous PRs https://github.com/sourcegraph/sourcegraph/pull/62706 and https://github.com/sourcegraph/sourcegraph/pull/62771 set up the scaffolding for implementing DB and RPC layers for Enterprise Portal, so now we can implement both in a single PR without massive diffs.

We need this RPC, in particular the pageSize=1 archived=false variant, for Cody Gateway to adopt Enterprise Portal, as Cody Gateway depends on license tags for certain features.

Closes https://linear.app/sourcegraph/issue/CORE-111

Usage in Cody Gateway

In production (not internal-only mode), this should only be used for diagnostics information. In the future, we will revisit the current use cases (identifying if a subscription is dev/internal, and finding a subscription's display name) and replace this usage in Cody Gateway with one of:

  • subscriptionsv1.GetEnterpriseSubscription
  • expanded codyaccessv1.GetCodyAccess
  • more specialized codyaccessv2 that can get everything in one go

For now, needing another round-trip should be acceptable, and in the migration I'll make sure failure to fetch the active license is handled gracefully and won't affect customer usage.

For a more in-depth view, see https://github.com/sourcegraph/sourcegraph/pull/62934 for the implementation of the actual integration.

DB query

Product EXPLAIN ANALYZE for a query for archived=false subscriptionid='$S2-subscription-id' shows this should be pretty quick:

                                                                                    QUERY PLAN                                                                                     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Sort  (cost=630.51..630.52 rows=2 width=1176) (actual time=1.311..1.313 rows=7 loops=1)
   Sort Key: licenses.created_at DESC
   Sort Method: quicksort  Memory: 39kB
   ->  Nested Loop Left Join  (cost=0.28..630.50 rows=2 width=1176) (actual time=0.300..1.292 rows=7 loops=1)
         Join Filter: (subscriptions.id = licenses.product_subscription_id)
         Filter: (subscriptions.archived_at IS NULL)
         ->  Seq Scan on product_licenses licenses  (cost=0.00..627.98 rows=2 width=1176) (actual time=0.277..1.263 rows=7 loops=1)
               Filter: (product_subscription_id = '58b95c21-c2d0-4b4b-8b15-bf1b926d3557'::uuid)
               Rows Removed by Filter: 3805
         ->  Materialize  (cost=0.28..2.50 rows=1 width=24) (actual time=0.003..0.003 rows=1 loops=7)
               ->  Index Scan using product_subscriptions_pkey on product_subscriptions subscriptions  (cost=0.28..2.50 rows=1 width=24) (actual time=0.019..0.019 rows=1 loops=1)
                     Index Cond: (id = '58b95c21-c2d0-4b4b-8b15-bf1b926d3557'::uuid)
 Planning Time: 0.113 ms
 Execution Time: 1.341 ms
(14 rows)

Test plan

DB integration tests, and similar manual testing to https://github.com/sourcegraph/sourcegraph/pull/62771 for the RPC layer, but this time requesting the subscription scope when creating an access token:

sg sams create-client-token -s 'enterprise_portal::subscription::read'

image

Screenshot 2024-05-27 at 10 07 59 AM

Screenshot 2024-05-27 at 10 07 59 AM

bobheadxi commented May 27, 2024

Copy link
Copy Markdown
Member Author

Comment thread cmd/enterprise-portal/internal/subscriptionsservice/v1.go Fixed
Comment thread cmd/enterprise-portal/internal/subscriptionsservice/v1.go Fixed
@bobheadxi bobheadxi force-pushed the 05-27-feat_enterprise-portal_subscriptions.listenterprisesubscriptionlicenses branch from 49220d7 to cfd65ae Compare May 27, 2024 17:16
@bobheadxi bobheadxi requested review from a team and unknwon May 27, 2024 17:16
Comment on lines 48 to 78

Check notice

Code scanning / Semgrep OSS

Semgrep Finding: security-semgrep-rules.semgrep-rules.generic.comment-tagging-rule

Code that highlight SECURITY in comment has changed. Please review the code for changes. The changes might be sensitive.
Base automatically changed from 05-17-enterprise-portal-cody-gateway-accesses-connectrpc to main May 27, 2024 20:39
@bobheadxi bobheadxi force-pushed the 05-27-feat_enterprise-portal_subscriptions.listenterprisesubscriptionlicenses branch from 60f1581 to 86beaab Compare May 27, 2024 20:42
@bobheadxi bobheadxi merged commit 4e170e3 into main May 28, 2024
@bobheadxi bobheadxi deleted the 05-27-feat_enterprise-portal_subscriptions.listenterprisesubscriptionlicenses branch May 28, 2024 19:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants