2018-07-16 15:23:54 +00:00
|
|
|
package platform
|
2018-07-05 22:07:53 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2018-12-17 16:13:39 +00:00
|
|
|
// ErrViewNotFound is the error msg for a missing View.
|
|
|
|
const ErrViewNotFound = "view not found"
|
2018-07-16 15:23:54 +00:00
|
|
|
|
2018-12-18 16:19:11 +00:00
|
|
|
// ops for view.
|
|
|
|
const (
|
|
|
|
OpFindViewByID = "FindViewByID"
|
|
|
|
OpFindViews = "FindViews"
|
|
|
|
OpCreateView = "CreateView"
|
|
|
|
OpUpdateView = "UpdateView"
|
|
|
|
OpDeleteView = "DeleteView"
|
|
|
|
)
|
|
|
|
|
2019-01-04 19:12:35 +00:00
|
|
|
// NOTE: This service has been DEPRECATED and should be removed. Views are now
|
|
|
|
// resources that are nested beneath dashboards.
|
|
|
|
//
|
2018-08-07 20:10:05 +00:00
|
|
|
// ViewService represents a service for managing View data.
|
|
|
|
type ViewService interface {
|
|
|
|
// FindViewByID returns a single View by ID.
|
|
|
|
FindViewByID(ctx context.Context, id ID) (*View, error)
|
2018-07-09 21:22:34 +00:00
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
// FindViews returns a list of Views that match filter and the total count of matching Views.
|
2018-07-05 22:07:53 +00:00
|
|
|
// Additional options provide pagination & sorting.
|
2018-08-07 20:10:05 +00:00
|
|
|
FindViews(ctx context.Context, filter ViewFilter) ([]*View, int, error)
|
2018-07-05 22:07:53 +00:00
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
// CreateView creates a new View and sets b.ID with the new identifier.
|
|
|
|
CreateView(ctx context.Context, b *View) error
|
2018-07-05 22:07:53 +00:00
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
// UpdateView updates a single View with changeset.
|
|
|
|
// Returns the new View state after update.
|
|
|
|
UpdateView(ctx context.Context, id ID, upd ViewUpdate) (*View, error)
|
2018-07-05 22:07:53 +00:00
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
// DeleteView removes a View by ID.
|
|
|
|
DeleteView(ctx context.Context, id ID) error
|
2018-07-05 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
// ViewUpdate is a struct for updating Views.
|
|
|
|
type ViewUpdate struct {
|
|
|
|
ViewContentsUpdate
|
|
|
|
Properties ViewProperties
|
2018-07-09 21:22:34 +00:00
|
|
|
}
|
|
|
|
|
2018-07-16 15:23:54 +00:00
|
|
|
// Valid validates the update struct. It expects minimal values to be set.
|
2018-12-17 16:13:39 +00:00
|
|
|
func (u ViewUpdate) Valid() *Error {
|
2018-08-07 20:10:05 +00:00
|
|
|
_, ok := u.Properties.(EmptyViewProperties)
|
2018-07-16 15:23:54 +00:00
|
|
|
if u.Name == nil && ok {
|
2018-12-17 16:13:39 +00:00
|
|
|
return &Error{
|
|
|
|
Code: EInvalid,
|
|
|
|
Msg: "expected at least one attribute to be updated",
|
|
|
|
}
|
2018-07-16 15:23:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-01-04 19:12:35 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
// ViewContentsUpdate is a struct for updating the non properties content of a View.
|
|
|
|
type ViewContentsUpdate struct {
|
2018-07-09 21:22:34 +00:00
|
|
|
Name *string `json:"name"`
|
2018-07-05 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
// ViewFilter represents a set of filter that restrict the returned results.
|
|
|
|
type ViewFilter struct {
|
2018-12-08 01:15:24 +00:00
|
|
|
ID *ID
|
|
|
|
Types []string
|
2018-07-05 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
// View holds positional and visual information for a View.
|
|
|
|
type View struct {
|
|
|
|
ViewContents
|
|
|
|
Properties ViewProperties
|
2018-07-05 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
2018-10-03 00:21:04 +00:00
|
|
|
// ViewContents is the id and name of a specific view.
|
2018-08-07 20:10:05 +00:00
|
|
|
type ViewContents struct {
|
2018-10-12 01:06:43 +00:00
|
|
|
ID ID `json:"id,omitempty"`
|
2018-07-09 21:22:34 +00:00
|
|
|
Name string `json:"name"`
|
2018-07-05 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
2018-10-03 00:21:04 +00:00
|
|
|
// ViewProperties is used to mark other structures as conforming to a View.
|
2018-08-07 20:10:05 +00:00
|
|
|
type ViewProperties interface {
|
2018-10-03 00:21:04 +00:00
|
|
|
viewProperties()
|
2018-12-08 01:15:24 +00:00
|
|
|
GetType() string
|
2018-07-05 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
// EmptyViewProperties is visualization that has no values
|
|
|
|
type EmptyViewProperties struct{}
|
2018-07-09 22:19:34 +00:00
|
|
|
|
2018-10-03 00:21:04 +00:00
|
|
|
func (v EmptyViewProperties) viewProperties() {}
|
2018-07-09 22:19:34 +00:00
|
|
|
|
2018-12-08 01:15:24 +00:00
|
|
|
func (v EmptyViewProperties) GetType() string { return "" }
|
|
|
|
|
2018-10-03 00:21:04 +00:00
|
|
|
// UnmarshalViewPropertiesJSON unmarshals JSON bytes into a ViewProperties.
|
2018-08-07 20:10:05 +00:00
|
|
|
func UnmarshalViewPropertiesJSON(b []byte) (ViewProperties, error) {
|
2018-07-05 22:07:53 +00:00
|
|
|
var v struct {
|
2018-08-07 20:10:05 +00:00
|
|
|
B json.RawMessage `json:"properties"`
|
2018-07-05 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := json.Unmarshal(b, &v); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-07-09 22:19:34 +00:00
|
|
|
if len(v.B) == 0 {
|
2018-08-07 20:10:05 +00:00
|
|
|
// Then there wasn't any visualization field, so there's no need unmarshal it
|
|
|
|
return EmptyViewProperties{}, nil
|
2018-07-09 22:19:34 +00:00
|
|
|
}
|
|
|
|
|
2018-07-05 22:07:53 +00:00
|
|
|
var t struct {
|
2018-08-07 20:10:05 +00:00
|
|
|
Shape string `json:"shape"`
|
2018-09-27 17:46:48 +00:00
|
|
|
Type string `json:"type"`
|
2018-07-05 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := json.Unmarshal(v.B, &t); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
var vis ViewProperties
|
|
|
|
switch t.Shape {
|
2018-09-27 17:46:48 +00:00
|
|
|
case "chronograf-v2":
|
|
|
|
switch t.Type {
|
2018-11-20 21:59:27 +00:00
|
|
|
case "xy":
|
|
|
|
var xyv XYViewProperties
|
|
|
|
if err := json.Unmarshal(v.B, &xyv); err != nil {
|
2018-09-27 17:46:48 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2018-11-20 21:59:27 +00:00
|
|
|
vis = xyv
|
2018-09-27 17:46:48 +00:00
|
|
|
case "single-stat":
|
|
|
|
var ssv SingleStatViewProperties
|
|
|
|
if err := json.Unmarshal(v.B, &ssv); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
vis = ssv
|
|
|
|
case "gauge":
|
|
|
|
var gv GaugeViewProperties
|
|
|
|
if err := json.Unmarshal(v.B, &gv); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
vis = gv
|
2018-10-01 20:33:27 +00:00
|
|
|
case "table":
|
|
|
|
var tv TableViewProperties
|
|
|
|
if err := json.Unmarshal(v.B, &tv); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
vis = tv
|
2018-11-28 01:03:13 +00:00
|
|
|
case "markdown":
|
|
|
|
var mv MarkdownViewProperties
|
|
|
|
if err := json.Unmarshal(v.B, &mv); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
vis = mv
|
2018-10-03 00:21:04 +00:00
|
|
|
case "log-viewer": // 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
|
2018-10-03 17:17:14 +00:00
|
|
|
case "line-plus-single-stat":
|
|
|
|
var lv LinePlusSingleStatProperties
|
|
|
|
if err := json.Unmarshal(v.B, &lv); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
vis = lv
|
2018-09-27 17:46:48 +00:00
|
|
|
}
|
2018-07-09 22:19:34 +00:00
|
|
|
case "empty":
|
2018-08-07 20:10:05 +00:00
|
|
|
var ev EmptyViewProperties
|
2018-07-09 22:19:34 +00:00
|
|
|
if err := json.Unmarshal(v.B, &ev); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
vis = ev
|
2018-07-05 22:07:53 +00:00
|
|
|
default:
|
2018-08-07 20:10:05 +00:00
|
|
|
return nil, fmt.Errorf("unknown type %v", t.Shape)
|
2018-07-05 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return vis, nil
|
|
|
|
}
|
|
|
|
|
2018-10-03 00:21:04 +00:00
|
|
|
// MarshalViewPropertiesJSON encodes a view into JSON bytes.
|
2018-08-07 20:10:05 +00:00
|
|
|
func MarshalViewPropertiesJSON(v ViewProperties) ([]byte, error) {
|
2018-07-05 22:07:53 +00:00
|
|
|
var s interface{}
|
|
|
|
switch vis := v.(type) {
|
2018-09-27 17:46:48 +00:00
|
|
|
case SingleStatViewProperties:
|
|
|
|
s = struct {
|
|
|
|
Shape string `json:"shape"`
|
|
|
|
SingleStatViewProperties
|
|
|
|
}{
|
2018-10-08 18:32:29 +00:00
|
|
|
Shape: "chronograf-v2",
|
2018-09-27 17:46:48 +00:00
|
|
|
SingleStatViewProperties: vis,
|
|
|
|
}
|
2018-10-01 20:33:27 +00:00
|
|
|
case TableViewProperties:
|
|
|
|
s = struct {
|
|
|
|
Shape string `json:"shape"`
|
|
|
|
TableViewProperties
|
|
|
|
}{
|
|
|
|
Shape: "chronograf-v2",
|
|
|
|
TableViewProperties: vis,
|
|
|
|
}
|
2018-09-27 17:46:48 +00:00
|
|
|
case GaugeViewProperties:
|
|
|
|
s = struct {
|
|
|
|
Shape string `json:"shape"`
|
|
|
|
GaugeViewProperties
|
|
|
|
}{
|
|
|
|
Shape: "chronograf-v2",
|
|
|
|
GaugeViewProperties: vis,
|
|
|
|
}
|
2018-11-20 21:59:27 +00:00
|
|
|
case XYViewProperties:
|
2018-09-27 17:46:48 +00:00
|
|
|
s = struct {
|
|
|
|
Shape string `json:"shape"`
|
2018-11-20 21:59:27 +00:00
|
|
|
XYViewProperties
|
2018-09-27 17:46:48 +00:00
|
|
|
}{
|
2018-11-20 21:59:27 +00:00
|
|
|
Shape: "chronograf-v2",
|
|
|
|
XYViewProperties: vis,
|
2018-09-27 17:46:48 +00:00
|
|
|
}
|
2018-10-03 17:17:14 +00:00
|
|
|
case LinePlusSingleStatProperties:
|
|
|
|
s = struct {
|
|
|
|
Shape string `json:"shape"`
|
|
|
|
LinePlusSingleStatProperties
|
|
|
|
}{
|
2018-10-08 18:32:29 +00:00
|
|
|
Shape: "chronograf-v2",
|
2018-10-03 17:17:14 +00:00
|
|
|
LinePlusSingleStatProperties: vis,
|
|
|
|
}
|
2018-11-28 01:03:13 +00:00
|
|
|
case MarkdownViewProperties:
|
|
|
|
s = struct {
|
|
|
|
Shape string `json:"shape"`
|
|
|
|
MarkdownViewProperties
|
|
|
|
}{
|
|
|
|
Shape: "chronograf-v2",
|
|
|
|
MarkdownViewProperties: vis,
|
|
|
|
}
|
2018-10-03 00:21:04 +00:00
|
|
|
case LogViewProperties:
|
|
|
|
s = struct {
|
|
|
|
Shape string `json:"shape"`
|
|
|
|
LogViewProperties
|
|
|
|
}{
|
|
|
|
Shape: "chronograf-v2",
|
|
|
|
LogViewProperties: vis,
|
|
|
|
}
|
2018-07-10 23:55:32 +00:00
|
|
|
default:
|
2018-07-09 22:19:34 +00:00
|
|
|
s = struct {
|
2018-08-07 20:10:05 +00:00
|
|
|
Shape string `json:"shape"`
|
|
|
|
EmptyViewProperties
|
2018-07-09 22:19:34 +00:00
|
|
|
}{
|
2018-08-07 20:10:05 +00:00
|
|
|
Shape: "empty",
|
|
|
|
EmptyViewProperties: EmptyViewProperties{},
|
2018-07-09 22:19:34 +00:00
|
|
|
}
|
2018-07-05 22:07:53 +00:00
|
|
|
}
|
|
|
|
return json.Marshal(s)
|
|
|
|
}
|
|
|
|
|
2018-10-03 00:21:04 +00:00
|
|
|
// MarshalJSON encodes a view to JSON bytes.
|
2018-08-07 20:10:05 +00:00
|
|
|
func (c View) MarshalJSON() ([]byte, error) {
|
|
|
|
vis, err := MarshalViewPropertiesJSON(c.Properties)
|
2018-07-05 22:07:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return json.Marshal(struct {
|
2018-08-07 20:10:05 +00:00
|
|
|
ViewContents
|
|
|
|
ViewProperties json.RawMessage `json:"properties"`
|
2018-07-05 22:07:53 +00:00
|
|
|
}{
|
2018-08-07 20:10:05 +00:00
|
|
|
ViewContents: c.ViewContents,
|
|
|
|
ViewProperties: vis,
|
2018-07-05 22:07:53 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-10-03 00:21:04 +00:00
|
|
|
// UnmarshalJSON decodes JSON bytes into the corresponding view type (those that implement ViewProperties).
|
2018-08-07 20:10:05 +00:00
|
|
|
func (c *View) UnmarshalJSON(b []byte) error {
|
|
|
|
if err := json.Unmarshal(b, &c.ViewContents); err != nil {
|
2018-07-05 22:07:53 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
v, err := UnmarshalViewPropertiesJSON(b)
|
2018-07-05 22:07:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-07 20:10:05 +00:00
|
|
|
c.Properties = v
|
2018-07-05 22:07:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-10-03 00:21:04 +00:00
|
|
|
// UnmarshalJSON decodes JSON bytes into the corresponding view update type (those that implement ViewProperties).
|
2018-08-07 20:10:05 +00:00
|
|
|
func (u *ViewUpdate) UnmarshalJSON(b []byte) error {
|
|
|
|
if err := json.Unmarshal(b, &u.ViewContentsUpdate); err != nil {
|
2018-07-09 21:22:34 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
v, err := UnmarshalViewPropertiesJSON(b)
|
2018-07-09 21:22:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-07 20:10:05 +00:00
|
|
|
u.Properties = v
|
2018-07-09 21:22:34 +00:00
|
|
|
return nil
|
|
|
|
}
|
2018-10-03 00:21:04 +00:00
|
|
|
|
|
|
|
// MarshalJSON encodes a view to JSON bytes.
|
2018-08-07 20:10:05 +00:00
|
|
|
func (u ViewUpdate) MarshalJSON() ([]byte, error) {
|
|
|
|
vis, err := MarshalViewPropertiesJSON(u.Properties)
|
2018-07-10 23:55:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return json.Marshal(struct {
|
2018-08-07 20:10:05 +00:00
|
|
|
ViewContentsUpdate
|
|
|
|
ViewProperties json.RawMessage `json:"properties,omitempty"`
|
2018-07-10 23:55:32 +00:00
|
|
|
}{
|
2018-08-07 20:10:05 +00:00
|
|
|
ViewContentsUpdate: u.ViewContentsUpdate,
|
|
|
|
ViewProperties: vis,
|
2018-07-10 23:55:32 +00:00
|
|
|
})
|
|
|
|
}
|
2018-07-09 21:22:34 +00:00
|
|
|
|
2018-10-03 17:17:14 +00:00
|
|
|
// LinePlusSingleStatProperties represents options for line plus single stat view in Chronograf
|
|
|
|
type LinePlusSingleStatProperties struct {
|
2018-11-28 01:03:13 +00:00
|
|
|
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"`
|
2018-10-03 17:17:14 +00:00
|
|
|
}
|
|
|
|
|
2018-11-20 21:59:27 +00:00
|
|
|
// XYViewProperties represents options for line, bar, step, or stacked view in Chronograf
|
|
|
|
type XYViewProperties struct {
|
2018-11-28 01:03:13 +00:00
|
|
|
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"`
|
2018-09-27 17:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SingleStatViewProperties represents options for single stat view in Chronograf
|
|
|
|
type SingleStatViewProperties struct {
|
2018-11-28 01:03:13 +00:00
|
|
|
Type string `json:"type"`
|
|
|
|
Queries []DashboardQuery `json:"queries"`
|
|
|
|
Prefix string `json:"prefix"`
|
|
|
|
Suffix string `json:"suffix"`
|
|
|
|
ViewColors []ViewColor `json:"colors"`
|
|
|
|
DecimalPlaces DecimalPlaces `json:"decimalPlaces"`
|
|
|
|
Note string `json:"note"`
|
|
|
|
ShowNoteWhenEmpty bool `json:"showNoteWhenEmpty"`
|
2018-09-27 17:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GaugeViewProperties represents options for gauge view in Chronograf
|
|
|
|
type GaugeViewProperties struct {
|
2018-11-28 01:03:13 +00:00
|
|
|
Type string `json:"type"`
|
|
|
|
Queries []DashboardQuery `json:"queries"`
|
|
|
|
Prefix string `json:"prefix"`
|
|
|
|
Suffix string `json:"suffix"`
|
|
|
|
ViewColors []ViewColor `json:"colors"`
|
|
|
|
DecimalPlaces DecimalPlaces `json:"decimalPlaces"`
|
|
|
|
Note string `json:"note"`
|
|
|
|
ShowNoteWhenEmpty bool `json:"showNoteWhenEmpty"`
|
2018-09-27 17:46:48 +00:00
|
|
|
}
|
|
|
|
|
2018-10-01 20:33:27 +00:00
|
|
|
// TableViewProperties represents options for table view in Chronograf
|
|
|
|
type TableViewProperties struct {
|
2018-11-28 01:03:13 +00:00
|
|
|
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"`
|
2018-10-01 20:33:27 +00:00
|
|
|
}
|
|
|
|
|
2018-10-03 00:21:04 +00:00
|
|
|
// 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"`
|
|
|
|
}
|
|
|
|
|
2018-11-20 21:59:27 +00:00
|
|
|
func (XYViewProperties) viewProperties() {}
|
2018-10-03 17:17:14 +00:00
|
|
|
func (LinePlusSingleStatProperties) viewProperties() {}
|
|
|
|
func (SingleStatViewProperties) viewProperties() {}
|
|
|
|
func (GaugeViewProperties) viewProperties() {}
|
|
|
|
func (TableViewProperties) viewProperties() {}
|
2018-11-28 01:03:13 +00:00
|
|
|
func (MarkdownViewProperties) viewProperties() {}
|
2018-10-03 17:17:14 +00:00
|
|
|
func (LogViewProperties) viewProperties() {}
|
2018-07-05 22:07:53 +00:00
|
|
|
|
2018-12-08 01:15:24 +00:00
|
|
|
func (v XYViewProperties) GetType() string { return v.Type }
|
|
|
|
func (v LinePlusSingleStatProperties) GetType() string { return v.Type }
|
|
|
|
func (v SingleStatViewProperties) 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 }
|
|
|
|
|
2018-07-05 22:07:53 +00:00
|
|
|
/////////////////////////////
|
|
|
|
// Old Chronograf Types
|
|
|
|
/////////////////////////////
|
|
|
|
|
2018-11-26 23:26:25 +00:00
|
|
|
// DashboardQuery represents a query used in a dashboard cell
|
2018-07-05 22:07:53 +00:00
|
|
|
type DashboardQuery struct {
|
2018-12-06 22:36:37 +00:00
|
|
|
Text string `json:"text"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
SourceID string `json:"sourceID"`
|
|
|
|
EditMode string `json:"editMode"` // Either "builder" or "advanced"
|
2018-12-10 18:16:27 +00:00
|
|
|
Name string `json:"name"` // Term or phrase that refers to the query
|
2018-12-06 22:36:37 +00:00
|
|
|
BuilderConfig BuilderConfig `json:"builderConfig"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type BuilderConfig struct {
|
2018-12-21 18:31:32 +00:00
|
|
|
Buckets []string `json:"buckets"`
|
|
|
|
Tags []struct {
|
|
|
|
Key string `json:"key"`
|
|
|
|
Values []string `json:"values"`
|
|
|
|
} `json:"tags"`
|
|
|
|
Functions []struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
} `json:"functions"`
|
2018-07-05 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Axis represents the visible extents of a visualization
|
|
|
|
type Axis struct {
|
2018-08-07 20:10:05 +00:00
|
|
|
Bounds []string `json:"bounds"` // bounds are an arbitrary list of client-defined strings that specify the viewport for a View
|
2018-07-05 22:07:53 +00:00
|
|
|
LegacyBounds [2]int64 `json:"-"` // legacy bounds are for testing a migration from an earlier version of axis
|
|
|
|
Label string `json:"label"` // label is a description of this Axis
|
|
|
|
Prefix string `json:"prefix"` // Prefix represents a label prefix for formatting axis values
|
|
|
|
Suffix string `json:"suffix"` // Suffix represents a label suffix for formatting axis values
|
|
|
|
Base string `json:"base"` // Base represents the radix for formatting axis values
|
|
|
|
Scale string `json:"scale"` // Scale is the axis formatting scale. Supported: "log", "linear"
|
|
|
|
}
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
// ViewColor represents the encoding of data into visualizations
|
|
|
|
type ViewColor struct {
|
2018-11-30 00:26:29 +00:00
|
|
|
ID string `json:"id"` // ID is the unique id of the View color
|
|
|
|
Type string `json:"type"` // Type is how the color is used. Accepted (min,max,threshold)
|
|
|
|
Hex string `json:"hex"` // Hex is the hex number of the color
|
|
|
|
Name string `json:"name"` // Name is the user-facing name of the hex color
|
|
|
|
Value float64 `json:"value"` // Value is the data value mapped to this color
|
2018-07-05 22:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Legend represents the encoding of data into a legend
|
|
|
|
type Legend struct {
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
Orientation string `json:"orientation,omitempty"`
|
|
|
|
}
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
// TableOptions is a type of options for a DashboardView with type Table
|
2018-07-05 22:07:53 +00:00
|
|
|
type TableOptions struct {
|
|
|
|
VerticalTimeAxis bool `json:"verticalTimeAxis"`
|
|
|
|
SortBy RenamableField `json:"sortBy"`
|
|
|
|
Wrapping string `json:"wrapping"`
|
|
|
|
FixFirstColumn bool `json:"fixFirstColumn"`
|
|
|
|
}
|
|
|
|
|
2018-08-07 20:10:05 +00:00
|
|
|
// RenamableField is a column/row field in a DashboardView of type Table
|
2018-07-05 22:07:53 +00:00
|
|
|
type RenamableField struct {
|
|
|
|
InternalName string `json:"internalName"`
|
|
|
|
DisplayName string `json:"displayName"`
|
|
|
|
Visible bool `json:"visible"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecimalPlaces indicates whether decimal places should be enforced, and how many digits it should show.
|
|
|
|
type DecimalPlaces struct {
|
|
|
|
IsEnforced bool `json:"isEnforced"`
|
|
|
|
Digits int32 `json:"digits"`
|
|
|
|
}
|