[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:
zhu733756
2021-08-16 11:41:29 +08:00
committed by zhu733756
parent 9df6df5544
commit 242ceb54f6
217 changed files with 119028 additions and 96 deletions

View 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"`
}

View 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
}