[v3.2] Add grafana dashboard importing API (#11)
* Add API to import grafana templates to kubesphere dashboard * Merge and fix the latest codes from kubesphere #2501 Signed-off-by: zhu733756 <talonzhu@yunify.com>
This commit is contained in:
15
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha1/dashboard_conversion.go
generated
vendored
Normal file
15
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha1/dashboard_conversion.go
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v1alpha1
|
||||
|
||||
func (_ *Dashboard) Hub() {}
|
||||
54
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha1/dashboard_types.go
generated
vendored
54
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha1/dashboard_types.go
generated
vendored
@@ -18,7 +18,6 @@ package v1alpha1
|
||||
|
||||
import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/json"
|
||||
"kubesphere.io/monitoring-dashboard/api/v1alpha1/panels"
|
||||
)
|
||||
|
||||
@@ -48,9 +47,14 @@ type Time struct {
|
||||
To string `json:"to,omitempty"`
|
||||
}
|
||||
|
||||
// Supported panel type
|
||||
// Supported panel
|
||||
type Panel struct {
|
||||
// It can only be one of the following three types
|
||||
// panel metadata
|
||||
PanelMeta `json:",inline"`
|
||||
|
||||
// A collection of queries
|
||||
// Only for panels with `graph` or `singlestat` type
|
||||
Targets []panels.Target `json:"targets,omitempty"`
|
||||
|
||||
// The panel row
|
||||
Row *panels.Row `json:",inline"`
|
||||
@@ -68,42 +72,13 @@ const (
|
||||
PanelSingleStat PanelType = "singlestat"
|
||||
)
|
||||
|
||||
func (p *Panel) UnmarshalJSON(data []byte) error {
|
||||
if len(data) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var t struct{ Type PanelType }
|
||||
err := json.Unmarshal(data, &t)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch t.Type {
|
||||
case PanelRow:
|
||||
p.Row = &panels.Row{}
|
||||
return json.Unmarshal(data, p.Row)
|
||||
case PanelGraph:
|
||||
p.Graph = &panels.Graph{}
|
||||
return json.Unmarshal(data, p.Graph)
|
||||
case PanelSingleStat:
|
||||
p.SingleStat = &panels.SingleStat{}
|
||||
return json.Unmarshal(data, p.SingleStat)
|
||||
}
|
||||
|
||||
return json.Unmarshal(data, p)
|
||||
}
|
||||
|
||||
func (p *Panel) MarshalJSON() (data []byte, err error) {
|
||||
switch {
|
||||
case p.Row != nil:
|
||||
return json.Marshal(p.Row)
|
||||
case p.Graph != nil:
|
||||
return json.Marshal(p.Graph)
|
||||
case p.SingleStat != nil:
|
||||
return json.Marshal(p.SingleStat)
|
||||
}
|
||||
return json.Marshal(p)
|
||||
type PanelMeta struct {
|
||||
// Name of the panel
|
||||
Title string `json:"title,omitempty"`
|
||||
// Panel ID
|
||||
Id int64 `json:"id,omitempty"`
|
||||
// Panel Type, one of `row`, `graph`, `singlestat`
|
||||
Type PanelType `json:"type"`
|
||||
}
|
||||
|
||||
// Templating defines a variable, which can be used as a placeholder in query
|
||||
@@ -115,6 +90,7 @@ type Templating struct {
|
||||
}
|
||||
|
||||
// +kubebuilder:object:root=true
|
||||
// +kubebuilder:subresource:status
|
||||
|
||||
// Dashboard is the Schema for the dashboards API
|
||||
type Dashboard struct {
|
||||
|
||||
8
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha1/panels/graph_types.go
generated
vendored
8
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha1/panels/graph_types.go
generated
vendored
@@ -5,15 +5,15 @@ package panels
|
||||
// Graph visualizes range query results into a linear graph
|
||||
type Graph struct {
|
||||
// Name of the graph panel
|
||||
Title string `json:"title,omitempty"`
|
||||
//Title string `json:"title,omitempty"`
|
||||
// Must be `graph`
|
||||
Type string `json:"type"`
|
||||
//Type string `json:"type"`
|
||||
// Panel ID
|
||||
Id int64 `json:"id,omitempty"`
|
||||
//Id int64 `json:"id,omitempty"`
|
||||
// Panel description
|
||||
Description string `json:"description,omitempty"`
|
||||
// A collection of queries
|
||||
Targets []Target `json:"targets,omitempty"`
|
||||
//Targets []Target `json:"targets,omitempty"`
|
||||
// Display as a bar chart
|
||||
Bars bool `json:"bars,omitempty"`
|
||||
// Set series color
|
||||
|
||||
6
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha1/panels/row_types.go
generated
vendored
6
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha1/panels/row_types.go
generated
vendored
@@ -5,9 +5,9 @@ package panels
|
||||
// Row groups relevant charts
|
||||
type Row struct {
|
||||
// Name of the row panel
|
||||
Title string `json:"title,omitempty"`
|
||||
//Title string `json:"title,omitempty"`
|
||||
// Must be `row`
|
||||
Type string `json:"type"`
|
||||
//Type string `json:"type"`
|
||||
// Panel ID
|
||||
Id int64 `json:"id,omitempty"`
|
||||
//Id int64 `json:"id,omitempty"`
|
||||
}
|
||||
|
||||
10
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha1/panels/singlestat_types.go
generated
vendored
10
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha1/panels/singlestat_types.go
generated
vendored
@@ -5,15 +5,15 @@ package panels
|
||||
// SingleStat shows instant query result
|
||||
type SingleStat struct {
|
||||
// Name of the signlestat panel
|
||||
Title string `json:"title,omitempty"`
|
||||
//Title string `json:"title,omitempty"`
|
||||
// Must be `singlestat`
|
||||
Type string `json:"type"`
|
||||
//Type string `json:"type"`
|
||||
// Panel ID
|
||||
Id int64 `json:"id,omitempty"`
|
||||
//Id int64 `json:"id,omitempty"`
|
||||
// A collection of queries
|
||||
Targets []Target `json:"targets,omitempty"`
|
||||
//Targets []Target `json:"targets,omitempty"`
|
||||
// Limit the decimal numbers
|
||||
Decimals int64 `json:"decimals,omitempty"`
|
||||
Decimals *int64 `json:"decimals,omitempty"`
|
||||
// Display unit
|
||||
Format string `json:"format,omitempty"`
|
||||
}
|
||||
|
||||
13
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha1/panels/zz_generated.deepcopy.go
generated
vendored
13
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha1/panels/zz_generated.deepcopy.go
generated
vendored
@@ -25,11 +25,6 @@ import ()
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Graph) DeepCopyInto(out *Graph) {
|
||||
*out = *in
|
||||
if in.Targets != nil {
|
||||
in, out := &in.Targets, &out.Targets
|
||||
*out = make([]Target, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
if in.Colors != nil {
|
||||
in, out := &in.Colors, &out.Colors
|
||||
*out = make([]string, len(*in))
|
||||
@@ -70,10 +65,10 @@ func (in *Row) DeepCopy() *Row {
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *SingleStat) DeepCopyInto(out *SingleStat) {
|
||||
*out = *in
|
||||
if in.Targets != nil {
|
||||
in, out := &in.Targets, &out.Targets
|
||||
*out = make([]Target, len(*in))
|
||||
copy(*out, *in)
|
||||
if in.Decimals != nil {
|
||||
in, out := &in.Decimals, &out.Decimals
|
||||
*out = new(int64)
|
||||
**out = **in
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
21
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha1/zz_generated.deepcopy.go
generated
vendored
21
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha1/zz_generated.deepcopy.go
generated
vendored
@@ -172,6 +172,12 @@ func (in *DashboardSpec) DeepCopy() *DashboardSpec {
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Panel) DeepCopyInto(out *Panel) {
|
||||
*out = *in
|
||||
out.PanelMeta = in.PanelMeta
|
||||
if in.Targets != nil {
|
||||
in, out := &in.Targets, &out.Targets
|
||||
*out = make([]panels.Target, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
if in.Row != nil {
|
||||
in, out := &in.Row, &out.Row
|
||||
*out = new(panels.Row)
|
||||
@@ -199,6 +205,21 @@ func (in *Panel) DeepCopy() *Panel {
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *PanelMeta) DeepCopyInto(out *PanelMeta) {
|
||||
*out = *in
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PanelMeta.
|
||||
func (in *PanelMeta) DeepCopy() *PanelMeta {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(PanelMeta)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Templating) DeepCopyInto(out *Templating) {
|
||||
*out = *in
|
||||
|
||||
26
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/annotations/dashboard_annotation_types.go
generated
vendored
Normal file
26
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/annotations/dashboard_annotation_types.go
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// +kubebuilder:object:generate=true
|
||||
|
||||
package anotations
|
||||
|
||||
// "github.com/grafana-tools/sdk,omitempty"
|
||||
// refers to https://pkg.go.dev/github.com/grafana-tools/sdk#Annotation
|
||||
|
||||
type Annotation struct {
|
||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||
Datasource string `json:"datasource,omitempty" yaml:"datasource,omitempty"`
|
||||
ShowLine bool `json:"showLine,omitempty" yaml:"showLine,omitempty"`
|
||||
IconColor string `json:"iconColor,omitempty" yaml:"iconColor,omitempty"`
|
||||
LineColor string `json:"lineColor,omitempty" yaml:"lineColor,omitempty"`
|
||||
IconSize uint `json:"iconSize,omitempty" yaml:"iconSize,omitempty"`
|
||||
Enable bool `json:"enable,omitempty" yaml:"enable,omitempty"`
|
||||
Query string `json:"query,omitempty" yaml:"query,omitempty"`
|
||||
Expr string `json:"expr,omitempty" yaml:"expr,omitempty"`
|
||||
Step string `json:"step,omitempty" yaml:"step,omitempty"`
|
||||
TextField string `json:"textField,omitempty" yaml:"textField,omitempty"`
|
||||
TextFormat string `json:"textFormat,omitempty" yaml:"textFormat,omitempty"`
|
||||
TitleFormat string `json:"titleFormat,omitempty" yaml:"titleFormat,omitempty"`
|
||||
TagsField string `json:"tagsField,omitempty" yaml:"tagsField,omitempty"`
|
||||
Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`
|
||||
TagKeys string `json:"tagKeys,omitempty" yaml:"tagKeys,omitempty"`
|
||||
Type string `json:"type,omitempty" yaml:"type,omitempty"`
|
||||
}
|
||||
43
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/annotations/zz_generated.deepcopy.go
generated
vendored
Normal file
43
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/annotations/zz_generated.deepcopy.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright 2020 The KubeSphere authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by controller-gen. DO NOT EDIT.
|
||||
|
||||
package anotations
|
||||
|
||||
import ()
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Annotation) DeepCopyInto(out *Annotation) {
|
||||
*out = *in
|
||||
if in.Tags != nil {
|
||||
in, out := &in.Tags, &out.Tags
|
||||
*out = make([]string, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Annotation.
|
||||
func (in *Annotation) DeepCopy() *Annotation {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(Annotation)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
224
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/dashboard_conversion.go
generated
vendored
Normal file
224
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/dashboard_conversion.go
generated
vendored
Normal file
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v1alpha2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"kubesphere.io/monitoring-dashboard/api/v1alpha1"
|
||||
v1alpha1panels "kubesphere.io/monitoring-dashboard/api/v1alpha1/panels"
|
||||
v1alpha2panels "kubesphere.io/monitoring-dashboard/api/v1alpha2/panels"
|
||||
v1alpha2templatings "kubesphere.io/monitoring-dashboard/api/v1alpha2/templatings"
|
||||
"kubesphere.io/monitoring-dashboard/api/v1alpha2/time"
|
||||
"sigs.k8s.io/controller-runtime/pkg/conversion"
|
||||
)
|
||||
|
||||
func (_ *Dashboard) Hub() {}
|
||||
|
||||
func (src *Dashboard) ConvertTo(dstRaw conversion.Hub) error {
|
||||
dst := dstRaw.(*v1alpha1.Dashboard)
|
||||
dst.ObjectMeta = src.ObjectMeta
|
||||
|
||||
dst.Spec.Title = src.Spec.Title
|
||||
dst.Spec.Description = src.Spec.Description
|
||||
dst.Spec.Time = v1alpha1.Time{
|
||||
From: src.Spec.Time.From,
|
||||
To: src.Spec.Time.To,
|
||||
}
|
||||
pls := []v1alpha1.Panel{}
|
||||
|
||||
for _, panel := range src.Spec.Panels {
|
||||
|
||||
if panel == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
t := v1alpha1.PanelType(panel.Type)
|
||||
if dst.Spec.DataSource == "" && panel.CommonPanel.Datasource != nil {
|
||||
dst.Spec.DataSource = point2string(panel.CommonPanel.Datasource)
|
||||
}
|
||||
|
||||
dstPanel := v1alpha1.Panel{
|
||||
PanelMeta: v1alpha1.PanelMeta{
|
||||
Title: panel.Title,
|
||||
Id: panel.Id,
|
||||
Type: t,
|
||||
},
|
||||
}
|
||||
|
||||
for _, target := range panel.CommonPanel.Targets {
|
||||
dstPanel.Targets = append(dstPanel.Targets, v1alpha1panels.Target{
|
||||
Expression: target.Expression,
|
||||
LegendFormat: target.LegendFormat,
|
||||
RefID: target.RefID,
|
||||
Step: target.Step,
|
||||
})
|
||||
}
|
||||
|
||||
switch t {
|
||||
case "graph":
|
||||
|
||||
if len(panel.CommonPanel.Colors) > 0 {
|
||||
dstPanel.Graph.Colors = panel.CommonPanel.Colors
|
||||
}
|
||||
|
||||
graph := panel.GraphPanel
|
||||
|
||||
if graph != nil {
|
||||
|
||||
yaxes := make([]v1alpha1panels.Yaxis, 0)
|
||||
for _, yaxis := range graph.Yaxes {
|
||||
yaxes = append(yaxes, v1alpha1panels.Yaxis{
|
||||
Decimals: yaxis.Decimals,
|
||||
Format: yaxis.Format,
|
||||
})
|
||||
}
|
||||
if len(yaxes) > 0 {
|
||||
dstPanel.Graph.Yaxes = yaxes
|
||||
}
|
||||
if panel.CommonPanel.Description != nil {
|
||||
dstPanel.Graph.Description = point2string(panel.CommonPanel.Description)
|
||||
}
|
||||
if graph.Bars {
|
||||
dstPanel.Graph.Bars = graph.Bars
|
||||
}
|
||||
if graph.Lines {
|
||||
dstPanel.Graph.Lines = graph.Lines
|
||||
}
|
||||
if graph.Stack {
|
||||
dstPanel.Graph.Stack = graph.Stack
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case "singlestat":
|
||||
|
||||
if panel.CommonPanel.Decimals != nil {
|
||||
dstPanel.SingleStat.Decimals = panel.CommonPanel.Decimals
|
||||
}
|
||||
|
||||
if panel.CommonPanel.Format != "" {
|
||||
dstPanel.SingleStat.Format = panel.CommonPanel.Format
|
||||
}
|
||||
|
||||
case "row":
|
||||
// var r v1alpha1panels.Row
|
||||
// dstPanel.Row = &r
|
||||
default:
|
||||
fmt.Println("unhandled panel type: skipped,type:", t)
|
||||
}
|
||||
|
||||
pls = append(pls, dstPanel)
|
||||
}
|
||||
|
||||
dst.Spec.Panels = pls
|
||||
|
||||
for _, temp := range src.Spec.Templatings {
|
||||
dst.Spec.Templatings = append(dst.Spec.Templatings, v1alpha1.Templating{
|
||||
Name: temp.Name,
|
||||
Query: temp.Query,
|
||||
})
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (dst *Dashboard) ConvertFrom(srcRaw conversion.Hub) error {
|
||||
src := srcRaw.(*v1alpha1.Dashboard)
|
||||
dst.ObjectMeta = src.ObjectMeta
|
||||
|
||||
dst.Spec.Title = src.Spec.Title
|
||||
dst.Spec.Description = src.Spec.Description
|
||||
dst.Spec.Time = time.Time{
|
||||
From: src.Spec.Time.From,
|
||||
To: src.Spec.Time.To,
|
||||
}
|
||||
pls := []*v1alpha2panels.Panel{}
|
||||
|
||||
for _, panel := range src.Spec.Panels {
|
||||
|
||||
t := v1alpha1.PanelType(panel.Type)
|
||||
|
||||
dstPanel := v1alpha2panels.Panel{
|
||||
CommonPanel: v1alpha2panels.CommonPanel{
|
||||
Title: panel.PanelMeta.Title,
|
||||
Id: panel.PanelMeta.Id,
|
||||
Type: string(panel.PanelMeta.Type),
|
||||
Datasource: &src.Spec.DataSource,
|
||||
},
|
||||
}
|
||||
|
||||
for _, target := range panel.Targets {
|
||||
dstPanel.CommonPanel.Targets = append(dstPanel.CommonPanel.Targets, v1alpha2panels.Target{
|
||||
Expression: target.Expression,
|
||||
LegendFormat: target.LegendFormat,
|
||||
RefID: target.RefID,
|
||||
Step: target.Step,
|
||||
})
|
||||
}
|
||||
|
||||
switch t {
|
||||
case "graph":
|
||||
graph := panel.Graph
|
||||
if graph != nil {
|
||||
dstPanel.CommonPanel.Description = &graph.Description
|
||||
yaxes := make([]v1alpha2panels.Axis, 0)
|
||||
for _, yaxis := range graph.Yaxes {
|
||||
yaxes = append(yaxes, v1alpha2panels.Axis{
|
||||
Decimals: yaxis.Decimals,
|
||||
Format: yaxis.Format,
|
||||
})
|
||||
}
|
||||
dstPanel.GraphPanel.Bars = graph.Bars
|
||||
dstPanel.GraphPanel.Lines = graph.Lines
|
||||
dstPanel.GraphPanel.Stack = graph.Stack
|
||||
dstPanel.GraphPanel.Yaxes = yaxes
|
||||
|
||||
}
|
||||
case "singlestat":
|
||||
singlestat := panel.SingleStat
|
||||
if singlestat != nil {
|
||||
dstPanel.CommonPanel.Decimals = singlestat.Decimals
|
||||
dstPanel.CommonPanel.Format = singlestat.Format
|
||||
}
|
||||
|
||||
case "row":
|
||||
// var r v1alpha2panels.RowPanel
|
||||
// dstPanel.RowPanel = &r
|
||||
default:
|
||||
fmt.Println("unhandled panel type: skipped,type:", t)
|
||||
}
|
||||
|
||||
pls = append(pls, &dstPanel)
|
||||
}
|
||||
|
||||
dst.Spec.Panels = pls
|
||||
|
||||
for _, temp := range src.Spec.Templatings {
|
||||
dst.Spec.Templatings = append(dst.Spec.Templatings, v1alpha2templatings.TemplateVar{
|
||||
Name: temp.Name,
|
||||
Query: temp.Query,
|
||||
})
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func point2string(p *string) string {
|
||||
if p == nil {
|
||||
return ""
|
||||
}
|
||||
return *p
|
||||
}
|
||||
92
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/dashboard_types.go
generated
vendored
Normal file
92
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/dashboard_types.go
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
Copyright 2020 The KubeSphere authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License")
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package v1alpha2
|
||||
|
||||
import (
|
||||
ants "kubesphere.io/monitoring-dashboard/api/v1alpha2/annotations"
|
||||
panels "kubesphere.io/monitoring-dashboard/api/v1alpha2/panels"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
templatings "kubesphere.io/monitoring-dashboard/api/v1alpha2/templatings"
|
||||
time "kubesphere.io/monitoring-dashboard/api/v1alpha2/time"
|
||||
)
|
||||
|
||||
// DashboardSpec defines the desired state of Dashboard
|
||||
type DashboardSpec struct {
|
||||
ID uint `json:"id,omitempty" `
|
||||
UID string `json:"uid,omitempty" `
|
||||
Title string `json:"title,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Editable bool `json:"editable,omitempty"`
|
||||
SharedCrosshair bool `json:"shared_crosshair,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
AutoRefresh string `json:"auto_refresh,omitempty"`
|
||||
Timezone string `json:"timezone,omitempty"`
|
||||
// Annotations
|
||||
Annotations []ants.Annotation `json:"annotations,omitempty"`
|
||||
// Time range
|
||||
Time time.Time `json:"time,omitempty"`
|
||||
Panels []*panels.Panel `json:"panels,omitempty"`
|
||||
// // Templating variables
|
||||
Templatings []templatings.TemplateVar `json:"templatings,omitempty"`
|
||||
}
|
||||
|
||||
// +kubebuilder:object:root=true
|
||||
// +kubebuilder:subresource:status
|
||||
// +kubebuilder:storageversion
|
||||
|
||||
// Dashboard is the Schema for the dashboards API
|
||||
type Dashboard struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||
|
||||
Spec DashboardSpec `json:"spec,omitempty"`
|
||||
}
|
||||
|
||||
// +kubebuilder:object:root=true
|
||||
|
||||
// DashboardList contains a list of Dashboard
|
||||
type DashboardList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ListMeta `json:"metadata,omitempty"`
|
||||
Items []Dashboard `json:"items"`
|
||||
}
|
||||
|
||||
// +kubebuilder:object:root=true
|
||||
// +kubebuilder:resource:scope="Cluster"
|
||||
// +kubebuilder:storageversion
|
||||
|
||||
// ClusterDashboard is the Schema for the culsterdashboards API
|
||||
type ClusterDashboard struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||
|
||||
Spec DashboardSpec `json:"spec,omitempty"`
|
||||
}
|
||||
|
||||
// +kubebuilder:object:root=true
|
||||
|
||||
// ClusterDashboardList contains a list of ClusterDashboard
|
||||
type ClusterDashboardList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ListMeta `json:"metadata,omitempty"`
|
||||
Items []ClusterDashboard `json:"items"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
SchemeBuilder.Register(&Dashboard{}, &DashboardList{})
|
||||
SchemeBuilder.Register(&ClusterDashboard{}, &ClusterDashboardList{})
|
||||
}
|
||||
34
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/groupversion_info.go
generated
vendored
Normal file
34
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/groupversion_info.go
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
Copyright 2020 The KubeSphere authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
// Package v1alpha2 contains API Schema definitions for the monitoring v1alpha2 API group
|
||||
// +kubebuilder:object:generate=true
|
||||
// +groupName=monitoring.kubesphere.io
|
||||
package v1alpha2
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"sigs.k8s.io/controller-runtime/pkg/scheme"
|
||||
)
|
||||
|
||||
var (
|
||||
// GroupVersion is group version used to register these objects
|
||||
GroupVersion = schema.GroupVersion{Group: "monitoring.kubesphere.io", Version: "v1alpha2"}
|
||||
|
||||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
|
||||
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
|
||||
|
||||
// AddToScheme adds the types in this group-version to the given scheme.
|
||||
AddToScheme = SchemeBuilder.AddToScheme
|
||||
)
|
||||
19
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/panels/bargauge_types.go
generated
vendored
Normal file
19
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/panels/bargauge_types.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// +kubebuilder:object:generate=true
|
||||
package panels
|
||||
|
||||
type BarGaugeOptions struct {
|
||||
Orientation string `json:"orientation,omitempty"`
|
||||
TextMode string `json:"textMode,omitempty"`
|
||||
ColorMode string `json:"colorMode,omitempty"`
|
||||
GraphMode string `json:"graphMode,omitempty"`
|
||||
JustifyMode string `json:"justifyMode,omitempty"`
|
||||
DisplayMode string `json:"displayMode,omitempty"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Mode string `json:"mode,omitempty"`
|
||||
}
|
||||
|
||||
// refers to https://pkg.go.dev/github.com/grafana-tools/sdk#BarGaugePanel
|
||||
type BarGaugePanel struct {
|
||||
Options *BarGaugeOptions `json:"options,omitempty"`
|
||||
// FieldConfig FieldConfig `json:"fieldConfig,omitempty"`
|
||||
}
|
||||
44
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/panels/common_types.go
generated
vendored
Normal file
44
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/panels/common_types.go
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
// +kubebuilder:object:generate=true
|
||||
|
||||
package panels
|
||||
|
||||
// Query editor options
|
||||
type CommonPanel struct {
|
||||
// Name of the panel
|
||||
Title string `json:"title,omitempty"`
|
||||
// Type of the panel
|
||||
Type string `json:"type,omitempty"`
|
||||
// Panel ID
|
||||
Id int64 `json:"id,omitempty"`
|
||||
// Description
|
||||
Description *string `json:"description,omitempty"`
|
||||
// Datasource
|
||||
Datasource *string `json:"datasource,omitempty"`
|
||||
// Height
|
||||
Height *string `json:"height,omitempty"`
|
||||
Decimals *int64 `json:"decimals,omitempty"`
|
||||
// A collection of queries
|
||||
Targets []Target `json:"targets,omitempty"`
|
||||
// Set series color
|
||||
Colors []string `json:"colors,omitempty"`
|
||||
// legend
|
||||
Legend []string `json:"legend,omitempty"`
|
||||
// Display unit
|
||||
Format string `json:"format,omitempty"`
|
||||
}
|
||||
|
||||
// +kubebuilder:object:generate=true
|
||||
|
||||
// Query editor options
|
||||
// Referers to https://pkg.go.dev/github.com/grafana-tools/sdk#Target
|
||||
type Target struct {
|
||||
// Reference ID
|
||||
RefID int64 `json:"refId,omitempty"`
|
||||
// only support prometheus,and the corresponding fields are as follows:
|
||||
// Input for fetching metrics.
|
||||
Expression string `json:"expr,omitempty"`
|
||||
// Legend format for outputs. You can make a dynamic legend with templating variables.
|
||||
LegendFormat string `json:"legendFormat,omitempty"`
|
||||
// Set series time interval
|
||||
Step string `json:"step,omitempty"`
|
||||
}
|
||||
229
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/panels/dashboard_panels_types.go
generated
vendored
Normal file
229
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/panels/dashboard_panels_types.go
generated
vendored
Normal file
@@ -0,0 +1,229 @@
|
||||
// +kubebuilder:object:generate=true
|
||||
|
||||
package panels
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// Supported panel type
|
||||
// type Panel struct {
|
||||
// // private property of the bargauge panel
|
||||
// Options *BarGaugeOptions `json:"options,omitempty"`
|
||||
|
||||
// // ****common properties start
|
||||
// // Name pf the panel
|
||||
// Title string `json:"title,omitempty"`
|
||||
// // The type of the panel
|
||||
// Type string `json:"type,omitempty"`
|
||||
// // Panel ID
|
||||
// Id int64 `json:"id,omitempty"`
|
||||
// // Panel description
|
||||
// Description string `json:"description,omitempty"`
|
||||
// // datasource
|
||||
// Datasource string `json:"datasource,omitempty"`
|
||||
// // A collection of queries
|
||||
// Targets []Target `json:"targets,omitempty"`
|
||||
// // Display as a bar chart
|
||||
// Bars bool `json:"bars,omitempty"`
|
||||
// // Set series color
|
||||
// Colors []string `json:"colors,omitempty"`
|
||||
// // color settings
|
||||
// // todo graph
|
||||
// Color []string `json:"color,omitempty"`
|
||||
// // Display as a line chart
|
||||
// Lines bool `json:"lines,omitempty"`
|
||||
// // Display as a stacked chart
|
||||
// Stack bool `json:"stack,omitempty"`
|
||||
// // legend
|
||||
// Legend []string `json:"legend,omitempty,flow"`
|
||||
// // height
|
||||
// Height string `json:"height,omitempty"`
|
||||
// // transparent
|
||||
// Transparent bool `json:"transparent,omitempty"`
|
||||
// HiddenColumns []string `json:"hidden_columns,omitempty,flow"`
|
||||
// TimeSeriesAggregations []string `json:"time_series_aggregations,omitempty"`
|
||||
// // value name
|
||||
// ValueName string `json:"valueName,omitempty"`
|
||||
// // *****common properties end
|
||||
|
||||
// // private property of graph panel
|
||||
// // Y-axis options
|
||||
// Yaxes []Yaxis `json:"yaxes,omitempty"`
|
||||
|
||||
// // private properties of singlestat panel
|
||||
// // spark line: full or bottom
|
||||
// SparkLine string `json:"sparkline,omitempty"`
|
||||
// // Limit the decimal numbers
|
||||
// Decimals int64 `json:"decimals,omitempty"`
|
||||
// // Display unit
|
||||
// Format string `json:"format,omitempty"`
|
||||
// // gauge
|
||||
// Gauge *Gauge `json:"gauge,omitempty"`
|
||||
|
||||
// // table panel has no private property
|
||||
|
||||
// // private properties of text panel
|
||||
// HTML string `json:"html,omitempty"`
|
||||
// Markdown string `json:"markdown,omitempty"`
|
||||
// }
|
||||
|
||||
type (
|
||||
Panel struct {
|
||||
CommonPanel `json:",inline"`
|
||||
*GraphPanel `json:",inline"`
|
||||
// RowPanel *RowPanel `json:",inline"`
|
||||
*SinglestatPanel `json:",inline"`
|
||||
*TablePanel `json:",inline"`
|
||||
*TextPanel `json:",inline"`
|
||||
*BarGaugePanel `json:",inline"`
|
||||
// *CustomPanel `json:",inline"`
|
||||
}
|
||||
probePanel struct {
|
||||
CommonPanel
|
||||
}
|
||||
|
||||
// CustomPanel map[string]runtime.RawExtension
|
||||
)
|
||||
|
||||
func (p *Panel) UnmarshalJSON(b []byte) (err error) {
|
||||
var probe probePanel
|
||||
if err = json.Unmarshal(b, &probe); err == nil {
|
||||
p.CommonPanel = probe.CommonPanel
|
||||
switch probe.Type {
|
||||
case "graph":
|
||||
var graph GraphPanel
|
||||
if err = json.Unmarshal(b, &graph); err == nil {
|
||||
if !isZero(reflect.ValueOf(graph)) {
|
||||
p.GraphPanel = &graph
|
||||
}
|
||||
}
|
||||
case "table":
|
||||
var table TablePanel
|
||||
if err = json.Unmarshal(b, &table); err == nil {
|
||||
if !isZero(reflect.ValueOf(table)) {
|
||||
p.TablePanel = &table
|
||||
}
|
||||
}
|
||||
case "text":
|
||||
var text TextPanel
|
||||
if err = json.Unmarshal(b, &text); err == nil {
|
||||
if !isZero(reflect.ValueOf(text)) {
|
||||
p.TextPanel = &text
|
||||
}
|
||||
}
|
||||
case "singlestat":
|
||||
var singlestat SinglestatPanel
|
||||
if err = json.Unmarshal(b, &singlestat); err == nil {
|
||||
if !isZero(reflect.ValueOf(singlestat)) {
|
||||
p.SinglestatPanel = &singlestat
|
||||
}
|
||||
}
|
||||
case "bargauge":
|
||||
var bargauge BarGaugePanel
|
||||
if err = json.Unmarshal(b, &bargauge); err == nil {
|
||||
if !isZero(reflect.ValueOf(bargauge)) {
|
||||
p.BarGaugePanel = &bargauge
|
||||
}
|
||||
}
|
||||
case "row":
|
||||
// var row RowPanel
|
||||
// if err = json.Unmarshal(b, &row); err == nil {
|
||||
// p.RowPanel = &row
|
||||
// }
|
||||
// default:
|
||||
// var custom = make(CustomPanel)
|
||||
// if err = json.Unmarshal(b, &custom); err == nil {
|
||||
// p.CustomPanel = &custom
|
||||
// }
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (p *Panel) MarshalJSON() ([]byte, error) {
|
||||
var outCommon = struct {
|
||||
CommonPanel
|
||||
}{p.CommonPanel}
|
||||
|
||||
switch p.Type {
|
||||
case "graph":
|
||||
if p.GraphPanel == nil {
|
||||
return json.Marshal(outCommon)
|
||||
}
|
||||
var outGraph = struct {
|
||||
CommonPanel
|
||||
GraphPanel
|
||||
}{p.CommonPanel, *p.GraphPanel}
|
||||
return json.Marshal(outGraph)
|
||||
case "table":
|
||||
if p.TablePanel == nil {
|
||||
return json.Marshal(outCommon)
|
||||
}
|
||||
var outTable = struct {
|
||||
CommonPanel
|
||||
TablePanel
|
||||
}{p.CommonPanel, *p.TablePanel}
|
||||
return json.Marshal(outTable)
|
||||
case "text":
|
||||
if p.TextPanel == nil {
|
||||
return json.Marshal(outCommon)
|
||||
}
|
||||
var outText = struct {
|
||||
CommonPanel
|
||||
TextPanel
|
||||
}{p.CommonPanel, *p.TextPanel}
|
||||
return json.Marshal(outText)
|
||||
case "singlestat":
|
||||
if p.SinglestatPanel == nil {
|
||||
return json.Marshal(outCommon)
|
||||
}
|
||||
var outSinglestat = struct {
|
||||
CommonPanel
|
||||
SinglestatPanel
|
||||
}{p.CommonPanel, *p.SinglestatPanel}
|
||||
return json.Marshal(outSinglestat)
|
||||
|
||||
case "bargauge":
|
||||
if p.BarGaugePanel == nil {
|
||||
return json.Marshal(outCommon)
|
||||
}
|
||||
var outBarGauge = struct {
|
||||
CommonPanel
|
||||
BarGaugePanel
|
||||
}{p.CommonPanel, *p.BarGaugePanel}
|
||||
return json.Marshal(outBarGauge)
|
||||
case "row":
|
||||
var outRow = struct {
|
||||
CommonPanel
|
||||
}{p.CommonPanel}
|
||||
return json.Marshal(outRow)
|
||||
// default:
|
||||
// var outCustom = struct {
|
||||
// CommonPanel
|
||||
// CustomPanel
|
||||
// }{p.CommonPanel, *p.CustomPanel}
|
||||
// return json.Marshal(outCustom)
|
||||
}
|
||||
return nil, errors.New("can't marshal unknown panel type")
|
||||
}
|
||||
|
||||
func isZero(value reflect.Value) bool {
|
||||
switch value.Kind() {
|
||||
case reflect.String:
|
||||
return value.Len() == 0
|
||||
case reflect.Bool:
|
||||
return !value.Bool()
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return value.Int() == 0
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
return value.Uint() == 0
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return value.Float() == 0
|
||||
case reflect.Interface, reflect.Ptr:
|
||||
return value.IsNil()
|
||||
}
|
||||
return reflect.DeepEqual(value.Interface(), reflect.Zero(value.Type()).Interface())
|
||||
}
|
||||
39
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/panels/graph_types.go
generated
vendored
Normal file
39
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/panels/graph_types.go
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
// +kubebuilder:object:generate=true
|
||||
|
||||
package panels
|
||||
|
||||
// Graph visualizes range query results into a linear graph
|
||||
type GraphPanel struct {
|
||||
// Display as a bar chart
|
||||
Bars bool `json:"bars,omitempty"`
|
||||
// Display as a line chart
|
||||
Lines bool `json:"lines,omitempty"`
|
||||
// Display as a stacked chart
|
||||
Stack bool `json:"stack,omitempty"`
|
||||
|
||||
Xaxis Axis `json:"xaxis,omitempty"`
|
||||
// Y-axis options
|
||||
Yaxes []Axis `json:"yaxes,omitempty"`
|
||||
}
|
||||
|
||||
type Axis struct {
|
||||
// Limit the decimal numbers
|
||||
Decimals int64 `json:"decimals,omitempty"`
|
||||
// Display unit
|
||||
Format string `json:"format,omitempty"`
|
||||
}
|
||||
|
||||
// type Legend struct {
|
||||
// AlignAsTable bool `json:"alignAsTable,omitempty"`
|
||||
// Avg bool `json:"avg,omitempty"`
|
||||
// Current bool `json:"current,omitempty" `
|
||||
// HideEmpty bool `json:"hideEmpty,omitempty"`
|
||||
// HideZero bool `json:"hideZero,omitempty"`
|
||||
// Max bool `json:"max,omitempty"`
|
||||
// Min bool `json:"min,omitempty"`
|
||||
// RightSide bool `json:"rightSide,omitempty"`
|
||||
// Show bool `json:"show,omitempty"`
|
||||
// SideWidth *uint `json:"sideWidth,omitempty"`
|
||||
// Total bool `json:"total,omitempty"`
|
||||
// Values bool `json:"values,omitempty"`
|
||||
// }
|
||||
7
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/panels/row_types.go
generated
vendored
Normal file
7
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/panels/row_types.go
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
// +kubebuilder:object:generate=true
|
||||
|
||||
package panels
|
||||
|
||||
// Row groups relevant charts
|
||||
type RowPanel struct {
|
||||
}
|
||||
31
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/panels/singlestat_types.go
generated
vendored
Normal file
31
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/panels/singlestat_types.go
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
// +kubebuilder:object:generate=true
|
||||
|
||||
package panels
|
||||
|
||||
// SingleStat shows instant query result
|
||||
type SinglestatPanel struct {
|
||||
// spark line: full or bottom
|
||||
SparkLine string `json:"sparkline,omitempty"`
|
||||
// gauge
|
||||
Gauge Gauge `json:"gauge,omitempty"`
|
||||
// value name
|
||||
ValueName string `json:"valueName,omitempty"`
|
||||
}
|
||||
|
||||
// Gauge for a stat
|
||||
type Gauge struct {
|
||||
MaxValue int64 `json:"maxValue,omitempty"`
|
||||
MinValue int64 `json:"minValue,omitempty"`
|
||||
Show bool `json:"show,omitempty"`
|
||||
ThresholdLabels bool `json:"thresholdLabels,omitempty"`
|
||||
ThresholdMarkers bool `json:"thresholdMarkers,omitempty"`
|
||||
}
|
||||
|
||||
// type SparkLine struct {
|
||||
// FillColor *string `json:"fillColor,omitempty"`
|
||||
// Full bool `json:"full,omitempty"`
|
||||
// LineColor *string `json:"lineColor,omitempty"`
|
||||
// Show bool `json:"show,omitempty"`
|
||||
// YMin *float64 `json:"ymin,omitempty"`
|
||||
// YMax *float64 `json:"ymax,omitempty"`
|
||||
// }
|
||||
14
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/panels/table_types.go
generated
vendored
Normal file
14
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/panels/table_types.go
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// +kubebuilder:object:generate=true
|
||||
|
||||
package panels
|
||||
|
||||
// a table panel
|
||||
type TablePanel struct {
|
||||
Sort *Sort `json:"sort,omitempty"`
|
||||
Scroll bool `json:"scroll,omitempty"`
|
||||
}
|
||||
|
||||
type Sort struct {
|
||||
Col int `json:"col,omitempty"`
|
||||
Desc bool `json:"desc,omitempty"`
|
||||
}
|
||||
10
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/panels/text_types.go
generated
vendored
Normal file
10
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/panels/text_types.go
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
// +kubebuilder:object:generate=true
|
||||
|
||||
package panels
|
||||
|
||||
// dashboard text type
|
||||
// referers to https://pkg.go.dev/github.com/K-Phoen/grabana/decoder#DashboardText
|
||||
type TextPanel struct {
|
||||
Mode string `json:"mode,omitempty"`
|
||||
Content string `json:"content,omitempty"`
|
||||
}
|
||||
296
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/panels/zz_generated.deepcopy.go
generated
vendored
Normal file
296
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/panels/zz_generated.deepcopy.go
generated
vendored
Normal file
@@ -0,0 +1,296 @@
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright 2020 The KubeSphere authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by controller-gen. DO NOT EDIT.
|
||||
|
||||
package panels
|
||||
|
||||
import ()
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Axis) DeepCopyInto(out *Axis) {
|
||||
*out = *in
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Axis.
|
||||
func (in *Axis) DeepCopy() *Axis {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(Axis)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *BarGaugeOptions) DeepCopyInto(out *BarGaugeOptions) {
|
||||
*out = *in
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BarGaugeOptions.
|
||||
func (in *BarGaugeOptions) DeepCopy() *BarGaugeOptions {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(BarGaugeOptions)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *BarGaugePanel) DeepCopyInto(out *BarGaugePanel) {
|
||||
*out = *in
|
||||
if in.Options != nil {
|
||||
in, out := &in.Options, &out.Options
|
||||
*out = new(BarGaugeOptions)
|
||||
**out = **in
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BarGaugePanel.
|
||||
func (in *BarGaugePanel) DeepCopy() *BarGaugePanel {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(BarGaugePanel)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *CommonPanel) DeepCopyInto(out *CommonPanel) {
|
||||
*out = *in
|
||||
if in.Description != nil {
|
||||
in, out := &in.Description, &out.Description
|
||||
*out = new(string)
|
||||
**out = **in
|
||||
}
|
||||
if in.Datasource != nil {
|
||||
in, out := &in.Datasource, &out.Datasource
|
||||
*out = new(string)
|
||||
**out = **in
|
||||
}
|
||||
if in.Height != nil {
|
||||
in, out := &in.Height, &out.Height
|
||||
*out = new(string)
|
||||
**out = **in
|
||||
}
|
||||
if in.Decimals != nil {
|
||||
in, out := &in.Decimals, &out.Decimals
|
||||
*out = new(int64)
|
||||
**out = **in
|
||||
}
|
||||
if in.Targets != nil {
|
||||
in, out := &in.Targets, &out.Targets
|
||||
*out = make([]Target, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
if in.Colors != nil {
|
||||
in, out := &in.Colors, &out.Colors
|
||||
*out = make([]string, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
if in.Legend != nil {
|
||||
in, out := &in.Legend, &out.Legend
|
||||
*out = make([]string, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CommonPanel.
|
||||
func (in *CommonPanel) DeepCopy() *CommonPanel {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(CommonPanel)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Gauge) DeepCopyInto(out *Gauge) {
|
||||
*out = *in
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Gauge.
|
||||
func (in *Gauge) DeepCopy() *Gauge {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(Gauge)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *GraphPanel) DeepCopyInto(out *GraphPanel) {
|
||||
*out = *in
|
||||
out.Xaxis = in.Xaxis
|
||||
if in.Yaxes != nil {
|
||||
in, out := &in.Yaxes, &out.Yaxes
|
||||
*out = make([]Axis, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GraphPanel.
|
||||
func (in *GraphPanel) DeepCopy() *GraphPanel {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(GraphPanel)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Panel) DeepCopyInto(out *Panel) {
|
||||
*out = *in
|
||||
in.CommonPanel.DeepCopyInto(&out.CommonPanel)
|
||||
if in.GraphPanel != nil {
|
||||
in, out := &in.GraphPanel, &out.GraphPanel
|
||||
*out = new(GraphPanel)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
if in.SinglestatPanel != nil {
|
||||
in, out := &in.SinglestatPanel, &out.SinglestatPanel
|
||||
*out = new(SinglestatPanel)
|
||||
**out = **in
|
||||
}
|
||||
if in.TablePanel != nil {
|
||||
in, out := &in.TablePanel, &out.TablePanel
|
||||
*out = new(TablePanel)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
if in.TextPanel != nil {
|
||||
in, out := &in.TextPanel, &out.TextPanel
|
||||
*out = new(TextPanel)
|
||||
**out = **in
|
||||
}
|
||||
if in.BarGaugePanel != nil {
|
||||
in, out := &in.BarGaugePanel, &out.BarGaugePanel
|
||||
*out = new(BarGaugePanel)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Panel.
|
||||
func (in *Panel) DeepCopy() *Panel {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(Panel)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *RowPanel) DeepCopyInto(out *RowPanel) {
|
||||
*out = *in
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RowPanel.
|
||||
func (in *RowPanel) DeepCopy() *RowPanel {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(RowPanel)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *SinglestatPanel) DeepCopyInto(out *SinglestatPanel) {
|
||||
*out = *in
|
||||
out.Gauge = in.Gauge
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SinglestatPanel.
|
||||
func (in *SinglestatPanel) DeepCopy() *SinglestatPanel {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(SinglestatPanel)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Sort) DeepCopyInto(out *Sort) {
|
||||
*out = *in
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Sort.
|
||||
func (in *Sort) DeepCopy() *Sort {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(Sort)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *TablePanel) DeepCopyInto(out *TablePanel) {
|
||||
*out = *in
|
||||
if in.Sort != nil {
|
||||
in, out := &in.Sort, &out.Sort
|
||||
*out = new(Sort)
|
||||
**out = **in
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TablePanel.
|
||||
func (in *TablePanel) DeepCopy() *TablePanel {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(TablePanel)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Target) DeepCopyInto(out *Target) {
|
||||
*out = *in
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Target.
|
||||
func (in *Target) DeepCopy() *Target {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(Target)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *TextPanel) DeepCopyInto(out *TextPanel) {
|
||||
*out = *in
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TextPanel.
|
||||
func (in *TextPanel) DeepCopy() *TextPanel {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(TextPanel)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
109
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/templatings/dashboard_templatings_types.go
generated
vendored
Normal file
109
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/templatings/dashboard_templatings_types.go
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
// +kubebuilder:object:generate=true
|
||||
|
||||
package templatings
|
||||
|
||||
//referers to https://pkg.go.dev/github.com/K-Phoen/grabana/decoder#DashboardVariable
|
||||
// type Templatings struct {
|
||||
// Interval *VariableInterval `json:"interval,omitempty"`
|
||||
// Custom *VariableCustom `json:"custom,omitempty"`
|
||||
// Query *VariableQuery `json:"query,omitempty"`
|
||||
// Const *VariableConst `json:"const,omitempty"`
|
||||
// Datasource *VariableDatasource `json:"datasource,omitempty"`
|
||||
// }
|
||||
|
||||
// type VariableInterval struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// Label string `json:"label,omitempty"`
|
||||
// Default string `json:"default,omitempty"`
|
||||
// Values []string `json:"values,omitempty,flow"`
|
||||
// }
|
||||
|
||||
// type VariableCustom struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// Label string `json:"label,omitempty"`
|
||||
// Default string `json:"default,omitempty"`
|
||||
// ValuesMap map[string]string `json:"values_map,omitempty"`
|
||||
// IncludeAll bool `json:"include_all,omitempty"`
|
||||
// AllValue string `json:"all_value,omitempty"`
|
||||
// }
|
||||
|
||||
// type VariableConst struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// Label string `json:"label,omitempty"`
|
||||
// Default string `json:"default,omitempty"`
|
||||
// ValuesMap map[string]string `json:"values_map,omitempty"`
|
||||
// }
|
||||
|
||||
// type VariableQuery struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// Label string `json:"label,omitempty"`
|
||||
// Datasource string `json:"datasource,omitempty"`
|
||||
// Request string `json:"request,omitempty"`
|
||||
// Regex string `json:"regex,omitempty"`
|
||||
// IncludeAll bool `json:"include_all,omitempty"`
|
||||
// DefaultAll bool `json:"default_all,omitempty"`
|
||||
// AllValue string `json:"all_value,omitempty"`
|
||||
// }
|
||||
|
||||
// type VariableDatasource struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// Label string `json:"label,omitempty"`
|
||||
// Query string `json:"query,omitempty"`
|
||||
// Regex string `json:"regex,omitempty"`
|
||||
// IncludeAll bool `json:"include_all,omitempty"`
|
||||
// }
|
||||
|
||||
// type TemplateVar struct {
|
||||
// // common properties, more than one containing
|
||||
// Name string `json:"name,omitempty"`
|
||||
// Type string `json:"type,omitempty"`
|
||||
// Auto bool `json:"auto,omitempty"`
|
||||
// AutoCount *int `json:"auto_count,omitempty"`
|
||||
// Label string `json:"label,omitempty"`
|
||||
// Default string `json:"default,omitempty"`
|
||||
// ValuesMap map[string]string `json:"values_map,omitempty"`
|
||||
// IncludeAll bool `json:"include_all,omitempty"`
|
||||
// AllValue string `json:"all_value,omitempty"`
|
||||
// Regex string `json:"regex,omitempty"`
|
||||
// // from type VariableInterval
|
||||
// Values []string `json:"values,omitempty,flow"`
|
||||
|
||||
// // type VariableCustom has no special field
|
||||
// // type VariableConst has no special field
|
||||
|
||||
// // from type VariableQuery
|
||||
// Datasource string `json:"datasource,omitempty"`
|
||||
// Request string `json:"request,omitempty"`
|
||||
// DefaultAll bool `json:"default_all,omitempty"`
|
||||
|
||||
// // from type VariableDatasource
|
||||
// Query string `json:"query,omitempty"`
|
||||
// }
|
||||
|
||||
// Refers to https://pkg.go.dev/github.com/grafana-tools/sdk#Templating
|
||||
//TemplateVar combines above types to one struct
|
||||
|
||||
type TemplateVar struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Auto bool `json:"auto,omitempty"`
|
||||
AutoCount *int `json:"auto_count,omitempty"`
|
||||
Datasource *string `json:"datasource,omitempty"`
|
||||
Options []Option `json:"options,omitempty"`
|
||||
IncludeAll bool `json:"includeAll,omitempty"`
|
||||
AllFormat string `json:"allFormat,omitempty"`
|
||||
AllValue string `json:"allValue,omitempty"`
|
||||
Multi bool `json:"multi,omitempty"`
|
||||
MultiFormat string `json:"multiFormat,omitempty"`
|
||||
Query string `json:"query,omitempty"`
|
||||
Regex string `json:"regex,omitempty"`
|
||||
Label string `json:"label,omitempty"`
|
||||
Hide uint8 `json:"hide,omitempty"`
|
||||
Sort int `json:"sort,omitempty"`
|
||||
}
|
||||
|
||||
type Option struct {
|
||||
Text string `json:"text,omitempty"`
|
||||
Value string `json:"value,omitempty"`
|
||||
Selected bool `json:"selected,omitempty"`
|
||||
}
|
||||
68
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/templatings/zz_generated.deepcopy.go
generated
vendored
Normal file
68
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/templatings/zz_generated.deepcopy.go
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright 2020 The KubeSphere authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by controller-gen. DO NOT EDIT.
|
||||
|
||||
package templatings
|
||||
|
||||
import ()
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Option) DeepCopyInto(out *Option) {
|
||||
*out = *in
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Option.
|
||||
func (in *Option) DeepCopy() *Option {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(Option)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *TemplateVar) DeepCopyInto(out *TemplateVar) {
|
||||
*out = *in
|
||||
if in.AutoCount != nil {
|
||||
in, out := &in.AutoCount, &out.AutoCount
|
||||
*out = new(int)
|
||||
**out = **in
|
||||
}
|
||||
if in.Datasource != nil {
|
||||
in, out := &in.Datasource, &out.Datasource
|
||||
*out = new(string)
|
||||
**out = **in
|
||||
}
|
||||
if in.Options != nil {
|
||||
in, out := &in.Options, &out.Options
|
||||
*out = make([]Option, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateVar.
|
||||
func (in *TemplateVar) DeepCopy() *TemplateVar {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(TemplateVar)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
13
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/time/dashboard_time_types.go
generated
vendored
Normal file
13
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/time/dashboard_time_types.go
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
// +kubebuilder:object:generate=true
|
||||
|
||||
package time
|
||||
|
||||
// Time ranges of the metrics for display
|
||||
type Time struct {
|
||||
// Start time in the format of `^now([+-][0-9]+[smhdwMy])?$`, eg. `now-1M`.
|
||||
// It denotes the end time is set to the last month since now.
|
||||
From string `json:"from,omitempty" json:"from,omitempty"`
|
||||
// End time in the format of `^now([+-][0-9]+[smhdwMy])?$`, eg. `now-1M`.
|
||||
// It denotes the start time is set to the last month since now.
|
||||
To string `json:"to,omitempty" json:"to,omitempty"`
|
||||
}
|
||||
38
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/time/zz_generated.deepcopy.go
generated
vendored
Normal file
38
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/time/zz_generated.deepcopy.go
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright 2020 The KubeSphere authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by controller-gen. DO NOT EDIT.
|
||||
|
||||
package time
|
||||
|
||||
import ()
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Time) DeepCopyInto(out *Time) {
|
||||
*out = *in
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Time.
|
||||
func (in *Time) DeepCopy() *Time {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(Time)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
190
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/zz_generated.deepcopy.go
generated
vendored
Normal file
190
vendor/kubesphere.io/monitoring-dashboard/api/v1alpha2/zz_generated.deepcopy.go
generated
vendored
Normal file
@@ -0,0 +1,190 @@
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright 2020 The KubeSphere authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by controller-gen. DO NOT EDIT.
|
||||
|
||||
package v1alpha2
|
||||
|
||||
import (
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
annotations "kubesphere.io/monitoring-dashboard/api/v1alpha2/annotations"
|
||||
"kubesphere.io/monitoring-dashboard/api/v1alpha2/panels"
|
||||
"kubesphere.io/monitoring-dashboard/api/v1alpha2/templatings"
|
||||
)
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ClusterDashboard) DeepCopyInto(out *ClusterDashboard) {
|
||||
*out = *in
|
||||
out.TypeMeta = in.TypeMeta
|
||||
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
||||
in.Spec.DeepCopyInto(&out.Spec)
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterDashboard.
|
||||
func (in *ClusterDashboard) DeepCopy() *ClusterDashboard {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(ClusterDashboard)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||
func (in *ClusterDashboard) DeepCopyObject() runtime.Object {
|
||||
if c := in.DeepCopy(); c != nil {
|
||||
return c
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ClusterDashboardList) DeepCopyInto(out *ClusterDashboardList) {
|
||||
*out = *in
|
||||
out.TypeMeta = in.TypeMeta
|
||||
in.ListMeta.DeepCopyInto(&out.ListMeta)
|
||||
if in.Items != nil {
|
||||
in, out := &in.Items, &out.Items
|
||||
*out = make([]ClusterDashboard, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterDashboardList.
|
||||
func (in *ClusterDashboardList) DeepCopy() *ClusterDashboardList {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(ClusterDashboardList)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||
func (in *ClusterDashboardList) DeepCopyObject() runtime.Object {
|
||||
if c := in.DeepCopy(); c != nil {
|
||||
return c
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Dashboard) DeepCopyInto(out *Dashboard) {
|
||||
*out = *in
|
||||
out.TypeMeta = in.TypeMeta
|
||||
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
||||
in.Spec.DeepCopyInto(&out.Spec)
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Dashboard.
|
||||
func (in *Dashboard) DeepCopy() *Dashboard {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(Dashboard)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||
func (in *Dashboard) DeepCopyObject() runtime.Object {
|
||||
if c := in.DeepCopy(); c != nil {
|
||||
return c
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *DashboardList) DeepCopyInto(out *DashboardList) {
|
||||
*out = *in
|
||||
out.TypeMeta = in.TypeMeta
|
||||
in.ListMeta.DeepCopyInto(&out.ListMeta)
|
||||
if in.Items != nil {
|
||||
in, out := &in.Items, &out.Items
|
||||
*out = make([]Dashboard, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DashboardList.
|
||||
func (in *DashboardList) DeepCopy() *DashboardList {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(DashboardList)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||
func (in *DashboardList) DeepCopyObject() runtime.Object {
|
||||
if c := in.DeepCopy(); c != nil {
|
||||
return c
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *DashboardSpec) DeepCopyInto(out *DashboardSpec) {
|
||||
*out = *in
|
||||
if in.Tags != nil {
|
||||
in, out := &in.Tags, &out.Tags
|
||||
*out = make([]string, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
if in.Annotations != nil {
|
||||
in, out := &in.Annotations, &out.Annotations
|
||||
*out = make([]annotations.Annotation, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
out.Time = in.Time
|
||||
if in.Panels != nil {
|
||||
in, out := &in.Panels, &out.Panels
|
||||
*out = make([]*panels.Panel, len(*in))
|
||||
for i := range *in {
|
||||
if (*in)[i] != nil {
|
||||
in, out := &(*in)[i], &(*out)[i]
|
||||
*out = new(panels.Panel)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
}
|
||||
}
|
||||
if in.Templatings != nil {
|
||||
in, out := &in.Templatings, &out.Templatings
|
||||
*out = make([]templatings.TemplateVar, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DashboardSpec.
|
||||
func (in *DashboardSpec) DeepCopy() *DashboardSpec {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(DashboardSpec)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
788
vendor/kubesphere.io/monitoring-dashboard/tools/converter/dashboard_converter.go
generated
vendored
Normal file
788
vendor/kubesphere.io/monitoring-dashboard/tools/converter/dashboard_converter.go
generated
vendored
Normal file
@@ -0,0 +1,788 @@
|
||||
package converter
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
yamlConverter "github.com/ghodss/yaml"
|
||||
"github.com/grafana-tools/sdk"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
v1alpha2 "kubesphere.io/monitoring-dashboard/api/v1alpha2"
|
||||
ansModel "kubesphere.io/monitoring-dashboard/api/v1alpha2/annotations"
|
||||
panelsModel "kubesphere.io/monitoring-dashboard/api/v1alpha2/panels"
|
||||
templatingsModel "kubesphere.io/monitoring-dashboard/api/v1alpha2/templatings"
|
||||
)
|
||||
|
||||
type k8sDashboard struct {
|
||||
APIVersion string `json:"apiVersion" yaml:"apiVersion"`
|
||||
Kind string `json:"kind" yaml:"kind"`
|
||||
Metadata map[string]string `json:"metadata" yaml:"metadata"`
|
||||
Spec *v1alpha2.DashboardSpec `json:"spec" yaml:"spec"`
|
||||
}
|
||||
|
||||
// Converter struct: this struct has a log property, so other newly added methods can access this log
|
||||
type Converter struct {
|
||||
OutputJson []byte
|
||||
OutputYaml []byte
|
||||
}
|
||||
|
||||
// NewConverter: new a Converter struct object with a logger object
|
||||
func NewConverter() *Converter {
|
||||
return &Converter{}
|
||||
}
|
||||
|
||||
// ConvertToDashboard converts the input json content to Dashboard model
|
||||
func (converter *Converter) ConvertToDashboard(content []byte, isClusterCrd bool, ns string, name string) (*k8sDashboard, error) {
|
||||
// convert to a dashboard
|
||||
dashboard, err := converter.convert(content, isClusterCrd)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could parse input: %s", err.Error())
|
||||
}
|
||||
|
||||
apiVersion := v1alpha2.GroupVersion.Group + "/" + v1alpha2.GroupVersion.Version
|
||||
|
||||
kind := "Dashboard"
|
||||
if isClusterCrd {
|
||||
kind = "ClusterDashboard"
|
||||
}
|
||||
|
||||
metadata := make(map[string]string)
|
||||
if ns == "" {
|
||||
ns = "default"
|
||||
}
|
||||
if !isClusterCrd {
|
||||
metadata["namespace"] = ns
|
||||
}
|
||||
metadata["name"] = name
|
||||
|
||||
return &k8sDashboard{
|
||||
APIVersion: apiVersion,
|
||||
Kind: kind,
|
||||
Metadata: metadata,
|
||||
Spec: dashboard,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
// ConvertDashboardToJson converts the input json content to json bytes content
|
||||
func (converter *Converter) ConvertDashboardToJson(content []byte, isClusterCrd bool, ns string, name string) error {
|
||||
manifest, err := converter.ConvertToDashboard(content, isClusterCrd, ns, name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not convert json content to dashboard: %s", err.Error())
|
||||
}
|
||||
convertedJson, err := json.Marshal(manifest)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not marshal dashboard to json: %s", err.Error())
|
||||
}
|
||||
|
||||
converter.OutputJson = convertedJson
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConvertDashboardToYaml converts the input json content to yaml bytes content
|
||||
func (converter *Converter) ConvertDashboardToYaml(content []byte, isClusterCrd bool, ns string, name string) error {
|
||||
err := converter.ConvertDashboardToJson(content, isClusterCrd, ns, name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not marshal dashboard to json: %s", err.Error())
|
||||
}
|
||||
convertedYaml, err := yamlConverter.JSONToYAML(converter.OutputJson)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not convert json to yaml: %s", err.Error())
|
||||
}
|
||||
|
||||
converter.OutputYaml = convertedYaml
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConvertFromFile converts the input json file to yaml/json bytes content
|
||||
func (converter *Converter) ConvertFromFile(input io.Reader, isClusterCrd bool, ns string, name string) error {
|
||||
content, err := ioutil.ReadAll(input)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not read input: %s", err.Error())
|
||||
}
|
||||
|
||||
err = converter.ConvertDashboardToYaml(content, isClusterCrd, ns, name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not convert from input: %s", err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConvertToKubsphereDashboardManifests converts to a k8s mainfest file
|
||||
func (converter *Converter) ConvertToKubsphereDashboardManifests(input io.Reader, output io.Writer, isClusterCrd bool, ns string, name string) error {
|
||||
|
||||
err := converter.ConvertFromFile(input, isClusterCrd, ns, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = output.Write([]byte(converter.OutputYaml))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// convert reads a input Converter file, then extract needed fields to the yaml model
|
||||
func (converter *Converter) convert(content []byte, isClusterCrd bool) (*v1alpha2.DashboardSpec, error) {
|
||||
|
||||
board := &sdk.Board{}
|
||||
if err := json.Unmarshal(content, board); err != nil {
|
||||
return nil, fmt.Errorf("could not unmarshall dashboard: %s", err.Error())
|
||||
}
|
||||
|
||||
// a yaml model
|
||||
dashboard := &v1alpha2.DashboardSpec{}
|
||||
|
||||
// starts to convert general settings
|
||||
converter.convertGeneralSettings(board, dashboard)
|
||||
// starts to convert templating variables
|
||||
converter.convertVariables(board.Templating.List, dashboard)
|
||||
// starts to convert annotations
|
||||
converter.convertAnnotations(board.Annotations.List, dashboard)
|
||||
// starts to convert pannels
|
||||
converter.convertPanels(board.Panels, dashboard, isClusterCrd)
|
||||
// starts to convert rows
|
||||
// some dashboards only include rows
|
||||
converter.convertRows(board.Rows, dashboard, isClusterCrd)
|
||||
|
||||
return dashboard, nil
|
||||
}
|
||||
|
||||
// convert GeneralSettings
|
||||
func (converter *Converter) convertGeneralSettings(board *sdk.Board, dashboard *v1alpha2.DashboardSpec) {
|
||||
dashboard.Title = board.Title
|
||||
dashboard.Editable = board.Editable
|
||||
dashboard.SharedCrosshair = board.SharedCrosshair
|
||||
dashboard.Tags = board.Tags
|
||||
dashboard.Time.From = board.Time.From
|
||||
dashboard.Time.To = board.Time.To
|
||||
dashboard.Timezone = board.Timezone
|
||||
|
||||
if board.Refresh != nil {
|
||||
dashboard.AutoRefresh = board.Refresh.Value
|
||||
}
|
||||
}
|
||||
|
||||
// convert Annotations
|
||||
func (converter *Converter) convertAnnotations(annotations []sdk.Annotation, dashboard *v1alpha2.DashboardSpec) {
|
||||
for _, annotation := range annotations {
|
||||
// grafana-sdk doesn't expose the "builtIn" field, so we work around that by skipping
|
||||
// the annotation we know to be built-in by its name
|
||||
if annotation.Name == "Annotations & Alerts" {
|
||||
continue
|
||||
}
|
||||
|
||||
if annotation.Type != "tags" {
|
||||
continue
|
||||
}
|
||||
|
||||
datasource := ""
|
||||
if annotation.Datasource != nil {
|
||||
datasource = *annotation.Datasource
|
||||
}
|
||||
|
||||
dashboard.Annotations = append(dashboard.Annotations, ansModel.Annotation{
|
||||
Name: annotation.Name,
|
||||
Datasource: datasource,
|
||||
IconColor: annotation.IconColor,
|
||||
Tags: annotation.Tags,
|
||||
ShowLine: annotation.ShowLine,
|
||||
LineColor: annotation.LineColor,
|
||||
IconSize: annotation.IconSize,
|
||||
Enable: annotation.Enable,
|
||||
Query: annotation.Query,
|
||||
Expr: annotation.Expr,
|
||||
Step: annotation.Step,
|
||||
TextField: annotation.TextField,
|
||||
TextFormat: annotation.TextFormat,
|
||||
TitleFormat: annotation.TitleFormat,
|
||||
TagsField: annotation.TagsField,
|
||||
TagKeys: annotation.TagKeys,
|
||||
Type: annotation.Type,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// convert templating variables
|
||||
func (converter *Converter) convertVariables(variables []sdk.TemplateVar, dashboard *v1alpha2.DashboardSpec) {
|
||||
for _, variable := range variables {
|
||||
if variable.Query == nil {
|
||||
continue
|
||||
}
|
||||
q, ok := variable.Query.(string)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
var options []templatingsModel.Option
|
||||
for _, op := range variable.Options {
|
||||
options = append(options, templatingsModel.Option{
|
||||
Text: op.Text,
|
||||
Value: op.Value,
|
||||
Selected: op.Selected,
|
||||
})
|
||||
}
|
||||
v := templatingsModel.TemplateVar{
|
||||
Name: variable.Name,
|
||||
Type: variable.Type,
|
||||
Auto: variable.Auto,
|
||||
AutoCount: variable.AutoCount,
|
||||
Datasource: variable.Datasource,
|
||||
Options: options,
|
||||
Query: q,
|
||||
IncludeAll: variable.IncludeAll,
|
||||
AllFormat: variable.AllFormat,
|
||||
AllValue: variable.AllValue,
|
||||
Multi: variable.Multi,
|
||||
MultiFormat: variable.MultiFormat,
|
||||
Regex: variable.Regex,
|
||||
Label: variable.Label,
|
||||
Hide: variable.Hide,
|
||||
Sort: variable.Sort,
|
||||
}
|
||||
dashboard.Templatings = append(dashboard.Templatings, v)
|
||||
}
|
||||
}
|
||||
|
||||
//convert rows
|
||||
func (converter *Converter) convertPanels(panels []*sdk.Panel, dashboard *v1alpha2.DashboardSpec, isClusterCrd bool) {
|
||||
|
||||
for _, panel := range panels {
|
||||
if panel.Type == "row" {
|
||||
for _, rowPanel := range panel.Panels {
|
||||
convertedPanel, ok := converter.convertDataPanel(rowPanel, isClusterCrd)
|
||||
if ok {
|
||||
dashboard.Panels = append(dashboard.Panels, convertedPanel)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
convertedPanel, ok := converter.convertDataPanel(*panel, isClusterCrd)
|
||||
if ok {
|
||||
dashboard.Panels = append(dashboard.Panels, convertedPanel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//convert rows
|
||||
func (converter *Converter) convertRows(rows []*sdk.Row, dashboard *v1alpha2.DashboardSpec, isClusterCrd bool) {
|
||||
|
||||
for _, row := range rows {
|
||||
if row == nil {
|
||||
continue
|
||||
}
|
||||
panels := row.Panels
|
||||
if panels == nil || len(rows) == 0 {
|
||||
continue
|
||||
}
|
||||
for _, pl := range panels {
|
||||
convertedPanel, ok := converter.convertDataPanel(pl, isClusterCrd)
|
||||
if ok {
|
||||
dashboard.Panels = append(dashboard.Panels, convertedPanel)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// convert different types of the given panel
|
||||
func (converter *Converter) convertDataPanel(panel sdk.Panel, isClusterCrd bool) (*panelsModel.Panel, bool) {
|
||||
switch panel.Type {
|
||||
case "graph":
|
||||
return converter.convertGraph(panel, isClusterCrd), true
|
||||
case "singlestat":
|
||||
return converter.convertSingleStat(panel, isClusterCrd), true
|
||||
case "bargauge":
|
||||
return converter.convertBarGauge(panel, isClusterCrd), true
|
||||
case "table":
|
||||
return converter.convertTable(panel, isClusterCrd), true
|
||||
case "text":
|
||||
return converter.convertText(panel), true
|
||||
default:
|
||||
if panel.OfType == sdk.CustomType {
|
||||
return converter.convertCustom(panel, isClusterCrd), true
|
||||
}
|
||||
}
|
||||
return &panelsModel.Panel{}, false
|
||||
}
|
||||
|
||||
// a graph panel
|
||||
func (converter *Converter) convertGraph(panel sdk.Panel, isClusterCrd bool) *panelsModel.Panel {
|
||||
// filled with values of the given fields
|
||||
var height *string
|
||||
if panel.Height != nil {
|
||||
var h = panel.Height.(string)
|
||||
height = &h
|
||||
}
|
||||
graph := &panelsModel.Panel{
|
||||
CommonPanel: panelsModel.CommonPanel{
|
||||
Title: panel.Title,
|
||||
Id: int64(panel.ID),
|
||||
Type: panel.Type,
|
||||
Description: panel.CommonPanel.Description,
|
||||
Height: height,
|
||||
Datasource: panel.Datasource,
|
||||
Colors: defaultColors(),
|
||||
},
|
||||
}
|
||||
|
||||
if panel.GraphPanel == nil {
|
||||
return graph
|
||||
}
|
||||
|
||||
graph.CommonPanel.Decimals = uintpointToInt64point(panel.GraphPanel.Decimals)
|
||||
graph.CommonPanel.Legend = converter.convertLegend(panel.GraphPanel.Legend)
|
||||
|
||||
graph.GraphPanel = &panelsModel.GraphPanel{
|
||||
Bars: panel.GraphPanel.Bars,
|
||||
Lines: panel.GraphPanel.Lines,
|
||||
Stack: panel.GraphPanel.Stack,
|
||||
Xaxis: panelsModel.Axis{
|
||||
Format: panel.GraphPanel.Xaxis.Format,
|
||||
Decimals: int64(panel.GraphPanel.Xaxis.Decimals),
|
||||
},
|
||||
}
|
||||
|
||||
// converts target
|
||||
if panel.GraphPanel.Targets != nil && len(panel.GraphPanel.Targets) > 0 {
|
||||
for index, target := range panel.GraphPanel.Targets {
|
||||
graphTarget := converter.convertTarget(target, index)
|
||||
if graphTarget == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
graph.CommonPanel.Targets = append(graph.CommonPanel.Targets, *graphTarget)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// converts yaxes
|
||||
for _, yaxis := range panel.GraphPanel.Yaxes {
|
||||
graph.GraphPanel.Yaxes = append(graph.GraphPanel.Yaxes, panelsModel.Axis{
|
||||
Format: handleGraphFormat(yaxis.Format),
|
||||
Decimals: int64(yaxis.Decimals),
|
||||
})
|
||||
break
|
||||
}
|
||||
|
||||
return graph
|
||||
}
|
||||
|
||||
func (converter *Converter) convertLegend(sdkLegend sdk.Legend) []string {
|
||||
var legend []string
|
||||
|
||||
if !sdkLegend.Show {
|
||||
legend = append(legend, "hide")
|
||||
}
|
||||
if sdkLegend.AlignAsTable {
|
||||
legend = append(legend, "as_table")
|
||||
}
|
||||
if sdkLegend.RightSide {
|
||||
legend = append(legend, "to_the_right")
|
||||
}
|
||||
if sdkLegend.Min {
|
||||
legend = append(legend, "min")
|
||||
}
|
||||
if sdkLegend.Max {
|
||||
legend = append(legend, "max")
|
||||
}
|
||||
if sdkLegend.Avg {
|
||||
legend = append(legend, "avg")
|
||||
}
|
||||
if sdkLegend.Current {
|
||||
legend = append(legend, "current")
|
||||
}
|
||||
if sdkLegend.Total {
|
||||
legend = append(legend, "total")
|
||||
}
|
||||
if sdkLegend.HideEmpty {
|
||||
legend = append(legend, "no_null_series")
|
||||
}
|
||||
if sdkLegend.HideZero {
|
||||
legend = append(legend, "no_zero_series")
|
||||
}
|
||||
|
||||
return legend
|
||||
}
|
||||
|
||||
// singlestat panel
|
||||
func (converter *Converter) convertSingleStat(panel sdk.Panel, isClusterCrd bool) *panelsModel.Panel {
|
||||
var height *string
|
||||
if panel.Height != nil {
|
||||
var h = panel.Height.(string)
|
||||
height = &h
|
||||
}
|
||||
singleStat := &panelsModel.Panel{
|
||||
CommonPanel: panelsModel.CommonPanel{
|
||||
Title: panel.Title,
|
||||
Id: int64(panel.ID),
|
||||
Type: panel.Type,
|
||||
Description: panel.CommonPanel.Description,
|
||||
Height: height,
|
||||
Datasource: panel.Datasource,
|
||||
},
|
||||
}
|
||||
|
||||
if panel.SinglestatPanel == nil {
|
||||
return singleStat
|
||||
}
|
||||
|
||||
singleStat.CommonPanel.Format = panel.SinglestatPanel.Format
|
||||
singleStat.CommonPanel.Decimals = intToInt64point(panel.SinglestatPanel.Decimals)
|
||||
|
||||
singleStat.SinglestatPanel = &panelsModel.SinglestatPanel{
|
||||
ValueName: panel.SinglestatPanel.ValueName,
|
||||
}
|
||||
|
||||
if len(panel.SinglestatPanel.Colors) == 3 {
|
||||
singleStat.CommonPanel.Colors = []string{
|
||||
panel.SinglestatPanel.Colors[0],
|
||||
panel.SinglestatPanel.Colors[1],
|
||||
panel.SinglestatPanel.Colors[2],
|
||||
}
|
||||
} else {
|
||||
singleStat.CommonPanel.Colors = defaultColors()
|
||||
}
|
||||
|
||||
if panel.SinglestatPanel.SparkLine.Show && panel.SinglestatPanel.SparkLine.Full {
|
||||
singleStat.SparkLine = "full"
|
||||
}
|
||||
if panel.SinglestatPanel.SparkLine.Show && !panel.SinglestatPanel.SparkLine.Full {
|
||||
singleStat.SparkLine = "bottom"
|
||||
}
|
||||
|
||||
// handles targets
|
||||
if panel.SinglestatPanel.Targets != nil && len(panel.SinglestatPanel.Targets) > 0 {
|
||||
for index, target := range panel.SinglestatPanel.Targets {
|
||||
target := converter.convertTarget(target, index)
|
||||
if target == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
singleStat.CommonPanel.Targets = append(singleStat.CommonPanel.Targets, *target)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// handles gauge
|
||||
singleStat.Gauge = panelsModel.Gauge{
|
||||
MaxValue: int64(panel.SinglestatPanel.Gauge.MaxValue),
|
||||
MinValue: int64(panel.SinglestatPanel.Gauge.MinValue),
|
||||
Show: panel.SinglestatPanel.Gauge.Show,
|
||||
ThresholdLabels: panel.SinglestatPanel.Gauge.ThresholdLabels,
|
||||
ThresholdMarkers: panel.SinglestatPanel.Gauge.ThresholdMarkers,
|
||||
}
|
||||
|
||||
return singleStat
|
||||
}
|
||||
|
||||
// gauge
|
||||
func (converter *Converter) convertCustom(panel sdk.Panel, isClusterCrd bool) *panelsModel.Panel {
|
||||
// set options
|
||||
var height *string
|
||||
if panel.Height != nil {
|
||||
var h = panel.Height.(string)
|
||||
height = &h
|
||||
}
|
||||
customPanel := &panelsModel.Panel{
|
||||
CommonPanel: panelsModel.CommonPanel{
|
||||
Title: panel.Title,
|
||||
Id: int64(panel.ID),
|
||||
Type: "singlestat",
|
||||
Description: panel.CommonPanel.Description,
|
||||
Height: height,
|
||||
Datasource: panel.Datasource,
|
||||
},
|
||||
}
|
||||
|
||||
if panel.CustomPanel == nil {
|
||||
return customPanel
|
||||
}
|
||||
|
||||
var sdkTargets []sdk.Target
|
||||
|
||||
custom := *panel.CustomPanel
|
||||
|
||||
if err := mapstructure.Decode(custom["targets"], &sdkTargets); err != nil {
|
||||
return customPanel
|
||||
}
|
||||
|
||||
var targets []panelsModel.Target
|
||||
|
||||
for index, target := range sdkTargets {
|
||||
t := converter.convertTarget(target, index)
|
||||
if t == nil {
|
||||
continue
|
||||
}
|
||||
targets = append(targets, *t)
|
||||
}
|
||||
|
||||
customPanel.CommonPanel.Targets = targets
|
||||
|
||||
return customPanel
|
||||
}
|
||||
|
||||
// bar gauge
|
||||
func (converter *Converter) convertBarGauge(panel sdk.Panel, isClusterCrd bool) *panelsModel.Panel {
|
||||
// set options
|
||||
var height *string
|
||||
if panel.Height != nil {
|
||||
var h = panel.Height.(string)
|
||||
height = &h
|
||||
}
|
||||
barGaugePanel := &panelsModel.Panel{
|
||||
CommonPanel: panelsModel.CommonPanel{
|
||||
Title: panel.Title,
|
||||
Id: int64(panel.ID),
|
||||
Type: panel.Type,
|
||||
Description: panel.CommonPanel.Description,
|
||||
Height: height,
|
||||
Datasource: panel.Datasource,
|
||||
},
|
||||
}
|
||||
|
||||
if panel.BarGaugePanel == nil {
|
||||
return barGaugePanel
|
||||
}
|
||||
|
||||
barGaugePanel.BarGaugePanel = &panelsModel.BarGaugePanel{
|
||||
Options: &panelsModel.BarGaugeOptions{
|
||||
Orientation: panel.BarGaugePanel.Options.Orientation,
|
||||
TextMode: panel.BarGaugePanel.Options.TextMode,
|
||||
ColorMode: panel.BarGaugePanel.Options.ColorMode,
|
||||
GraphMode: panel.BarGaugePanel.Options.GraphMode,
|
||||
JustifyMode: panel.BarGaugePanel.Options.JustifyMode,
|
||||
DisplayMode: panel.BarGaugePanel.Options.DisplayMode,
|
||||
Content: panel.BarGaugePanel.Options.Content,
|
||||
Mode: panel.BarGaugePanel.Options.Mode,
|
||||
},
|
||||
}
|
||||
|
||||
// handles targets
|
||||
if panel.BarGaugePanel.Targets != nil && len(panel.BarGaugePanel.Targets) > 0 {
|
||||
for index, target := range panel.BarGaugePanel.Targets {
|
||||
barGaugeTarget := converter.convertTarget(target, index)
|
||||
if barGaugeTarget == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
barGaugePanel.CommonPanel.Targets = append(barGaugePanel.CommonPanel.Targets, *barGaugeTarget)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return barGaugePanel
|
||||
}
|
||||
|
||||
// converts a table panel
|
||||
func (converter *Converter) convertTable(panel sdk.Panel, isClusterCrd bool) *panelsModel.Panel {
|
||||
var height *string
|
||||
if panel.Height != nil {
|
||||
var h = panel.Height.(string)
|
||||
height = &h
|
||||
}
|
||||
tablePanel := &panelsModel.Panel{
|
||||
CommonPanel: panelsModel.CommonPanel{
|
||||
Title: panel.Title,
|
||||
Id: int64(panel.ID),
|
||||
Type: panel.Type,
|
||||
Description: panel.CommonPanel.Description,
|
||||
Height: height,
|
||||
Datasource: panel.Datasource,
|
||||
},
|
||||
}
|
||||
|
||||
if panel.TablePanel == nil {
|
||||
return tablePanel
|
||||
}
|
||||
|
||||
tablePanel.TablePanel = &panelsModel.TablePanel{
|
||||
Scroll: panel.TablePanel.Scroll,
|
||||
}
|
||||
|
||||
if panel.TablePanel.Targets != nil && len(panel.TablePanel.Targets) > 0 {
|
||||
for index, target := range panel.TablePanel.Targets {
|
||||
graphTarget := converter.convertTarget(target, index)
|
||||
if graphTarget == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
tablePanel.CommonPanel.Targets = append(tablePanel.CommonPanel.Targets, *graphTarget)
|
||||
}
|
||||
}
|
||||
|
||||
if panel.TablePanel.Sort != nil {
|
||||
tablePanel.TablePanel.Sort = &panelsModel.Sort{
|
||||
Col: panel.TablePanel.Sort.Col,
|
||||
Desc: panel.TablePanel.Sort.Desc,
|
||||
}
|
||||
}
|
||||
|
||||
return tablePanel
|
||||
}
|
||||
|
||||
// converts a text panel
|
||||
func (converter *Converter) convertText(panel sdk.Panel) *panelsModel.Panel {
|
||||
var height *string
|
||||
if panel.Height != nil {
|
||||
var h = panel.Height.(string)
|
||||
height = &h
|
||||
}
|
||||
|
||||
textPanel := &panelsModel.Panel{
|
||||
CommonPanel: panelsModel.CommonPanel{
|
||||
Title: panel.Title,
|
||||
Id: int64(panel.ID),
|
||||
Type: panel.Type,
|
||||
Description: panel.CommonPanel.Description,
|
||||
Height: height,
|
||||
Datasource: panel.Datasource,
|
||||
},
|
||||
}
|
||||
|
||||
if panel.TextPanel == nil {
|
||||
return textPanel
|
||||
}
|
||||
|
||||
textPanel.TextPanel = &panelsModel.TextPanel{
|
||||
Mode: panel.TextPanel.Mode,
|
||||
Content: panel.TextPanel.Content,
|
||||
}
|
||||
|
||||
return textPanel
|
||||
}
|
||||
|
||||
func (converter *Converter) convertTarget(target sdk.Target, index int) *panelsModel.Target {
|
||||
// looks like a prometheus target
|
||||
return converter.convertPrometheusTarget(target, index)
|
||||
}
|
||||
|
||||
func (converter *Converter) convertPrometheusTarget(target sdk.Target, index int) *panelsModel.Target {
|
||||
t := &panelsModel.Target{
|
||||
// RefID: target.RefID,
|
||||
RefID: int64(index) + 1,
|
||||
LegendFormat: handleLegendFormat(target.LegendFormat),
|
||||
}
|
||||
|
||||
// adjusts the query expression to adapt to the ks cluster
|
||||
converedExpr := convertExpr(target.Expr)
|
||||
if converedExpr == "" {
|
||||
t.Expression = target.Expr
|
||||
return t
|
||||
}
|
||||
|
||||
t.Expression = fmt.Sprintf("%s", converedExpr)
|
||||
t.Step = toString(target.Step)
|
||||
return t
|
||||
|
||||
}
|
||||
|
||||
func panelSpan(panel sdk.Panel) int64 {
|
||||
return int64(panel.ID)
|
||||
}
|
||||
|
||||
func defaultOption(opt sdk.Current) string {
|
||||
if opt.Value == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return opt.Value.(string)
|
||||
}
|
||||
|
||||
func handleZimu(z string) int64 {
|
||||
n, _ := strconv.Atoi(z)
|
||||
return int64(n) + 1
|
||||
}
|
||||
|
||||
func toString(step int) string {
|
||||
// number := int(step / 60)
|
||||
// if number == 0 {
|
||||
// return strconv.Itoa(step) + "s"
|
||||
// }
|
||||
// if number > 60 {
|
||||
// return strconv.Itoa(number/60) + "h"
|
||||
// }
|
||||
// return strconv.Itoa(number) + "m"
|
||||
return "1m"
|
||||
}
|
||||
|
||||
func handleGraphFormat(f string) string {
|
||||
|
||||
if f == "bytes" || f == "Bps" {
|
||||
f = "Byte"
|
||||
} else if f == "percent" || f == "percentunit" {
|
||||
f = "percent (0.0-1.0)"
|
||||
} else {
|
||||
f = "none"
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
func handleLegendFormat(l string) string {
|
||||
badPat := regexp.MustCompile(`\{(\s+\w+\s+)\}`)
|
||||
if match := badPat.Match([]byte(l)); match {
|
||||
f := func(s string) string {
|
||||
stripReg := regexp.MustCompile(`\s+`)
|
||||
return stripReg.ReplaceAllString(s, "")
|
||||
}
|
||||
return badPat.ReplaceAllStringFunc(l, f)
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
func pointToString(des *string) string {
|
||||
d := ""
|
||||
if des != nil {
|
||||
d = *des
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func uintpointToInt64point(up *uint) *int64 {
|
||||
if up != nil {
|
||||
var t = int64(*up)
|
||||
return &t
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func intToInt64point(o int) *int64 {
|
||||
var c = int64(o)
|
||||
return &c
|
||||
}
|
||||
|
||||
func defaultColors() []string {
|
||||
return []string{"#60acfc", "#23c2db", "#64d5b2", "#d5ec5a", "#ffb64e", "#fb816d", "#d15c7f"}
|
||||
}
|
||||
|
||||
func convertExpr(expr string) string {
|
||||
|
||||
// free the door if don't match a `[{}]` regex style
|
||||
pat := regexp.MustCompile(`[\{\}]`)
|
||||
if !pat.Match([]byte(expr)) {
|
||||
return ""
|
||||
}
|
||||
// handles $interval or $__interval
|
||||
pat1 := regexp.MustCompile(`\$_{0,2}interval`)
|
||||
if pat1.Match([]byte(expr)) {
|
||||
expr = pat1.ReplaceAllString(expr, "3m")
|
||||
}
|
||||
|
||||
// if contains irate/rate/count func, just removes `\{.*\}`
|
||||
pat2 := regexp.MustCompile(`\{.*?\}`)
|
||||
if matchCommon := pat2.Match([]byte(expr)); matchCommon {
|
||||
expr = pat2.ReplaceAllString(expr, "")
|
||||
}
|
||||
|
||||
// if contains count, removes `>\d+`
|
||||
pat3 := regexp.MustCompile(`>\d+`)
|
||||
if matchCount := pat3.Match([]byte(expr)); matchCount {
|
||||
expr = pat3.ReplaceAllString(expr, "")
|
||||
}
|
||||
return expr
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user