Skip to content

Commit d4d6736

Browse files
authored
pipelines history: new command for listing pipeline updates, with max results and json flag (#3285)
## Changes pipelines history: new command for listing pipeline updates ➜ ../.databricks/pipelines history --help Retrieve past runs for a pipeline identified by KEY, the unique name of the pipeline as defined in its YAML file. Usage: pipelines history [flags] [KEY] Filter Flags: --end-time string Filter updates before this time (format: 2025-01-15T10:30:00Z) --start-time string Filter updates after this time (format: 2025-01-15T10:30:00Z) ## Tests unit tests for timestamp binary search functions Example output: <img width="562" height="614" alt="image" src="https://github.com/user-attachments/assets/64283e9e-4684-410c-bb58-5286d040f636" />
1 parent 146dce6 commit d4d6736

File tree

7 files changed

+560
-39
lines changed

7 files changed

+560
-39
lines changed

acceptance/pipelines/install-pipelines-cli/output.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Available Commands:
1616
destroy Destroy a pipelines project
1717
dry-run Validate correctness of the pipeline's graph
1818
help Help about any command
19+
history Retrieve past runs for a pipeline
1920
init Initialize a new pipelines project
2021
logs Retrieve events for a pipeline
2122
open Open a pipeline in the browser
@@ -61,6 +62,7 @@ Available Commands:
6162
destroy Destroy a pipelines project
6263
dry-run Validate correctness of the pipeline's graph
6364
help Help about any command
65+
history Retrieve past runs for a pipeline
6466
init Initialize a new pipelines project
6567
logs Retrieve events for a pipeline
6668
open Open a pipeline in the browser
@@ -99,6 +101,7 @@ Available Commands:
99101
destroy Destroy a pipelines project
100102
dry-run Validate correctness of the pipeline's graph
101103
help Help about any command
104+
history Retrieve past runs for a pipeline
102105
init Initialize a new pipelines project
103106
logs Retrieve events for a pipeline
104107
open Open a pipeline in the browser

cmd/pipelines/history.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package pipelines
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/databricks/cli/bundle"
7+
"github.com/databricks/cli/bundle/phases"
8+
"github.com/databricks/cli/bundle/statemgmt"
9+
"github.com/databricks/cli/cmd/bundle/utils"
10+
"github.com/databricks/cli/cmd/root"
11+
"github.com/databricks/cli/libs/cmdgroup"
12+
"github.com/databricks/cli/libs/cmdio"
13+
"github.com/databricks/cli/libs/logdiag"
14+
"github.com/databricks/databricks-sdk-go/service/pipelines"
15+
"github.com/spf13/cobra"
16+
)
17+
18+
func historyCommand() *cobra.Command {
19+
cmd := &cobra.Command{
20+
Use: "history [flags] [KEY]",
21+
Args: root.MaximumNArgs(1),
22+
Short: "Retrieve past runs for a pipeline",
23+
Long: `Retrieve past runs for a pipeline identified by KEY, the unique name of the pipeline as defined in its YAML file.`,
24+
}
25+
26+
var startTimeStr string
27+
var endTimeStr string
28+
29+
type pipelineHistoryData struct {
30+
Key string
31+
Updates []pipelines.UpdateInfo
32+
}
33+
34+
historyGroup := cmdgroup.NewFlagGroup("Filter")
35+
historyGroup.FlagSet().StringVar(&startTimeStr, "start-time", "", "Filter updates after this time (format: 2025-01-15T10:30:00Z)")
36+
historyGroup.FlagSet().StringVar(&endTimeStr, "end-time", "", "Filter updates before this time (format: 2025-01-15T10:30:00Z)")
37+
wrappedCmd := cmdgroup.NewCommandWithGroupFlag(cmd)
38+
wrappedCmd.AddFlagGroup(historyGroup)
39+
40+
cmd.RunE = func(cmd *cobra.Command, args []string) error {
41+
ctx := logdiag.InitContext(cmd.Context())
42+
cmd.SetContext(ctx)
43+
44+
b := utils.ConfigureBundleWithVariables(cmd)
45+
if b == nil || logdiag.HasError(ctx) {
46+
return root.ErrAlreadyPrinted
47+
}
48+
49+
phases.Initialize(ctx, b)
50+
if logdiag.HasError(ctx) {
51+
return root.ErrAlreadyPrinted
52+
}
53+
54+
// Load the deployment state to get pipeline IDs from resource
55+
bundle.ApplySeqContext(ctx, b,
56+
statemgmt.StatePull(),
57+
statemgmt.Load(),
58+
)
59+
if logdiag.HasError(ctx) {
60+
return root.ErrAlreadyPrinted
61+
}
62+
63+
key, err := resolvePipelineArgument(ctx, b, args)
64+
if err != nil {
65+
return err
66+
}
67+
68+
pipelineId, err := resolvePipelineIdFromKey(ctx, b, key)
69+
if err != nil {
70+
return err
71+
}
72+
73+
w := b.WorkspaceClient()
74+
75+
startTimePtr, err := parseTimeToUnixMillis(startTimeStr)
76+
if err != nil {
77+
return err
78+
}
79+
80+
endTimePtr, err := parseTimeToUnixMillis(endTimeStr)
81+
if err != nil {
82+
return err
83+
}
84+
85+
updates, err := fetchPipelineUpdates(ctx, w, startTimePtr, endTimePtr, pipelineId)
86+
if err != nil {
87+
return fmt.Errorf("failed to fetch pipeline updates: %w", err)
88+
}
89+
90+
data := pipelineHistoryData{
91+
Key: key,
92+
Updates: updates,
93+
}
94+
return cmdio.RenderWithTemplate(ctx, data, "", pipelineHistoryTemplate)
95+
}
96+
97+
return cmd
98+
}

0 commit comments

Comments
 (0)