-
Notifications
You must be signed in to change notification settings - Fork 72
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
Use Go SDK Iterators when listing resources with the CLI #1202
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1202 +/- ##
==========================================
+ Coverage 52.05% 52.43% +0.37%
==========================================
Files 308 308
Lines 17470 17586 +116
==========================================
+ Hits 9094 9221 +127
+ Misses 7706 7672 -34
- Partials 670 693 +23 ☔ View full report in Codecov by Sentry. |
Nice work, glad to see this. |
# Conflicts: # bundle/schema/docs/bundle_descriptions.json
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.
Looking great. A thought I had while reading this: as we're leaning on reflection to pick the right rendering mode, we'll need to work on integration tests for all generated commands in all output modes. With the mocking support in the SDK, we can probably come up with something (relatively) lightweight that gets us the coverage.
As for integration tests like what you're mentioning, I think it would be a reasonable idea to have coverage like that anyways to make sure the SDK/CLI work properly for all API calls, separately from this PR. Definitely, we need to make sure this is accounted for though, as issues won't be caught at compile time anymore. |
CLI: * Improved error message when no .databrickscfg ([#1223](#1223)). * Use Go SDK Iterators when listing resources with the CLI ([#1202](#1202)). Bundles: * Only set ComputeID value when `--compute-id` flag provided ([#1229](#1229)). * Add correct tag value for models in dev mode ([#1230](#1230)). * Upgrade Terraform provider to 1.37.0 ([#1235](#1235)). Internal: * Fix CLI nightlies on our UC workspaces ([#1225](#1225)). * Handle alias types for map keys in toTyped conversion ([#1232](#1232)).
CLI: * Improved error message when no .databrickscfg ([#1223](#1223)). * Use Go SDK Iterators when listing resources with the CLI ([#1202](#1202)). Bundles: * Only set ComputeID value when `--compute-id` flag provided ([#1229](#1229)). * Add correct tag value for models in dev mode ([#1230](#1230)). * Upgrade Terraform provider to 1.37.0 ([#1235](#1235)). Internal: * Fix CLI nightlies on our UC workspaces ([#1225](#1225)). * Handle alias types for map keys in toTyped conversion ([#1232](#1232)).
## Changes In #1202 the semantics of `cmdio.RenderJson` was changes to always render the JSON object. Before we would only render it if `--output json` was specified. This PR fixes the logs to print human-readable log lines instead of a JSON object. This PR also removes the now unused `cmdio.Render` method. ## Tests Manually: ``` ➜ bundle-playground git:(master) ✗ cli workspace import-dir ./tmp /Users/[email protected]/test-import-1 -p aws-prod-ucws Importing files from ./tmp a -> /Users/[email protected]/test-import-1/a Import complete. The files are available at /Users/[email protected]/test-import-1 ``` ``` ➜ bundle-playground git:(master) ✗ cli workspace export-dir /Users/[email protected]/test-export-1 ./tmp-2 -p aws-prod-ucws Exporting files from /Users/[email protected]/test-export-1 /Users/[email protected]/test-export-1/b -> tmp-2/b Exported complete. The files are available at ./tmp-2 ```
Changes
Currently, when the CLI run a list API call (like list jobs), it uses the
List*All
methods from the SDK, which list all resources in the collection. This is very slow for large collections: if you need to list all jobs from a workspace that has 10,000+ jobs, you'll be waiting for at least 100 RPCs to complete before seeing any output.Instead of using List*All() methods, the SDK recently added an iterator data structure that allows traversing the collection without needing to completely list it first. New pages are fetched lazily if the next requested item belongs to the next page. Using the List() methods that return these iterators, the CLI can proactively print out some of the response before the complete collection has been fetched.
This involves a pretty major rewrite of the rendering logic in
cmdio
. The idea there is to define custom rendering logic based on the type of the provided resource. There are three renderer interfaces:There are also three renderer implementations:
listing.Iterator
from the Go SDK. This implements jsonRenderer and templateRenderer, buffering 20 resources at a time before writing them to the output.Callers will either use
cmdio.Render()
for rendering individual resources orio.Reader
orcmdio.RenderIterator()
for rendering an iterator. This separate method is needed to safely be able to match on the type of the iterator, since Go does not allow runtime type matches on generic types with an existential type parameter.One other change that needs to happen is to split the templates used for text representation of list resources into a header template and a row template. The template is now executed multiple times for List API calls, but the header should only be printed once. To support this, I have added
headerTemplate
tocmdIO
, and I have also changedRenderWithTemplate
to include aheaderTemplate
parameter everywhere.Tests