Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(flags): support Statsig webhook provider and secrets format #85132

Merged
merged 11 commits into from
Feb 18, 2025

Conversation

aliu39
Copy link
Member

@aliu39 aliu39 commented Feb 13, 2025

Closes https://github.com/getsentry/team-replay/issues/537

Ref

Test coverage is based on these docs and an actual statsig webhook setup, using ngrok + devserver. I also used this setup to verify the signing scheme and secret format/lengths.

Decisions:
Only statsig::config_change events are relevant for change tracking. This is subclassed by flag type in metadata.type. The choices are "Gate" (boolean release flags), "Experiment" (JSON) and more.
-> I decided to only track gate changes for now, since we don't record non-bool flag evaluations.

FlagWebhookSigningSecretValidator: Statsig secrets have format "webhook-". There's no documentation on min/max length but I've seen 48, 50, 51 so it's variable. I've chosen to enforce a min/max of 32-64. Validation for other providers is unchanged (exactly 32 characters)

TODO:

  • get an example of an archive event and handle it as a delete action -> both archive and unarchive use the archived action, which is annoying since we can't categorize as create/delete. Deciding to drop these events.

@aliu39 aliu39 requested a review from a team as a code owner February 13, 2025 05:43
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 13, 2025
Copy link

codecov bot commented Feb 13, 2025

Codecov Report

Attention: Patch coverage is 98.98477% with 2 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/flags/providers.py 97.29% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #85132      +/-   ##
==========================================
+ Coverage   87.97%   87.98%   +0.01%     
==========================================
  Files        9620     9619       -1     
  Lines      543130   543933     +803     
  Branches    21021    21021              
==========================================
+ Hits       477800   478575     +775     
- Misses      65025    65053      +28     
  Partials      305      305              

@michellewzhang
Copy link
Member

michellewzhang commented Feb 13, 2025

I've chosen to enforce a min/max of 32-64.

this will need to be updated in the frontend because the input box for provider secrets is limited to 32 char to pass backend validation (since prev secrets were all 32 char). i think it might be best to standardize all of them to 32 char for simplicity, but not tied to this

@aliu39
Copy link
Member Author

aliu39 commented Feb 13, 2025

i think it might be best to standardize all of them to 32 char for simplicity, but not tied to this

This won't be possible for Statsig since all the secrets I've gotten from creating a webhook are >32 chars.
I can try special casing the input box so >32 is allowed for Statsig only. For FE and BE, all other providers' secrets should still be enforced to 32

@michellewzhang
Copy link
Member

michellewzhang commented Feb 13, 2025

i think it might be best to standardize all of them to 32 char for simplicity, but not tied to this

This won't be possible for Statsig since all the secrets I've gotten from creating a webhook are >32 chars. I can try special casing the input box so >32 is allowed for Statsig only. For FE and BE, all other providers' secrets should still be enforced to 32

ohh ok i see - yeah try casing on the input box (applies to both the sidebar input box & also the settings input box, maybe somewhere else too but i forget the exact places) and see if that works

two spots i can find:

<TextField
name="secret"
label={t('Secret')}
maxLength={32}
minLength={32}
required
help={t(
'Paste the signing secret given by your provider when creating the webhook.'
)}
/>

<StyledAlert showIcon type="warning" icon={<IconWarning />}>
{t('Make sure the secret is 32 characters long.')}
</StyledAlert>

@aliu39 aliu39 requested a review from cmanallen February 13, 2025 23:40
@aliu39
Copy link
Member Author

aliu39 commented Feb 13, 2025

Oo great thanks for the refs!

Copy link
Member

@cmanallen cmanallen left a comment

Choose a reason for hiding this comment

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

Looks good. Did you test with ngrok?

@aliu39
Copy link
Member Author

aliu39 commented Feb 14, 2025

@cmanallen yeah I tested with ngrok and based the coverage here on some sample events

@aliu39 aliu39 merged commit 9723427 into master Feb 18, 2025
49 checks passed
@aliu39 aliu39 deleted the aliu/statsig-provider branch February 18, 2025 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants