Skip to content

Commit

Permalink
add CLI argument for live data poll rate
Browse files Browse the repository at this point in the history
  • Loading branch information
salazarm committed Oct 9, 2023
1 parent dd1399d commit ceb223f
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 13 deletions.
4 changes: 2 additions & 2 deletions js_modules/dagster-ui/packages/app-oss/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {CommunityNux} from './NUX/CommunityNux';
import {extractInitializationData} from './extractInitializationData';
import {telemetryLink} from './telemetryLink';

const {pathPrefix, telemetryEnabled} = extractInitializationData();
const {pathPrefix, telemetryEnabled, liveDataPollRate} = extractInitializationData();

const apolloLinks = [logLink, errorLink, timeStartLink];

Expand All @@ -38,7 +38,7 @@ const appCache = createAppCache();
// eslint-disable-next-line import/no-default-export
export default function AppPage() {
return (
<LiveDataPollRateContext.Provider value={2000}>
<LiveDataPollRateContext.Provider value={liveDataPollRate ?? 2000}>
<AppProvider appCache={appCache} config={config}>
<AppTopNav searchPlaceholder="Search…" allowGlobalReload>
<UserSettingsButton />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
const ELEMENT_ID = 'initialization-data';
const PREFIX_PLACEHOLDER = '__PATH_PREFIX__';
const TELEMETRY_PLACEHOLDER = '__TELEMETRY_ENABLED__';
const LIVE_DATA_POLL_RATE = '__LIVE_DATA_POLL_RATE__';

let value: {pathPrefix: string; telemetryEnabled: boolean} | undefined = undefined;
let value: {pathPrefix: string; telemetryEnabled: boolean; liveDataPollRate?: number} | undefined =
undefined;

// Determine the path prefix value, which is set server-side.
// This value will be used for prefixing paths for the GraphQL
// endpoint and dynamically loaded bundles.
export const extractInitializationData = (): {
pathPrefix: string;
telemetryEnabled: boolean;
liveDataPollRate?: number;
} => {
if (!value) {
value = {pathPrefix: '', telemetryEnabled: false};
Expand All @@ -22,6 +25,9 @@ export const extractInitializationData = (): {
if (parsed.telemetryEnabled !== TELEMETRY_PLACEHOLDER) {
value.telemetryEnabled = parsed.telemetryEnabled;
}
if (parsed.liveDataPollRate !== LIVE_DATA_POLL_RATE) {
value.liveDataPollRate = parsed.liveDataPollRate;
}
}
}
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export default function Document() {
__html: `
{
"pathPrefix": "__PATH_PREFIX__",
"telemetryEnabled": "__TELEMETRY_ENABLED__"
"telemetryEnabled": "__TELEMETRY_ENABLED__",
"liveDataPollRate": "__LIVE_DATA_POLL_RATE__"
}
`,
}}
Expand Down
3 changes: 3 additions & 0 deletions python_modules/dagster-webserver/dagster_webserver/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Optional
from dagster import (
_check as check,
)
Expand All @@ -12,6 +13,7 @@
def create_app_from_workspace_process_context(
workspace_process_context: IWorkspaceProcessContext,
path_prefix: str = "",
live_data_poll_rate: Optional[int] = None,
**kwargs,
) -> Starlette:
check.inst_param(
Expand All @@ -34,4 +36,5 @@ def create_app_from_workspace_process_context(
return DagsterWebserver(
workspace_process_context,
path_prefix,
live_data_poll_rate,
).create_asgi_app(**kwargs)
15 changes: 13 additions & 2 deletions python_modules/dagster-webserver/dagster_webserver/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ def create_dagster_webserver_cli():
required=False,
hidden=True,
)
@click.option(
"--live-data-poll-rate",
help="Rate at which the dagster UI polls for updated asset data (defaults to 2 seconds)",
type=click.INT,
required=False,
default=2000,
show_default=True
)
@click.version_option(version=__version__, prog_name="dagster-webserver")
def dagster_webserver(
host: str,
Expand All @@ -175,6 +183,7 @@ def dagster_webserver(
dagster_log_level: str,
code_server_log_level: str,
instance_ref: Optional[str],
live_data_poll_rate: int,
**kwargs: ClickArgValue,
):
if suppress_warnings:
Expand Down Expand Up @@ -205,7 +214,7 @@ def dagster_webserver(
code_server_log_level=code_server_log_level,
) as workspace_process_context:
host_dagster_ui_with_workspace_process_context(
workspace_process_context, host, port, path_prefix, uvicorn_log_level
workspace_process_context, host, port, path_prefix, uvicorn_log_level, live_data_poll_rate
)


Expand All @@ -227,18 +236,20 @@ def host_dagster_ui_with_workspace_process_context(
port: Optional[int],
path_prefix: str,
log_level: str,
live_data_poll_rate: int,
):
check.inst_param(
workspace_process_context, "workspace_process_context", IWorkspaceProcessContext
)
host = check.opt_str_param(host, "host", "127.0.0.1")
check.opt_int_param(port, "port")
check.str_param(path_prefix, "path_prefix")
check.int_param(live_data_poll_rate, "live_data_poll_rate")

logger = logging.getLogger(WEBSERVER_LOGGER_NAME)

app = create_app_from_workspace_process_context(
workspace_process_context, path_prefix, lifespan=_lifespan
workspace_process_context, path_prefix, live_data_poll_rate, lifespan=_lifespan
)

if not port:
Expand Down
18 changes: 11 additions & 7 deletions python_modules/dagster-webserver/dagster_webserver/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import io
import uuid
from os import path, walk
from typing import Generic, List, TypeVar
from typing import Generic, List, Optional, TypeVar

import dagster._check as check
from dagster import __version__ as dagster_version
Expand Down Expand Up @@ -40,16 +40,15 @@

class DagsterWebserver(GraphQLServer, Generic[T_IWorkspaceProcessContext]):
_process_context: T_IWorkspaceProcessContext
_uses_app_path_prefix: bool

def __init__(
self,
process_context: T_IWorkspaceProcessContext,
app_path_prefix: str = "",
uses_app_path_prefix: bool = True,
live_data_poll_rate: Optional[int] = None,
):
self._process_context = process_context
self._uses_app_path_prefix = uses_app_path_prefix
self._live_data_poll_rate = live_data_poll_rate
super().__init__(app_path_prefix)

def build_graphql_schema(self) -> Schema:
Expand Down Expand Up @@ -209,17 +208,22 @@ def index_html_endpoint(self, request: Request):
**{"Content-Security-Policy": self.make_csp_header(nonce)},
**self.make_security_headers(),
}
return HTMLResponse(
content = (
rendered_template.replace(
"BUILDTIME_ASSETPREFIX_REPLACE_ME", f"{self._app_path_prefix}"
)
.replace("__PATH_PREFIX__", self._app_path_prefix)
.replace(
'"__TELEMETRY_ENABLED__"', str(context.instance.telemetry_enabled).lower()
)
.replace("NONCE-PLACEHOLDER", nonce),
headers=headers,
.replace("NONCE-PLACEHOLDER", nonce)
)

if self._live_data_poll_rate:
content = content.replace(
"__LIVE_DATA_POLL_RATE__", str(self._live_data_poll_rate)
)
return HTMLResponse(content, headers=headers)
except FileNotFoundError:
raise Exception("""
Can't find webapp files.
Expand Down
9 changes: 9 additions & 0 deletions python_modules/dagster/dagster/_cli/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ def dev_command_options(f):
help="Host to use for the Dagster webserver.",
required=False,
)
@click.option(
"--live-data-poll-rate",
help="Rate at which the dagster UI polls for updated asset data ",
default="2000",
show_default=True,
required=False,
)
@deprecated(
breaking_version="2.0", subject="--dagit-port and --dagit-host args", emit_runtime_warning=False
)
Expand All @@ -89,6 +96,7 @@ def dev_command(
log_level: str,
port: Optional[str],
host: Optional[str],
live_data_poll_rate: Optional[str],
**kwargs: ClickArgValue,
) -> None:
# check if dagster-webserver installed, crash if not
Expand Down Expand Up @@ -163,6 +171,7 @@ def dev_command(
+ (["--port", port] if port else [])
+ (["--host", host] if host else [])
+ (["--dagster-log-level", log_level])
+ (["--live-data-poll-rate", live_data_poll_rate] if live_data_poll_rate else [])
+ args
)
daemon_process = open_ipc_subprocess(
Expand Down

0 comments on commit ceb223f

Please sign in to comment.