Skip to content

Commit 0a1e94d

Browse files
authored
Loki loading (#80)
* vendors loki Signed-off-by: Owen Diehl <[email protected]> * loki backend support Signed-off-by: Owen Diehl <[email protected]> * updates changelog Signed-off-by: Owen Diehl <[email protected]> * updates to yaml v3 Signed-off-by: Owen Diehl <[email protected]>
1 parent 219ab28 commit 0a1e94d

File tree

1,220 files changed

+254141
-1490
lines changed

Some content is hidden

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

1,220 files changed

+254141
-1490
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## unreleased / master
44

5+
* [FEATURE] Added loki backend support for the rules commands, configurable with `--backend=loki` (defaults to cortex).
6+
57
## v0.2.4
68

79
* [BUGFIX] Fix alertmanager registration subcommand and path for the configuration API #72

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/gogo/protobuf v1.3.1
1313
github.com/golang/snappy v0.0.1
1414
github.com/google/go-cmp v0.4.0
15+
github.com/grafana/loki v1.6.2-0.20200831213751-f905e77259f2
1516
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
1617
github.com/opentracing/opentracing-go v1.2.0
1718
github.com/pkg/errors v0.9.1
@@ -23,7 +24,6 @@ require (
2324
github.com/stretchr/testify v1.5.1
2425
google.golang.org/api v0.29.0
2526
gopkg.in/alecthomas/kingpin.v2 v2.2.6
26-
gopkg.in/yaml.v2 v2.3.0
2727
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
2828
gotest.tools v2.2.0+incompatible
2929
)
@@ -42,3 +42,6 @@ replace github.com/gocql/gocql => github.com/grafana/gocql v0.0.0-20200605141915
4242

4343
// Using a 3rd-party branch for custom dialer - see https://github.com/bradfitz/gomemcache/pull/86
4444
replace github.com/bradfitz/gomemcache => github.com/themihai/gomemcache v0.0.0-20180902122335-24332e2d58ab
45+
46+
// Same as Cortex, we can't upgrade to grpc 1.30.0 until go.etcd.io/etcd will support it.
47+
replace google.golang.org/grpc => google.golang.org/grpc v1.29.1

go.sum

Lines changed: 58 additions & 32 deletions
Large diffs are not rendered by default.

pkg/client/alerts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"github.com/pkg/errors"
88
log "github.com/sirupsen/logrus"
9-
"gopkg.in/yaml.v2"
9+
"gopkg.in/yaml.v3"
1010
)
1111

1212
const alertmanagerAPIPath = "/api/v1/alerts"

pkg/client/rules.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/pkg/errors"
99
"github.com/prometheus/prometheus/pkg/rulefmt"
1010
log "github.com/sirupsen/logrus"
11-
"gopkg.in/yaml.v2"
11+
"gopkg.in/yaml.v3"
1212
)
1313

1414
// CreateRuleGroup creates a new rule group

pkg/commands/chunks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/prometheus/prometheus/pkg/labels"
1717
"github.com/sirupsen/logrus"
1818
"gopkg.in/alecthomas/kingpin.v2"
19-
"gopkg.in/yaml.v2"
19+
"gopkg.in/yaml.v3"
2020

2121
chunkTool "github.com/grafana/cortex-tools/pkg/chunk"
2222
"github.com/grafana/cortex-tools/pkg/chunk/filter"
@@ -68,7 +68,7 @@ func (cfg *SchemaConfig) Load() error {
6868
}
6969

7070
decoder := yaml.NewDecoder(f)
71-
decoder.SetStrict(true)
71+
decoder.KnownFields(true)
7272
return decoder.Decode(&cfg)
7373
}
7474

pkg/commands/migrate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"os"
55

66
"gopkg.in/alecthomas/kingpin.v2"
7-
"gopkg.in/yaml.v2"
7+
"gopkg.in/yaml.v3"
88

99
"github.com/grafana/cortex-tools/pkg/chunk/migrate"
1010
"github.com/grafana/cortex-tools/pkg/chunk/migrate/reader"
@@ -30,7 +30,7 @@ func (c *migrateChunksCommandOptions) run(k *kingpin.ParseContext) error {
3030
}
3131

3232
decoder := yaml.NewDecoder(f)
33-
decoder.SetStrict(true)
33+
decoder.KnownFields(true)
3434

3535
if err := decoder.Decode(&c.Config); err != nil {
3636
return err

pkg/commands/rules.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ var (
3535
Name: "last_rule_load_success_timestamp_seconds",
3636
Help: "The timestamp of the last successful rule load.",
3737
})
38+
39+
backends = []string{rules.CortexBackend, rules.LokiBackend} // list of supported backend types
3840
)
3941

4042
// RuleCommand configures and executes rule related cortex operations
@@ -43,6 +45,9 @@ type RuleCommand struct {
4345

4446
cli *client.CortexClient
4547

48+
// Backend type (cortex | loki)
49+
Backend string
50+
4651
// Get Rule Groups Configs
4752
Namespace string
4853
RuleGroup string
@@ -73,6 +78,7 @@ type RuleCommand struct {
7378
func (r *RuleCommand) Register(app *kingpin.Application) {
7479
rulesCmd := app.Command("rules", "View & edit rules stored in cortex.").PreAction(r.setup)
7580
rulesCmd.Flag("key", "Api key to use when contacting cortex, alternatively set $CORTEX_API_KEY.").Default("").Envar("CORTEX_API_KEY").StringVar(&r.ClientConfig.Key)
81+
rulesCmd.Flag("backend", "Backend type to interact with: <cortex|loki>").Default("cortex").EnumVar(&r.Backend, backends...)
7682

7783
// Register rule commands
7884
listCmd := rulesCmd.
@@ -323,7 +329,7 @@ func (r *RuleCommand) deleteRuleGroup(k *kingpin.ParseContext) error {
323329
}
324330

325331
func (r *RuleCommand) loadRules(k *kingpin.ParseContext) error {
326-
nss, err := rules.ParseFiles(r.RuleFilesList)
332+
nss, err := rules.ParseFiles(r.Backend, r.RuleFilesList)
327333
if err != nil {
328334
return errors.Wrap(err, "load operation unsuccessful, unable to parse rules files")
329335
}
@@ -372,7 +378,7 @@ func (r *RuleCommand) diffRules(k *kingpin.ParseContext) error {
372378
return errors.Wrap(err, "diff operation unsuccessful, unable to load rules files")
373379
}
374380

375-
nss, err := rules.ParseFiles(r.RuleFilesList)
381+
nss, err := rules.ParseFiles(r.Backend, r.RuleFilesList)
376382
if err != nil {
377383
return errors.Wrap(err, "diff operation unsuccessful, unable to parse rules files")
378384
}
@@ -426,7 +432,7 @@ func (r *RuleCommand) syncRules(k *kingpin.ParseContext) error {
426432
return errors.Wrap(err, "sync operation unsuccessful, unable to load rules files")
427433
}
428434

429-
nss, err := rules.ParseFiles(r.RuleFilesList)
435+
nss, err := rules.ParseFiles(r.Backend, r.RuleFilesList)
430436
if err != nil {
431437
return errors.Wrap(err, "sync operation unsuccessful, unable to parse rules files")
432438
}
@@ -527,7 +533,7 @@ func (r *RuleCommand) prepare(k *kingpin.ParseContext) error {
527533
return errors.Wrap(err, "prepare operation unsuccessful, unable to load rules files")
528534
}
529535

530-
namespaces, err := rules.ParseFiles(r.RuleFilesList)
536+
namespaces, err := rules.ParseFiles(r.Backend, r.RuleFilesList)
531537
if err != nil {
532538
return errors.Wrap(err, "prepare operation unsuccessful, unable to parse rules files")
533539
}
@@ -559,7 +565,7 @@ func (r *RuleCommand) lint(k *kingpin.ParseContext) error {
559565
return errors.Wrap(err, "prepare operation unsuccessful, unable to load rules files")
560566
}
561567

562-
namespaces, err := rules.ParseFiles(r.RuleFilesList)
568+
namespaces, err := rules.ParseFiles(r.Backend, r.RuleFilesList)
563569
if err != nil {
564570
return errors.Wrap(err, "prepare operation unsuccessful, unable to parse rules files")
565571
}
@@ -593,7 +599,7 @@ func (r *RuleCommand) checkRecordingRuleNames(k *kingpin.ParseContext) error {
593599
return errors.Wrap(err, "check operation unsuccessful, unable to load rules files")
594600
}
595601

596-
namespaces, err := rules.ParseFiles(r.RuleFilesList)
602+
namespaces, err := rules.ParseFiles(r.Backend, r.RuleFilesList)
597603
if err != nil {
598604
return errors.Wrap(err, "check operation unsuccessful, unable to parse rules files")
599605
}

pkg/printer/printer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/alecthomas/chroma/quick"
99
"github.com/mitchellh/colorstring"
1010
"github.com/prometheus/prometheus/pkg/rulefmt"
11-
"gopkg.in/yaml.v2"
11+
"gopkg.in/yaml.v3"
1212

1313
"github.com/grafana/cortex-tools/pkg/rules"
1414
)

pkg/rules/compare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/google/go-cmp/cmp"
1010
"github.com/mitchellh/colorstring"
1111
"github.com/prometheus/prometheus/pkg/rulefmt"
12-
yaml "gopkg.in/yaml.v2"
12+
yaml "gopkg.in/yaml.v3"
1313
)
1414

1515
var (

0 commit comments

Comments
 (0)