blob: 1fdf8e9713c9e19480b3cd13b719aa09266efbf5 [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COBALT_SRC_LOCAL_AGGREGATION_1_1_BACKFILL_MANAGER_H_
#define COBALT_SRC_LOCAL_AGGREGATION_1_1_BACKFILL_MANAGER_H_
#include "src/local_aggregation_1_1/aggregation_procedures/aggregation_procedure.h"
#include "src/local_aggregation_1_1/local_aggregation.pb.h"
#include "src/public/lib/clock_interfaces.h"
#include "src/public/lib/statusor/statusor.h"
#include "src/registry/metric_definition.pb.h"
namespace cobalt::local_aggregation {
// BackfillManager is responsible for computing the list of aggregation periods for which no
// observations were generated for a particular report.
class BackfillManager {
public:
// |total_backfill_window| The maximum number of past days (with respect to UTC) to generate
// daily/hourly observations for. In addition, for hourly procedures, the BackfillManager may
// return TimeInfos for previous hours of the current day.
explicit BackfillManager(uint32_t total_backfill_window);
// CalculateBackfill returns a list of TimeInfos corresponding to aggregation periods for which
// observations have not yet been generated.
//
// |last_time_info| The last `TimeInfo` for which an observation has been generated.
// |end_time| The most recent time to consider (inclusive).
// |civil_time_converter| Converts time points into civil times for a given time zone.
// |metric| The metric definition associated with the observations.
// |is_daily| If true, we should generate daily TimeInfos, otherwise generate hourly.
[[nodiscard]] lib::statusor::StatusOr<std::vector<util::TimeInfo>> CalculateBackfill(
util::TimeInfo last_time_info, std::chrono::system_clock::time_point end_time,
const util::CivilTimeConverterInterface& civil_time_converter, const MetricDefinition& metric,
bool is_daily) const;
private:
// The number of days in the past for which we should generate observations.
uint32_t backstop_days_;
};
} // namespace cobalt::local_aggregation
#endif // COBALT_SRC_LOCAL_AGGREGATION_1_1_BACKFILL_MANAGER_H_