Skip to content

Commit

Permalink
refactor: remove feature flag logic for larger dyno sizes (#2985)
Browse files Browse the repository at this point in the history
* fix: re-type error checking for largerDynoFeatureFlag presence

* refactor: remove feature flag logic for larger dyno sizes

* fix: update ps:type test and remove ps:scale test

* refactor: remove unnecessary feature flag logic from tests

* linting fix
  • Loading branch information
k80bowman authored Aug 21, 2024
1 parent 4d24f5e commit 725f5c3
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 216 deletions.
26 changes: 0 additions & 26 deletions packages/cli/src/commands/ps/scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,6 @@ export default class Scale extends Command {
const argv = restParse.argv as string[]
const {app} = flags

// will remove this flag once we have
// successfully launched larger dyno sizes
let isLargerDyno = false
const {body: largerDynoFeatureFlag} = await this.heroku.get<Heroku.AccountFeature>('/account/features/frontend-larger-dynos')
.catch((error: HTTPError) => {
if (error.statusCode === 404) {
return {body: {enabled: false}}
}

throw error
})

function parse(args: string[]) {
return compact(args.map(arg => {
const change = arg.match(/^([\w-]+)([=+-]\d+)(?::([\w-]+))?$/)
Expand All @@ -65,20 +53,6 @@ export default class Scale extends Command {

const changes = parse(argv)

// checks for larger dyno sizes
// if the feature is not enabled
if (!largerDynoFeatureFlag.enabled) {
changes.forEach(({size}) => {
const largerDynoNames = /^(?!standard-[12]x$)(performance|private|shield)-(l-ram|xl|2xl)$/i
isLargerDyno = largerDynoNames.test(size)

if (isLargerDyno) {
const availableDynoSizes = 'eco, basic, standard-1x, standard-2x, performance-m, performance-l, private-s, private-m, private-l, shield-s, shield-m, shield-l'
ux.error(`No such size as ${size}. Use ${availableDynoSizes}.`, {exit: 1})
}
})
}

if (changes.length === 0) {
const {body: formation} = await this.heroku.get<Heroku.Formation[]>(`/apps/${app}/formation`)
const {body: appProps} = await this.heroku.get<Heroku.App>(`/apps/${app}`)
Expand Down
26 changes: 0 additions & 26 deletions packages/cli/src/commands/ps/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,6 @@ export default class Type extends Command {
const argv = restParse.argv as string[]
const {app} = flags

// will remove this flag once we have
// successfully launched larger dyno sizes
let isLargerDyno = false
const {body: largerDynoFeatureFlag} = await this.heroku.get<Heroku.AccountFeature>('/account/features/frontend-larger-dynos')
.catch((error: HTTPError) => {
if (error.statusCode === 404) {
return {body: {enabled: false}}
}

throw error
})

const parse = async () => {
if (!argv || argv.length === 0)
return []
Expand All @@ -160,20 +148,6 @@ export default class Type extends Command {

const changes = await parse()

// checks for larger dyno sizes
// if the feature is not enabled
if (!largerDynoFeatureFlag.enabled) {
changes.forEach(({size}) => {
const largerDynoNames = /^(?!standard-[12]x$)(performance|private|shield)-(l-ram|xl|2xl)$/i
isLargerDyno = largerDynoNames.test(size)

if (isLargerDyno) {
const availableDynoSizes = 'eco, basic, standard-1x, standard-2x, performance-m, performance-l, private-s, private-m, private-l, shield-s, shield-m, shield-l'
ux.error(`No such size as ${size}. Use ${availableDynoSizes}.`, {exit: 1})
}
})
}

if (changes.length > 0) {
ux.action.start(`Scaling dynos on ${color.magenta(app)}`)
await this.heroku.patch(`/apps/${app}/formation`, {body: {updates: changes}})
Expand Down
80 changes: 0 additions & 80 deletions packages/cli/test/unit/commands/ps/scale.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,8 @@ import runCommand from '../../../helpers/runCommand'
import * as nock from 'nock'
import {expect} from 'chai'
import stripAnsi = require('strip-ansi')
import heredoc from 'tsheredoc'
import {CLIError} from '@oclif/core/lib/errors'

describe('ps:scale', function () {
// will remove this flag once we have
// successfully launched larger dyno sizes
function featureFlagPayload(isEnabled = false) {
return {
enabled: isEnabled,
}
}

afterEach(function () {
return nock.cleanAll()
})
Expand All @@ -37,30 +27,6 @@ describe('ps:scale', function () {
api.done()
})

it('scales up a new large dyno size if feature flag is enabled', async function () {
const api = nock('https://api.heroku.com:443')
.get('/account/features/frontend-larger-dynos')
.reply(200, featureFlagPayload(true))
.patch('/apps/myapp/formation', {updates: [{type: 'web', quantity: '1', size: 'Performance-L-RAM'}]})
.reply(200, [{type: 'web', quantity: 1, size: 'Performance-L-RAM'}])
.get('/apps/myapp')
.reply(200, {name: 'myapp'})

await runCommand(Cmd, [
'--app',
'myapp',
'web=1:Performance-L-RAM',
])

api.done()

expect(stdout.output).to.eq('')
expect(stderr.output).to.equal(heredoc`
Scaling dynos...
Scaling dynos... done, now running web at 1:Performance-L-RAM
`)
})

it('shows formation with shield dynos for apps in a shielded private space', async function () {
const api = nock('https://api.heroku.com')
.get('/apps/myapp/formation')
Expand Down Expand Up @@ -153,50 +119,4 @@ describe('ps:scale', function () {
expect(stderr.output).to.contain('Scaling dynos... done, now running web at 2:Free\n')
api.done()
})

it('errors if user attempts to scale up using new larger dyno size and feature flag is NOT enabled', async function () {
const api = nock('https://api.heroku.com')
.get('/account/features/frontend-larger-dynos')
.reply(200, featureFlagPayload())

try {
await runCommand(Cmd, [
'--app',
'myapp',
'web=1:Performance-L-RAM',
])
} catch (error) {
const {message, oclif} = error as CLIError

expect(message).to.eq('No such size as Performance-L-RAM. Use eco, basic, standard-1x, standard-2x, performance-m, performance-l, private-s, private-m, private-l, shield-s, shield-m, shield-l.')
expect(oclif.exit).to.eq(1)
}

api.done()

expect(stdout.output).to.eq('')
})

it("errors if user attempts to scale up using new larger dyno size and feature flag doesn't exist", async function () {
const api = nock('https://api.heroku.com')
.get('/account/features/frontend-larger-dynos')
.reply(404, {})

try {
await runCommand(Cmd, [
'--app',
'myapp',
'web=1:Performance-L-RAM',
])
} catch (error) {
const {message, oclif} = error as CLIError

expect(message).to.eq('No such size as Performance-L-RAM. Use eco, basic, standard-1x, standard-2x, performance-m, performance-l, private-s, private-m, private-l, shield-s, shield-m, shield-l.')
expect(oclif.exit).to.eq(1)
}

api.done()

expect(stdout.output).to.eq('')
})
})
85 changes: 1 addition & 84 deletions packages/cli/test/unit/commands/ps/type.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,9 @@ import runCommand from '../../../helpers/runCommand'
import * as nock from 'nock'
import {expect} from 'chai'
import expectOutput from '../../../helpers/utils/expectOutput'
import {CLIError} from '@oclif/core/lib/errors'
import heredoc from 'tsheredoc'

describe('ps:type', function () {
// will remove this flag once we have
// successfully launched larger dyno sizes
function featureFlagPayload(isEnabled = false) {
return {
enabled: isEnabled,
}
}

function app(args = {}) {
const base = {name: 'myapp'}
return Object.assign(base, args)
Expand Down Expand Up @@ -78,10 +69,8 @@ describe('ps:type', function () {
api.done()
})

it('switches to performance-l-ram dyno when feature flag is enabled', async function () {
it('switches to performance-l-ram dyno', async function () {
const api = nock('https://api.heroku.com')
.get('/account/features/frontend-larger-dynos')
.reply(200, featureFlagPayload(true))
.get('/apps/myapp')
.reply(200, app())
.get('/apps/myapp/formation')
Expand Down Expand Up @@ -206,76 +195,4 @@ describe('ps:type', function () {
`)
api.done()
})

it('errors when user requests larger dynos and feature flag is NOT enabled', async function () {
const api = nock('https://api.heroku.com')
.get('/account/features/frontend-larger-dynos')
.reply(200, featureFlagPayload())
.get('/apps/myapp/formation')
.reply(200, [{type: 'web', quantity: 1, size: 'performance-l-ram'}, {type: 'web', quantity: 2, size: 'performance-l-ram'}])

try {
await runCommand(Cmd, [
'--app',
'myapp',
'web=performance-l-ram',
])
} catch (error) {
const {message, oclif} = error as CLIError

expect(message).to.eq('No such size as performance-l-ram. Use eco, basic, standard-1x, standard-2x, performance-m, performance-l, private-s, private-m, private-l, shield-s, shield-m, shield-l.')
expect(oclif.exit).to.eq(1)
}

api.done()
expect(stdout.output).to.eq('')
})

it('errors when user requests larger dynos and feature flag is NOT enabled when changing all type sizes', async function () {
const api = nock('https://api.heroku.com')
.get('/account/features/frontend-larger-dynos')
.reply(200, featureFlagPayload())
.get('/apps/myapp/formation')
.reply(200, [{type: 'web', quantity: 1, size: 'performance-2xl'}, {type: 'web', quantity: 2, size: 'performance-2xl'}])

try {
await runCommand(Cmd, [
'--app',
'myapp',
'performance-2xl',
])
} catch (error) {
const {message, oclif} = error as CLIError

expect(message).to.eq('No such size as performance-2xl. Use eco, basic, standard-1x, standard-2x, performance-m, performance-l, private-s, private-m, private-l, shield-s, shield-m, shield-l.')
expect(oclif.exit).to.eq(1)
}

api.done()
expect(stdout.output).to.eq('')
})

it("errors when user requests larger dynos and feature flag doesn't exist", async function () {
const api = nock('https://api.heroku.com')
.get('/account/features/frontend-larger-dynos')
.reply(404, {})
.get('/apps/myapp/formation')
.reply(200, [{type: 'web', quantity: 1, size: 'performance-2xl'}, {type: 'web', quantity: 2, size: 'performance-2xl'}])

try {
await runCommand(Cmd, [
'--app',
'myapp',
'web=performance-l-ram',
])
} catch (error) {
const {message, oclif} = error as CLIError

expect(message).to.eq('No such size as performance-l-ram. Use eco, basic, standard-1x, standard-2x, performance-m, performance-l, private-s, private-m, private-l, shield-s, shield-m, shield-l.')
expect(oclif.exit).to.eq(1)
}

api.done()
expect(stdout.output).to.eq('')
})
})

0 comments on commit 725f5c3

Please sign in to comment.