Skip to content

Commit

Permalink
iterate through all available logs for precomputation and query gets (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Hridoy Roy authored Jun 3, 2022
1 parent 0e8bcc1 commit 802ba78
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions vault/activity_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,23 +490,6 @@ func (a *ActivityLog) getMostRecentActivityLogSegment(ctx context.Context) ([]ti
return timeutil.GetMostRecentContiguousMonths(logTimes), nil
}

// getMostRecentActivityLogSegment gets the times (in UTC) associated with the most recent
// contiguous set of activity logs, sorted in decreasing order (latest to earliest)
func (a *ActivityLog) getMostRecentNonContiguousActivityLogSegments(ctx context.Context) ([]time.Time, error) {
logTimes, err := a.availableLogs(ctx)
if err != nil {
return nil, err
}
if len(logTimes) <= 12 {
return logTimes, nil
}
contiguousMonths := timeutil.GetMostRecentContiguousMonths(logTimes)
if len(contiguousMonths) >= 12 {
return contiguousMonths, nil
}
return logTimes[:12], nil
}

// getLastEntitySegmentNumber returns the (non-negative) last segment number for the :startTime:, if it exists
func (a *ActivityLog) getLastEntitySegmentNumber(ctx context.Context, startTime time.Time) (uint64, bool, error) {
p, err := a.view.List(ctx, activityEntityBasePath+fmt.Sprint(startTime.Unix())+"/")
Expand Down Expand Up @@ -2046,9 +2029,9 @@ func (a *ActivityLog) precomputedQueryWorker(ctx context.Context) error {
lastMonth := intent.PreviousMonth
a.logger.Info("computing queries", "month", time.Unix(lastMonth, 0).UTC())

times, err := a.getMostRecentNonContiguousActivityLogSegments(ctx)
times, err := a.availableLogs(ctx)
if err != nil {
a.logger.Warn("could not list recent segments", "error", err)
a.logger.Warn("could not list available logs", "error", err)
return err
}
if len(times) == 0 {
Expand Down Expand Up @@ -2597,10 +2580,10 @@ func (a *ActivityLog) writeExport(ctx context.Context, rw http.ResponseWriter, f
// Find the months with activity log data that are between the start and end
// months. We want to walk this in cronological order so the oldest instance of a
// client usage is recorded, not the most recent.
times, err := a.getMostRecentNonContiguousActivityLogSegments(ctx)
times, err := a.availableLogs(ctx)
if err != nil {
a.logger.Warn("failed to list recent segments", "error", err)
return fmt.Errorf("failed to list recent segments: %w", err)
a.logger.Warn("failed to list available log segments", "error", err)
return fmt.Errorf("failed to list available log segments: %w", err)
}
sort.Slice(times, func(i, j int) bool {
// sort in chronological order to produce the output we want showing what
Expand Down

0 comments on commit 802ba78

Please sign in to comment.