diff --git a/archives/archives.go b/archives/archives.go index 6cfaecb..35f5503 100644 --- a/archives/archives.go +++ b/archives/archives.go @@ -14,10 +14,10 @@ import ( "path/filepath" "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/aws/cwatch" "github.com/nyaruka/gocommon/dates" "github.com/nyaruka/rp-archiver/runtime" ) @@ -967,71 +967,21 @@ 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)) - msgsDim := types.Dimension{Name: aws.String("ArchiveType"), Value: aws.String("msgs")} - runsDim := types.Dimension{Name: aws.String("ArchiveType"), Value: aws.String("runs")} + msgsDim := cwatch.Dimension("ArchiveType", "msgs") + runsDim := cwatch.Dimension("ArchiveType", "runs") metrics := []types.MetricDatum{ - {MetricName: aws.String("ArchivingElapsed"), Value: aws.Float64(timeTaken.Seconds()), Unit: types.StandardUnitSeconds}, - { - MetricName: aws.String("RecordsArchived"), - Dimensions: []types.Dimension{msgsDim}, - Value: aws.Float64(float64(totalMsgsRecordsArchived)), - Unit: types.StandardUnitCount, - }, - { - MetricName: aws.String("RecordsArchived"), - Dimensions: []types.Dimension{runsDim}, - Value: aws.Float64(float64(totalRunsRecordsArchived)), - Unit: types.StandardUnitCount, - }, - { - MetricName: aws.String("ArchivesCreated"), - Dimensions: []types.Dimension{msgsDim}, - Value: aws.Float64(float64(totalMsgsArchivesCreated)), - Unit: types.StandardUnitCount, - }, - { - MetricName: aws.String("ArchivesCreated"), - Dimensions: []types.Dimension{runsDim}, - Value: aws.Float64(float64(totalRunsArchivesCreated)), - Unit: types.StandardUnitCount, - }, - { - MetricName: aws.String("ArchivesFailed"), - Dimensions: []types.Dimension{msgsDim}, - Value: aws.Float64(float64(totalMsgsArchivesFailed)), - Unit: types.StandardUnitCount, - }, - { - MetricName: aws.String("ArchivesFailed"), - Dimensions: []types.Dimension{runsDim}, - Value: aws.Float64(float64(totalRunsArchivesFailed)), - Unit: types.StandardUnitCount, - }, - { - MetricName: aws.String("RollupsCreated"), - Dimensions: []types.Dimension{msgsDim}, - Value: aws.Float64(float64(totalMsgsRollupsCreated)), - Unit: types.StandardUnitCount, - }, - { - MetricName: aws.String("RollupsCreated"), - Dimensions: []types.Dimension{runsDim}, - Value: aws.Float64(float64(totalRunsRollupsCreated)), - Unit: types.StandardUnitCount, - }, - { - MetricName: aws.String("RollupsFailed"), - Dimensions: []types.Dimension{msgsDim}, - Value: aws.Float64(float64(totalMsgsRollupsFailed)), - Unit: types.StandardUnitCount, - }, - { - MetricName: aws.String("RollupsFailed"), - Dimensions: []types.Dimension{runsDim}, - Value: aws.Float64(float64(totalRunsRollupsFailed)), - Unit: types.StandardUnitCount, - }, + cwatch.Datum("ArchivingElapsed", timeTaken.Seconds(), types.StandardUnitSeconds), + cwatch.Datum("RecordsArchived", float64(totalMsgsRecordsArchived), types.StandardUnitCount, msgsDim), + cwatch.Datum("RecordsArchived", float64(totalRunsRecordsArchived), types.StandardUnitCount, runsDim), + cwatch.Datum("ArchivesCreated", float64(totalMsgsArchivesCreated), types.StandardUnitCount, msgsDim), + cwatch.Datum("ArchivesCreated", float64(totalRunsArchivesCreated), types.StandardUnitCount, runsDim), + cwatch.Datum("ArchivesFailed", float64(totalMsgsArchivesFailed), types.StandardUnitCount, msgsDim), + cwatch.Datum("ArchivesFailed", float64(totalRunsArchivesFailed), types.StandardUnitCount, runsDim), + cwatch.Datum("RollupsCreated", float64(totalMsgsRollupsCreated), types.StandardUnitCount, msgsDim), + cwatch.Datum("RollupsCreated", float64(totalRunsRollupsCreated), types.StandardUnitCount, runsDim), + cwatch.Datum("RollupsFailed", float64(totalMsgsRollupsFailed), types.StandardUnitCount, msgsDim), + cwatch.Datum("RollupsFailed", float64(totalRunsRollupsFailed), types.StandardUnitCount, runsDim), } if err = rt.CW.Send(ctx, metrics...); err != nil { diff --git a/go.mod b/go.mod index 3177a05..cc12087 100644 --- a/go.mod +++ b/go.mod @@ -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.3 + github.com/nyaruka/gocommon v1.60.4 github.com/samber/slog-multi v1.2.0 github.com/samber/slog-sentry v1.2.2 github.com/stretchr/testify v1.10.0 diff --git a/go.sum b/go.sum index cf341be..b9f2bf3 100644 --- a/go.sum +++ b/go.sum @@ -71,8 +71,8 @@ github.com/naoina/toml v0.1.1 h1:PT/lllxVVN0gzzSqSlHEmP8MJB4MY2U7STGxiouV4X8= github.com/naoina/toml v0.1.1/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E= github.com/nyaruka/ezconf v0.3.0 h1:kGvJqVN8AHowb4HdaHAviJ0Z3yI5Pyekp1WqibFEaGk= github.com/nyaruka/ezconf v0.3.0/go.mod h1:89GUW6EPRNLIxT7lC4LWnjWTgZeQwRoX7lBmc8ralAU= -github.com/nyaruka/gocommon v1.60.3 h1:fPQ9t6NX+mu7JQ7nXefgpBs8paqGvGXq3eA7VscsAVo= -github.com/nyaruka/gocommon v1.60.3/go.mod h1:kFJuOq8COneV7ssfK6xgCMJ8gP8fQifLQnNXBnE4YL0= +github.com/nyaruka/gocommon v1.60.4 h1:QpnSJailgaXpfjFjjuKTy/4NufgfmGfdFGib8khXm9o= +github.com/nyaruka/gocommon v1.60.4/go.mod h1:kFJuOq8COneV7ssfK6xgCMJ8gP8fQifLQnNXBnE4YL0= github.com/nyaruka/null/v2 v2.0.3 h1:rdmMRQyVzrOF3Jff/gpU/7BDR9mQX0lcLl4yImsA3kw= github.com/nyaruka/null/v2 v2.0.3/go.mod h1:OCVeCkCXwrg5/qE6RU0c1oUVZBy+ZDrT+xYg1XSaIWA= github.com/nyaruka/phonenumbers v1.4.3 h1:tR71UJ+DZu7TSkxoG8JI8HzHJkPD/m4KNiUX34Fvmlo=