-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Send initialization data in the NewReport message #2317
Changes from 10 commits
4d2f46a
d08e875
67cdf71
a24ae97
b7b78ba
c43d649
4d341dc
ff8bb72
26d300f
69bfab7
513ddaf
26228d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ import { | |
SessionEvent, | ||
WidgetStates, | ||
SessionState, | ||
Config, | ||
} from "autogen/proto" | ||
|
||
import { RERUN_PROMPT_MODAL_DIALOG } from "lib/baseconsts" | ||
|
@@ -287,14 +288,12 @@ export class App extends PureComponent<Props, State> { | |
|
||
try { | ||
dispatchProto(msgProto, "type", { | ||
initialize: (initializeMsg: Initialize) => | ||
this.handleInitialize(initializeMsg), | ||
newReport: (newReportMsg: NewReport) => | ||
this.handleNewReport(newReportMsg), | ||
sessionStateChanged: (msg: SessionState) => | ||
this.handleSessionStateChanged(msg), | ||
sessionEvent: (evtMsg: SessionEvent) => | ||
this.handleSessionEvent(evtMsg), | ||
newReport: (newReportMsg: NewReport) => | ||
this.handleNewReport(newReportMsg), | ||
delta: (deltaMsg: Delta) => | ||
this.handleDeltaMsg( | ||
deltaMsg, | ||
|
@@ -378,64 +377,6 @@ export class App extends PureComponent<Props, State> { | |
}) | ||
} | ||
|
||
/** | ||
* Handler for ForwardMsg.initialize messages | ||
* @param initializeMsg an Initialize protobuf | ||
*/ | ||
handleInitialize = (initializeMsg: Initialize): void => { | ||
const { | ||
Comment on lines
-381
to
-386
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic now lives in the "handleOneTimeInitialization" function |
||
sessionId, | ||
environmentInfo, | ||
userInfo, | ||
config, | ||
sessionState, | ||
} = initializeMsg | ||
|
||
if ( | ||
sessionId == null || | ||
!environmentInfo || | ||
!userInfo || | ||
!config || | ||
!sessionState | ||
) { | ||
throw new Error("InitializeMsg is missing a required field") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm assuming this part isn't necessary now. Are we just assuming the correct message is sent down (totally fine, but just checking)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these checks happen within the SessionInfo constructor, so this was just essentially duplicate logic |
||
} | ||
|
||
if (App.hasStreamlitVersionChanged(initializeMsg)) { | ||
window.location.reload() | ||
return | ||
} | ||
|
||
SessionInfo.current = new SessionInfo({ | ||
sessionId, | ||
streamlitVersion: environmentInfo.streamlitVersion, | ||
pythonVersion: environmentInfo.pythonVersion, | ||
installationId: userInfo.installationId, | ||
installationIdV1: userInfo.installationIdV1, | ||
installationIdV2: userInfo.installationIdV2, | ||
authorEmail: userInfo.email, | ||
maxCachedMessageAge: config.maxCachedMessageAge, | ||
commandLine: initializeMsg.commandLine, | ||
userMapboxToken: config.mapboxToken, | ||
}) | ||
|
||
MetricsManager.current.initialize({ | ||
gatherUsageStats: Boolean(config.gatherUsageStats), | ||
}) | ||
|
||
MetricsManager.current.enqueue("createReport", { | ||
pythonVersion: SessionInfo.current.pythonVersion, | ||
}) | ||
|
||
this.setState({ | ||
sharingEnabled: Boolean(config.sharingEnabled), | ||
allowRunOnSave: Boolean(config.allowRunOnSave), | ||
}) | ||
|
||
this.props.s4aCommunication.connect() | ||
this.handleSessionStateChanged(sessionState) | ||
} | ||
|
||
/** | ||
* Handler for ForwardMsg.sessionStateChanged messages | ||
* @param stateChangeProto a SessionState protobuf | ||
|
@@ -530,9 +471,24 @@ export class App extends PureComponent<Props, State> { | |
* @param newReportProto a NewReport protobuf | ||
*/ | ||
handleNewReport = (newReportProto: NewReport): void => { | ||
const initialize = newReportProto.initialize as Initialize | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just out of curiosity, does the protobuf not return the correct type here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the larger protobufjs typescript issue: message fields are typed as interfaces, not classes ( |
||
|
||
if (App.hasStreamlitVersionChanged(initialize)) { | ||
window.location.reload() | ||
return | ||
} | ||
|
||
// First, handle initialization logic. Each NewReport message has | ||
// initialization data. If this is the _first_ time we're receiving | ||
// the NewReport message, we perform some one-time initialization. | ||
if (!SessionInfo.isSet()) { | ||
// We're not initialized. Perform one-time initialization. | ||
this.handleOneTimeInitialization(initialize) | ||
} | ||
|
||
const { reportHash } = this.state | ||
const { | ||
id: reportId, | ||
reportId, | ||
name: reportName, | ||
scriptPath, | ||
deployParams, | ||
|
@@ -561,6 +517,31 @@ export class App extends PureComponent<Props, State> { | |
} | ||
} | ||
|
||
/** | ||
* Performs one-time initialization. This is called from `handleNewReport`. | ||
*/ | ||
handleOneTimeInitialization = (initialize: Initialize): void => { | ||
SessionInfo.current = SessionInfo.fromInitializeMessage(initialize) | ||
|
||
const config = initialize.config as Config | ||
|
||
MetricsManager.current.initialize({ | ||
gatherUsageStats: config.gatherUsageStats, | ||
}) | ||
|
||
MetricsManager.current.enqueue("createReport", { | ||
pythonVersion: SessionInfo.current.pythonVersion, | ||
}) | ||
|
||
this.setState({ | ||
sharingEnabled: config.sharingEnabled, | ||
allowRunOnSave: config.allowRunOnSave, | ||
}) | ||
|
||
this.props.s4aCommunication.connect() | ||
this.handleSessionStateChanged(initialize.sessionState) | ||
} | ||
|
||
/** | ||
* Handler for ForwardMsg.reportFinished messages | ||
* @param status the ReportFinishedStatus that the report finished with | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this PR, but I was making changes to App.tsx - none of these props exist