Documentation
¶
Overview ¶
Package check evaluates PromQL "contracts": lists of expressions that must each return a non-empty result. It is shared by the `promql-cli check` subcommand and the REPL's `.assert` command.
Index ¶
- Variables
- func Write(w io.Writer, format string, rep Report, color bool) error
- func WriteJSON(w io.Writer, rep Report) error
- func WriteJUnit(w io.Writer, rep Report) error
- func WriteResult(w io.Writer, r Result, color bool)
- func WriteTAP(w io.Writer, rep Report)
- func WriteText(w io.Writer, rep Report, color bool)
- type Check
- type Report
- type Result
- type Runner
- type Status
Constants ¶
This section is empty.
Variables ¶
var Formats = []string{"text", "tap", "junit", "json"}
Formats lists the supported report formats.
Functions ¶
func Write ¶
Write renders rep in the given format ("text" when empty). color only applies to the text format.
func WriteJUnit ¶
WriteJUnit prints the report as a single JUnit <testsuite>.
func WriteResult ¶
WriteResult prints one check as a text block: a status line, then, for failures and errors, the expression (when it differs from the name) and why.
Types ¶
type Check ¶
type Check struct {
Name string `json:"name"` // preceding comment line, or the expression itself
Expr string `json:"expr"`
Line int `json:"line"` // 1-based line in the contract file; 0 when ad hoc
}
Check is one expression of a contract.
func ParseContract ¶
ParseContract reads a contract: one PromQL expression per line, blank lines and '#' comment lines ignored. The '#' comment line immediately preceding an expression (no blank line in between) becomes its name; without one the name is the expression itself.
func ParseContractFile ¶
ParseContractFile is ParseContract on the file at path.
type Report ¶
Report is the outcome of running a whole contract.
type Result ¶
type Result struct {
Check
Status Status `json:"status"`
Detail string `json:"detail,omitempty"` // why a check failed or errored
}
Result is the outcome of running a Check.
type Runner ¶
type Runner struct {
Engine *promql.Engine
Queryable storage.Queryable
// Parser must match the engine's parser options (experimental functions).
// Nil means a parser with experimental functions enabled.
Parser promparser.Parser
At time.Time
// Timeout bounds each evaluation; zero means 30s.
Timeout time.Duration
}
Runner evaluates checks against a queryable at a fixed instant.
type Status ¶
type Status string
Status is the outcome of a single check.
const ( // StatusPass means the expression returned a non-empty result. StatusPass Status = "pass" // StatusFail means the expression evaluated but returned an empty result. StatusFail Status = "fail" // StatusError means the expression could not be parsed or evaluated. StatusError Status = "error" )