Skip to content

Commit fda371e

Browse files
authored
Update examples. Add data source template generation. (#18)
* Update examples. Add data source template generation. * Update help * Add comments to stdout for template generation * Update comment * Add timestamp formats for https://metallb.io/ * Update README --------- Co-authored-by: Tony Meehan <[email protected]>
1 parent e790f9e commit fda371e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+238
-37
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
# preq
22

3-
`preq` (prounounced "preek") is a free and open community-driven reliability problem detector. Use `preq` to:
3+
`preq` (prounounced "preek") is a free and open community-driven reliability problem detector
4+
5+
[Documentation](https://docs.prequel.dev/cres/introduction) | [Slack](https://prequel-dev.slack.com/) | [Playground](https://play.prequel.dev/) | [Mailing List](https://www.detect.sh)
6+
7+
---
8+
9+
Use `preq` to:
410

511
- detect the latest bugs, misconfigurations, anti-patterns, and known issues from a community of practitioners
612
- provide engineers, on-call support, and SRE agents with impact and community recommended mitigations
7-
- hunt for new problems in logs, metrics, and traces
8-
9-
Learn more at https://docs.prequel.dev.
13+
- hunt for new problems in distributed systems
1014

1115
## Overview
1216

13-
`preq` provides the latest Common Reliability Enumerations (CREs) created by the community and Prequel's Reliability Research Team. Reliability Intelligence from CREs helps teams see the most problems and see them first so they can prioritize, pinpoint, and act to mitigate outages.
17+
`preq` uses Common Reliability Enumerations (CREs) created by the problem detection community and Prequel's Reliability Research Team to detect reliability problems. Reliability Intelligence from CREs helps teams see the most problems and see them first so they can prioritize, pinpoint, and act to mitigate outages.
1418

1519
`preq` is powered by a rules engine that performs distributed matching and correlation of sequences of events across logs, metrics, traces, and other data sources to detect reliability problems. CREs provides accurate and timely context for a human or SRE agent to take action on problems.
1620

cmd/preq/preq.go

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ var (
4242
var cli struct {
4343
Disabled bool `short:"d" help:"Do not run community CREs"`
4444
Stop string `short:"e" help:"Stop time"`
45+
Generate bool `short:"g" help:"Generate data sources template"`
4546
JsonLogs bool `short:"j" help:"Print logs in JSON format to stderr" default:"false"`
46-
Skip int `short:"k" help:"Skip the first N lines for timestamp detection" default:"20"`
47+
Skip int `short:"k" help:"Skip the first N lines for timestamp detection" default:"50"`
4748
Level string `short:"l" help:"Print logs at this level to stderr"`
48-
ReportFile string `short:"n" help:"Report filename"`
49+
Filename string `short:"n" help:"Report or data source template output file name"`
4950
Quiet bool `short:"q" help:"Quiet mode, do not print progress"`
5051
Rules string `short:"r" help:"Path to a CRE file"`
5152
Source string `short:"s" help:"Path to a data source file"`
@@ -225,6 +226,37 @@ func main() {
225226
os.Exit(1)
226227
}
227228

229+
if cli.Generate {
230+
231+
var (
232+
currRulesVer *semver.Version
233+
template []byte
234+
fn string
235+
)
236+
237+
if currRulesVer, _, err = rules.GetCurrentRulesVersion(defaultConfigDir); err != nil {
238+
log.Error().Err(err).Msg("Failed to get current rules version")
239+
}
240+
241+
if template, err = ruleMatchers.DataSourceTemplate(currRulesVer); err != nil {
242+
log.Error().Err(err).Msg("Failed to generate data source template")
243+
ux.RulesError(err)
244+
os.Exit(1)
245+
}
246+
247+
if fn, err = ux.WriteDataSourceTemplate(cli.Filename, currRulesVer, template); err != nil {
248+
log.Error().Err(err).Msg("Failed to write data source template")
249+
ux.DataError(err)
250+
os.Exit(1)
251+
}
252+
253+
if fn != "" {
254+
fmt.Fprintf(os.Stdout, "Wrote data source template to %s\n", fn)
255+
}
256+
257+
os.Exit(0)
258+
}
259+
228260
if len(sources) == 0 {
229261
ux.PrintUsage()
230262
os.Exit(1)
@@ -267,14 +299,14 @@ LOOP:
267299
}
268300

269301
switch {
270-
case cli.ReportFile == stdoutReport:
302+
case cli.Filename == stdoutReport:
271303
if err = report.PrintReport(); err != nil {
272304
log.Error().Err(err).Msg("Failed to print report")
273305
ux.RulesError(err)
274306
os.Exit(1)
275307
}
276-
case cli.ReportFile != "":
277-
if reportPath, err = report.Write(cli.ReportFile); err != nil {
308+
case cli.Filename != "":
309+
if reportPath, err = report.Write(cli.Filename); err != nil {
278310
log.Error().Err(err).Msg("Failed to write full report")
279311
ux.RulesError(err)
280312
os.Exit(1)

examples/00-rules-document-example.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ rules:
22
- cre:
33
id: cre-2025-0
44
metadata:
5-
id: rule-id=0
5+
id: rule-id-0
66
hash: rule-hash-0
77
rule:
88
set:

examples/01-set-single-example.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
rules:
22
- cre:
33
id: set-example
4+
metadata:
5+
id: rule-id
46
rule:
57
set:
68
event:

examples/02-set-multiple-example-bad-window.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
rules:
22
- cre:
33
id: set-example-2
4+
metadata:
5+
id: rule-id
46
rule:
57
set:
68
window: 1s

examples/02-set-multiple-example-good-window.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
rules:
22
- cre:
33
id: set-example-2
4+
metadata:
5+
id: rule-id
46
rule:
57
set:
68
window: 10s

examples/03-set-negative-example.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
rules:
22
- cre:
33
id: set-negative
4+
metadata:
5+
id: rule-id
46
rule:
57
set:
68
window: 10s

examples/04-set-1x1-example.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
rules:
22
- cre:
33
id: set-1x1
4+
metadata:
5+
id: rule-id
46
rule:
57
set:
68
event:

examples/05-bad-set-example.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
rules:
22
- cre:
33
id: bad-order
4+
metadata:
5+
id: rule-id
46
rule:
57
set:
68
event:

examples/06-bad-set-example.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
rules:
22
- cre:
33
id: bad-negate
4+
metadata:
5+
id: rule-id
46
rule:
57
set:
68
event:

0 commit comments

Comments
 (0)