-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added listing cluster filtering for cluster lookups (#1754)
## Changes We added a custom resolver for the cluster to add filtering for the cluster source when we list all clusters. Without the filtering listing could take a very long time (5-10 mins) which leads to lookup timeouts. ## Tests Existing unit tests passing
- Loading branch information
1 parent
ceefa80
commit 02e8387
Showing
5 changed files
with
119 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package variable | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/databricks/databricks-sdk-go" | ||
"github.com/databricks/databricks-sdk-go/service/compute" | ||
) | ||
|
||
var lookupOverrides = map[string]resolverFunc{ | ||
"Cluster": resolveCluster, | ||
} | ||
|
||
// We added a custom resolver for the cluster to add filtering for the cluster source when we list all clusters. | ||
// Without the filtering listing could take a very long time (5-10 mins) which leads to lookup timeouts. | ||
func resolveCluster(ctx context.Context, w *databricks.WorkspaceClient, name string) (string, error) { | ||
result, err := w.Clusters.ListAll(ctx, compute.ListClustersRequest{ | ||
FilterBy: &compute.ListClustersFilterBy{ | ||
ClusterSources: []compute.ClusterSource{compute.ClusterSourceApi, compute.ClusterSourceUi}, | ||
}, | ||
}) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
|
||
tmp := map[string][]compute.ClusterDetails{} | ||
for _, v := range result { | ||
key := v.ClusterName | ||
tmp[key] = append(tmp[key], v) | ||
} | ||
alternatives, ok := tmp[name] | ||
if !ok || len(alternatives) == 0 { | ||
return "", fmt.Errorf("cluster named '%s' does not exist", name) | ||
} | ||
if len(alternatives) > 1 { | ||
return "", fmt.Errorf("there are %d instances of clusters named '%s'", len(alternatives), name) | ||
} | ||
return alternatives[0].ClusterId, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters