Skip to content

Commit

Permalink
feature(gatsby): Enable partial releases of flags to a % of users (#2…
Browse files Browse the repository at this point in the history
…8387)

* feature(gatsby): Enable partial releases of flags to a % of users

* switch to a general 'testFitness' function for one-off checks on flags

* typescripting

* cleanup comment

* Add FAST_REFRESH

* Opt-in QoD & LazyImages for ~10% of users

* update snapshot for newline

* includePrelease for semver checks

* no double isCI in IFlag interface

* type unknownConfigFlags array

* don't treat unfit flags are unknown

* Update packages/gatsby/src/utils/flags.ts

* fix lint

Co-authored-by: Michal Piechowiak <[email protected]>
  • Loading branch information
KyleAMathews and pieh authored Dec 10, 2020
1 parent 592d3d1 commit ad65656
Show file tree
Hide file tree
Showing 7 changed files with 509 additions and 61 deletions.
3 changes: 0 additions & 3 deletions examples/using-drupal/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
module.exports = {
flags: {
DEV_SSR: true,
},
siteMetadata: {
title: `Gatsby with Drupal`,
},
Expand Down
11 changes: 6 additions & 5 deletions packages/gatsby/src/services/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,24 +175,25 @@ export async function initialize({
}

// Setup flags
if (config && config.flags) {
if (config) {
// TODO: this should be handled in FAST_REFRESH configuration and not be one-off here.
if (
config.flags.FAST_REFRESH &&
config.flags?.FAST_REFRESH &&
process.env.GATSBY_HOT_LOADER &&
process.env.GATSBY_HOT_LOADER !== `fast-refresh`
) {
delete config.flags.FAST_REFRESH
reporter.warn(
reporter.stripIndent(`
Both FAST_REFRESH gatsby-config flag and GATSBY_HOT_LOADER environment variable is used with conflicting setting ("${process.env.GATSBY_HOT_LOADER}").
Will use react-hot-loader.
To use Fast Refresh either do not use GATSBY_HOT_LOADER environment variable or set it to "fast-refresh".
`)
)
}

const availableFlags = require(`../utils/flags`).default
// Get flags
const { enabledConfigFlags, unknownFlagMessage, message } = handleFlags(
Expand Down Expand Up @@ -220,7 +221,7 @@ export async function initialize({
})

// Track the usage of config.flags
if (enabledConfigFlags.length > 0) {
if (config.flags) {
telemetry.trackFeatureIsUsed(`ConfigFlags`)
}
}
Expand Down
189 changes: 187 additions & 2 deletions packages/gatsby/src/utils/__tests__/__snapshots__/handle-flags.ts.snap
Original file line number Diff line number Diff line change
@@ -1,19 +1,159 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`handle flags filters out flags marked false 1`] = `
Object {
"enabledConfigFlags": Array [
Object {
"command": "all",
"description": "test",
"env": "GATSBY_EXPERIMENTAL_SOMETHING_COOL",
"experimental": false,
"name": "ALL_COMMANDS",
"telemetryId": "test",
"testFitness": [Function],
"umbrellaIssue": "test",
},
Object {
"command": "all",
"description": "test",
"env": "GATSBY_READY_TO_GO",
"experimental": false,
"name": "PARTIAL_RELEASE",
"telemetryId": "test",
"testFitness": [Function],
"umbrellaIssue": "test",
},
Object {
"command": "all",
"description": "test",
"env": "GATSBY_READY_TO_GO_NEW_LODASH",
"experimental": false,
"name": "PARTIAL_RELEASE_ONLY_NEW_LODASH",
"telemetryId": "test",
"testFitness": [Function],
"umbrellaIssue": "test",
},
],
"message": "The following flags are active:
- ALL_COMMANDS · (Umbrella Issue (test)) · test
We're shipping new features! For final testing, we're rolling them out first to a small % of Gatsby users
and your site was automatically choosen as one of them. With your help, we'll then release them to everyone in the next minor release.
We greatly appreciate your help testing the change. Please report any feedback good or bad in the umbrella issue. If you do encounter problems, please disable the flag by setting it to false in your gatsby-config.js like:
flags: {
THE_FLAG: false
}
The following flags were automatically enabled on your site:
- PARTIAL_RELEASE · (Umbrella Issue (test)) · test
- PARTIAL_RELEASE_ONLY_NEW_LODASH · (Umbrella Issue (test)) · test
There are 5 other flags available that you might be interested in:
- FAST_DEV · Enable all experiments aimed at improving develop server start time
- DEV_SSR · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/28138)) · SSR pages on full reloads during develop. Helps you detect SSR bugs and fix them without needing to do full builds.
- QUERY_ON_DEMAND · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/27620)) · Only run queries when needed instead of running all queries upfront. Speeds starting the develop server.
- ONLY_BUILDS · (Umbrella Issue (test)) · test
- YET_ANOTHER · (Umbrella Issue (test)) · test
",
"unknownFlagMessage": "",
}
`;
exports[`handle flags opts in sites to a flag if their site is selected for partial release 1`] = `
Object {
"enabledConfigFlags": Array [
Object {
"command": "all",
"description": "test",
"env": "GATSBY_READY_TO_GO",
"experimental": false,
"name": "PARTIAL_RELEASE",
"telemetryId": "test",
"testFitness": [Function],
"umbrellaIssue": "test",
},
Object {
"command": "all",
"description": "test",
"env": "GATSBY_READY_TO_GO_NEW_LODASH",
"experimental": false,
"name": "PARTIAL_RELEASE_ONLY_NEW_LODASH",
"telemetryId": "test",
"testFitness": [Function],
"umbrellaIssue": "test",
},
],
"message": "
We're shipping new features! For final testing, we're rolling them out first to a small % of Gatsby users
and your site was automatically choosen as one of them. With your help, we'll then release them to everyone in the next minor release.
We greatly appreciate your help testing the change. Please report any feedback good or bad in the umbrella issue. If you do encounter problems, please disable the flag by setting it to false in your gatsby-config.js like:
flags: {
THE_FLAG: false
}
The following flags were automatically enabled on your site:
- PARTIAL_RELEASE · (Umbrella Issue (test)) · test
- PARTIAL_RELEASE_ONLY_NEW_LODASH · (Umbrella Issue (test)) · test
",
"unknownFlagMessage": "",
}
`;
exports[`handle flags returns a message about unknown flags in the config 1`] = `
Object {
"enabledConfigFlags": Array [
Object {
"command": "all",
"description": "test",
"env": "GATSBY_EXPERIMENTAL_SOMETHING_COOL",
"experimental": false,
"name": "ALL_COMMANDS",
"telemetryId": "test",
"testFitness": [Function],
"umbrellaIssue": "test",
},
Object {
"command": "all",
"description": "test",
"env": "GATSBY_READY_TO_GO",
"experimental": false,
"name": "PARTIAL_RELEASE",
"telemetryId": "test",
"testFitness": [Function],
"umbrellaIssue": "test",
},
Object {
"command": "all",
"description": "test",
"env": "GATSBY_READY_TO_GO_NEW_LODASH",
"experimental": false,
"name": "PARTIAL_RELEASE_ONLY_NEW_LODASH",
"telemetryId": "test",
"testFitness": [Function],
"umbrellaIssue": "test",
},
],
"message": "The following flags are active:
- ALL_COMMANDS · (Umbrella Issue (test)) · test
We're shipping new features! For final testing, we're rolling them out first to a small % of Gatsby users
and your site was automatically choosen as one of them. With your help, we'll then release them to everyone in the next minor release.
We greatly appreciate your help testing the change. Please report any feedback good or bad in the umbrella issue. If you do encounter problems, please disable the flag by setting it to false in your gatsby-config.js like:
flags: {
THE_FLAG: false
}
The following flags were automatically enabled on your site:
- PARTIAL_RELEASE · (Umbrella Issue (test)) · test
- PARTIAL_RELEASE_ONLY_NEW_LODASH · (Umbrella Issue (test)) · test
There are 5 other flags available that you might be interested in:
- FAST_DEV · Enable all experiments aimed at improving develop server start time
- DEV_SSR · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/28138)) · SSR pages on full reloads during develop. Helps you detect SSR bugs and fix them without needing to do full builds.
Expand All @@ -27,39 +167,71 @@ There are 5 other flags available that you might be interested in:
}
`;
exports[`handle flags returns validConfigFlags and a message 1`] = `
exports[`handle flags returns enabledConfigFlags and a message 1`] = `
Object {
"enabledConfigFlags": Array [
Object {
"command": "develop",
"description": "Enable all experiments aimed at improving develop server start time",
"env": "GATSBY_EXPERIMENTAL_FAST_DEV",
"experimental": false,
"includedFlags": Array [
"DEV_SSR",
"QUERY_ON_DEMAND",
],
"name": "FAST_DEV",
"telemetryId": "test",
"testFitness": [Function],
},
Object {
"command": "all",
"description": "test",
"env": "GATSBY_EXPERIMENTAL_SOMETHING_COOL",
"experimental": false,
"name": "ALL_COMMANDS",
"telemetryId": "test",
"testFitness": [Function],
"umbrellaIssue": "test",
},
Object {
"command": "all",
"description": "test",
"env": "GATSBY_READY_TO_GO",
"experimental": false,
"name": "PARTIAL_RELEASE",
"telemetryId": "test",
"testFitness": [Function],
"umbrellaIssue": "test",
},
Object {
"command": "all",
"description": "test",
"env": "GATSBY_READY_TO_GO_NEW_LODASH",
"experimental": false,
"name": "PARTIAL_RELEASE_ONLY_NEW_LODASH",
"telemetryId": "test",
"testFitness": [Function],
"umbrellaIssue": "test",
},
Object {
"command": "develop",
"description": "SSR pages on full reloads during develop. Helps you detect SSR bugs and fix them without needing to do full builds.",
"env": "GATSBY_EXPERIMENTAL_DEV_SSR",
"experimental": false,
"name": "DEV_SSR",
"telemetryId": "test",
"testFitness": [Function],
"umbrellaIssue": "https://github.com/gatsbyjs/gatsby/discussions/28138",
},
Object {
"command": "develop",
"description": "Only run queries when needed instead of running all queries upfront. Speeds starting the develop server.",
"env": "GATSBY_EXPERIMENTAL_QUERY_ON_DEMAND",
"experimental": false,
"name": "QUERY_ON_DEMAND",
"noCi": true,
"noCI": true,
"telemetryId": "test",
"testFitness": [Function],
"umbrellaIssue": "https://github.com/gatsbyjs/gatsby/discussions/27620",
},
],
Expand All @@ -69,6 +241,19 @@ Object {
- DEV_SSR · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/28138)) · SSR pages on full reloads during develop. Helps you detect SSR bugs and fix them without needing to do full builds.
- QUERY_ON_DEMAND · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/27620)) · Only run queries when needed instead of running all queries upfront. Speeds starting the develop server.
We're shipping new features! For final testing, we're rolling them out first to a small % of Gatsby users
and your site was automatically choosen as one of them. With your help, we'll then release them to everyone in the next minor release.
We greatly appreciate your help testing the change. Please report any feedback good or bad in the umbrella issue. If you do encounter problems, please disable the flag by setting it to false in your gatsby-config.js like:
flags: {
THE_FLAG: false
}
The following flags were automatically enabled on your site:
- PARTIAL_RELEASE · (Umbrella Issue (test)) · test
- PARTIAL_RELEASE_ONLY_NEW_LODASH · (Umbrella Issue (test)) · test
There are 2 other flags available that you might be interested in:
- ONLY_BUILDS · (Umbrella Issue (test)) · test
- YET_ANOTHER · (Umbrella Issue (test)) · test
Expand Down
Loading

0 comments on commit ad65656

Please sign in to comment.