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

cody: experimental feature flag for .com#49920

Merged
novoselrok merged 3 commits into
mainfrom
rn/cody-dotcom-feature-flag
Mar 23, 2023
Merged

cody: experimental feature flag for .com#49920
novoselrok merged 3 commits into
mainfrom
rn/cody-dotcom-feature-flag

Conversation

@novoselrok

Copy link
Copy Markdown
Contributor

Test plan

  • Non-dotcom instances should work as before
  • If cody-experimental feature flag is not created, dotcom users will not be able to use completions endpoint and embeddings GQL API
  • If cody-experimental feature flag override is created for a user, that user should have access to completions and embeddings on dot com
  • Unauthorized users should not have access to either

@novoselrok novoselrok requested a review from eseliger March 23, 2023 17:03
@cla-bot cla-bot Bot added the cla-signed label Mar 23, 2023
Comment on lines +16 to +21
userFlags, err := db.FeatureFlags().GetUserFlags(ctx, a.UID)
if err != nil {
return false, err
}

return userFlags["cody-experimental"], nil

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use featureflag.FromContext(ctx).GetBoolOr("cody-experimental", false) to get the correct result here, there cloud also be a global flag set :)

Comment on lines +85 to +86
if envvar.SourcegraphDotComMode() {
isEnabled, err := cody.IsCodyExperimentalFeatureFlagEnabled(ctx, r.db)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for correctness of error messages, should we move this check after the next one, so the feature flag will be evaluated after the setting is checked?
Same for others.

Comment on lines +46 to +47
ctx, cancel := context.WithTimeout(r.Context(), maxRequestDuration)
defer cancel()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this related?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just moved it up a couple of lines because now we need the ctx variable earlier.

@eseliger eseliger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's go!

Comment on lines 55 to 57
completionsConfig := conf.Get().Completions
if completionsConfig == nil || !completionsConfig.Enabled {
http.Error(w, "completions are not configured or disabled", http.StatusInternalServerError)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the same about ordering here.

defer cancel()

if envvar.SourcegraphDotComMode() {
isEnabled := cody.IsCodyExperimentalFeatureFlagEnabled(ctx)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to be sure, did you check it works on this endpoint, too? I know we initialize the FF store on the resolver CTX, but not sure about HTTP handlers. (I hope we do that, but might want to check :))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@novoselrok novoselrok merged commit 3c90dda into main Mar 23, 2023
@novoselrok novoselrok deleted the rn/cody-dotcom-feature-flag branch March 23, 2023 18:06
eseliger pushed a commit that referenced this pull request Apr 17, 2023
## Test plan

<!-- All pull requests REQUIRE a test plan:
https://docs.sourcegraph.com/dev/background-information/testing_principles
-->
* Non-dotcom instances should work as before
* If `cody-experimental` feature flag is not created, dotcom users will
not be able to use completions endpoint and embeddings GQL API
* If `cody-experimental` feature flag override is created for a user,
that user should have access to completions and embeddings on dot com
* Unauthorized users should not have access to either

(cherry picked from commit 3c90dda)
@eseliger eseliger mentioned this pull request Apr 17, 2023
coury-clark pushed a commit that referenced this pull request Apr 17, 2023
This backports both 
- #49920
- #50668 

to 5.0. The former is cherry picked to reduce merge conflicts and make
potential future cherry picks a bit easier.
I also had to backport adding a bazelignore entry for `client/cody`
because I couldn't update the build files on this branch anymore. There
seems to have been a few misses in buildfile updates so this PR is
unfortunately quite noisy.

## Test plan

CI and code review.

---------

Co-authored-by: Rok Novosel <rok@sourcegraph.com>
Co-authored-by: Beyang Liu <beyang@sourcegraph.com>
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.

2 participants