Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update cabonapi to v0.17.0 #1074

Merged
merged 22 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions database/redis/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ func NewDatabase(logger moira.Logger, config DatabaseConfig, nh NotificationHist

// NewTestDatabase use it only for tests.
func NewTestDatabase(logger moira.Logger) *DbConnector {
return NewDatabase(logger, DatabaseConfig{
Addrs: []string{"0.0.0.0:6379"},
},
return NewDatabase(
logger, DatabaseConfig{
Addrs: []string{"0.0.0.0:6379"},
MetricsTTL: time.Hour,
},
NotificationHistoryConfig{
NotificationHistoryTTL: time.Hour * 48,
},
Expand All @@ -104,7 +106,8 @@ func NewTestDatabase(logger moira.Logger) *DbConnector {
TransactionHeuristicLimit: 10000,
ResaveTime: 30 * time.Second,
},
testSource)
testSource,
)
}

// NewTestDatabaseWithIncorrectConfig use it only for tests.
Expand Down
19 changes: 11 additions & 8 deletions database/redis/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import (
"strings"
"time"

"github.com/moira-alert/moira/notifier"

"github.com/go-redis/redis/v8"

"github.com/moira-alert/moira"
"github.com/moira-alert/moira/database/redis/reply"
)

// Separate const to prevent cyclic dependencies.
almostinf marked this conversation as resolved.
Show resolved Hide resolved
// Original const is declared in notifier package, notifier depends on all metric source packages.
// Thus it prevents us from using database in tests for local metric source.
const notificationsLimitUnlimited = int64(-1)

type notificationTypes struct {
Valid, ToRemove, ToResaveNew, ToResaveOld []*moira.ScheduledNotification
}
Expand Down Expand Up @@ -294,8 +297,8 @@ func (connector *DbConnector) FetchNotifications(to int64, limit int64) ([]*moir
}

// No limit
if limit == notifier.NotificationsLimitUnlimited {
return connector.fetchNotifications(to, notifier.NotificationsLimitUnlimited)
if limit == notificationsLimitUnlimited {
return connector.fetchNotifications(to, notificationsLimitUnlimited)
}

count, err := connector.notificationsCount(to)
Expand All @@ -305,7 +308,7 @@ func (connector *DbConnector) FetchNotifications(to int64, limit int64) ([]*moir

// Hope count will be not greater then limit when we call fetchNotificationsNoLimit
if limit > connector.notification.TransactionHeuristicLimit && count < limit/2 {
return connector.fetchNotifications(to, notifier.NotificationsLimitUnlimited)
return connector.fetchNotifications(to, notificationsLimitUnlimited)
}

return connector.fetchNotifications(to, limit)
Expand Down Expand Up @@ -354,7 +357,7 @@ func (connector *DbConnector) fetchNotifications(to int64, limit int64) ([]*moir
// sorted by timestamp in one transaction with or without limit, depending on whether limit is nil.
func getNotificationsInTxWithLimit(ctx context.Context, tx *redis.Tx, to int64, limit int64) ([]*moira.ScheduledNotification, error) {
var rng *redis.ZRangeBy
if limit != notifier.NotificationsLimitUnlimited {
if limit != notificationsLimitUnlimited {
rng = &redis.ZRangeBy{Min: "-inf", Max: strconv.FormatInt(to, 10), Offset: 0, Count: limit}
} else {
rng = &redis.ZRangeBy{Min: "-inf", Max: strconv.FormatInt(to, 10)}
Expand Down Expand Up @@ -393,15 +396,15 @@ func getLimitedNotifications(

limitedNotifications := notifications

if limit != notifier.NotificationsLimitUnlimited {
if limit != notificationsLimitUnlimited {
limitedNotifications = limitNotifications(notifications)
lastTs := limitedNotifications[len(limitedNotifications)-1].Timestamp

if len(notifications) == len(limitedNotifications) {
// this means that all notifications have same timestamp,
// we hope that all notifications with same timestamp should fit our memory
var err error
limitedNotifications, err = getNotificationsInTxWithLimit(ctx, tx, lastTs, notifier.NotificationsLimitUnlimited)
limitedNotifications, err = getNotificationsInTxWithLimit(ctx, tx, lastTs, notificationsLimitUnlimited)
if err != nil {
return nil, fmt.Errorf("failed to get notification without limit in transaction: %w", err)
}
Expand Down
31 changes: 15 additions & 16 deletions database/redis/notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/moira-alert/moira"
"github.com/moira-alert/moira/clock"
logging "github.com/moira-alert/moira/logging/zerolog_adapter"
"github.com/moira-alert/moira/notifier"
"github.com/stretchr/testify/assert"

. "github.com/smartystreets/goconvey/convey"
Expand Down Expand Up @@ -59,7 +58,7 @@ func TestScheduledNotification(t *testing.T) {
})

Convey("Test fetch notifications", func() {
actual, err := database.FetchNotifications(now-database.getDelayedTimeInSeconds(), notifier.NotificationsLimitUnlimited) //nolint
actual, err := database.FetchNotifications(now-database.getDelayedTimeInSeconds(), notificationsLimitUnlimited) //nolint
So(err, ShouldBeNil)
So(actual, ShouldResemble, []*moira.ScheduledNotification{&notificationOld})

Expand All @@ -68,7 +67,7 @@ func TestScheduledNotification(t *testing.T) {
So(total, ShouldEqual, 2)
So(actual, ShouldResemble, []*moira.ScheduledNotification{&notification, &notificationNew})

actual, err = database.FetchNotifications(now+database.getDelayedTimeInSeconds(), notifier.NotificationsLimitUnlimited) //nolint
actual, err = database.FetchNotifications(now+database.getDelayedTimeInSeconds(), notificationsLimitUnlimited) //nolint
So(err, ShouldBeNil)
So(actual, ShouldResemble, []*moira.ScheduledNotification{&notification, &notificationNew})

Expand Down Expand Up @@ -128,7 +127,7 @@ func TestScheduledNotification(t *testing.T) {
So(total, ShouldEqual, 0)
So(actual, ShouldResemble, []*moira.ScheduledNotification{})

actual, err = database.FetchNotifications(now+database.getDelayedTimeInSeconds(), notifier.NotificationsLimitUnlimited) //nolint
actual, err = database.FetchNotifications(now+database.getDelayedTimeInSeconds(), notificationsLimitUnlimited) //nolint
So(err, ShouldBeNil)
So(actual, ShouldResemble, []*moira.ScheduledNotification{})
})
Expand Down Expand Up @@ -167,7 +166,7 @@ func TestScheduledNotification(t *testing.T) {
So(total, ShouldEqual, 0)
So(actual, ShouldResemble, []*moira.ScheduledNotification{})

actual, err = database.FetchNotifications(now+database.getDelayedTimeInSeconds(), notifier.NotificationsLimitUnlimited) //nolint
actual, err = database.FetchNotifications(now+database.getDelayedTimeInSeconds(), notificationsLimitUnlimited) //nolint
So(err, ShouldBeNil)
So(actual, ShouldResemble, []*moira.ScheduledNotification{})
})
Expand Down Expand Up @@ -197,7 +196,7 @@ func TestScheduledNotificationErrorConnection(t *testing.T) {
So(err, ShouldNotBeNil)
So(total, ShouldEqual, 0)

actual2, err := database.FetchNotifications(0, notifier.NotificationsLimitUnlimited)
actual2, err := database.FetchNotifications(0, notificationsLimitUnlimited)
So(err, ShouldNotBeNil)
So(actual2, ShouldBeNil)

Expand Down Expand Up @@ -284,7 +283,7 @@ func TestFetchNotifications(t *testing.T) {

Convey("Test fetch notifications without limit", func() {
addNotifications(database, []moira.ScheduledNotification{notification, notificationNew, notificationOld})
actual, err := database.FetchNotifications(now+database.getDelayedTimeInSeconds(), notifier.NotificationsLimitUnlimited) //nolint
actual, err := database.FetchNotifications(now+database.getDelayedTimeInSeconds(), notificationsLimitUnlimited) //nolint
So(err, ShouldBeNil)
So(actual, ShouldResemble, []*moira.ScheduledNotification{&notificationOld, &notification, &notificationNew})

Expand Down Expand Up @@ -330,7 +329,7 @@ func TestGetNotificationsInTxWithLimit(t *testing.T) {
Convey("Test with zero notifications without limit", func() {
addNotifications(database, []moira.ScheduledNotification{})
err := client.Watch(ctx, func(tx *redis.Tx) error {
actual, err := getNotificationsInTxWithLimit(ctx, tx, now+database.getDelayedTimeInSeconds()*2, notifier.NotificationsLimitUnlimited)
actual, err := getNotificationsInTxWithLimit(ctx, tx, now+database.getDelayedTimeInSeconds()*2, notificationsLimitUnlimited)
So(err, ShouldBeNil)
So(actual, ShouldResemble, []*moira.ScheduledNotification{})
return nil
Expand All @@ -344,7 +343,7 @@ func TestGetNotificationsInTxWithLimit(t *testing.T) {
Convey("Test all notifications without limit", func() {
addNotifications(database, []moira.ScheduledNotification{notification, notificationNew, notificationOld})
err := client.Watch(ctx, func(tx *redis.Tx) error {
actual, err := getNotificationsInTxWithLimit(ctx, tx, now+database.getDelayedTimeInSeconds()*2, notifier.NotificationsLimitUnlimited)
actual, err := getNotificationsInTxWithLimit(ctx, tx, now+database.getDelayedTimeInSeconds()*2, notificationsLimitUnlimited)
So(err, ShouldBeNil)
So(actual, ShouldResemble, []*moira.ScheduledNotification{&notificationOld, &notification, &notificationNew})
return nil
Expand Down Expand Up @@ -418,7 +417,7 @@ func TestGetLimitedNotifications(t *testing.T) {
Convey("Test all notifications with different timestamps without limit", func() {
notifications := []*moira.ScheduledNotification{&notificationOld, &notification, &notificationNew}
err := client.Watch(ctx, func(tx *redis.Tx) error {
actual, err := getLimitedNotifications(ctx, tx, notifier.NotificationsLimitUnlimited, notifications)
actual, err := getLimitedNotifications(ctx, tx, notificationsLimitUnlimited, notifications)
So(err, ShouldBeNil)
So(actual, ShouldResemble, []*moira.ScheduledNotification{&notificationOld, &notification, &notificationNew})
return nil
Expand Down Expand Up @@ -913,7 +912,7 @@ func TestFetchNotificationsDo(t *testing.T) {

Convey("Without limit", func() {
addNotifications(database, []moira.ScheduledNotification{notification, notificationNew, notificationOld})
actual, err := database.fetchNotificationsDo(now+database.getDelayedTimeInSeconds(), notifier.NotificationsLimitUnlimited)
actual, err := database.fetchNotificationsDo(now+database.getDelayedTimeInSeconds(), notificationsLimitUnlimited)
So(err, ShouldBeNil)
So(actual, ShouldResemble, []*moira.ScheduledNotification{&notificationOld, &notification, &notificationNew})

Expand All @@ -936,7 +935,7 @@ func TestFetchNotificationsDo(t *testing.T) {

Convey("Without limit", func() {
addNotifications(database, []moira.ScheduledNotification{})
actual, err := database.fetchNotificationsDo(now+database.getDelayedTimeInSeconds(), notifier.NotificationsLimitUnlimited)
actual, err := database.fetchNotificationsDo(now+database.getDelayedTimeInSeconds(), notificationsLimitUnlimited)
So(err, ShouldBeNil)
So(actual, ShouldResemble, []*moira.ScheduledNotification{})

Expand All @@ -947,7 +946,7 @@ func TestFetchNotificationsDo(t *testing.T) {

Convey("Test all notification with ts and without limit in db", func() {
addNotifications(database, []moira.ScheduledNotification{notification, notificationNew, notificationOld, notification4})
actual, err := database.fetchNotificationsDo(now+database.getDelayedTimeInSeconds(), notifier.NotificationsLimitUnlimited)
actual, err := database.fetchNotificationsDo(now+database.getDelayedTimeInSeconds(), notificationsLimitUnlimited)
So(err, ShouldBeNil)
So(actual, ShouldResemble, []*moira.ScheduledNotification{&notificationOld, &notification4, &notification, &notificationNew})

Expand Down Expand Up @@ -1016,7 +1015,7 @@ func TestFetchNotificationsDo(t *testing.T) {

Convey("Without limit", func() {
addNotifications(database, []moira.ScheduledNotification{notificationOld, notificationOld2, notification, notificationNew, notificationNew2, notificationNew3})
actual, err := database.fetchNotificationsDo(now+database.getDelayedTimeInSeconds()+3, notifier.NotificationsLimitUnlimited)
actual, err := database.fetchNotificationsDo(now+database.getDelayedTimeInSeconds()+3, notificationsLimitUnlimited)
So(err, ShouldBeNil)
So(actual, ShouldResemble, []*moira.ScheduledNotification{&notificationOld, &notificationOld2, &notification, &notificationNew, &notificationNew3})

Expand Down Expand Up @@ -1052,7 +1051,7 @@ func TestFetchNotificationsDo(t *testing.T) {

Convey("Without limit", func() {
addNotifications(database, []moira.ScheduledNotification{notificationOld, notificationOld2, notification, notificationNew, notificationNew2, notificationNew3})
actual, err := database.fetchNotificationsDo(now+database.getDelayedTimeInSeconds()+3, notifier.NotificationsLimitUnlimited)
actual, err := database.fetchNotificationsDo(now+database.getDelayedTimeInSeconds()+3, notificationsLimitUnlimited)
So(err, ShouldBeNil)
So(actual, ShouldResemble, []*moira.ScheduledNotification{&notificationOld, &notificationOld2, &notification, &notificationNew, &notificationNew2})

Expand Down Expand Up @@ -1092,7 +1091,7 @@ func TestFetchNotificationsDo(t *testing.T) {

Convey("without limit", func() {
addNotifications(database, []moira.ScheduledNotification{notificationOld, notificationOld2, notification, notificationNew, notificationNew2, notificationNew3})
actual, err := database.fetchNotificationsDo(now+database.getDelayedTimeInSeconds()+3, notifier.NotificationsLimitUnlimited)
actual, err := database.fetchNotificationsDo(now+database.getDelayedTimeInSeconds()+3, notificationsLimitUnlimited)
So(err, ShouldBeNil)
So(actual, ShouldResemble, []*moira.ScheduledNotification{&notificationOld, &notificationOld2, &notification, &notificationNew, &notificationNew3})

Expand Down
51 changes: 24 additions & 27 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22
require (
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible
github.com/PagerDuty/go-pagerduty v1.5.1
github.com/ansel1/merry v1.6.2
github.com/ansel1/merry v1.8.0
github.com/aws/aws-sdk-go v1.44.293
github.com/blevesearch/bleve/v2 v2.3.8
github.com/bwmarrin/discordgo v0.25.0
Expand All @@ -15,7 +15,7 @@ require (
github.com/dustin/go-humanize v1.0.1
github.com/go-chi/chi v4.1.2+incompatible
github.com/go-chi/render v1.0.1
github.com/go-graphite/carbonapi v0.16.0
github.com/go-graphite/carbonapi v0.17.0
github.com/go-graphite/protocol v1.0.0
github.com/go-redis/redis/v8 v8.11.5
github.com/go-redsync/redsync/v4 v4.4.4
Expand Down Expand Up @@ -57,13 +57,11 @@ require (
)

require (
bitbucket.org/tebeka/strftime v0.0.0-20140926081919-2194253a23c0 // indirect
github.com/JaderDias/movingmedian v0.0.0-20220813210630-d8c6b6de8835 // indirect
github.com/Masterminds/sprig/v3 v3.2.3
github.com/RoaringBitmap/roaring v1.3.0 // indirect
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 // indirect
github.com/ansel1/merry/v2 v2.1.1 // indirect
github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df // indirect
github.com/ansel1/merry/v2 v2.2.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.8.0 // indirect
github.com/blend/go-sdk v2.0.0+incompatible // indirect
Expand All @@ -82,21 +80,19 @@ require (
github.com/blevesearch/zapx/v13 v13.3.8 // indirect
github.com/blevesearch/zapx/v14 v14.3.8 // indirect
github.com/blevesearch/zapx/v15 v15.3.11 // indirect
github.com/bradfitz/gomemcache v0.0.0-20221031212613-62deef7fc822 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-expirecache v0.0.0-20170314133854-743ef98b2adb // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgryski/go-onlinestats v0.0.0-20170612111826-1c7d19468768 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/disintegration/imaging v1.6.2 // indirect
github.com/evmar/gocairo v0.0.0-20160222165215-ddd30f837497 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.5 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/geo v0.0.0-20230421003525-6adc56603217 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gomodule/redigo v1.8.9 // indirect
github.com/gomodule/redigo v1.9.2 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.6.0
github.com/gopherjs/gopherjs v1.17.2 // indirect
Expand All @@ -115,7 +111,7 @@ require (
github.com/lomik/og-rek v0.0.0-20170411191824-628eefeb8d80 // indirect
github.com/lomik/zapwriter v0.0.0-20210624082824-c1161d1eb463 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/maruel/natural v1.1.0 // indirect
github.com/maruel/natural v1.1.1 // indirect
github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404 // indirect
github.com/mattermost/ldap v0.0.0-20231116144001-0f480c025956 // indirect
github.com/mattermost/logr/v2 v2.0.21 // indirect
Expand All @@ -125,46 +121,43 @@ require (
github.com/mjibson/go-dsp v0.0.0-20180508042940-11479a337f12 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/msaf1980/go-stringutils v0.1.4 // indirect
github.com/msaf1980/go-stringutils v0.1.6 // indirect
github.com/mschoch/smat v0.2.0 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/natefinch/atomic v1.0.1 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pelletier/go-toml/v2 v2.2.1 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/smartystreets/assertions v1.2.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.16.0 // indirect
github.com/stretchr/objx v0.5.1 // indirect
github.com/stretchr/testify v1.8.4
github.com/subosito/gotenv v1.4.2 // indirect
github.com/spf13/viper v1.18.2 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/stretchr/testify v1.9.0
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tinylib/msgp v1.1.9 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/wangjohn/quickselect v0.0.0-20161129230411-ed8402a42d5f // indirect
github.com/wiggin77/merror v1.0.5 // indirect
github.com/wiggin77/srslog v1.0.1 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
golang.org/x/image v0.18.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
gonum.org/v1/gonum v0.12.0 // indirect
gonum.org/v1/gonum v0.15.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
Expand Down Expand Up @@ -199,9 +192,13 @@ require (
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/swaggo/files v1.0.1 // indirect
github.com/swaggo/swag v1.8.12 // indirect
github.com/tebeka/strftime v0.1.5 // indirect
golang.org/x/tools v0.22.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/grpc v1.62.0 // indirect
Expand Down
Loading
Loading