Skip to content
Merged
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: 0 additions & 2 deletions apps/dev-playground/server/.env.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
DATABRICKS_HOST=
DATABRICKS_WAREHOUSE_ID=
DATABRICKS_WORKSPACE_ID=
DATABRICKS_APP_PORT=8000
FLASK_RUN_HOST=0.0.0.0
NODE_ENV='development'
OTEL_EXPORTER_OTLP_ENDPOINT='http://localhost:4318'
OTEL_RESOURCE_ATTRIBUTES='service.sample_attribute=dev'
Expand Down
1 change: 1 addition & 0 deletions packages/app-kit/src/analytics/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {
export class AnalyticsPlugin extends Plugin {
name = "analytics";
envVars = [];
requiresDatabricksClient = true;

protected static description = "Analytics plugin for data analysis";
protected declare config: IAnalyticsConfig;
Expand Down
3 changes: 3 additions & 0 deletions packages/app-kit/src/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export abstract class Plugin<
protected telemetry: ITelemetry;
protected abstract envVars: string[];

/** If the plugin requires the Databricks client to be set in the request context */
requiresDatabricksClient = false;

static phase: PluginPhase = "normal";
name: string;

Expand Down
16 changes: 16 additions & 0 deletions packages/app-kit/src/plugin/tests/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,22 @@ describe("Plugin", () => {
});
});

describe("requiresDatabricksClient", () => {
test("should default to false", () => {
const plugin = new TestPlugin(config);
expect(plugin.requiresDatabricksClient).toBe(false);
});

test("should allow plugins to override to true", () => {
class PluginWithDatabricksClient extends TestPlugin {
requiresDatabricksClient = true;
}

const plugin = new PluginWithDatabricksClient(config);
expect(plugin.requiresDatabricksClient).toBe(true);
});
});

describe("integration scenarios", () => {
test("should handle complex execution flow with all interceptors", async () => {
const plugin = new TestPlugin({
Expand Down
24 changes: 19 additions & 5 deletions packages/app-kit/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ dotenv.config({ path: path.resolve(process.cwd(), "./server/.env") });
export class ServerPlugin extends Plugin {
public static DEFAULT_CONFIG = {
autoStart: true,
staticPath: path.resolve(process.cwd(), "client", "dist"),
staticPath: ServerPlugin.findDefaultStaticPath(),
host: process.env.FLASK_RUN_HOST || "0.0.0.0",
port: Number(process.env.DATABRICKS_APP_PORT) || 8000,
watch: process.env.NODE_ENV === "development",
};

public name = "server" as const;
public envVars = ["DATABRICKS_APP_PORT", "FLASK_RUN_HOST"];
public envVars: string[] = [];
private serverApplication: express.Application;
private server: HTTPServer | null;
private devModeManager?: DevModeManager;
Expand Down Expand Up @@ -65,9 +65,8 @@ export class ServerPlugin extends Plugin {

async start(): Promise<express.Application> {
this.serverApplication.use(express.json());
this.serverApplication.use(await databricksClientMiddleware());

this.extendRoutes();
await this.extendRoutes();

for (const extension of this.serverExtensions) {
extension(this.serverApplication);
Expand Down Expand Up @@ -156,7 +155,7 @@ export class ServerPlugin extends Plugin {
return this;
}

private extendRoutes() {
private async extendRoutes() {
if (!this.config.plugins) return;

this.serverApplication.get("/health", (_, res) => {
Expand All @@ -169,6 +168,10 @@ export class ServerPlugin extends Plugin {
if (plugin?.injectRoutes && typeof plugin.injectRoutes === "function") {
const router = express.Router();

// add databricks client middleware to the router if the plugin needs the request context
if (plugin.requiresDatabricksClient)
router.use(await databricksClientMiddleware());

plugin.injectRoutes(router);

this.serverApplication.use(`/api/${plugin.name}`, router);
Expand Down Expand Up @@ -222,6 +225,17 @@ export class ServerPlugin extends Plugin {
return configObject;
}

private static findDefaultStaticPath() {
const staticPaths = ["dist", "client/dist", "build", "public", "out"];
const cwd = process.cwd();
for (const p of staticPaths) {
if (fs.existsSync(path.resolve(cwd, p, "index.html"))) {
return path.resolve(cwd, p);
}
}
return undefined;
}

private _gracefulShutdown() {
console.log("Starting graceful shutdown...");

Expand Down
3 changes: 0 additions & 3 deletions packages/app-kit/src/telemetry/telemetry-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ export class TelemetryManager {
if (this.sdk) return;

if (!process.env.OTEL_EXPORTER_OTLP_ENDPOINT) {
console.log(
"[Telemetry] OTEL_EXPORTER_OTLP_ENDPOINT not set; telemetry disabled",
);
return;
}

Expand Down