lint

package
v0.0.0-...-1e79993 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2024 License: Apache-2.0 Imports: 16 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ResultSuccess = Result{
	Severity: Success,
	Message:  "OK",
}

Functions

func FixUneditableRule

func FixUneditableRule(d *Dashboard)

func Inspect

func Inspect(node syntax.Expr, f func(syntax.Expr) bool)

Types

type Annotation

type Annotation struct {
	Name       string      `json:"name"`
	Datasource interface{} `json:"datasource,omitempty"`
}

func (*Annotation) GetDataSource

func (a *Annotation) GetDataSource() (Datasource, error)

type ConfigurationEntry

type ConfigurationEntry struct {
	Reason    string `json:"reason,omitempty"`
	Dashboard string `json:"dashboard,omitempty"`
	Panel     string `json:"panel,omitempty"`
	// Alerts are currently included, so we can read in configuration for Mixtool.
	Alert string `json:"alert,omitempty"`
	// This gets (un)marshalled as a string, because a 0 index is valid, but also the zero value of an int
	TargetIdx string `json:"targetIdx"`
}

ConfigurationEntry will exist precisely once for every instance of a rule violation you wish exclude or downgrade to a warning. Each ConfigurationEntry will have to be an *exact* match to the combination of attributes set. Reason will not be evaluated, and is an opportunity for the author to explain why the exception, or downgrade to warning exists.

func (*ConfigurationEntry) IsMatch

func (ce *ConfigurationEntry) IsMatch(r ResultContext) bool

type ConfigurationFile

type ConfigurationFile struct {
	Exclusions map[string]*ConfigurationRuleEntries `yaml:"exclusions"`
	Warnings   map[string]*ConfigurationRuleEntries `yaml:"warnings"`
	Verbose    bool                                 `yaml:"-"`
	Autofix    bool                                 `yaml:"-"`
}

ConfigurationFile contains a map for rule exclusions, and warnings, where the key is the rule name to be excluded or downgraded to a warning

func NewConfigurationFile

func NewConfigurationFile() *ConfigurationFile

func (*ConfigurationFile) Apply

func (*ConfigurationFile) Load

func (cf *ConfigurationFile) Load(path string) error

type ConfigurationRuleEntries

type ConfigurationRuleEntries struct {
	Reason  string               `json:"reason,omitempty"`
	Entries []ConfigurationEntry `json:"entries,omitempty"`
}

func (*ConfigurationRuleEntries) AddEntry

type Dashboard

type Dashboard struct {
	Inputs     []Input `json:"__inputs"`
	Title      string  `json:"title,omitempty"`
	Templating struct {
		List []Template `json:"list"`
	} `json:"templating"`
	Annotations struct {
		List []Annotation `json:"list"`
	} `json:"annotations"`
	Rows     []Row   `json:"rows,omitempty"`
	Panels   []Panel `json:"panels,omitempty"`
	Editable bool    `json:"editable,omitempty"`
}

Dashboard is a deliberately incomplete representation of the Dashboard type in grafana. The properties which are extracted from JSON are only those used for linting purposes.

func NewDashboard

func NewDashboard(buf []byte) (Dashboard, error)

func (*Dashboard) GetPanels

func (d *Dashboard) GetPanels() []Panel

GetPanels returns the all panels whether they are nested in the (now deprecated) "rows" property or in the top level "panels" property. This also monkeypatches Target.Idx into each panel which is used to uniquely identify panel targets while linting.

func (*Dashboard) GetTemplateByType

func (d *Dashboard) GetTemplateByType(t string) []Template

GetTemplateByType returns all dashboard templates which match the provided type. Type comparison is case insensitive as it uses strings.EqualFold()

func (*Dashboard) Marshal

func (d *Dashboard) Marshal() ([]byte, error)

type DashboardResult

type DashboardResult struct {
	Result
	Fix func(*Dashboard)
}

type DashboardRuleFunc

type DashboardRuleFunc struct {
	// contains filtered or unexported fields
}

func NewTemplateDatasourceRule

func NewTemplateDatasourceRule() *DashboardRuleFunc

func NewTemplateInstanceRule

func NewTemplateInstanceRule() *DashboardRuleFunc

func NewTemplateJobRule

func NewTemplateJobRule() *DashboardRuleFunc

func NewTemplateLabelPromQLRule

func NewTemplateLabelPromQLRule() *DashboardRuleFunc

func NewTemplateOnTimeRangeReloadRule

func NewTemplateOnTimeRangeReloadRule() *DashboardRuleFunc

func NewUneditableRule

func NewUneditableRule() *DashboardRuleFunc

func (DashboardRuleFunc) Description

func (f DashboardRuleFunc) Description() string

func (DashboardRuleFunc) Lint

func (f DashboardRuleFunc) Lint(d Dashboard, s *ResultSet)

func (DashboardRuleFunc) Name

func (f DashboardRuleFunc) Name() string

type DashboardRuleResults

type DashboardRuleResults struct {
	Results []DashboardResult
}

func (*DashboardRuleResults) AddError

func (r *DashboardRuleResults) AddError(d Dashboard, message string)

func (*DashboardRuleResults) AddFixableError

func (r *DashboardRuleResults) AddFixableError(d Dashboard, message string, fix func(*Dashboard))

func (*DashboardRuleResults) AddWarning

func (r *DashboardRuleResults) AddWarning(d Dashboard, message string)

type Datasource

type Datasource struct {
	UID  string `json:"uid"`
	Type string `json:"type"`
}

func GetDataSource

func GetDataSource(raw interface{}) (Datasource, error)

type FieldConfig

type FieldConfig struct {
	Defaults  dashboard.FieldConfig
	Overrides []dashboard.DashboardFieldConfigSourceOverrides
}

type FixableResult

type FixableResult struct {
	Result
	Fix func(*Dashboard) // if nil, it cannot be fixed
}

type Input

type Input struct {
	Name     string `json:"name"`
	Label    string `json:"label"`
	Type     string `json:"type"`
	PluginID string `json:"pluginId"`
}

Input is a deliberately incomplete representation of the Dashboard -> Input type in grafana. The properties which are extracted from JSON are only those used for linting purposes.

type Panel

type Panel struct {
	Id          int             `json:"id"`
	Title       string          `json:"title"`
	Description string          `json:"description,omitempty"`
	Targets     []Target        `json:"targets,omitempty"`
	Datasource  interface{}     `json:"datasource,omitempty"`
	Type        string          `json:"type"`
	Panels      []Panel         `json:"panels,omitempty"`
	FieldConfig *FieldConfig    `json:"fieldConfig,omitempty"`
	Options     json.RawMessage `json:"options,omitempty"`
}

Panel is a deliberately incomplete representation of the Dashboard -> Panel type in grafana. The properties which are extracted from JSON are only those used for linting purposes.

func (*Panel) GetDataSource

func (p *Panel) GetDataSource() (Datasource, error)

func (*Panel) GetPanels

func (p *Panel) GetPanels() []Panel

GetPanels returns the all panels nested inside the panel (inc the current panel)

type PanelResult

type PanelResult struct {
	Result
	Fix func(Dashboard, *Panel)
}

type PanelRuleFunc

type PanelRuleFunc struct {
	// contains filtered or unexported fields
}

func NewPanelDatasourceRule

func NewPanelDatasourceRule() *PanelRuleFunc

func NewPanelNoTargetsRule

func NewPanelNoTargetsRule() *PanelRuleFunc

func NewPanelTitleDescriptionRule

func NewPanelTitleDescriptionRule() *PanelRuleFunc

func NewPanelUnitsRule

func NewPanelUnitsRule() *PanelRuleFunc

func (PanelRuleFunc) Description

func (f PanelRuleFunc) Description() string

func (PanelRuleFunc) Lint

func (f PanelRuleFunc) Lint(d Dashboard, s *ResultSet)

func (PanelRuleFunc) Name

func (f PanelRuleFunc) Name() string

type PanelRuleResults

type PanelRuleResults struct {
	Results []PanelResult
}

func (*PanelRuleResults) AddError

func (r *PanelRuleResults) AddError(d Dashboard, p Panel, message string)

type RawTemplateValue

type RawTemplateValue map[string]interface{}

func (*RawTemplateValue) Get

func (raw *RawTemplateValue) Get() (TemplateValue, error)

type ReduceOptions

type ReduceOptions struct {
	Fields string `json:"fields,omitempty"`
}

oversimplified Reduce options

type Result

type Result struct {
	Severity Severity
	Message  string
}

func (Result) TtyPrint

func (r Result) TtyPrint()

type ResultContext

type ResultContext struct {
	Result    RuleResults
	Rule      Rule
	Dashboard *Dashboard
	Panel     *Panel
	Target    *Target
}

ResultContext is used by ResultSet to keep all the state data about a lint execution and it's results.

type ResultSet

type ResultSet struct {
	// contains filtered or unexported fields
}

func (*ResultSet) AddResult

func (rs *ResultSet) AddResult(r ResultContext)

AddResult adds a result to the ResultSet, applying the current configuration if set

func (*ResultSet) AutoFix

func (rs *ResultSet) AutoFix(d *Dashboard) int

func (*ResultSet) ByRule

func (rs *ResultSet) ByRule() map[string][]ResultContext

func (*ResultSet) Configure

func (rs *ResultSet) Configure(c *ConfigurationFile)

Configure adds, and applies the provided configuration to all results currently in the ResultSet

func (*ResultSet) MaximumSeverity

func (rs *ResultSet) MaximumSeverity() Severity

func (*ResultSet) ReportByRule

func (rs *ResultSet) ReportByRule()

type Row

type Row struct {
	Panels []Panel `json:"panels,omitempty"`
}

Row is a deliberately incomplete representation of the Dashboard -> Row type in grafana. The properties which are extracted from JSON are only those used for linting purposes.

func (*Row) GetPanels

func (r *Row) GetPanels() []Panel

GetPanels returns the all panels nested inside the row

type Rule

type Rule interface {
	Description() string
	Name() string
	Lint(Dashboard, *ResultSet)
}

func NewDashboardRuleFunc

func NewDashboardRuleFunc(name, description string, fn func(Dashboard) DashboardRuleResults) Rule

func NewPanelRuleFunc

func NewPanelRuleFunc(name, description string, fn func(Dashboard, Panel) PanelRuleResults) Rule

func NewTargetRuleFunc

func NewTargetRuleFunc(name, description string, fn func(Dashboard, Panel, Target) TargetRuleResults) Rule

type RuleResults

type RuleResults struct {
	Results []FixableResult
}

type RuleSet

type RuleSet struct {
	// contains filtered or unexported fields
}

RuleSet contains a list of linting rules.

func NewRuleSet

func NewRuleSet() RuleSet

func (*RuleSet) Add

func (s *RuleSet) Add(r Rule)

func (*RuleSet) Lint

func (s *RuleSet) Lint(dashboards []Dashboard) (*ResultSet, error)

func (*RuleSet) Rules

func (s *RuleSet) Rules() []Rule

type Severity

type Severity int
const (
	Success Severity = iota
	Exclude
	Quiet
	Warning
	Error
	Fixed

	Prometheus = "prometheus"
	Loki       = "loki"
)

type StatOptions

type StatOptions struct {
	ReduceOptions ReduceOptions `json:"reduceOptions,omitempty"`
}

Stat panel options is a deliberately incomplete representation of the stat panel options from grafana. The properties which are extracted from JSON are only those used for linting purposes.

type Target

type Target struct {
	Idx        int         `json:"-"` // This is the only (best?) way to uniquely identify a target, it is set by GetPanels
	Datasource interface{} `json:"datasource,omitempty"`
	Expr       string      `json:"expr,omitempty"`
	PanelId    int         `json:"panelId,omitempty"`
	RefId      string      `json:"refId,omitempty"`
	Hide       bool        `json:"hide"`
}

Target is a deliberately incomplete representation of the Dashboard -> Panel -> Target type in grafana. The properties which are extracted from JSON are only those used for linting purposes.

func (*Target) GetDataSource

func (t *Target) GetDataSource() (Datasource, error)

type TargetResult

type TargetResult struct {
	Result
	Fix func(Dashboard, Panel, *Target)
}

type TargetRuleFunc

type TargetRuleFunc struct {
	// contains filtered or unexported fields
}

func NewTargetCounterAggRule

func NewTargetCounterAggRule() *TargetRuleFunc

func NewTargetInstanceRule

func NewTargetInstanceRule() *TargetRuleFunc

func NewTargetJobRule

func NewTargetJobRule() *TargetRuleFunc

func NewTargetLogQLAutoRule

func NewTargetLogQLAutoRule() *TargetRuleFunc

func NewTargetLogQLRule

func NewTargetLogQLRule() *TargetRuleFunc

func NewTargetPromQLRule

func NewTargetPromQLRule() *TargetRuleFunc

NewTargetPromQLRule builds a lint rule for panels with Prometheus queries which checks: - the query is valid PromQL - the query contains two matchers within every selector - `{job=~"$job", instance=~"$instance"}` - the query is not empty - if the query references another panel then make sure that panel exists

func NewTargetRateIntervalRule

func NewTargetRateIntervalRule() *TargetRuleFunc

NewTargetRateIntervalRule builds a lint rule for panels with Prometheus queries which checks all range vector selectors use $__rate_interval.

func (TargetRuleFunc) Description

func (f TargetRuleFunc) Description() string

func (TargetRuleFunc) Lint

func (f TargetRuleFunc) Lint(d Dashboard, s *ResultSet)

func (TargetRuleFunc) Name

func (f TargetRuleFunc) Name() string

type TargetRuleResults

type TargetRuleResults struct {
	Results []TargetResult
}

func (*TargetRuleResults) AddError

func (r *TargetRuleResults) AddError(d Dashboard, p Panel, t Target, message string)

type Template

type Template struct {
	Name       string             `json:"name"`
	Label      string             `json:"label"`
	Type       string             `json:"type"`
	RawQuery   interface{}        `json:"query"`
	Query      string             `json:"-"`
	Datasource interface{}        `json:"datasource,omitempty"`
	Multi      bool               `json:"multi"`
	AllValue   string             `json:"allValue,omitempty"`
	Current    RawTemplateValue   `json:"current"`
	Options    []RawTemplateValue `json:"options"`
	Refresh    int                `json:"refresh"`
}

Target is a deliberately incomplete representation of the Dashboard -> Template type in grafana. The properties which are extracted from JSON are only those used for linting purposes.

func (*Template) GetDataSource

func (t *Template) GetDataSource() (Datasource, error)

func (*Template) UnmarshalJSON

func (t *Template) UnmarshalJSON(buf []byte) error

type TemplateValue

type TemplateValue struct {
	Text  string `json:"text"`
	Value string `json:"value"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL