-
Notifications
You must be signed in to change notification settings - Fork 2
/
table_databricks_pipeline_event.go
145 lines (128 loc) · 3.7 KB
/
table_databricks_pipeline_event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package databricks
import (
"context"
"github.com/databricks/databricks-sdk-go/service/pipelines"
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
)
//// TABLE DEFINITION
func tableDatabricksPipelineEvent(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "databricks_pipeline_event",
Description: "Retrieves events for a pipeline.",
List: &plugin.ListConfig{
ParentHydrate: listPipelines,
Hydrate: listPipelineEvents,
KeyColumns: plugin.OptionalColumns([]string{"pipeline_id"}),
},
Columns: databricksAccountColumns([]*plugin.Column{
{
Name: "id",
Description: "A time-based, globally unique id.",
Type: proto.ColumnType_STRING,
},
{
Name: "pipeline_id",
Description: "Unique identifier of pipeline.",
Type: proto.ColumnType_STRING,
},
{
Name: "event_type",
Description: "The type of event.",
Type: proto.ColumnType_STRING,
},
{
Name: "level",
Description: "The severity level of the event.",
Type: proto.ColumnType_STRING,
},
{
Name: "maturity_level",
Description: "The maturity level of the event.",
Type: proto.ColumnType_STRING,
},
{
Name: "message",
Description: "The display message associated with the event.",
Type: proto.ColumnType_STRING,
},
{
Name: "timestamp",
Description: "The time of the event.",
Type: proto.ColumnType_TIMESTAMP,
},
// JSON fields
{
Name: "error",
Description: "Information about an error captured by the event.",
Type: proto.ColumnType_JSON,
},
{
Name: "origin",
Description: "Describes where the event originates from.",
Type: proto.ColumnType_JSON,
},
{
Name: "sequence",
Description: "A sequencing object to identify and order events.",
Type: proto.ColumnType_JSON,
},
// Standard Steampipe columns
{
Name: "title",
Description: "The title of the resource.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Id"),
},
}),
}
}
type pipelineEventInfo struct {
pipelines.PipelineEvent
PipelineId string
}
//// LIST FUNCTION
func listPipelineEvents(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
logger := plugin.Logger(ctx)
pipelineId := h.Item.(pipelines.PipelineStateInfo).PipelineId
if d.EqualsQualString("pipeline_id") != "" && d.EqualsQualString("pipeline_id") != pipelineId {
return nil, nil
}
// Limiting the results
maxLimit := int32(250)
if d.QueryContext.Limit != nil {
limit := int32(*d.QueryContext.Limit)
if limit < maxLimit {
maxLimit = limit
}
}
request := pipelines.ListPipelineEventsRequest{
MaxResults: int(maxLimit),
PipelineId: pipelineId,
}
// Create client
client, err := getWorkspaceClient(ctx, d)
if err != nil {
logger.Error("databricks_pipeline_event.listPipelineEvents", "connection_error", err)
return nil, err
}
for {
response, err := client.Pipelines.Impl().ListPipelineEvents(ctx, request)
if err != nil {
logger.Error("databricks_pipeline_event.listPipelineEvents", "api_error", err)
return nil, err
}
for _, item := range response.Events {
d.StreamListItem(ctx, pipelineEventInfo{item, pipelineId})
// Context can be cancelled due to manual cancellation or if the limit has been hit
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
if response.NextPageToken == "" {
return nil, nil
}
request.PageToken = response.NextPageToken
}
}