Skip to content

fix(stepfunctions): Add document URI check for save telemetry and enable deployment from WFS #7315

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/stepFunctions/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async function registerStepFunctionCommands(
}),
Commands.register('aws.stepfunctions.publishStateMachine', async (node?: any) => {
const region: string | undefined = node?.regionCode
await publishStateMachine(awsContext, outputChannel, region)
await publishStateMachine({ awsContext: awsContext, outputChannel: outputChannel, region: region })
})
)
}
Expand Down
23 changes: 15 additions & 8 deletions packages/core/src/stepFunctions/commands/publishStateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ import { refreshStepFunctionsTree } from '../explorer/stepFunctionsNodes'
import { PublishStateMachineWizard, PublishStateMachineWizardState } from '../wizards/publishStateMachineWizard'
const localize = nls.loadMessageBundle()

export async function publishStateMachine(
awsContext: AwsContext,
outputChannel: vscode.OutputChannel,
interface publishStateMachineParams {
awsContext: AwsContext
outputChannel: vscode.OutputChannel
region?: string
) {
text?: vscode.TextDocument
}
export async function publishStateMachine(params: publishStateMachineParams) {
const logger: Logger = getLogger()
let textDocument: vscode.TextDocument | undefined

const textDocument = vscode.window.activeTextEditor?.document
if (params.text) {
textDocument = params.text
} else {
textDocument = vscode.window.activeTextEditor?.document
}

if (!textDocument) {
logger.error('Could not get active text editor for state machine definition')
Expand Down Expand Up @@ -53,17 +60,17 @@ export async function publishStateMachine(
}

try {
const response = await new PublishStateMachineWizard(region).run()
const response = await new PublishStateMachineWizard(params.region).run()
if (!response) {
return
}
const client = new DefaultStepFunctionsClient(response.region)

if (response?.createResponse) {
await createStateMachine(response.createResponse, text, outputChannel, response.region, client)
await createStateMachine(response.createResponse, text, params.outputChannel, response.region, client)
refreshStepFunctionsTree(response.region)
} else if (response?.updateResponse) {
await updateStateMachine(response.updateResponse, text, outputChannel, response.region, client)
await updateStateMachine(response.updateResponse, text, params.outputChannel, response.region, client)
}
} catch (err) {
logger.error(err as Error)
Expand Down
13 changes: 10 additions & 3 deletions packages/core/src/stepFunctions/workflowStudio/handleMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,22 @@ async function saveFileMessageHandler(request: SaveFileRequestMessage, context:
}

/**
* Handler for saving a file and starting the state machine deployment flow, while also switching to default editor.
* Handler for saving a file and starting the state machine deployment flow while staying in WFS view.
* Triggered when the user triggers 'Save and Deploy' action in WFS
* @param request The request message containing the file contents.
* @param context The webview context containing the necessary information for saving the file.
*/
async function saveFileAndDeployMessageHandler(request: SaveFileRequestMessage, context: WebviewContext) {
await saveFileMessageHandler(request, context)
await closeCustomEditorMessageHandler(context)
await publishStateMachine(globals.awsContext, globals.outputChannel)
await publishStateMachine({
awsContext: globals.awsContext,
outputChannel: globals.outputChannel,
text: context.textDocument,
})

telemetry.ui_click.emit({
elementId: 'stepfunctions_saveAndDeploy',
})
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,18 @@ export class WorkflowStudioEditor {

// The text document acts as our model, thus we send and event to the webview on file save to trigger update
contextObject.disposables.push(
vscode.workspace.onDidSaveTextDocument(async () => {
await telemetry.stepfunctions_saveFile.run(async (span) => {
span.record({
id: contextObject.fileId,
saveType: 'MANUAL_SAVE',
source: 'VSCODE',
isInvalidJson: isInvalidJsonFile(contextObject.textDocument),
vscode.workspace.onDidSaveTextDocument(async (savedDocument) => {
if (savedDocument.uri.toString() === this.documentUri.toString()) {
await telemetry.stepfunctions_saveFile.run(async (span) => {
span.record({
id: contextObject.fileId,
saveType: 'MANUAL_SAVE',
source: 'VSCODE',
isInvalidJson: isInvalidJsonFile(contextObject.textDocument),
})
await broadcastFileChange(contextObject, 'MANUAL_SAVE')
})
await broadcastFileChange(contextObject, 'MANUAL_SAVE')
})
}
})
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "State Machine deployments can now be initiated directly from Workflow Studio without closing the editor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "Step Function performance metrics now accurately reflect only Workflow Studio document activity"
}
Loading