report

package
v1.2.28 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultFormat dumps Report as Text.
	DefaultFormat = "graph"

	// YAMLFormat dumps Report as YAML.
	YAMLFormat = "yaml"

	// JSONFormat dumps Report as JSON.
	JSONFormat = "json"

	// PrometheusFormat converts Report to Prometheus metrics.
	// This format is only used internally by Promcheck and cannot be set via cli flags.
	PrometheusFormat = "prometheus"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// Report represents the report data
	Report Report `json:"promcheck" yaml:"promcheck"`
	// contains filtered or unexported fields
}

Builder represents the report.

func NewBuilder

func NewBuilder(opts ...BuilderOption) *Builder

NewBuilder returns a new Builder.

func (*Builder) AddSection

func (b *Builder) AddSection(file, group, name, expression string, failed, success []string)

AddSection adds a new section to the report.

func (*Builder) AddTotalCheckedGroups added in v1.0.2

func (b *Builder) AddTotalCheckedGroups(count int)

AddTotalCheckedGroups adds checked groups to the total amount. TotalGroups is used for report metrics.

func (*Builder) Dump

func (b *Builder) Dump() error

Dump prints the report to the builder's output target in the desired format.

func (*Builder) DumpJSON

func (b *Builder) DumpJSON() error

DumpJSON prints the report to the builder's output target in json format.

func (*Builder) DumpPrometheusMetrics added in v1.1.0

func (b *Builder) DumpPrometheusMetrics() error

DumpPrometheusMetrics converts the report to Prometheus metrics.

func (*Builder) DumpTree

func (b *Builder) DumpTree() error

DumpTree prints the report to the builder's output target in text format.

func (*Builder) DumpYAML

func (b *Builder) DumpYAML() error

DumpYAML prints the report to the builder's output target in yaml format.

func (*Builder) HasContent

func (b *Builder) HasContent() bool

HasContent checks if we actually have anything to report.

func (*Builder) ToJSON

func (b *Builder) ToJSON() (string, error)

ToJSON returns the report in json format.

func (*Builder) ToPrometheusMetrics added in v1.1.0

func (b *Builder) ToPrometheusMetrics() error

ToPrometheusMetrics returns the report as Prometheus metrics served by the exporter.

func (*Builder) ToTree

func (b *Builder) ToTree() (string, error)

ToTree returns the report as a tree structure in text format.

func (*Builder) ToYAML

func (b *Builder) ToYAML() (string, error)

ToYAML returns the report in yaml format.

type BuilderOption added in v1.1.3

type BuilderOption func(*Builder)

BuilderOption represents builder options.

func WithFormat added in v1.1.3

func WithFormat(format string) BuilderOption

WithFormat sets the builder's output format.

func WithMetrics added in v1.1.3

func WithMetrics(metrics metrics.Metrics) BuilderOption

WithMetrics configures the Builder to use custom specified metrics.

func WithWriter added in v1.1.3

func WithWriter(w io.Writer) BuilderOption

WithWriter specifies a custom io.Writer to write to. By default, os.Stdout is used.

func WithoutColor added in v1.1.3

func WithoutColor() BuilderOption

WithoutColor passing this BuilderOption to the NewBuilder disables terminal color.

type Report

type Report struct {
	// Sections represents a list of result data
	Sections Sections `json:"results,omitempty" yaml:"results,omitempty"`

	// TotalRules represents the total amount of checked groups
	TotalGroups int `json:"groups_total,omitempty" yaml:"groups_total,omitempty"`

	// TotalGroups represents the total amount of checked rules
	TotalRules int `json:"rules_total,omitempty" yaml:"rules_total,omitempty"`

	// TotalSelectorsFailed represents the total amount of probed selectors not containing a result value
	TotalSelectorsFailed int `json:"selectors_failed_total,omitempty" yaml:"selectors_failed_total,omitempty"`

	// TotalSelectorsSuccess represents the total amount of probed selectors containing a result value
	TotalSelectorsSuccess int `json:"selectors_success_total,omitempty" yaml:"selectors_success_total,omitempty"`

	// RatioFailedTotal represents the ratio of selectors without a result value / total amount of selectors
	RatioFailedTotal float32 `json:"ratio_failed_total,omitempty" yaml:"ratio_failed_total,omitempty"`
}

Report represents report data.

func (Report) Len

func (s Report) Len() int

Len returns the list size.

type Section

type Section struct {
	// File represents the file name of the checked rule
	File string `json:"file" yaml:"file"`

	// Group represents the group name of the checked rule
	Group string `json:"group" yaml:"group"`

	// Name represents the recording rule or alert name
	Name string `json:"name" yaml:"name"`

	// Expression represents the rule's PromQL expression string
	Expression string `json:"expression" yaml:"expression"`

	// NoResults represents a list of the rule's PromQL selectors which did not successfully returned a result value
	NoResults []string `json:"no_results" yaml:"no_results"`

	// Results represents a list of the rule's PromQL selectors which successfully returned a result value
	Results []string `json:"results" yaml:"results"`
}

Section represents a report section.

type Sections

type Sections []Section

Sections represents a collection of sections.

type Tree

type Tree interface {
	AddNode(text string) Tree
	AddSubtree(tree Tree)
	Nodes() []Tree
	String() string
	Print() string
}

Tree represents tree structure.

Jump to

Keyboard shortcuts

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