Documentation
¶
Overview ¶
Package stats reads the console's audit log and counts the refusals by code and by the token or node that triggered them, so that grammar work starts with the constructs users hit most. It reads a local file and never touches the network.
The export is the one form meant to leave the machine: it holds counts, codes, engine names and SQL shapes, statements whose literals, identifiers and comments are replaced by fixed markers. Every string in it comes from a closed vocabulary (ShapeToken), so it holds no literal, identifier or refusal message of the log.
Index ¶
Constants ¶
const ( // Uncoded groups the refusals of a log written before refusal codes. Uncoded = "uncoded" // NoToken groups the refusals that point at no token. NoToken = "-" // MaxShape bounds a shape, in bytes. MaxShape = 300 // ExportNote heads an export. ExportNote = "locksql refusal statistics: SQL shapes only, literals, identifiers and comments removed" )
Variables ¶
This section is empty.
Functions ¶
func ExportToken ¶
ExportToken is a refusal token as an export may hold it: a keyword, a known function name or punctuation stays (upper-cased), any other word becomes "id", and no token is NoToken.
func Shape ¶
Shape replaces the literals, identifiers and comments of sql by markers and keeps its keywords, known function names and punctuation, one token per space. It reads any text, valid SQL or not, and never returns a byte of a literal, an identifier or a comment.
func ShapeToken ¶
ShapeToken reports whether tok belongs to the closed vocabulary of shapes: a marker, a keyword, a known function name or punctuation.
Types ¶
type Count ¶
type Count struct {
Code string `json:"code"`
Token string `json:"token,omitempty"`
N int `json:"n"`
}
Count is the number of refusals of a code, and of a token under it.
type Export ¶
type Export struct {
Version string `json:"locksql_version"`
Note string `json:"note"`
Refusals int `json:"refusals"`
Skipped int `json:"skipped"`
ByCode []Count `json:"by_code"`
ByConstruct []Count `json:"by_construct"`
Shapes []ShapeCount `json:"shapes"`
}
Export is the anonymised report.
type Report ¶
type Report struct {
// Refusals is the number of refusal records, Skipped the number of
// lines that are not audit records.
Refusals, Skipped int
ByCode []Count
// ByToken counts per code and token (upper-cased; NoToken when the
// refusal points at none).
ByToken []Count
// contains filtered or unexported fields
}
Report counts the refusals of an audit log.
func (*Report) WriteExport ¶
WriteExport writes the anonymised report as JSON. version is the locksql version, kept only when it is a plain version string.