Skip to content

Commit

Permalink
Fix all the breaking things
Browse files Browse the repository at this point in the history
Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
  • Loading branch information
codesome committed May 14, 2020
1 parent 44ad285 commit fa70438
Show file tree
Hide file tree
Showing 32 changed files with 539 additions and 190 deletions.
5 changes: 2 additions & 3 deletions cmd/thanos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,8 @@ func runQuery(
queryableCreator = query.NewQueryableCreator(logger, proxy)
engine = promql.NewEngine(
promql.EngineOpts{
Logger: logger,
Reg: reg,
MaxConcurrent: maxConcurrentQueries,
Logger: logger,
Reg: reg,
// TODO(bwplotka): Expose this as a flag: https://github.com/thanos-io/thanos/issues/703.
MaxSamples: math.MaxInt32,
Timeout: queryTimeout,
Expand Down
8 changes: 4 additions & 4 deletions cmd/thanos/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/storage/tsdb"
"github.com/prometheus/prometheus/tsdb"
kingpin "gopkg.in/alecthomas/kingpin.v2"

"github.com/thanos-io/thanos/pkg/component"
Expand Down Expand Up @@ -81,8 +81,8 @@ func registerReceive(m map[string]setupFunc, app *kingpin.Application) {

replicationFactor := cmd.Flag("receive.replication-factor", "How many times to replicate incoming write requests.").Default("1").Uint64()

tsdbMinBlockDuration := modelDuration(cmd.Flag("tsdb.min-block-duration", "Min duration for local TSDB blocks").Default("2h").Hidden())
tsdbMaxBlockDuration := modelDuration(cmd.Flag("tsdb.max-block-duration", "Max duration for local TSDB blocks").Default("2h").Hidden())
tsdbMinBlockDuration := cmd.Flag("tsdb.min-block-duration", "Min duration for local TSDB blocks").Default("2h").Hidden().Int64()
tsdbMaxBlockDuration := cmd.Flag("tsdb.max-block-duration", "Max duration for local TSDB blocks").Default("2h").Hidden().Int64()
ignoreBlockSize := cmd.Flag("shipper.ignore-unequal-block-size", "If true receive will not require min and max block size flags to be set to the same value. Only use this if you want to keep long retention and compaction enabled, as in the worst case it can result in ~2h data loss for your Thanos bucket storage.").Default("false").Hidden().Bool()

walCompression := cmd.Flag("tsdb.wal-compression", "Compress the tsdb WAL.").Default("true").Bool()
Expand All @@ -104,7 +104,7 @@ func registerReceive(m map[string]setupFunc, app *kingpin.Application) {
tsdbOpts := &tsdb.Options{
MinBlockDuration: *tsdbMinBlockDuration,
MaxBlockDuration: *tsdbMaxBlockDuration,
RetentionDuration: *retention,
RetentionDuration: int64(*retention),
NoLockfile: true,
WALCompression: *walCompression,
}
Expand Down
18 changes: 9 additions & 9 deletions cmd/thanos/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/rules"
"github.com/prometheus/prometheus/storage/tsdb"
tsdb "github.com/prometheus/prometheus/tsdb"
tsdberrors "github.com/prometheus/prometheus/tsdb/errors"
"github.com/prometheus/prometheus/util/strutil"
"github.com/thanos-io/thanos/pkg/alert"
Expand Down Expand Up @@ -73,10 +73,10 @@ func registerRule(m map[string]setupFunc, app *kingpin.Application) {
Default("1m"))
evalInterval := modelDuration(cmd.Flag("eval-interval", "The default evaluation interval to use.").
Default("30s"))
tsdbBlockDuration := modelDuration(cmd.Flag("tsdb.block-duration", "Block duration for TSDB block.").
Default("2h"))
tsdbRetention := modelDuration(cmd.Flag("tsdb.retention", "Block retention time on local disk.").
Default("48h"))
tsdbBlockDuration := cmd.Flag("tsdb.block-duration", "Block duration for TSDB block.").
Default("2h").Int64()
tsdbRetention := cmd.Flag("tsdb.retention", "Block retention time on local disk.").
Default("48h").Int64()

walCompression := cmd.Flag("tsdb.wal-compression", "Compress the tsdb WAL.").Default("true").Bool()

Expand Down Expand Up @@ -125,9 +125,9 @@ func registerRule(m map[string]setupFunc, app *kingpin.Application) {
}

tsdbOpts := &tsdb.Options{
MinBlockDuration: *tsdbBlockDuration,
MaxBlockDuration: *tsdbBlockDuration,
RetentionDuration: *tsdbRetention,
MinBlockDuration: *tsdbBlockDuration / int64(time.Millisecond),
MaxBlockDuration: *tsdbBlockDuration / int64(time.Millisecond),
RetentionDuration: *tsdbRetention / int64(time.Millisecond),
NoLockfile: true,
WALCompression: *walCompression,
}
Expand Down Expand Up @@ -425,7 +425,7 @@ func runRule(
}
alertQ.Push(res)
}
st := tsdb.Adapter(db, 0)
st := db

opts := rules.ManagerOptions{
NotifyFunc: notify,
Expand Down
59 changes: 50 additions & 9 deletions cmd/thanos/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package main

import (
"errors"
"fmt"
"io/ioutil"

"github.com/go-kit/kit/log"
Expand All @@ -12,7 +14,7 @@ import (
"github.com/opentracing/opentracing-go"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/prometheus/pkg/rulefmt"
"github.com/prometheus/prometheus/tsdb/errors"
tsdb_errors "github.com/prometheus/prometheus/tsdb/errors"
"gopkg.in/alecthomas/kingpin.v2"
"gopkg.in/yaml.v2"
)
Expand All @@ -36,7 +38,7 @@ func registerCheckRules(m map[string]setupFunc, app *kingpin.CmdClause, pre stri
}

func checkRulesFiles(logger log.Logger, files *[]string) error {
failed := errors.MultiError{}
failed := tsdb_errors.MultiError{}

for _, f := range *files {
n, errs := checkRules(logger, f)
Expand Down Expand Up @@ -66,9 +68,50 @@ type ThanosRuleGroups struct {
Groups []ThanosRuleGroup `yaml:"groups"`
}

func checkRules(logger log.Logger, filename string) (int, errors.MultiError) {
// Validate validates all rules in the rule groups.
// This is copied from Prometheus.
// TODO: Replace this with upstream implementation after https://github.com/prometheus/prometheus/issues/7128 is fixed.
func (g *ThanosRuleGroups) Validate() (errs []error) {
set := map[string]struct{}{}

for _, g := range g.Groups {
if g.Name == "" {
errs = append(errs, errors.New("Groupname should not be empty"))
}

if _, ok := set[g.Name]; ok {
errs = append(
errs,
fmt.Errorf("groupname: \"%s\" is repeated in the same file", g.Name),
)
}

set[g.Name] = struct{}{}

for i, r := range g.Rules {
for _, node := range r.Validate() {
var ruleName string
if r.Alert.Value != "" {
ruleName = r.Alert.Value
} else {
ruleName = r.Record.Value
}
errs = append(errs, &rulefmt.Error{
Group: g.Name,
Rule: i,
RuleName: ruleName,
Err: node,
})
}
}
}

return errs
}

func checkRules(logger log.Logger, filename string) (int, tsdb_errors.MultiError) {
level.Info(logger).Log("msg", "checking", "filename", filename)
checkErrors := errors.MultiError{}
checkErrors := tsdb_errors.MultiError{}

b, err := ioutil.ReadFile(filename)
if err != nil {
Expand All @@ -82,9 +125,7 @@ func checkRules(logger log.Logger, filename string) (int, errors.MultiError) {
return 0, checkErrors
}

// We need to convert Thanos rules to Prometheus rules so we can use their validation.
promRgs := thanosRuleGroupsToPromRuleGroups(rgs)
if errs := promRgs.Validate(); errs != nil {
if errs := rgs.Validate(); errs != nil {
for _, e := range errs {
checkErrors.Add(e)
}
Expand All @@ -105,12 +146,12 @@ func thanosRuleGroupsToPromRuleGroups(ruleGroups ThanosRuleGroups) rulefmt.RuleG
group := rulefmt.RuleGroup{
Name: g.Name,
Interval: g.Interval,
Rules: []rulefmt.Rule{},
Rules: []rulefmt.RuleNode{},
}
for _, r := range g.Rules {
group.Rules = append(
group.Rules,
rulefmt.Rule{
rulefmt.RuleNode{
Record: r.Record,
Alert: r.Alert,
Expr: r.Expr,
Expand Down
31 changes: 15 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,52 @@ require (
github.com/fatih/structtag v1.1.0
github.com/fortytw2/leaktest v1.3.0
github.com/fsnotify/fsnotify v1.4.7
github.com/go-kit/kit v0.9.0
github.com/go-openapi/strfmt v0.19.2
github.com/go-kit/kit v0.10.0
github.com/go-openapi/strfmt v0.19.4
github.com/gogo/protobuf v1.3.1
github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9
github.com/golang/snappy v0.0.1
github.com/googleapis/gax-go v2.0.2+incompatible
github.com/gophercloud/gophercloud v0.6.0
github.com/gophercloud/gophercloud v0.8.0
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/hashicorp/golang-lru v0.5.3
github.com/leanovate/gopter v0.2.4
github.com/lightstep/lightstep-tracer-go v0.18.0
github.com/lightstep/lightstep-tracer-go v0.18.1
github.com/lovoo/gcloud-opentracing v0.3.0
github.com/miekg/dns v1.1.22
github.com/miekg/dns v1.1.27
github.com/minio/minio-go/v6 v6.0.53
github.com/mozillazg/go-cos v0.13.0
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f
github.com/oklog/run v1.0.0
github.com/oklog/run v1.1.0
github.com/oklog/ulid v1.3.1
github.com/olekukonko/tablewriter v0.0.2
github.com/opentracing/basictracer-go v1.0.0
github.com/opentracing/opentracing-go v1.1.1-0.20200124165624-2876d2018785
github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0
github.com/prometheus/alertmanager v0.20.0
github.com/prometheus/client_golang v1.5.0
github.com/prometheus/client_golang v1.5.1
github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.9.1
github.com/prometheus/prometheus v1.8.2-0.20200213233353-b90be6f32a33
github.com/prometheus/prometheus v1.8.2-0.20200407102557-cd73b3d33e06
github.com/uber/jaeger-client-go v2.20.1+incompatible
github.com/uber/jaeger-lib v2.2.0+incompatible
go.elastic.co/apm v1.5.0
go.elastic.co/apm/module/apmot v1.5.0
go.uber.org/automaxprocs v1.2.0
golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
golang.org/x/text v0.3.2
golang.org/x/tools v0.0.0-20200306191617-51e69f71924f // indirect
google.golang.org/api v0.14.0
google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9
google.golang.org/grpc v1.25.1
google.golang.org/api v0.20.0
google.golang.org/genproto v0.0.0-20200305110556-506484158171
google.golang.org/grpc v1.27.1
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/fsnotify.v1 v1.4.7
gopkg.in/yaml.v2 v2.2.7
gopkg.in/yaml.v2 v2.2.8
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71
)

// We want to replace the client-go version with a specific commit hash,
Expand All @@ -69,8 +70,6 @@ require (
replace (
// Mitigation for: https://github.com/Azure/go-autorest/issues/414
github.com/Azure/go-autorest => github.com/Azure/go-autorest v12.3.0+incompatible
// Make sure Cortex is not forcing us to some other Prometheus version.
github.com/prometheus/prometheus => github.com/prometheus/prometheus v1.8.2-0.20200110114423-1e64d757f711 // master ~ v2.15.2
k8s.io/api => k8s.io/api v0.0.0-20190620084959-7cf5895f2711
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.0.0-20190620085554-14e95df34f1f
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190612205821-1799e75a0719
Expand Down
Loading

0 comments on commit fa70438

Please sign in to comment.