iterate through all available logs for precomputation and query gets (#15768)
This commit is contained in:
parent
fece4cf9ac
commit
671aaf1fe0
|
@ -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())+"/")
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue