Skip to content

Commit

Permalink
Merge branch 'master' into feat/add-get-dsn-route
Browse files Browse the repository at this point in the history
  • Loading branch information
almostinf committed Dec 22, 2023
2 parents 5f6f01d + ad9cd9b commit ec439dd
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 33 deletions.
16 changes: 3 additions & 13 deletions checker/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package worker

import (
"errors"
"runtime"
"sync/atomic"
"time"

Expand Down Expand Up @@ -127,17 +126,8 @@ func (check *Checker) startCheckerWorker(w checkerWorker) error {
return nil
}

maxParallelChecks := w.MaxParallelChecks()
if maxParallelChecks == 0 {
maxParallelChecks = runtime.NumCPU()

check.Logger.Info().
Int("number_of_cpu", maxParallelChecks).
Msg("MaxParallel" + w.Name() + "Checks is not configured, set it to the number of CPU")
}

const maxParallelChecksMaxValue = 1024 * 8
if maxParallelChecks > maxParallelChecksMaxValue {
if w.MaxParallelChecks() > maxParallelChecksMaxValue {
return errors.New("MaxParallel" + w.Name() + "Checks value is too large")
}

Expand All @@ -146,10 +136,10 @@ func (check *Checker) startCheckerWorker(w checkerWorker) error {

triggerIdsToCheckChan := check.startTriggerToCheckGetter(
w.GetTriggersToCheck,
maxParallelChecks,
w.MaxParallelChecks(),
)

for i := 0; i < maxParallelChecks; i++ {
for i := 0; i < w.MaxParallelChecks(); i++ {
check.tomb.Go(func() error {
return check.startTriggerHandler(
triggerIdsToCheckChan,
Expand Down
32 changes: 32 additions & 0 deletions cmd/checker/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"runtime"

"github.com/moira-alert/moira"
"github.com/moira-alert/moira/checker"
"github.com/moira-alert/moira/cmd"
Expand Down Expand Up @@ -39,6 +41,8 @@ type checkerConfig struct {
MaxParallelChecks int `yaml:"max_parallel_checks"`
// Max concurrent remote checkers to run. Equals to the number of processor cores found on Moira host by default or when variable is defined as 0.
MaxParallelRemoteChecks int `yaml:"max_parallel_remote_checks"`
// Max concurrent prometheus checkers to run. Equals to the number of processor cores found on Moira host by default or when variable is defined as 0.
MaxParallelPrometheusChecks int `yaml:"max_parallel_prometheus_checks"`
// Specify log level by entities
SetLogLevel triggersLogConfig `yaml:"set_log_level"`
// Metric event pop operation batch size
Expand All @@ -47,6 +51,15 @@ type checkerConfig struct {
MetricEventPopDelay string `yaml:"metric_event_pop_delay"`
}

func handleParallelChecks(parallelChecks *int) bool {
if parallelChecks != nil && *parallelChecks == 0 {
*parallelChecks = runtime.NumCPU()
return true
}

return false
}

func (config *checkerConfig) getSettings(logger moira.Logger) *checker.Config {
logTriggersToLevel := make(map[string]string)
for _, v := range config.SetLogLevel.TriggersToLevel {
Expand All @@ -56,13 +69,32 @@ func (config *checkerConfig) getSettings(logger moira.Logger) *checker.Config {
Int("number_of_triggers", len(logTriggersToLevel)).
Msg("Found dynamic log rules in config for some triggers")

if handleParallelChecks(&config.MaxParallelChecks) {
logger.Info().
Int("number_of_cpu", config.MaxParallelChecks).
Msg("MaxParallelChecks is not configured, set it to the number of CPU")
}

if handleParallelChecks(&config.MaxParallelRemoteChecks) {
logger.Info().
Int("number_of_cpu", config.MaxParallelRemoteChecks).
Msg("MaxParallelRemoteChecks is not configured, set it to the number of CPU")
}

if handleParallelChecks(&config.MaxParallelPrometheusChecks) {
logger.Info().
Int("number_of_cpu", config.MaxParallelPrometheusChecks).
Msg("MaxParallelPrometheusChecks is not configured, set it to the number of CPU")
}

return &checker.Config{
CheckInterval: to.Duration(config.CheckInterval),
LazyTriggersCheckInterval: to.Duration(config.LazyTriggersCheckInterval),
NoDataCheckInterval: to.Duration(config.NoDataCheckInterval),
StopCheckingIntervalSeconds: int64(to.Duration(config.StopCheckingInterval).Seconds()),
MaxParallelLocalChecks: config.MaxParallelChecks,
MaxParallelRemoteChecks: config.MaxParallelRemoteChecks,
MaxParallelPrometheusChecks: config.MaxParallelPrometheusChecks,
LogTriggersToLevel: logTriggersToLevel,
MetricEventPopBatchSize: int64(config.MetricEventPopBatchSize),
MetricEventPopDelay: to.Duration(config.MetricEventPopDelay),
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ require (
github.com/google/go-cmp v0.5.9
github.com/gotokatsuya/ipare v0.0.0-20161202043954-fd52c5b6c44b
github.com/gregdel/pushover v1.1.0
github.com/karriereat/blackfriday-slack v0.1.0
github.com/moira-alert/go-chart v0.0.0-20231107064049-444c44a558ef
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.13
github.com/patrickmn/go-cache v2.1.0+incompatible
Expand All @@ -51,6 +50,7 @@ require github.com/prometheus/common v0.37.0
require (
github.com/mattermost/mattermost/server/public v0.0.9
github.com/mitchellh/mapstructure v1.5.0
github.com/moira-alert/blackfriday-slack v0.1.2
github.com/swaggo/http-swagger v1.3.4
)

Expand Down Expand Up @@ -156,13 +156,13 @@ require (
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20200924195034-c827fd4f18b9 // indirect
golang.org/x/image v0.13.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
gonum.org/v1/gonum v0.12.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
Expand Down
23 changes: 8 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,6 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
github.com/k0kubun/pp v2.3.0+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3tgzSScAn6HmfYukg=
github.com/karriereat/blackfriday-slack v0.1.0 h1:5v7TOdIgxFlcxykNjZZHlED2+5Xnx3rJws47hcxBWYY=
github.com/karriereat/blackfriday-slack v0.1.0/go.mod h1:iM9iGxIpITGTuxl7benyJWiuXspkh5zLseXRKhTOu3M=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.12.2/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
Expand Down Expand Up @@ -903,8 +901,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/moira-alert/go-chart v0.0.0-20230220064910-812fb2829b9b h1:3eY3xHOj6Sh0f5Un6i9CFdqXNikLgPuGosg7+ZTpwbQ=
github.com/moira-alert/go-chart v0.0.0-20230220064910-812fb2829b9b/go.mod h1:Ezwok1WdoXI/W7cWe5leDLYf5WrA4nUFZWtKNT3tCs8=
github.com/moira-alert/blackfriday-slack v0.1.2 h1:W6VbDlHDBxoB7X+OJ+3xZZuzMcQ0qTcblhLLnm/xQ7U=
github.com/moira-alert/blackfriday-slack v0.1.2/go.mod h1:tYMK3laTzU1wgxeOpUPdw36KHD3eTyQNDfxtg1nXLWI=
github.com/moira-alert/go-chart v0.0.0-20231107064049-444c44a558ef h1:hSEQ/9B23MTYQCxx+GTRW5P1eWaqtgEMEqOxXs/YNKE=
github.com/moira-alert/go-chart v0.0.0-20231107064049-444c44a558ef/go.mod h1:ktrkvZGboMQfYyBXAV05imlVxGIvVdeCn5vz91Fw1vE=
github.com/msaf1980/go-stringutils v0.1.4 h1:UwsIT0hplHVucqbknk3CoNqKkmIuSHhsbBldXxyld5U=
Expand Down Expand Up @@ -1157,8 +1155,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand All @@ -1174,8 +1172,6 @@ golang.org/x/exp v0.0.0-20200924195034-c827fd4f18b9/go.mod h1:1phAWC201xIgDyaFpm
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.10.0 h1:gXjUUtwtx5yOE0VKWq1CH4IJAClq4UGgUA3i+rpON9M=
golang.org/x/image v0.10.0/go.mod h1:jtrku+n79PfroUbvDdeUWMAI+heR786BofxrbiSF+J0=
golang.org/x/image v0.13.0 h1:3cge/F/QTkNLauhf2QoE9zp+7sr+ZcL4HnoZmdwg9sg=
golang.org/x/image v0.13.0/go.mod h1:6mmbMOeV28HuMTgA6OSRkdXKYw/t5W9Uwn2Yv1r3Yxk=
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down Expand Up @@ -1206,7 +1202,6 @@ golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -1419,8 +1414,8 @@ golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand All @@ -1442,9 +1437,8 @@ golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -1512,7 +1506,6 @@ golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k=
golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss=
golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
2 changes: 1 addition & 1 deletion senders/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strings"
"time"

slackdown "github.com/karriereat/blackfriday-slack"
"github.com/mitchellh/mapstructure"
slackdown "github.com/moira-alert/blackfriday-slack"
"github.com/moira-alert/moira"
"github.com/moira-alert/moira/senders"
blackfriday "github.com/russross/blackfriday/v2"
Expand Down

0 comments on commit ec439dd

Please sign in to comment.