Skip to content

Commit 91d80dd

Browse files
authored
Add repository snapshot destination field to NotebookRuntimeOptions (#2078)
* Add repository snapshot destination field to NotebookRuntimeOptions * Improve code clarity and add more tests
1 parent 5980f45 commit 91d80dd

5 files changed

Lines changed: 94 additions & 7 deletions

File tree

core/actions/notebook_test.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ defaultLocation: US
108108
defaultNotebookRuntimeOptions:
109109
outputBucket: gs://some-bucket
110110
runtimeTemplateName: projects/test-project/locations/us-central1/notebookRuntimeTemplates/test-template
111+
repositorySnapshotDestination:
112+
repositorySnapshotUri: gs://some-other-bucket
111113
`);
112114
fs.writeFileSync(path.join(projectDir, "definitions/notebook.ipynb"), EMPTY_NOTEBOOK_CONTENTS);
113115

@@ -120,12 +122,59 @@ defaultNotebookRuntimeOptions:
120122
defaultNotebookRuntimeOptions: {
121123
outputBucket: "gs://some-bucket",
122124
runtimeTemplateName:
123-
"projects/test-project/locations/us-central1/notebookRuntimeTemplates/test-template"
125+
"projects/test-project/locations/us-central1/notebookRuntimeTemplates/test-template",
126+
repositorySnapshotDestination: {
127+
repositorySnapshotUri: "gs://some-other-bucket"
128+
}
129+
},
130+
warehouse: "bigquery"
131+
});
132+
});
133+
134+
test(`notebook default runtime options snapshot destination defaults to output bucket`, () => {
135+
const projectDir = createSimpleNotebookProject(`
136+
defaultProject: dataform
137+
defaultLocation: US
138+
defaultNotebookRuntimeOptions:
139+
outputBucket: gs://some-bucket
140+
runtimeTemplateName: projects/test-project/locations/us-central1/notebookRuntimeTemplates/test-template
141+
repositorySnapshotDestination: {}
142+
`);
143+
fs.writeFileSync(path.join(projectDir, "definitions/notebook.ipynb"), EMPTY_NOTEBOOK_CONTENTS);
144+
145+
const result = runMainInVm(coreExecutionRequestFromPath(projectDir));
146+
147+
expect(result.compile.compiledGraph.graphErrors.compilationErrors).deep.equals([]);
148+
expect(asPlainObject(result.compile.compiledGraph.projectConfig)).deep.equals({
149+
defaultDatabase: "dataform",
150+
defaultLocation: "US",
151+
defaultNotebookRuntimeOptions: {
152+
outputBucket: "gs://some-bucket",
153+
runtimeTemplateName:
154+
"projects/test-project/locations/us-central1/notebookRuntimeTemplates/test-template",
155+
repositorySnapshotDestination: {
156+
repositorySnapshotUri: "gs://some-bucket"
157+
}
124158
},
125159
warehouse: "bigquery"
126160
});
127161
});
128162

163+
test(`notebook default runtime options throw for snapshot destination with no uri or output bucket`, () => {
164+
const projectDir = createSimpleNotebookProject(`
165+
defaultProject: dataform
166+
defaultLocation: US
167+
defaultNotebookRuntimeOptions:
168+
runtimeTemplateName: projects/test-project/locations/us-central1/notebookRuntimeTemplates/test-template
169+
repositorySnapshotDestination: {}
170+
`);
171+
fs.writeFileSync(path.join(projectDir, "definitions/notebook.ipynb"), EMPTY_NOTEBOOK_CONTENTS);
172+
173+
expect(() => runMainInVm(coreExecutionRequestFromPath(projectDir))).to.throw(
174+
"Invalid repository_snapshot_destination: either repository_snapshot_uri or output_bucket has to be defined"
175+
);
176+
});
177+
129178
suite("sqlx and JS API config options", () => {
130179
test(`for notebooks`, () => {
131180
const projectDir = tmpDirFixture.createNewTmpDir();

core/workflow_settings.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,27 @@ export function workflowSettingsAsProjectConfig(
124124
}
125125
if (workflowSettings.defaultNotebookRuntimeOptions) {
126126
projectConfig.defaultNotebookRuntimeOptions = {};
127-
if (workflowSettings.defaultNotebookRuntimeOptions.outputBucket) {
128-
projectConfig.defaultNotebookRuntimeOptions.outputBucket =
129-
workflowSettings.defaultNotebookRuntimeOptions.outputBucket;
127+
const {outputBucket, runtimeTemplateName, repositorySnapshotDestination} =
128+
workflowSettings.defaultNotebookRuntimeOptions;
129+
if (outputBucket) {
130+
projectConfig.defaultNotebookRuntimeOptions.outputBucket = outputBucket;
130131
}
131-
if (workflowSettings.defaultNotebookRuntimeOptions.runtimeTemplateName) {
132-
projectConfig.defaultNotebookRuntimeOptions.runtimeTemplateName =
133-
workflowSettings.defaultNotebookRuntimeOptions.runtimeTemplateName;
132+
if (runtimeTemplateName) {
133+
projectConfig.defaultNotebookRuntimeOptions.runtimeTemplateName = runtimeTemplateName;
134+
}
135+
if (repositorySnapshotDestination) {
136+
projectConfig.defaultNotebookRuntimeOptions.repositorySnapshotDestination = {};
137+
if (repositorySnapshotDestination.repositorySnapshotUri) {
138+
projectConfig.defaultNotebookRuntimeOptions.repositorySnapshotDestination.repositorySnapshotUri =
139+
repositorySnapshotDestination.repositorySnapshotUri;
140+
} else if (outputBucket) {
141+
projectConfig.defaultNotebookRuntimeOptions.repositorySnapshotDestination.repositorySnapshotUri =
142+
outputBucket;
143+
} else {
144+
throw Error(
145+
"Invalid repository_snapshot_destination: either repository_snapshot_uri or output_bucket " +
146+
"has to be defined");
147+
}
134148
}
135149
}
136150
if(workflowSettings.defaultIcebergConfig) {

examples/extreme_weather_programming/workflow_settings.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ defaultAssertionDataset: dataform_extreme_weather_programming_example_assertions
55
defaultNotebookRuntimeOptions:
66
outputBucket: gs://some-bucket
77
runtimeTemplateName: projects/test-project/locations/us-central1/notebookRuntimeTemplates/test-template
8+
repositorySnapshotDestination:
9+
repositorySnapshotUri: gs://some-other-bucket

protos/configs.proto

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,11 @@ message ActionConfig {
680680
}
681681
}
682682

683+
message RepositorySnapshotDestinationConfig {
684+
// Storage URI to upload the repository snapshot to.
685+
string repository_snapshot_uri = 1;
686+
}
687+
683688
message NotebookRuntimeOptionsConfig {
684689
oneof output_sink {
685690
// Storage bucket to output notebooks to after their execution.
@@ -689,4 +694,13 @@ message NotebookRuntimeOptionsConfig {
689694
// Colab runtime template (https://cloud.google.com/colab/docs/runtimes), from
690695
// which a runtime is created for notebook executions.
691696
string runtime_template_name = 2;
697+
698+
// The destination for the snapshot of repository files to be available for
699+
// read-only access inside a notebook runtime.
700+
oneof repository_snapshot_storage {
701+
// Storage URI to upload the snapshot to.
702+
// For empty URI it defaults to the provided output_bucket.
703+
RepositorySnapshotDestinationConfig repository_snapshot_destination = 3;
704+
}
705+
692706
}

protos/core.proto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,20 @@ message Notebook {
310310
string notebook_contents = 7;
311311
}
312312

313+
message RepositorySnapshotDestination {
314+
string repository_snapshot_uri = 1;
315+
}
316+
313317
message NotebookRuntimeOptions {
314318
oneof output_sink {
315319
string output_bucket = 1;
316320
}
317321

318322
string runtime_template_name = 2;
323+
324+
oneof repository_snapshot_storage {
325+
RepositorySnapshotDestination repository_snapshot_destination = 3;
326+
}
319327
}
320328

321329
// Data Preparation Related entries

0 commit comments

Comments
 (0)