Skip to content

Commit

Permalink
DLT diagnostics (#1471)
Browse files Browse the repository at this point in the history
## Changes
- Report diagnostics based on ERROR and WARN pipeline events
- Add "more info" action to relevant events in the resource explorer,
open a file and notification when clicked
- Add generic "run bundle resource" action (a but unrelated to the rest
of the changes...)


## Tests
Manual and existing tests
  • Loading branch information
ilia-db authored Nov 28, 2024
1 parent 1f1df4b commit 7b962ff
Show file tree
Hide file tree
Showing 10 changed files with 472 additions and 28 deletions.
37 changes: 36 additions & 1 deletion packages/databricks-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet && databricks.context.bundle.deploymentState == idle",
"category": "Databricks"
},
{
"command": "databricks.bundle.deployAndRunFromInput",
"icon": "$(run)",
"title": "Deploy the bundle and run a resource",
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet && databricks.context.bundle.deploymentState == idle",
"category": "Databricks"
},
{
"command": "databricks.bundle.deployAndRunJob",
"icon": "$(run)",
Expand Down Expand Up @@ -248,10 +255,24 @@
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet && databricks.context.bundle.deploymentState == idle",
"category": "Databricks"
},
{
"command": "databricks.bundle.clearPipelineDiagnostics",
"icon": "$(clear-all)",
"title": "Clear pipeline diagnostics",
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet",
"category": "Databricks"
},
{
"command": "databricks.bundle.showPipelineEventDetails",
"icon": "$(info)",
"title": "Show more information",
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet",
"category": "Databricks"
},
{
"command": "databricks.bundle.cancelRun",
"title": "Cancel run",
"icon": "$(debug-stop)",
"icon": "$(stop)",
"enablement": "databricks.context.activated && databricks.context.bundle.isTargetSet && databricks.context.bundle.deploymentState == idle",
"category": "Databricks"
},
Expand Down Expand Up @@ -638,6 +659,16 @@
"when": "view == dabsResourceExplorerView && viewItem =~ /^databricks.bundle.resource=pipelines.runnable.*$/ && databricks.context.bundle.deploymentState == idle",
"group": "navigation@0"
},
{
"command": "databricks.bundle.showPipelineEventDetails",
"when": "view == dabsResourceExplorerView && viewItem =~ /^databricks.bundle.*.has-pipeline-details.*$/",
"group": "inline@0"
},
{
"command": "databricks.bundle.showPipelineEventDetails",
"when": "view == dabsResourceExplorerView && viewItem =~ /^databricks.bundle.*.has-pipeline-details.*$/",
"group": "navigation@0"
},
{
"command": "databricks.bundle.cancelRun",
"when": "view == dabsResourceExplorerView && viewItem =~ /^databricks.bundle.*.cancellable.*$/ && databricks.context.bundle.deploymentState == idle",
Expand Down Expand Up @@ -780,6 +811,10 @@
"command": "databricks.bundle.deployAndRunSelectedTables",
"when": "false"
},
{
"command": "databricks.bundle.showPipelineEventDetails",
"when": "false"
},
{
"command": "databricks.bundle.cancelRun",
"when": "false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import {BundleRunStatusManager} from "./run/BundleRunStatusManager";
import {ConfigModel} from "../configuration/models/ConfigModel";
import {mock, instance, when} from "ts-mockito";
import assert from "assert";
import {EventEmitter} from "vscode";
import {EventEmitter, Uri} from "vscode";
import {install, InstalledClock} from "@sinonjs/fake-timers";
import {ConnectionManager} from "../configuration/ConnectionManager";
import {locationToRange} from "./BundlePipelinesManager";
import path from "node:path";
import os from "os";
import fs from "fs/promises";

describe(__filename, () => {
describe("BundlePipelinesManager", () => {
let connectionManager: ConnectionManager;
let runStatusManager: BundleRunStatusManager;
let configModel: ConfigModel;
Expand Down Expand Up @@ -117,7 +121,7 @@ describe(__filename, () => {
/* eslint-disable @typescript-eslint/naming-convention */
const finalFullRefreshRun = {
data: {
creation_time: 200,
creation_time: 300,
refresh_selection: [],
state: "COMPLETED",
},
Expand All @@ -138,4 +142,59 @@ describe(__filename, () => {
assert(datasets.has("table_new"));
assert(datasets.has("table_final"));
});

describe("locationToRange", () => {
it("should return correct range for a given location in a text file", async () => {
const uri = Uri.file("/path/to/file.py");
// eslint-disable-next-line @typescript-eslint/naming-convention
const location = {path: "/path/to/file.py", line_number: 10};
const range = await locationToRange(uri, location);
assert.strictEqual(range.start.line, 9);
assert.strictEqual(range.end.line, 9);
});

it("should return correct range for a given location in a notebook file", async () => {
const uri = Uri.file("/path/to/notebook.ipynb");
const location = {
path: "/path/to/notebook.ipynb",
// eslint-disable-next-line @typescript-eslint/naming-convention
line_number: 5,
// eslint-disable-next-line @typescript-eslint/naming-convention
notebook_cell_number: 2,
};
const range = await locationToRange(uri, location, "IPYNB");
assert.strictEqual(range.start.line, 4);
assert.strictEqual(range.end.line, 4);
});

it("should handle PY_DBNB file type correctly", async () => {
// const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "test-"));
const filePath = path.join(os.tmpdir(), "notebook.py");
const uri = Uri.file(filePath);
const fileContent = `# Databricks notebook source
print('cell 1')
# COMMAND ----------
print('cell 2')
print('still cell 2')
# COMMAND ----------
print('cell 3')`;

await fs.writeFile(filePath, fileContent);

const location = {
path: filePath,
// eslint-disable-next-line @typescript-eslint/naming-convention
line_number: 1,
// eslint-disable-next-line @typescript-eslint/naming-convention
notebook_cell_number: 3,
};

const range = await locationToRange(uri, location, "PY_DBNB");
assert.strictEqual(range.start.line, 9);
assert.strictEqual(range.end.line, 9);
});
});
});
Loading

0 comments on commit 7b962ff

Please sign in to comment.