Skip to content

Commit

Permalink
Include rollups in monthlies failed metric as well as monthlies creat…
Browse files Browse the repository at this point in the history
…ed from scratch
  • Loading branch information
rowanseymour committed Jul 8, 2022
1 parent 26c2000 commit 065cffa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions archives/archives.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,19 +770,21 @@ func createArchives(ctx context.Context, db *sqlx.DB, config *Config, s3Client s
}

// RollupOrgArchives rolls up monthly archives from our daily archives
func RollupOrgArchives(ctx context.Context, now time.Time, config *Config, db *sqlx.DB, s3Client s3iface.S3API, org Org, archiveType ArchiveType) ([]*Archive, error) {
func RollupOrgArchives(ctx context.Context, now time.Time, config *Config, db *sqlx.DB, s3Client s3iface.S3API, org Org, archiveType ArchiveType) ([]*Archive, []*Archive, error) {
ctx, cancel := context.WithTimeout(ctx, time.Hour*3)
defer cancel()

log := logrus.WithFields(logrus.Fields{"org_id": org.ID, "org_name": org.Name, "archive_type": archiveType})
created := make([]*Archive, 0, 1)

// get our missing monthly archives
archives, err := GetMissingMonthlyArchives(ctx, db, now, org, archiveType)
if err != nil {
return nil, err
return nil, nil, err
}

created := make([]*Archive, 0, len(archives))
failed := make([]*Archive, 0, 1)

// build them from rollups
for _, archive := range archives {
log := log.WithFields(logrus.Fields{"start_date": archive.StartDate})
Expand All @@ -791,20 +793,23 @@ func RollupOrgArchives(ctx context.Context, now time.Time, config *Config, db *s
err = BuildRollupArchive(ctx, db, config, s3Client, archive, now, org, archiveType)
if err != nil {
log.WithError(err).Error("error building monthly archive")
failed = append(failed, archive)
continue
}

if config.UploadToS3 {
err = UploadArchive(ctx, s3Client, config.S3Bucket, archive)
if err != nil {
log.WithError(err).Error("error writing archive to s3")
failed = append(failed, archive)
continue
}
}

err = WriteArchiveToDB(ctx, db, archive)
if err != nil {
log.WithError(err).Error("error writing record to db")
failed = append(failed, archive)
continue
}

Expand All @@ -820,7 +825,7 @@ func RollupOrgArchives(ctx context.Context, now time.Time, config *Config, db *s
created = append(created, archive)
}

return created, nil
return created, failed, nil
}

const setArchiveDeleted = `
Expand Down Expand Up @@ -909,12 +914,13 @@ func ArchiveOrg(ctx context.Context, now time.Time, cfg *Config, db *sqlx.DB, s3
log.WithFields(logrus.Fields{"elapsed": elapsed, "records_per_second": rate}).Info("completed archival for org")
}

monthliesRolledUp, err := RollupOrgArchives(ctx, now, cfg, db, s3Client, org, archiveType)
rollupsCreated, rollupsFailed, err := RollupOrgArchives(ctx, now, cfg, db, s3Client, org, archiveType)
if err != nil {
return nil, nil, nil, nil, nil, errors.Wrapf(err, "error rolling up archives")
}

monthliesCreated = append(monthliesCreated, monthliesRolledUp...)
monthliesCreated = append(monthliesCreated, rollupsCreated...)
monthliesFailed = append(monthliesFailed, rollupsFailed...)

// finally delete any archives not yet actually archived
var deleted []*Archive
Expand Down
2 changes: 1 addition & 1 deletion archives/archives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ func TestArchiveActiveOrgs(t *testing.T) {
"archiver.runs_archives_created": {41},
"archiver.runs_archives_failed": {1},
"archiver.runs_rollups_created": {3},
"archiver.runs_rollups_failed": {1},
"archiver.runs_rollups_failed": {2},
}, mockAnalytics.Gauges)
}

Expand Down

0 comments on commit 065cffa

Please sign in to comment.