forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.go
1080 lines (958 loc) · 34.7 KB
/
dashboard.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package influxdb
import (
"context"
"encoding/json"
"fmt"
"net/url"
"sort"
"time"
)
// ErrDashboardNotFound is the error msg for a missing dashboard.
const ErrDashboardNotFound = "dashboard not found"
// ErrCellNotFound is the error msg for a missing cell.
const ErrCellNotFound = "cell not found"
// ErrViewNotFound is the error msg for a missing View.
const ErrViewNotFound = "view not found"
// ops for dashboard service.
const (
OpFindDashboardByID = "FindDashboardByID"
OpFindDashboards = "FindDashboards"
OpCreateDashboard = "CreateDashboard"
OpUpdateDashboard = "UpdateDashboard"
OpAddDashboardCell = "AddDashboardCell"
OpRemoveDashboardCell = "RemoveDashboardCell"
OpUpdateDashboardCell = "UpdateDashboardCell"
OpGetDashboardCellView = "GetDashboardCellView"
OpUpdateDashboardCellView = "UpdateDashboardCellView"
OpDeleteDashboard = "DeleteDashboard"
OpReplaceDashboardCells = "ReplaceDashboardCells"
)
// DashboardService represents a service for managing dashboard data.
type DashboardService interface {
// FindDashboardByID returns a single dashboard by ID.
FindDashboardByID(ctx context.Context, id ID) (*Dashboard, error)
// FindDashboards returns a list of dashboards that match filter and the total count of matching dashboards.
// Additional options provide pagination & sorting.
FindDashboards(ctx context.Context, filter DashboardFilter, opts FindOptions) ([]*Dashboard, int, error)
// CreateDashboard creates a new dashboard and sets b.ID with the new identifier.
CreateDashboard(ctx context.Context, b *Dashboard) error
// UpdateDashboard updates a single dashboard with changeset.
// Returns the new dashboard state after update.
UpdateDashboard(ctx context.Context, id ID, upd DashboardUpdate) (*Dashboard, error)
// AddDashboardCell adds a cell to a dashboard.
AddDashboardCell(ctx context.Context, id ID, c *Cell, opts AddDashboardCellOptions) error
// RemoveDashboardCell removes a dashboard.
RemoveDashboardCell(ctx context.Context, dashboardID, cellID ID) error
// UpdateDashboardCell replaces the dashboard cell with the provided ID.
UpdateDashboardCell(ctx context.Context, dashboardID, cellID ID, upd CellUpdate) (*Cell, error)
// GetDashboardCellView retrieves a dashboard cells view.
GetDashboardCellView(ctx context.Context, dashboardID, cellID ID) (*View, error)
// UpdateDashboardCellView retrieves a dashboard cells view.
UpdateDashboardCellView(ctx context.Context, dashboardID, cellID ID, upd ViewUpdate) (*View, error)
// DeleteDashboard removes a dashboard by ID.
DeleteDashboard(ctx context.Context, id ID) error
// ReplaceDashboardCells replaces all cells in a dashboard
ReplaceDashboardCells(ctx context.Context, id ID, c []*Cell) error
}
// Dashboard represents all visual and query data for a dashboard.
type Dashboard struct {
ID ID `json:"id,omitempty"`
OrganizationID ID `json:"orgID,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
Cells []*Cell `json:"cells"`
Meta DashboardMeta `json:"meta"`
}
// DashboardMeta contains meta information about dashboards
type DashboardMeta struct {
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// DefaultDashboardFindOptions are the default find options for dashboards
var DefaultDashboardFindOptions = FindOptions{
SortBy: "ID",
}
// SortDashboards sorts a slice of dashboards by a field.
func SortDashboards(opts FindOptions, ds []*Dashboard) {
var sorter func(i, j int) bool
switch opts.SortBy {
case "CreatedAt":
sorter = func(i, j int) bool {
return ds[j].Meta.CreatedAt.After(ds[i].Meta.CreatedAt)
}
case "UpdatedAt":
sorter = func(i, j int) bool {
return ds[j].Meta.UpdatedAt.After(ds[i].Meta.UpdatedAt)
}
case "Name":
sorter = func(i, j int) bool {
return ds[i].Name < ds[j].Name
}
default:
sorter = func(i, j int) bool {
if opts.Descending {
return ds[i].ID > ds[j].ID
}
return ds[i].ID < ds[j].ID
}
}
sort.Slice(ds, sorter)
}
// Cell holds positional information about a cell on dashboard and a reference to a cell.
type Cell struct {
ID ID `json:"id,omitempty"`
CellProperty
View *View `json:"-"`
}
// Marshals the cell
func (c *Cell) MarshalJSON() ([]byte, error) {
type resp struct {
ID *ID `json:"id,omitempty"`
Name string `json:"name,omitempty"`
ViewProperties json.RawMessage `json:"properties,omitempty"`
CellProperty
}
response := resp{
CellProperty: c.CellProperty,
}
if c.ID != 0 {
response.ID = &c.ID
}
if c.View != nil {
response.Name = c.View.Name
rawJSON, err := MarshalViewPropertiesJSON(c.View.Properties)
if err != nil {
return nil, err
}
response.ViewProperties = rawJSON
}
return json.Marshal(response)
}
func (c *Cell) UnmarshalJSON(b []byte) error {
var newCell struct {
ID ID `json:"id,omitempty"`
Name string `json:"name,omitempty"`
ViewProperties json.RawMessage `json:"properties,omitempty"`
CellProperty
}
if err := json.Unmarshal(b, &newCell); err != nil {
return err
}
c.ID = newCell.ID
c.CellProperty = newCell.CellProperty
if newCell.Name != "" {
if c.View == nil {
c.View = new(View)
}
c.View.Name = newCell.Name
}
props, err := UnmarshalViewPropertiesJSON(newCell.ViewProperties)
if err == nil {
if c.View == nil {
c.View = new(View)
}
c.View.Properties = props
}
return nil
}
// CellProperty contains the properties of a cell.
type CellProperty struct {
X int32 `json:"x"`
Y int32 `json:"y"`
W int32 `json:"w"`
H int32 `json:"h"`
}
// DashboardFilter is a filter for dashboards.
type DashboardFilter struct {
IDs []*ID
OrganizationID *ID
Organization *string
}
// QueryParams turns a dashboard filter into query params
//
// It implements PagingFilter.
func (f DashboardFilter) QueryParams() map[string][]string {
qp := url.Values{}
for _, id := range f.IDs {
if id != nil {
qp.Add("id", id.String())
}
}
if f.OrganizationID != nil {
qp.Add("orgID", f.OrganizationID.String())
}
if f.Organization != nil {
qp.Add("org", *f.Organization)
}
return qp
}
// DashboardUpdate is the patch structure for a dashboard.
type DashboardUpdate struct {
Name *string `json:"name"`
Description *string `json:"description"`
Cells *[]*Cell `json:"cells"`
}
// Apply applies an update to a dashboard.
func (u DashboardUpdate) Apply(d *Dashboard) error {
if u.Name != nil {
d.Name = *u.Name
}
if u.Description != nil {
d.Description = *u.Description
}
if u.Cells != nil {
d.Cells = *u.Cells
}
return nil
}
// Valid returns an error if the dashboard update is invalid.
func (u DashboardUpdate) Valid() *Error {
if u.Name == nil && u.Description == nil {
return &Error{
Code: EInvalid,
Msg: "must update at least one attribute",
}
}
return nil
}
// AddDashboardCellOptions are options for adding a dashboard.
type AddDashboardCellOptions struct {
View *View
}
// CellUpdate is the patch structure for a cell.
type CellUpdate struct {
X *int32 `json:"x"`
Y *int32 `json:"y"`
W *int32 `json:"w"`
H *int32 `json:"h"`
}
// Apply applies an update to a Cell.
func (u CellUpdate) Apply(c *Cell) error {
if u.X != nil {
c.X = *u.X
}
if u.Y != nil {
c.Y = *u.Y
}
if u.W != nil {
c.W = *u.W
}
if u.H != nil {
c.H = *u.H
}
return nil
}
// Valid returns an error if the cell update is invalid.
func (u CellUpdate) Valid() *Error {
if u.H == nil && u.W == nil && u.Y == nil && u.X == nil {
return &Error{
Code: EInvalid,
Msg: "must update at least one attribute",
}
}
return nil
}
// ViewUpdate is a struct for updating Views.
type ViewUpdate struct {
ViewContentsUpdate
Properties ViewProperties
}
// Valid validates the update struct. It expects minimal values to be set.
func (u ViewUpdate) Valid() *Error {
_, ok := u.Properties.(EmptyViewProperties)
if u.Name == nil && ok {
return &Error{
Code: EInvalid,
Msg: "expected at least one attribute to be updated",
}
}
return nil
}
// Apply updates a view with the view updates properties.
func (u ViewUpdate) Apply(v *View) error {
if err := u.Valid(); err != nil {
return err
}
if u.Name != nil {
v.Name = *u.Name
}
if u.Properties != nil {
v.Properties = u.Properties
}
return nil
}
// ViewContentsUpdate is a struct for updating the non properties content of a View.
type ViewContentsUpdate struct {
Name *string `json:"name"`
}
// ViewFilter represents a set of filter that restrict the returned results.
type ViewFilter struct {
ID *ID
Types []string
}
// View holds positional and visual information for a View.
type View struct {
ViewContents
Properties ViewProperties
}
// ViewContents is the id and name of a specific view.
type ViewContents struct {
ID ID `json:"id,omitempty"`
Name string `json:"name"`
}
// Values for all supported view property types.
const (
ViewPropertyTypeCheck = "check"
ViewPropertyTypeGauge = "gauge"
ViewPropertyTypeHeatMap = "heatmap"
ViewPropertyTypeHistogram = "histogram"
ViewPropertyTypeLogViewer = "log-viewer"
ViewPropertyTypeMarkdown = "markdown"
ViewPropertyTypeScatter = "scatter"
ViewPropertyTypeSingleStat = "single-stat"
ViewPropertyTypeSingleStatPlusLine = "line-plus-single-stat"
ViewPropertyTypeTable = "table"
ViewPropertyTypeXY = "xy"
ViewPropertyTypeMosaic = "mosaic"
ViewPropertyTypeBand = "band"
)
// ViewProperties is used to mark other structures as conforming to a View.
type ViewProperties interface {
viewProperties()
GetType() string
}
// EmptyViewProperties is visualization that has no values
type EmptyViewProperties struct{}
func (v EmptyViewProperties) viewProperties() {}
func (v EmptyViewProperties) GetType() string { return "" }
// UnmarshalViewPropertiesJSON unmarshals JSON bytes into a ViewProperties.
func UnmarshalViewPropertiesJSON(b []byte) (ViewProperties, error) {
var v struct {
B json.RawMessage `json:"properties"`
}
if err := json.Unmarshal(b, &v); err != nil {
return nil, err
}
if len(v.B) == 0 {
// Then there wasn't any visualization field, so there's no need unmarshal it
return EmptyViewProperties{}, nil
}
var t struct {
Shape string `json:"shape"`
Type string `json:"type"`
}
if err := json.Unmarshal(v.B, &t); err != nil {
return nil, err
}
var vis ViewProperties
switch t.Shape {
case "chronograf-v2":
switch t.Type {
case ViewPropertyTypeCheck:
var cv CheckViewProperties
if err := json.Unmarshal(v.B, &cv); err != nil {
return nil, err
}
vis = cv
case ViewPropertyTypeXY:
var xyv XYViewProperties
if err := json.Unmarshal(v.B, &xyv); err != nil {
return nil, err
}
vis = xyv
case ViewPropertyTypeSingleStat:
var ssv SingleStatViewProperties
if err := json.Unmarshal(v.B, &ssv); err != nil {
return nil, err
}
vis = ssv
case ViewPropertyTypeGauge:
var gv GaugeViewProperties
if err := json.Unmarshal(v.B, &gv); err != nil {
return nil, err
}
vis = gv
case ViewPropertyTypeTable:
var tv TableViewProperties
if err := json.Unmarshal(v.B, &tv); err != nil {
return nil, err
}
vis = tv
case ViewPropertyTypeMarkdown:
var mv MarkdownViewProperties
if err := json.Unmarshal(v.B, &mv); err != nil {
return nil, err
}
vis = mv
case ViewPropertyTypeLogViewer: // happens in log viewer stays in log viewer.
var lv LogViewProperties
if err := json.Unmarshal(v.B, &lv); err != nil {
return nil, err
}
vis = lv
case ViewPropertyTypeSingleStatPlusLine:
var lv LinePlusSingleStatProperties
if err := json.Unmarshal(v.B, &lv); err != nil {
return nil, err
}
vis = lv
case ViewPropertyTypeHistogram:
var hv HistogramViewProperties
if err := json.Unmarshal(v.B, &hv); err != nil {
return nil, err
}
vis = hv
case ViewPropertyTypeHeatMap:
var hv HeatmapViewProperties
if err := json.Unmarshal(v.B, &hv); err != nil {
return nil, err
}
vis = hv
case ViewPropertyTypeScatter:
var sv ScatterViewProperties
if err := json.Unmarshal(v.B, &sv); err != nil {
return nil, err
}
vis = sv
case ViewPropertyTypeMosaic:
var mv MosaicViewProperties
if err := json.Unmarshal(v.B, &mv); err != nil {
return nil, err
}
vis = mv
case ViewPropertyTypeBand:
var bv BandViewProperties
if err := json.Unmarshal(v.B, &bv); err != nil {
return nil, err
}
vis = bv
}
case "empty":
var ev EmptyViewProperties
if err := json.Unmarshal(v.B, &ev); err != nil {
return nil, err
}
vis = ev
default:
return nil, fmt.Errorf("unknown shape %v", t.Shape)
}
return vis, nil
}
// MarshalViewPropertiesJSON encodes a view into JSON bytes.
func MarshalViewPropertiesJSON(v ViewProperties) ([]byte, error) {
var s interface{}
switch vis := v.(type) {
case SingleStatViewProperties:
s = struct {
Shape string `json:"shape"`
SingleStatViewProperties
}{
Shape: "chronograf-v2",
SingleStatViewProperties: vis,
}
case TableViewProperties:
s = struct {
Shape string `json:"shape"`
TableViewProperties
}{
Shape: "chronograf-v2",
TableViewProperties: vis,
}
case GaugeViewProperties:
s = struct {
Shape string `json:"shape"`
GaugeViewProperties
}{
Shape: "chronograf-v2",
GaugeViewProperties: vis,
}
case XYViewProperties:
s = struct {
Shape string `json:"shape"`
XYViewProperties
}{
Shape: "chronograf-v2",
XYViewProperties: vis,
}
case BandViewProperties:
s = struct {
Shape string `json:"shape"`
BandViewProperties
}{
Shape: "chronograf-v2",
BandViewProperties: vis,
}
case LinePlusSingleStatProperties:
s = struct {
Shape string `json:"shape"`
LinePlusSingleStatProperties
}{
Shape: "chronograf-v2",
LinePlusSingleStatProperties: vis,
}
case HistogramViewProperties:
s = struct {
Shape string `json:"shape"`
HistogramViewProperties
}{
Shape: "chronograf-v2",
HistogramViewProperties: vis,
}
case HeatmapViewProperties:
s = struct {
Shape string `json:"shape"`
HeatmapViewProperties
}{
Shape: "chronograf-v2",
HeatmapViewProperties: vis,
}
case ScatterViewProperties:
s = struct {
Shape string `json:"shape"`
ScatterViewProperties
}{
Shape: "chronograf-v2",
ScatterViewProperties: vis,
}
case MosaicViewProperties:
s = struct {
Shape string `json:"shape"`
MosaicViewProperties
}{
Shape: "chronograf-v2",
MosaicViewProperties: vis,
}
case MarkdownViewProperties:
s = struct {
Shape string `json:"shape"`
MarkdownViewProperties
}{
Shape: "chronograf-v2",
MarkdownViewProperties: vis,
}
case LogViewProperties:
s = struct {
Shape string `json:"shape"`
LogViewProperties
}{
Shape: "chronograf-v2",
LogViewProperties: vis,
}
case CheckViewProperties:
s = struct {
Shape string `json:"shape"`
CheckViewProperties
}{
Shape: "chronograf-v2",
CheckViewProperties: vis,
}
default:
s = struct {
Shape string `json:"shape"`
EmptyViewProperties
}{
Shape: "empty",
EmptyViewProperties: EmptyViewProperties{},
}
}
return json.Marshal(s)
}
// MarshalJSON encodes a view to JSON bytes.
func (v View) MarshalJSON() ([]byte, error) {
viewProperties, err := MarshalViewPropertiesJSON(v.Properties)
if err != nil {
return nil, err
}
return json.Marshal(struct {
ViewContents
ViewProperties json.RawMessage `json:"properties"`
}{
ViewContents: v.ViewContents,
ViewProperties: viewProperties,
})
}
// UnmarshalJSON decodes JSON bytes into the corresponding view type (those that implement ViewProperties).
func (c *View) UnmarshalJSON(b []byte) error {
if err := json.Unmarshal(b, &c.ViewContents); err != nil {
return err
}
v, err := UnmarshalViewPropertiesJSON(b)
if err != nil {
return err
}
c.Properties = v
return nil
}
// UnmarshalJSON decodes JSON bytes into the corresponding view update type (those that implement ViewProperties).
func (u *ViewUpdate) UnmarshalJSON(b []byte) error {
if err := json.Unmarshal(b, &u.ViewContentsUpdate); err != nil {
return err
}
v, err := UnmarshalViewPropertiesJSON(b)
if err != nil {
return err
}
u.Properties = v
return nil
}
// MarshalJSON encodes a view to JSON bytes.
func (u ViewUpdate) MarshalJSON() ([]byte, error) {
vis, err := MarshalViewPropertiesJSON(u.Properties)
if err != nil {
return nil, err
}
return json.Marshal(struct {
ViewContentsUpdate
ViewProperties json.RawMessage `json:"properties,omitempty"`
}{
ViewContentsUpdate: u.ViewContentsUpdate,
ViewProperties: vis,
})
}
// LinePlusSingleStatProperties represents options for line plus single stat view in Chronograf
type LinePlusSingleStatProperties struct {
Queries []DashboardQuery `json:"queries"`
Axes map[string]Axis `json:"axes"`
Type string `json:"type"`
Legend Legend `json:"legend"`
ViewColors []ViewColor `json:"colors"`
Prefix string `json:"prefix"`
Suffix string `json:"suffix"`
DecimalPlaces DecimalPlaces `json:"decimalPlaces"`
Note string `json:"note"`
ShowNoteWhenEmpty bool `json:"showNoteWhenEmpty"`
XColumn string `json:"xColumn"`
YColumn string `json:"yColumn"`
ShadeBelow bool `json:"shadeBelow"`
Position string `json:"position"`
TimeFormat string `json:"timeFormat"`
HoverDimension string `json:"hoverDimension"`
LegendOpacity float64 `json:"legendOpacity"`
LegendOrientationThreshold int `json:"legendOrientationThreshold"`
}
// XYViewProperties represents options for line, bar, step, or stacked view in Chronograf
type XYViewProperties struct {
Queries []DashboardQuery `json:"queries"`
Axes map[string]Axis `json:"axes"`
Type string `json:"type"`
Legend Legend `json:"legend"`
Geom string `json:"geom"` // Either "line", "step", "stacked", or "bar"
ViewColors []ViewColor `json:"colors"`
Note string `json:"note"`
ShowNoteWhenEmpty bool `json:"showNoteWhenEmpty"`
XColumn string `json:"xColumn"`
YColumn string `json:"yColumn"`
ShadeBelow bool `json:"shadeBelow"`
Position string `json:"position"`
TimeFormat string `json:"timeFormat"`
HoverDimension string `json:"hoverDimension"`
LegendOpacity float64 `json:"legendOpacity"`
LegendOrientationThreshold int `json:"legendOrientationThreshold"`
}
// BandViewProperties represents options for the band view
type BandViewProperties struct {
Queries []DashboardQuery `json:"queries"`
Axes map[string]Axis `json:"axes"`
Type string `json:"type"`
Legend Legend `json:"legend"`
Geom string `json:"geom"`
ViewColors []ViewColor `json:"colors"`
Note string `json:"note"`
ShowNoteWhenEmpty bool `json:"showNoteWhenEmpty"`
TimeFormat string `json:"timeFormat"`
HoverDimension string `json:"hoverDimension"`
XColumn string `json:"xColumn"`
YColumn string `json:"yColumn"`
UpperColumn string `json:"upperColumn"`
MainColumn string `json:"mainColumn"`
LowerColumn string `json:"lowerColumn"`
LegendOpacity float64 `json:"legendOpacity"`
LegendOrientationThreshold int `json:"legendOrientationThreshold"`
}
// CheckViewProperties represents options for a view representing a check
type CheckViewProperties struct {
Type string `json:"type"`
CheckID string `json:"checkID"`
Queries []DashboardQuery `json:"queries"`
ViewColors []string `json:"colors"`
LegendOpacity float64 `json:"legendOpacity"`
LegendOrientationThreshold int `json:"legendOrientationThreshold"`
}
// SingleStatViewProperties represents options for single stat view in Chronograf
type SingleStatViewProperties struct {
Type string `json:"type"`
Queries []DashboardQuery `json:"queries"`
Prefix string `json:"prefix"`
TickPrefix string `json:"tickPrefix"`
Suffix string `json:"suffix"`
TickSuffix string `json:"tickSuffix"`
ViewColors []ViewColor `json:"colors"`
DecimalPlaces DecimalPlaces `json:"decimalPlaces"`
Note string `json:"note"`
ShowNoteWhenEmpty bool `json:"showNoteWhenEmpty"`
LegendOpacity float64 `json:"legendOpacity"`
LegendOrientationThreshold int `json:"legendOrientationThreshold"`
}
// HistogramViewProperties represents options for histogram view in Chronograf
type HistogramViewProperties struct {
Type string `json:"type"`
Queries []DashboardQuery `json:"queries"`
ViewColors []ViewColor `json:"colors"`
XColumn string `json:"xColumn"`
FillColumns []string `json:"fillColumns"`
XDomain []float64 `json:"xDomain,omitempty"`
XAxisLabel string `json:"xAxisLabel"`
Position string `json:"position"`
BinCount int `json:"binCount"`
Note string `json:"note"`
ShowNoteWhenEmpty bool `json:"showNoteWhenEmpty"`
LegendOpacity float64 `json:"legendOpacity"`
LegendOrientationThreshold int `json:"legendOrientationThreshold"`
}
// HeatmapViewProperties represents options for heatmap view in Chronograf
type HeatmapViewProperties struct {
Type string `json:"type"`
Queries []DashboardQuery `json:"queries"`
ViewColors []string `json:"colors"`
BinSize int32 `json:"binSize"`
XColumn string `json:"xColumn"`
YColumn string `json:"yColumn"`
XDomain []float64 `json:"xDomain,omitempty"`
YDomain []float64 `json:"yDomain,omitempty"`
XAxisLabel string `json:"xAxisLabel"`
YAxisLabel string `json:"yAxisLabel"`
XPrefix string `json:"xPrefix"`
XSuffix string `json:"xSuffix"`
YPrefix string `json:"yPrefix"`
YSuffix string `json:"ySuffix"`
Note string `json:"note"`
ShowNoteWhenEmpty bool `json:"showNoteWhenEmpty"`
TimeFormat string `json:"timeFormat"`
LegendOpacity float64 `json:"legendOpacity"`
LegendOrientationThreshold int `json:"legendOrientationThreshold"`
}
// ScatterViewProperties represents options for scatter view in Chronograf
type ScatterViewProperties struct {
Type string `json:"type"`
Queries []DashboardQuery `json:"queries"`
ViewColors []string `json:"colors"`
FillColumns []string `json:"fillColumns"`
SymbolColumns []string `json:"symbolColumns"`
XColumn string `json:"xColumn"`
YColumn string `json:"yColumn"`
XDomain []float64 `json:"xDomain,omitempty"`
YDomain []float64 `json:"yDomain,omitempty"`
XAxisLabel string `json:"xAxisLabel"`
YAxisLabel string `json:"yAxisLabel"`
XPrefix string `json:"xPrefix"`
XSuffix string `json:"xSuffix"`
YPrefix string `json:"yPrefix"`
YSuffix string `json:"ySuffix"`
Note string `json:"note"`
ShowNoteWhenEmpty bool `json:"showNoteWhenEmpty"`
TimeFormat string `json:"timeFormat"`
LegendOpacity float64 `json:"legendOpacity"`
LegendOrientationThreshold int `json:"legendOrientationThreshold"`
}
// MosaicViewProperties represents options for mosaic view in Chronograf
type MosaicViewProperties struct {
Type string `json:"type"`
Queries []DashboardQuery `json:"queries"`
ViewColors []string `json:"colors"`
FillColumns []string `json:"fillColumns"`
XColumn string `json:"xColumn"`
YSeriesColumns []string `json:"ySeriesColumns"`
XDomain []float64 `json:"xDomain,omitempty"`
YDomain []float64 `json:"yDomain,omitempty"`
XAxisLabel string `json:"xAxisLabel"`
YAxisLabel string `json:"yAxisLabel"`
XPrefix string `json:"xPrefix"`
XSuffix string `json:"xSuffix"`
YPrefix string `json:"yPrefix"`
YSuffix string `json:"ySuffix"`
Note string `json:"note"`
ShowNoteWhenEmpty bool `json:"showNoteWhenEmpty"`
TimeFormat string `json:"timeFormat"`
LegendOpacity float64 `json:"legendOpacity"`
LegendOrientationThreshold int `json:"legendOrientationThreshold"`
}
// GaugeViewProperties represents options for gauge view in Chronograf
type GaugeViewProperties struct {
Type string `json:"type"`
Queries []DashboardQuery `json:"queries"`
Prefix string `json:"prefix"`
TickPrefix string `json:"tickPrefix"`
Suffix string `json:"suffix"`
TickSuffix string `json:"tickSuffix"`
ViewColors []ViewColor `json:"colors"`
DecimalPlaces DecimalPlaces `json:"decimalPlaces"`
Note string `json:"note"`
ShowNoteWhenEmpty bool `json:"showNoteWhenEmpty"`
}
// TableViewProperties represents options for table view in Chronograf
type TableViewProperties struct {
Type string `json:"type"`
Queries []DashboardQuery `json:"queries"`
ViewColors []ViewColor `json:"colors"`
TableOptions TableOptions `json:"tableOptions"`
FieldOptions []RenamableField `json:"fieldOptions"`
TimeFormat string `json:"timeFormat"`
DecimalPlaces DecimalPlaces `json:"decimalPlaces"`
Note string `json:"note"`
ShowNoteWhenEmpty bool `json:"showNoteWhenEmpty"`
}
type MarkdownViewProperties struct {
Type string `json:"type"`
Note string `json:"note"`
}
// LogViewProperties represents options for log viewer in Chronograf.
type LogViewProperties struct {
Type string `json:"type"`
Columns []LogViewerColumn `json:"columns"`
}
// LogViewerColumn represents a specific column in a Log Viewer.
type LogViewerColumn struct {
Name string `json:"name"`
Position int32 `json:"position"`
Settings []LogColumnSetting `json:"settings"`
}
// LogColumnSetting represent the settings for a specific column of a Log Viewer.
type LogColumnSetting struct {
Type string `json:"type"`
Value string `json:"value"`
Name string `json:"name,omitempty"`
}
func (XYViewProperties) viewProperties() {}
func (BandViewProperties) viewProperties() {}
func (LinePlusSingleStatProperties) viewProperties() {}
func (SingleStatViewProperties) viewProperties() {}
func (HistogramViewProperties) viewProperties() {}
func (HeatmapViewProperties) viewProperties() {}
func (ScatterViewProperties) viewProperties() {}
func (MosaicViewProperties) viewProperties() {}
func (GaugeViewProperties) viewProperties() {}
func (TableViewProperties) viewProperties() {}
func (MarkdownViewProperties) viewProperties() {}
func (LogViewProperties) viewProperties() {}
func (CheckViewProperties) viewProperties() {}
func (v XYViewProperties) GetType() string { return v.Type }
func (v BandViewProperties) GetType() string { return v.Type }
func (v LinePlusSingleStatProperties) GetType() string { return v.Type }
func (v SingleStatViewProperties) GetType() string { return v.Type }
func (v HistogramViewProperties) GetType() string { return v.Type }
func (v HeatmapViewProperties) GetType() string { return v.Type }
func (v ScatterViewProperties) GetType() string { return v.Type }
func (v MosaicViewProperties) GetType() string { return v.Type }
func (v GaugeViewProperties) GetType() string { return v.Type }
func (v TableViewProperties) GetType() string { return v.Type }
func (v MarkdownViewProperties) GetType() string { return v.Type }
func (v LogViewProperties) GetType() string { return v.Type }
func (v CheckViewProperties) GetType() string { return v.Type }
/////////////////////////////
// Old Chronograf Types
/////////////////////////////
// DashboardQuery represents a query used in a dashboard cell
type DashboardQuery struct {
Text string `json:"text"`
EditMode string `json:"editMode"` // Either "builder" or "advanced"
Name string `json:"name"` // Term or phrase that refers to the query
BuilderConfig BuilderConfig `json:"builderConfig"`
}
type BuilderConfig struct {
Buckets []string `json:"buckets"`
Tags []struct {
Key string `json:"key"`
Values []string `json:"values"`
AggregateFunctionType string `json:"aggregateFunctionType"`
} `json:"tags"`
Functions []struct {
Name string `json:"name"`
} `json:"functions"`
AggregateWindow struct {
Period string `json:"period"`
FillValues bool `json:"fillValues"`
} `json:"aggregateWindow"`
}
// MarshalJSON is necessary for the time being. UI keeps breaking
// b/c it relies on these slices being populated/not nil. Other
// consumers may have same issue.
func (b BuilderConfig) MarshalJSON() ([]byte, error) {
type alias BuilderConfig
copyCfg := alias(b)
if copyCfg.Buckets == nil {
copyCfg.Buckets = []string{}
}
if copyCfg.Tags == nil {