Skip to content

Commit

Permalink
Update gocommon
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Dec 13, 2024
1 parent 5c71762 commit 16d1993
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 50 deletions.
24 changes: 12 additions & 12 deletions archives/archives.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,18 +968,18 @@ func ArchiveActiveOrgs(rt *runtime.Runtime) error {
timeTaken := dates.Now().Sub(start)
slog.Info("archiving of active orgs complete", "time_taken", timeTaken, "num_orgs", len(orgs))

rt.CW.Queue(types.MetricDatum{MetricName: aws.String("ArchiveElapsed"), Value: aws.Float64(timeTaken.Seconds())})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("OrgsArchived"), Value: aws.Float64(float64(len(orgs)))})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("MsgsRecordsArchived"), Value: aws.Float64(float64(totalMsgsRecordsArchived))})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("MsgsArchivedsCreated"), Value: aws.Float64(float64(totalMsgsArchivesCreated))})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("MsgsArchivedsFailed"), Value: aws.Float64(float64(totalMsgsArchivesFailed))})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("MsgsRollupsCreated"), Value: aws.Float64(float64(totalMsgsRollupsCreated))})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("MsgsRollupsFailed"), Value: aws.Float64(float64(totalMsgsRollupsFailed))})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("RunsRecordsArchived"), Value: aws.Float64(float64(totalRunsRecordsArchived))})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("RunsArchivedsCreated"), Value: aws.Float64(float64(totalRunsArchivesCreated))})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("RunsArchivedsFailed"), Value: aws.Float64(float64(totalRunsArchivesFailed))})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("RunsRollupsCreated"), Value: aws.Float64(float64(totalRunsRollupsCreated))})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("RunsRollupsFailed"), Value: aws.Float64(float64(totalRunsRollupsFailed))})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("ArchiveElapsed"), Value: aws.Float64(timeTaken.Seconds()), Unit: types.StandardUnitSeconds})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("OrgsArchived"), Value: aws.Float64(float64(len(orgs))), Unit: types.StandardUnitCount})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("MsgsRecordsArchived"), Value: aws.Float64(float64(totalMsgsRecordsArchived)), Unit: types.StandardUnitCount})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("MsgsArchivedsCreated"), Value: aws.Float64(float64(totalMsgsArchivesCreated)), Unit: types.StandardUnitCount})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("MsgsArchivedsFailed"), Value: aws.Float64(float64(totalMsgsArchivesFailed)), Unit: types.StandardUnitCount})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("MsgsRollupsCreated"), Value: aws.Float64(float64(totalMsgsRollupsCreated)), Unit: types.StandardUnitCount})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("MsgsRollupsFailed"), Value: aws.Float64(float64(totalMsgsRollupsFailed)), Unit: types.StandardUnitCount})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("RunsRecordsArchived"), Value: aws.Float64(float64(totalRunsRecordsArchived)), Unit: types.StandardUnitCount})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("RunsArchivedsCreated"), Value: aws.Float64(float64(totalRunsArchivesCreated)), Unit: types.StandardUnitCount})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("RunsArchivedsFailed"), Value: aws.Float64(float64(totalRunsArchivesFailed)), Unit: types.StandardUnitCount})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("RunsRollupsCreated"), Value: aws.Float64(float64(totalRunsRollupsCreated)), Unit: types.StandardUnitCount})
rt.CW.Queue(types.MetricDatum{MetricName: aws.String("RunsRollupsFailed"), Value: aws.Float64(float64(totalRunsRollupsFailed)), Unit: types.StandardUnitCount})

analytics.Gauge("archiver.archive_elapsed", timeTaken.Seconds())
analytics.Gauge("archiver.orgs_archived", float64(len(orgs)))
Expand Down
31 changes: 3 additions & 28 deletions archives/archives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import (
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
"github.com/nyaruka/gocommon/analytics"
cwatchmock "github.com/nyaruka/gocommon/aws/cwatch/mock"
"github.com/nyaruka/gocommon/aws/cwatch"
"github.com/nyaruka/gocommon/dates"
"github.com/nyaruka/rp-archiver/runtime"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -47,7 +45,7 @@ func setup(t *testing.T) (context.Context, *runtime.Runtime) {

slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug})))

CW, err := cwatchmock.NewMockCWService(config.AWSAccessKeyID, config.AWSSecretAccessKey, config.AWSRegion, config.CloudwatchNamespace, config.DeploymentID)
CW, err := cwatch.NewService(config.AWSAccessKeyID, config.AWSSecretAccessKey, config.AWSRegion, config.CloudwatchNamespace, config.DeploymentID)
require.NoError(t, err)

return ctx, &runtime.Runtime{Config: config, DB: db, S3: s3Client, CW: CW}
Expand Down Expand Up @@ -505,13 +503,7 @@ func TestArchiveActiveOrgs(t *testing.T) {
analytics.RegisterBackend(mockAnalytics)
analytics.Start()

assert.Equal(t, rt.CW.(*cwatchmock.MockCWService).Batcher, []types.MetricDatum(nil))
assert.False(t, rt.CW.(*cwatchmock.MockCWService).Stopped)

rt.CW.StartQueue(wg)

assert.Equal(t, rt.CW.(*cwatchmock.MockCWService).Batcher, []types.MetricDatum{})
assert.False(t, rt.CW.(*cwatchmock.MockCWService).Stopped)
rt.CW.StartQueue(wg, time.Millisecond*100)

dates.SetNowFunc(dates.NewSequentialNow(time.Date(2018, 1, 8, 12, 30, 0, 0, time.UTC), time.Second))
defer dates.SetNowFunc(time.Now)
Expand All @@ -534,24 +526,7 @@ func TestArchiveActiveOrgs(t *testing.T) {
"archiver.runs_rollups_failed": {1},
}, mockAnalytics.Gauges)

assert.Equal(t, rt.CW.(*cwatchmock.MockCWService).Batcher, []types.MetricDatum{
{MetricName: aws.String("ArchiveElapsed"), Value: aws.Float64(848)},
{MetricName: aws.String("OrgsArchived"), Value: aws.Float64(3)},
{MetricName: aws.String("MsgsRecordsArchived"), Value: aws.Float64(5)},
{MetricName: aws.String("MsgsArchivedsCreated"), Value: aws.Float64(92)},
{MetricName: aws.String("MsgsArchivedsFailed"), Value: aws.Float64(0)},
{MetricName: aws.String("MsgsRollupsCreated"), Value: aws.Float64(3)},
{MetricName: aws.String("MsgsRollupsFailed"), Value: aws.Float64(0)},
{MetricName: aws.String("RunsRecordsArchived"), Value: aws.Float64(5)},
{MetricName: aws.String("RunsArchivedsCreated"), Value: aws.Float64(41)},
{MetricName: aws.String("RunsArchivedsFailed"), Value: aws.Float64(1)},
{MetricName: aws.String("RunsRollupsCreated"), Value: aws.Float64(3)},
{MetricName: aws.String("RunsRollupsFailed"), Value: aws.Float64(1)},
})

analytics.Stop()

rt.CW.StopQueue()
assert.True(t, rt.CW.(*cwatchmock.MockCWService).Stopped)

}
14 changes: 6 additions & 8 deletions cmd/rp-archiver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,15 @@ func main() {
analytics.RegisterBackend(analytics.NewLibrato(config.LibratoUsername, config.LibratoToken, config.InstanceName, time.Second, wg))
}

if rt.Config.DeploymentID != "dev" {
rt.CW, err = cwatch.NewService(config.AWSAccessKeyID, config.AWSSecretAccessKey, config.AWSRegion, config.CloudwatchNamespace, config.DeploymentID)
if err != nil {
logger.Error("unable to create cloudwatch service", "error", err)
} else {
logger.Info("cloudwatch service ok", "state", "starting")
}
rt.CW, err = cwatch.NewService(config.AWSAccessKeyID, config.AWSSecretAccessKey, config.AWSRegion, config.CloudwatchNamespace, config.DeploymentID)
if err != nil {
logger.Error("unable to create cloudwatch service", "error", err)
} else {
logger.Info("cloudwatch service ok", "state", "starting")
}

Check warning on line 135 in cmd/rp-archiver/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/rp-archiver/main.go#L130-L135

Added lines #L130 - L135 were not covered by tests

analytics.Start()
rt.CW.StartQueue(wg)
rt.CW.StartQueue(wg, time.Second*3)

Check warning on line 138 in cmd/rp-archiver/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/rp-archiver/main.go#L138

Added line #L138 was not covered by tests

if config.Once {
doArchival(rt)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/jmoiron/sqlx v1.4.0
github.com/lib/pq v1.10.9
github.com/nyaruka/ezconf v0.3.0
github.com/nyaruka/gocommon v1.60.2-0.20241213113333-112a0bc4c3ee
github.com/nyaruka/gocommon v1.60.2
github.com/samber/slog-multi v1.2.0
github.com/samber/slog-sentry v1.2.2
github.com/stretchr/testify v1.10.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ github.com/nyaruka/gocommon v1.60.2-0.20241213113120-30b1b04a98e8 h1:wK38pZqJ6yJ
github.com/nyaruka/gocommon v1.60.2-0.20241213113120-30b1b04a98e8/go.mod h1:kFJuOq8COneV7ssfK6xgCMJ8gP8fQifLQnNXBnE4YL0=
github.com/nyaruka/gocommon v1.60.2-0.20241213113333-112a0bc4c3ee h1:MH7kxmPa53XrbDROcK8vzYYw+Im0NMwGL/knR8TsSqE=
github.com/nyaruka/gocommon v1.60.2-0.20241213113333-112a0bc4c3ee/go.mod h1:kFJuOq8COneV7ssfK6xgCMJ8gP8fQifLQnNXBnE4YL0=
github.com/nyaruka/gocommon v1.60.2 h1:AvvSSAV70SV49ocNtvjpdb9NlcdiA2OQAL4NYVUcuV0=
github.com/nyaruka/gocommon v1.60.2/go.mod h1:kFJuOq8COneV7ssfK6xgCMJ8gP8fQifLQnNXBnE4YL0=
github.com/nyaruka/librato v1.1.1 h1:0nTYtJLl3Sn7lX3CuHsLf+nXy1k/tGV0OjVxLy3Et4s=
github.com/nyaruka/librato v1.1.1/go.mod h1:fme1Fu1PT2qvkaBZyw8WW+SrnFe2qeeCWpvqmAaKAKE=
github.com/nyaruka/null/v2 v2.0.3 h1:rdmMRQyVzrOF3Jff/gpU/7BDR9mQX0lcLl4yImsA3kw=
Expand Down
2 changes: 1 addition & 1 deletion runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ type Runtime struct {
Config *Config
DB *sqlx.DB
S3 *s3x.Service
CW cwatch.CWService
CW *cwatch.Service
}

0 comments on commit 16d1993

Please sign in to comment.