Skip to content
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

Prototype: Run debuggable blueprints as separate process SOFIE-1548 #985

Draft
wants to merge 11 commits into
base: release51
Choose a base branch
from

Conversation

Julusian
Copy link
Member

@Julusian Julusian commented Jul 13, 2023

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

feature prototype

What is the new behavior (if this is a feature change)?

This allows for running the blueprints as their own process, to allow for easier debugging, avoiding the need to attach a debugger to the whole of Sofie and stepping through a lot of core code.

This is very incomplete, with a lot of TODOs and bits which havent been implemented, most notably this is only done for the studio blueprint and not showstyle or system.


The approach I have taken is to add this ProxiedStudioBlueprint class to Sofie, which implements the StudioBlueprintManifest exported by blueprints. Inside of this class, it sets up a socket.io client, which is utilised to call methods on the remote blueprints service.

Inside of the blueprints this can be utilised with a simple script:

import { runForBlueprints } from '@sofie-automation/blueprints-proxy/dist/host'

// @ts-expect-error Unknown property
global.VERSION = 'test'
// @ts-expect-error Unknown property
global.VERSION_TSR = 'test'
// @ts-expect-error Unknown property
global.VERSION_INTEGRATION = 'test'
// @ts-expect-error Unknown property
global.TRANSLATION_BUNDLES = '[]'

import studioManifest from './main/studio/index'
import showStyleManifest from './main/showStyle/index'

runForBlueprints(studioManifest, showStyleManifest)

For this to work, any importing of png or svg files has to be disabled, and some other changes may need to be made to get it to run happily outside of webpack. It was not investigated on how to improve this to avoid needing to make many hacks.

Inside of runForBlueprints it is setting up the socket.io server, and is reconstructing the contexts as proxied versions and calling into the proper blueprint methods.

Being sent over socket.io when calling a method is any required data to construct the appropriate Context class, and any other parameters being provided to the method. Various methods on the Context classes are now returning Promises. This does require changes to the blueprint interfaces and usages, but this is a necessary cost of this change. These async methods make a call back to Sofie over the socket.io, to perform their operation. This may not be required for every method, but it was done to many for consisntency, and to avoid adding any real logic to the proxy or needing to change it in the future

Limitations:

  • It is not handling that some methods can be optional
  • Breakpoints can cause timeouts
  • Calling an unknown blueprint method can cause the connection to hang
  • Hardcoded address of the socket.io server, and the proxy is forced to enabled
  • The static properties of the blueprint (blueprintVersion, studioConfigSchema etc are not being considered)
  • A large payload may cause the connection to die due to packet size limits.

Other information:

Socket.io was chosen as a quick and easy way to prototype with hacked together but bidirectional RPC abilities. A final implementation should review if this is the right tool to use. Plain HTTP was considered, but as that would require calls being performed in both directions, would add complexity and more fragility to the setup.

Status

  • Code documentation for the relevant parts in the code have been added/updated by the PR author
  • The functionality has been tested by the PR author
  • The functionality has been tested by NRK

@Julusian Julusian changed the title Prototype: Run debuggable blueprints as separate process Prototype: Run debuggable blueprints as separate process SOFIE-1548 Jul 13, 2023
@codecov
Copy link

codecov bot commented Jul 13, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -4.37 ⚠️

Comparison is base (b4b5dbc) 81.04% compared to head (5925c93) 76.67%.

Additional details and impacted files
@@              Coverage Diff              @@
##           release51     #985      +/-   ##
=============================================
- Coverage      81.04%   76.67%   -4.37%     
=============================================
  Files            141       32     -109     
  Lines          27221     5809   -21412     
  Branches        2189      573    -1616     
=============================================
- Hits           22061     4454   -17607     
+ Misses          5133     1353    -3780     
+ Partials          27        2      -25     
Impacted Files Coverage Δ
packages/blueprints-integration/src/context.ts 100.00% <100.00%> (ø)

... and 110 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant