audit

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KindDashboard = "dashboard"
	KindAlert     = "alert"
	KindRecording = "recording rule"
)

Variables

This section is empty.

Functions

func Gate

func Gate(res *Result, baseline *Result, opts GateOptions) []string

Types

type Consumer

type Consumer struct {
	Kind string `json:"kind"`
	Name string `json:"name"`
}

type ExprGroup

type ExprGroup struct {
	Name  string
	Exprs []string
}

type GateOptions

type GateOptions struct {
	MaxUnusedPct float64
	MaxSeries    int
}

type LabelStat

type LabelStat struct {
	Name    string   `json:"name"`
	Values  int      `json:"values"`
	Samples []string `json:"samples,omitempty"`
	IDLike  bool     `json:"idLike"`
}

type MetricReport

type MetricReport struct {
	Name           string      `json:"name"`
	Series         int         `json:"series"`
	Consumers      []Consumer  `json:"consumers,omitempty"`
	OffenderLabels []LabelStat `json:"offenderLabels,omitempty"`
	TransitiveOnly bool        `json:"transitiveOnly,omitempty"`
	MonthlyCostUSD float64     `json:"monthlyCostUSD,omitempty"`
	RAMBytes       int64       `json:"ramBytes,omitempty"`
}

type MetricSource

type MetricSource interface {
	MetricNames(ctx context.Context) ([]string, error)
	SeriesCounts(ctx context.Context, names []string) (map[string]int, error)
	LabelStats(ctx context.Context, metric string) ([]LabelStat, error)
	Rules(ctx context.Context) ([]RuleInfo, error)
}

type Options

type Options struct {
	PrometheusURL   string
	Lookback        string
	CostPer1k       float64
	BytesPerSeries  int
	SeriesThreshold int
	LabelThreshold  int
	Top             int
	Now             func() time.Time
}

type Result

type Result struct {
	GeneratedAt     time.Time      `json:"generatedAt"`
	PrometheusURL   string         `json:"prometheusURL"`
	GrafanaURL      string         `json:"grafanaURL,omitempty"`
	Version         string         `json:"version,omitempty"`
	Lookback        string         `json:"lookback"`
	Summary         Summary        `json:"summary"`
	Unused          []MetricReport `json:"unused"`
	HighCardinality []MetricReport `json:"highCardinality"`
	DancesAlone     []RuleInfo     `json:"dancesAlone"`
	UnparsedExprs   []string       `json:"unparsedExprs,omitempty"`
}

func Run

func Run(ctx context.Context, metrics MetricSource, usages []UsageSource, opts Options) (*Result, error)

type RuleInfo

type RuleInfo struct {
	Group  string `json:"group,omitempty"`
	Name   string `json:"name"`
	Kind   string `json:"kind"`
	Expr   string `json:"expr"`
	Output string `json:"output,omitempty"`
}

type Summary

type Summary struct {
	TotalMetrics           int     `json:"totalMetrics"`
	UsedMetrics            int     `json:"usedMetrics"`
	UnusedMetrics          int     `json:"unusedMetrics"`
	UnusedPct              float64 `json:"unusedPct"`
	TotalSeries            int     `json:"totalSeries"`
	ReclaimableSeries      int     `json:"reclaimableSeries"`
	LabelReclaimableSeries int     `json:"labelReclaimableSeries,omitempty"`
	EstMonthlySavingsUSD   float64 `json:"estMonthlySavingsUSD,omitempty"`
	EstRAMSavingsBytes     int64   `json:"estRAMSavingsBytes,omitempty"`
}

type UsageSource

type UsageSource interface {
	Dashboards(ctx context.Context) ([]ExprGroup, error)
	AlertRules(ctx context.Context) ([]ExprGroup, error)
}

Jump to

Keyboard shortcuts

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