forked from grafadruid/go-druid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
supervisor_types.go
261 lines (235 loc) · 7.89 KB
/
supervisor_types.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
package druid
// InputIngestionSpec is the root-level type defining an ingestion spec used
// by Apache Druid.
type InputIngestionSpec struct {
Type string `json:"type"`
DataSchema *DataSchema `json:"dataSchema,omitempty"`
IOConfig *IOConfig `json:"ioConfig,omitempty"`
TuningConfig *TuningConfig `json:"tuningConfig,omitempty"`
}
// IngestionSpecData is the core supervisor specification data returned by druid supervisor APIs.
// It is a part of OutputIngestionSpec.
type IngestionSpecData struct {
DataSchema *DataSchema `json:"dataSchema,omitempty"`
IOConfig *IOConfig `json:"ioConfig,omitempty"`
TuningConfig *TuningConfig `json:"tuningConfig,omitempty"`
}
// OutputIngestionSpec is full supervisor specification format returned by druid supervisor APIs.
type OutputIngestionSpec struct {
Type string `json:"type"`
Context string `json:"context"`
Suspended bool `json:"suspended"`
Spec *IngestionSpecData `json:"spec"`
}
// SupervisorAuditHistory is audit data for supervisor reurned by supervisor audit history APIs.
type SupervisorAuditHistory struct {
Spec OutputIngestionSpec `json:"spec"`
Version string `json:"version"`
}
// SupervisorStatusPayload is an object representing the status of supervisor.
type SupervisorStatusPayload struct {
Datasource string `json:"dataSource"`
Stream string `json:"stream"`
State string `json:"state"`
Partitions int `json:"partitions"`
Replicas int `json:"replicas"`
DurationSeconds int `json:"durationSeconds"`
Suspended bool `json:"suspended"`
}
// SupervisorStatus is a response object containing status of a supervisor alongside
// with the response metadata.
type SupervisorStatus struct {
SupervisorId string `json:"id"`
GenerationTime string `json:"generationTime"`
Payload *SupervisorStatusPayload `json:"payload"`
}
// SupervisorState is a short form of supervisor state returned by druid APIs.
type SupervisorState struct {
ID string `json:"id"`
State string `json:"state"`
DetailedState string `json:"detailedState"`
Healthy bool `json:"healthy"`
Suspended bool `json:"suspended"`
}
type SupervisorStateWithSpec struct {
SupervisorState
Spec *InputIngestionSpec `json:"spec"`
}
// defaultKafkaIngestionSpec returns a default InputIngestionSpec with basic ingestion
// specification fields initialized.
func defaultKafkaIngestionSpec() *InputIngestionSpec {
spec := &InputIngestionSpec{
Type: "kafka",
DataSchema: &DataSchema{
DataSource: "test",
TimeStampSpec: &TimestampSpec{
Column: "ts",
Format: "auto",
},
TransformSpec: &TransformSpec{
Transforms: []Transform{},
},
DimensionsSpec: &DimensionsSpec{
Dimensions: DimensionSet{},
},
GranularitySpec: &GranularitySpec{
Type: "uniform",
SegmentGranularity: "DAY",
QueryGranularity: &QueryGranularitySpec{"none"},
Rollup: false,
},
},
IOConfig: &IOConfig{
Type: "",
Topic: "",
InputFormat: &InputFormat{
Type: "json",
},
TaskDuration: "PT1H",
ConsumerProperties: &ConsumerProperties{
BootstrapServers: "",
},
UseEarliestOffset: false,
FlattenSpec: &FlattenSpec{
Fields: FieldList{},
},
},
}
return spec
}
// NewIngestionSpec returns a default InputIngestionSpec and applies any
// options passed to it.
func NewIngestionSpec(options ...IngestionSpecOptions) *InputIngestionSpec {
spec := defaultKafkaIngestionSpec()
for _, fn := range options {
fn(spec)
}
return spec
}
// IngestionSpecOptions allows for configuring a InputIngestionSpec.
type IngestionSpecOptions func(*InputIngestionSpec)
// SetType sets the type of the supervisor (IOConfig).
func SetType(stype string) IngestionSpecOptions {
return func(spec *InputIngestionSpec) {
if stype != "" {
spec.Type = stype
}
}
}
// SetIOConfigType sets the type of the supervisor IOConfig.
func SetIOConfigType(ioctype string) IngestionSpecOptions {
return func(spec *InputIngestionSpec) {
if ioctype != "" {
spec.IOConfig.Type = ioctype
}
}
}
// SetTopic sets the Kafka topic to consume data from.
func SetTopic(topic string) IngestionSpecOptions {
return func(spec *InputIngestionSpec) {
if topic != "" {
spec.IOConfig.Topic = topic
}
}
}
// SetDataSource sets the name of the dataSource used in Druid.
func SetDataSource(ds string) IngestionSpecOptions {
return func(spec *InputIngestionSpec) {
if ds != "" {
spec.DataSchema.DataSource = ds
}
}
}
// SetInputFormat sets the input format type, i.e. json, protobuf etc.
func SetInputFormat(format string) IngestionSpecOptions {
return func(spec *InputIngestionSpec) {
if format != "" {
spec.IOConfig.InputFormat.Type = format
}
}
}
// SetBrokers sets the addresses of Kafka brokers. in the list form: 'kafka01:9092,
// kafka02:9092,kafka03:9092' or as a cluster DNS: kafka.default.svc.cluster.local:9092”.
func SetBrokers(brokers string) IngestionSpecOptions {
return func(spec *InputIngestionSpec) {
if brokers != "" {
spec.IOConfig.ConsumerProperties.BootstrapServers = brokers
}
}
}
// SetTaskDuration sets the upper limit for druid ingestion task.
func SetTaskDuration(duration string) IngestionSpecOptions {
return func(spec *InputIngestionSpec) {
if duration != "" {
spec.IOConfig.TaskDuration = duration
}
}
}
// SetDimensions sets druid datasource dimensions.
func SetDimensions(dimensions DimensionSet) IngestionSpecOptions {
return func(spec *InputIngestionSpec) {
spec.DataSchema.DimensionsSpec.Dimensions = dimensions
}
}
// SetDimensionsAutodiscovery sets druid autodiscovery for datasource dimensions.
func SetDimensionsAutodiscovery(discover bool) IngestionSpecOptions {
return func(spec *InputIngestionSpec) {
spec.DataSchema.DimensionsSpec.UseSchemaDiscovery = discover
}
}
// SetUseEarliestOffset configures kafka druid ingestion supervisor to start reading
// from the earliest or latest offsets in Kafka.
func SetUseEarliestOffset(useEarliestOffset bool) IngestionSpecOptions {
return func(spec *InputIngestionSpec) {
spec.IOConfig.UseEarliestOffset = useEarliestOffset
}
}
// SetTimestampColumn sets timestamp column for the druid datasource.
func SetTimestampColumn(column string) IngestionSpecOptions {
return func(spec *InputIngestionSpec) {
if column != "" {
spec.DataSchema.TimeStampSpec = &TimestampSpec{
Column: column,
Format: "auto",
}
}
}
}
// SetGranularitySpec sets granularity spec settings that are applied at druid ingestion partitioning stage.
func SetGranularitySpec(segmentGranularity string, queryGranularity *QueryGranularitySpec, rollup bool) IngestionSpecOptions {
return func(spec *InputIngestionSpec) {
spec.DataSchema.GranularitySpec = &GranularitySpec{
Type: "uniform",
SegmentGranularity: segmentGranularity,
QueryGranularity: queryGranularity,
Rollup: rollup,
}
}
}
func SetEnvironmentDynamicConfigProvider(dynamicConfig EnvironmentVariableDynamicConfigProvider) IngestionSpecOptions {
return func(spec *InputIngestionSpec) {
spec.IOConfig.ConsumerProperties.DruidDynamicConfigProvider = &DynamicConfigProvider{dynamicConfig}
}
}
func SetMapStringDynamicConfigProvider(dynamicConfig MapStringDynamicConfigProvider) IngestionSpecOptions {
return func(spec *InputIngestionSpec) {
spec.IOConfig.ConsumerProperties.DruidDynamicConfigProvider = &DynamicConfigProvider{dynamicConfig}
}
}
// SetSQLInputSource configures sql input source.
func SetSQLInputSource(dbType, connectURI, user, password string, sqls []string) IngestionSpecOptions {
return func(spec *InputIngestionSpec) {
spec.IOConfig.InputSource = &InputSource{
Type: "sql",
SQLs: sqls,
Database: &Database{
Type: dbType,
ConnectorConfig: &ConnectorConfig{
ConnectURI: connectURI,
User: user,
Password: password,
},
},
}
}
}