Skip to content

Commit 5537c36

Browse files
committed
Extend pipelines history command
1 parent ff5eed5 commit 5537c36

7 files changed

Lines changed: 120 additions & 19 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Show table names and default to 5 rows in `pipelines show`, and support pipeline IDs in `pipelines history`. ([#6871](https://github.com/databricks/cli/pull/6871))

‎.nextchanges/cli/pipelines-show-default.md‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎acceptance/pipelines/history/basic/out.test.toml‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
=== default history by pipeline id
3+
4+
>>> [CLI] pipelines history [UUID]
5+
Updates Summary for pipeline [UUID]:
6+
Update ID: update-3
7+
State: COMPLETED
8+
Creation Time: [TIMESTAMP]
9+
Full Refresh: false
10+
Validate Only: false
11+
Update ID: update-2
12+
State: FAILED
13+
Creation Time: [TIMESTAMP]
14+
Full Refresh: false
15+
Validate Only: true
16+
Update ID: update-1
17+
State: CANCELED
18+
Creation Time: [TIMESTAMP]
19+
Full Refresh: false
20+
Validate Only: false
21+
22+
=== json output
23+
24+
>>> [CLI] pipelines history [UUID] --output json
25+
{
26+
"Key": "[UUID]",
27+
"Updates": [
28+
{
29+
"creation_time": [NUMID],
30+
"state": "COMPLETED",
31+
"update_id": "update-3",
32+
"validate_only": false
33+
},
34+
{
35+
"creation_time": [NUMID],
36+
"state": "FAILED",
37+
"update_id": "update-2",
38+
"validate_only": true
39+
},
40+
{
41+
"creation_time": [NUMID],
42+
"state": "CANCELED",
43+
"update_id": "update-1",
44+
"validate_only": false
45+
}
46+
]
47+
}
48+
49+
=== wire request uses pipeline id
50+
51+
>>> print_requests.py //api/2.0/pipelines/[UUID]/updates --get
52+
{
53+
"method": "GET",
54+
"path": "/api/2.0/pipelines/[UUID]/updates"
55+
}
56+
{
57+
"method": "GET",
58+
"path": "/api/2.0/pipelines/[UUID]/updates"
59+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
title "default history by pipeline id\n"
2+
trace $CLI pipelines history 3fb8e5a1-0d2c-4a6b-9f1e-2c7d8e9f0a1b
3+
4+
title "json output\n"
5+
trace $CLI pipelines history 3fb8e5a1-0d2c-4a6b-9f1e-2c7d8e9f0a1b --output json
6+
7+
title "wire request uses pipeline id\n"
8+
trace print_requests.py //api/2.0/pipelines/3fb8e5a1-0d2c-4a6b-9f1e-2c7d8e9f0a1b/updates --get
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Cloud = false
2+
3+
EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"]
4+
RecordRequests = true
5+
6+
[[Server]]
7+
Pattern = "GET /api/2.0/pipelines/{pipeline_id}/updates"
8+
Response.Body = '''
9+
{
10+
"updates": [
11+
{"update_id": "update-3", "state": "COMPLETED", "creation_time": 1640995200000, "validate_only": false},
12+
{"update_id": "update-2", "state": "FAILED", "creation_time": 1640908800000, "validate_only": true},
13+
{"update_id": "update-1", "state": "CANCELED", "creation_time": 1640822400000, "validate_only": false}
14+
]
15+
}
16+
'''

‎cmd/pipelines/history.go‎

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,26 @@ package pipelines
22

33
import (
44
"fmt"
5+
"regexp"
56

67
"github.com/databricks/cli/cmd/bundle/utils"
78
"github.com/databricks/cli/cmd/root"
9+
"github.com/databricks/cli/libs/cmdctx"
810
"github.com/databricks/cli/libs/cmdgroup"
911
"github.com/databricks/cli/libs/cmdio"
12+
databricks "github.com/databricks/databricks-sdk-go"
1013
"github.com/databricks/databricks-sdk-go/service/pipelines"
1114
"github.com/spf13/cobra"
1215
)
1316

17+
var pipelineIDRegex = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)
18+
1419
func historyCommand() *cobra.Command {
1520
cmd := &cobra.Command{
16-
Use: "history [flags] [KEY]",
21+
Use: "history [flags] [KEY|PIPELINE_ID]",
1722
Args: root.MaximumNArgs(1),
1823
Short: "Retrieve past runs for a pipeline",
19-
Long: `Retrieve past runs for a pipeline identified by KEY, the unique name of the pipeline as defined in its YAML file.`,
24+
Long: `Retrieve past runs for a pipeline identified by KEY, the unique name of the pipeline as defined in its YAML file, or by PIPELINE_ID, the unique identifier of the pipeline.`,
2025
}
2126

2227
var startTimeStr string
@@ -34,25 +39,36 @@ func historyCommand() *cobra.Command {
3439
wrappedCmd.AddFlagGroup(historyGroup)
3540

3641
cmd.RunE = func(cmd *cobra.Command, args []string) error {
37-
b, err := utils.ProcessBundle(cmd, utils.ProcessOptions{
38-
InitIDs: true,
39-
})
40-
if err != nil {
41-
return err
42-
}
43-
ctx := cmd.Context()
42+
var key, pipelineId string
43+
var w *databricks.WorkspaceClient
44+
if len(args) == 1 && pipelineIDRegex.MatchString(args[0]) {
45+
if err := root.MustWorkspaceClient(cmd, args); err != nil {
46+
return err
47+
}
48+
pipelineId = args[0]
49+
key = pipelineId
50+
w = cmdctx.WorkspaceClient(cmd.Context())
51+
} else {
52+
b, err := utils.ProcessBundle(cmd, utils.ProcessOptions{
53+
InitIDs: true,
54+
})
55+
if err != nil {
56+
return err
57+
}
58+
ctx := cmd.Context()
4459

45-
key, err := resolvePipelineArgument(ctx, b, args)
46-
if err != nil {
47-
return err
48-
}
60+
key, err = resolvePipelineArgument(ctx, b, args)
61+
if err != nil {
62+
return err
63+
}
4964

50-
pipelineId, err := resolvePipelineIdFromKey(ctx, b, key)
51-
if err != nil {
52-
return err
65+
pipelineId, err = resolvePipelineIdFromKey(ctx, b, key)
66+
if err != nil {
67+
return err
68+
}
69+
w = b.WorkspaceClient(ctx)
5370
}
54-
55-
w := b.WorkspaceClient(ctx)
71+
ctx := cmd.Context()
5672

5773
startTimePtr, err := parseTimeToUnixMillis(startTimeStr)
5874
if err != nil {

0 commit comments

Comments
 (0)