Skip to content

Commit

Permalink
Improve usability around telemetry
Browse files Browse the repository at this point in the history
 - Properly prints the right command to enable telemetry
 - Ties the code to a variable so that there will be a build error if
   the key changes
 - Optimize first run so it doesn't need to spin up the RPC layer just
   to set commands
 - Make testnet command ask user to opt into telemetry
  • Loading branch information
NullSoldier committed Feb 11, 2022
1 parent 2222ea9 commit d659ff3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 25 deletions.
5 changes: 4 additions & 1 deletion ironfish-cli/src/commands/start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ describe('start command', () => {
const accounts = {
accountExists: jest.fn(),
getDefaultAccount: jest.fn(),
createAccount: jest.fn().mockImplementation((name: string) => {
name
}),
}

const peerNetwork = {
Expand Down Expand Up @@ -138,7 +141,7 @@ describe('start command', () => {
expectCli(ctx.stdout).include(`Peer Identity`)
// telemetry
expectCli(ctx.stdout).include(
`To help improve Ironfish, opt in to collecting telemetry`,
`To help improve Iron Fish, opt in to collecting telemetry`,
)
expect(setConfig).toHaveBeenCalledWith('isFirstRun', false)
expect(setConfig).toHaveBeenCalledWith('telemetryNodeId', expect.any(String))
Expand Down
34 changes: 18 additions & 16 deletions ironfish-cli/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ import {
VerboseFlag,
VerboseFlagKey,
} from '../flags'
import { ONE_FISH_IMAGE, TELEMETRY_BANNER } from '../images'
import { ONE_FISH_IMAGE } from '../images'

export const ENABLE_TELEMETRY_CONFIG_KEY = 'enableTelemetry'
const DEFAULT_ACCOUNT_NAME = 'default'

export default class Start extends IronfishCommand {
Expand Down Expand Up @@ -229,29 +230,30 @@ export default class Start extends IronfishCommand {
* Information displayed the first time a node is running
*/
async firstRun(node: IronfishNode): Promise<void> {
// Try to get the user to display telementry
if (!node.config.get('enableTelemetry')) {
this.log(TELEMETRY_BANNER)
this.log('')
this.log('Thank you for installing the Iron Fish Node.')

if (!node.config.get(ENABLE_TELEMETRY_CONFIG_KEY)) {
this.log('')
this.log('To help improve Iron Fish, opt in to collecting telemetry by running')
this.log(` > ironfish config:set ${ENABLE_TELEMETRY_CONFIG_KEY} true`)
}

// Create a default account on startup
if (!node.accounts.getDefaultAccount()) {
if (node.accounts.accountExists(DEFAULT_ACCOUNT_NAME)) {
await node.accounts.setDefaultAccount(DEFAULT_ACCOUNT_NAME)
this.log(`The default account is now: ${DEFAULT_ACCOUNT_NAME}\n`)
} else {
await this.sdk.clientMemory.connect(node)
this.log('')

const result = await this.sdk.clientMemory.createAccount({
name: DEFAULT_ACCOUNT_NAME,
})
if (!node.accounts.accountExists(DEFAULT_ACCOUNT_NAME)) {
const account = await node.accounts.createAccount(DEFAULT_ACCOUNT_NAME, true)

this.log(
`New default account created: ${DEFAULT_ACCOUNT_NAME} \nAccount's public address: ${result?.content.publicAddress}\n`,
)
this.log(`New default account created: ${account.name}`)
this.log(`Account's public address: ${account.publicAddress}`)
} else {
this.log(`The default account is now: ${DEFAULT_ACCOUNT_NAME}`)
await node.accounts.setDefaultAccount(DEFAULT_ACCOUNT_NAME)
}
}

this.log('')
node.internal.set('isFirstRun', false)
node.internal.set('telemetryNodeId', uuid())
await node.internal.save()
Expand Down
22 changes: 22 additions & 0 deletions ironfish-cli/src/commands/testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CliUx } from '@oclif/core'
import { WebApi } from 'ironfish'
import { IronfishCommand } from '../command'
import { DataDirFlag, DataDirFlagKey, VerboseFlag, VerboseFlagKey } from '../flags'
import { ENABLE_TELEMETRY_CONFIG_KEY } from './start'

export default class Testnet extends IronfishCommand {
static hidden = false
Expand All @@ -26,6 +27,10 @@ export default class Testnet extends IronfishCommand {
default: false,
description: "Don't update your graffiti",
}),
skipTelemetry: flags.boolean({
default: false,
description: "Don't update your telemetry",
}),
}

static args = [
Expand Down Expand Up @@ -89,11 +94,15 @@ export default class Testnet extends IronfishCommand {
const existingNodeName = (await node.getConfig({ name: 'nodeName' })).content.nodeName
const existingGraffiti = (await node.getConfig({ name: 'blockGraffiti' })).content
.blockGraffiti
const telemetryEnabled = (await node.getConfig({ name: ENABLE_TELEMETRY_CONFIG_KEY }))
.content.enableTelemetry

const updateNodeName = existingNodeName !== user.graffiti && !flags.skipName
const updateGraffiti = existingGraffiti !== user.graffiti && !flags.skipGraffiti
const needsUpdate = updateNodeName || updateGraffiti

let updateTelemetry = !telemetryEnabled && !flags.skipTelemetry

if (!needsUpdate) {
this.log('Your node is already up to date!')
this.exit(0)
Expand Down Expand Up @@ -124,6 +133,14 @@ export default class Testnet extends IronfishCommand {
this.log('')
}

if (!flags.confirm && updateTelemetry) {
updateTelemetry = await CliUx.ux.confirm(
'Do you want to help improve Iron Fish by enabling Telemetry? (y)es / (n)o',
)

this.log('')
}

if (updateNodeName) {
await node.setConfig({ name: 'nodeName', value: user.graffiti })
this.log(
Expand All @@ -137,5 +154,10 @@ export default class Testnet extends IronfishCommand {
`✅ Updated GRAFFITI from ${existingGraffiti || '{NOT SET}'} to ${user.graffiti}`,
)
}

if (updateTelemetry) {
await node.setConfig({ name: ENABLE_TELEMETRY_CONFIG_KEY, value: true })
this.log('✅ Telemetry Enabled 🙏')
}
}
}
8 changes: 0 additions & 8 deletions ironfish-cli/src/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,3 @@ export const TWO_FISH_IMAGE =
::::::::::::: ::::::::::::::::::::: ::::::::::::: ::::::::::::::::::::: \n\
:::::::::::: ::::::::::::::::::: :::::::::::: ::::::::::::::::::: \n\
:::::::::: :::::::::::::::: :::::::::: :::::::::::::::: '

export const TELEMETRY_BANNER = `
#################################################################
# Thank you for installing the Iron Fish Node. #
# To help improve Ironfish, opt in to collecting telemetry #
# by setting telemetry=true in your configuration file #
#################################################################
`

0 comments on commit d659ff3

Please sign in to comment.