Service Debugging (VS Code)
  • 03 Jun 2024
  • Dark
    Light
  • PDF

Service Debugging (VS Code)

  • Dark
    Light
  • PDF

Article summary

Overview

VS Code is a Dataloop application that provides a comprehensive environment to debug FaaS application services.
The built-in code editor provides the convenience of viewing, editing, and debugging code files in the same environment where FaaS applications are built and deployed.

By using this powerful tool, you can quickly identify and resolve issues in your FaaS applications and update the FaaS codebase (package) accordingly.


Prerequisites

Before you use VS Code for your FaaS application, ensure you follow these requirements:

  1. Install your FaaS application: "To connect with VS Code, make sure you've installed your FaaS application and have a FaaS service. FaaS services can be found in the Services tab within the CloudOps.
  2. Activate the FaaS service: VS Code can only be connected to active services.
  3. Use SDK Version 1.73.0 or higher: VS Code can connect only to FaaS services running SDK version 1.73.0 and above. SDK version can be updated in the Service Actions > Edit Service Settings > Advanced.
  4. Use Python 3.8 and above In your custom Docker image: Any specified docker image must use Python 3.8 and above. Dataloop default docker image already uses the correct Python version.

Considerations

  1. Avoid navigating to other pages within the Dataloop platform while VS Code is open. For cross-platform work, simply open another browser tab.
  2. The VS Code editor for GPU-type machines is currently Beta version only.
  3. Multiple services cannot be connected to VS Code within the same browser tab. To work with VS Code simultaneously on another service, open a new browser tab.
  4. FaaS services cannot be paused while connected to VS Code.

Compute

  1. Instance Allocation
    Initiating a VS Code session, a new instance is allocated to the service. Any other running instances (if there are any) will be temporarily shut down and will resume once the session is terminated.

    Scaling Down Resources

    Reducing allocated resources to a single instance can cause resource shortages during high loads. Executions might be queued until the session is terminated, potentially causing delays.
    To learn more about executions processing during VS Code session, click here.

  2. Resource Consumption
    While VS Code session is active, it will allocate computing resources to the service, using computing hours. Make sure to terminate the session once you're done to avoid unnecessary consumption of resources.
    The project will consume compute hours when VS Code session is on.


Starting a Session

To activate VS Code for one of your activated FaaS services, follow these steps:

  1. In the Dataloop navigation menu, go to CloudOps > Services tab. In the Services tab, you can find all your available FaaS services.

  2. Click Service Actions > Open VS Code from the list. Make sure to review the VS Code prerequisites.

  1. Confirm the Service Scale Up the service instances. For more information, read here.

  2. VS Code will open inside a new frame at the bottom of the Dataloop platform. It can take a few minutes for the session to be initialized while Dataloop sets the environment according to the Docker image set for the service or any dependencies specified via a requirements file.


Activity Sidebar

  1. Explorer: Browse the files of your FaaS application (package).
    image.png
  2. Search: Search your files for a string or regular expression.
    image.png
  3. Source Control: Manage application files with VS Code's Git support.
    image.png
  4. Run & Debug: Debug your application by setting breakpoints and inspecting variables.
    image.png

Adjusting Display Window

  1. Use the top bar buttons to maximize or minimize the pane.
  1. To switch between themes, follow these steps:
    1. Click Settings.
    2. Choose Themes > Color Theme. A dialog box will open, allowing you to switch between Light or Dark themes or any other available options.

For more information about the user interface, see the User Interface article.


Debugging

The VS Code editor allows you to easily debug your FaaS service by setting up breakpoints, inspecting variables, and stepping through the code, all against a live Dataloop instance.


  1. If you have multiple files available in your codebase, click the "Source Control" button on the activity bar of VS Code and then select the file from which you wish to start debugging.
    image.png

  2. To bring up the Debug view, select the "Run and Debug" button in the sidebar.
    image.png

  3. Set breakpoints or add custom debug configuration before starting the debug session.

  4. In the Debug View, initiate a debugging session by clicking the "Start Debugging" button. If you wish to use a custom configuration, select it from the dropdown list first.
    image.png

  5. After the debug session starts, you can manage it with the Debugging action:
    Pause, Step Over, Step In, Step Out, Restart, and Stop. For more details, refer to this article
    image.png


Create Executions

When VS Code is connected to a service, new executions (created by event/cron/manual triggers) or executions that didn't start running yet will be queued until initiating the VS Code debugger or terminating the VS Code session.

Once the debugger is running, the executions will be processed according to the debugger settings (any breakpoints or configuration).

Our Recommendation: Trigger your functions while the debugger is active to test and debug your code with real time executions.

Visual Studio Code IDE

As Dataloop's VS Code application is based on Visual Studio Code, explore this article to master the VS Code debugger.


Updating a Package

The service codebase, which is the FaaS package, can be updated directly from the VS Code editor or console. Once you update the codebase files, you can push the updates to modify the package, and a new version will be created.
To start using the updated package for your version, updating the service is required.

Service Update During the VS Code Session

Updating a service is not allowed when VS Code is activated. To update the service with any changes, terminate the VS Code session first (click X).


Updating a Service

As mentioned above, updating a service that is connected to the VS Code is not allowed for any reason (update compute settings, package version, etc.).

To update the service, first terminate the VS Code session (click X). Updating the service version can be done via the SDK (locally) or from the Dataloop interface:

  1. Select CloudOps > Services tab.
  2. Select the service from the list.
  3. In the General Details section on the right-side panel of your service, click on the Update button next to the version.

Terminating a Session

  1. Click on the X icon in the top-right corner of the opened VS Code window. There is no option to save your updates.
  2. The following dialog will open, click Yes, Terminate to approve session termination.

After the session concludes, the resources allocated to VS Code will adapt in accordance with the service configuration, including features such as autoscaling and minimum replica settings. Any pending tasks or executions in the queue will automatically resume and begin running as soon as a running instance becomes available.