blob: 5a724ab04e45476365d9f52c88179b3c9c5448fd [file] [log] [blame]
#ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_STORE_STORE_H_
#define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_STORE_STORE_H_
#include <memory>
#include <vector>
#include "absl/time/time.h"
#include "resource.pb.h"
#include "router_interface.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wconversion"
#include <string>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "nlohmann/json.hpp"
#include "tlbmc/collector/collector.h"
#include "topology_config.pb.h"
#include "fru.pb.h"
#include "tlbmc/sensors/sensor.h"
namespace milotic_tlbmc {
// Store is responsible for creating, owning and managing all the telemetry
// collectors and facilitating access to the data collected by collectors.
class Store {
public:
struct Metrics {
nlohmann::json ToJson() const {
nlohmann::json json;
json["ConfigParseDuration"] = absl::FormatDuration(config_parse_duration);
json["FruScanAndCollectorCreateDuration"] =
absl::FormatDuration(fru_scan_and_collector_create_duration);
json["TopologyConfigLoadDuration"] =
absl::FormatDuration(topology_config_load_duration);
json["SensorCollectorCreateDuration"] =
absl::FormatDuration(sensor_collector_create_duration);
json["TimeToReady"] = absl::FormatDuration(time_to_ready);
return json;
}
// Key Time based metrics which would be tracked to catch any performance
// regressions.
absl::Duration config_parse_duration = absl::InfiniteDuration();
absl::Duration fru_scan_and_collector_create_duration =
absl::InfiniteDuration();
absl::Duration topology_config_load_duration = absl::InfiniteDuration();
absl::Duration sensor_collector_create_duration = absl::InfiniteDuration();
absl::Duration time_to_ready = absl::InfiniteDuration();
// TODO(rahulkpr): Add runtime correctable and uncorrectable errors.
};
virtual ~Store() = default;
// Configures the tlbmc collectors.
// A key usage of this method is to configure the sampling interval of the
// data.
virtual absl::Status ConfigureCollection(const Collector::Config& config,
Collector::Type type) const = 0;
// Returns the sorted list of sensor names contained by the given Config name.
virtual std::vector<std::string> GetAllSensorKeysByConfigName(
const std::string& board_config_name) const = 0;
// Returns all the sensors sorted by sensor name.
virtual std::vector<std::shared_ptr<const Sensor>> GetAllSensors() const = 0;
// Returns the sensor for the given sensor key.
virtual std::shared_ptr<const Sensor> GetSensorBySensorKey(
const std::string& sensor_key) const = 0;
// Returns the sensor for the given board config name and given sensor
// key.
virtual std::shared_ptr<const Sensor> GetSensorByConfigNameAndSensorKey(
const std::string& board_config_name,
const std::string& sensor_key) const = 0;
// FRU accessors.
virtual absl::StatusOr<const Fru*> GetFru(absl::string_view key) const = 0;
virtual absl::StatusOr<const FruTable*> GetAllFrus() const = 0;
virtual absl::StatusOr<const TopologyConfigNode*> GetFruTopology(
absl::string_view config_name) const = 0;
// Returns the topology config of all configs.
virtual absl::StatusOr<const TopologyConfig*> GetTopologyConfig() const = 0;
// Returns all the config names.
virtual absl::StatusOr<std::vector<std::string>> GetAllConfigNames()
const = 0;
// Returns the config name of the given FRU key.
virtual absl::StatusOr<std::string> GetConfigNameByFruKey(
absl::string_view fru_key) const = 0;
virtual absl::StatusOr<std::string> GetFruKeyByConfigName(
absl::string_view config_name) const = 0;
// Converts the store to a JSON object.
virtual nlohmann::json ToJson() const = 0;
// Returns the scheduler stats for the store.
virtual nlohmann::json GetSchedulerStats() const = 0;
// Returns the metrics for the store.
virtual Metrics GetMetrics() const = 0;
// Set Smart Router to let it know of any updates to store.
virtual void SetSmartRouter(::crow::RouterInterface* smart_router) = 0;
// Converts the store to a string.
virtual std::string ToString() const = 0;
};
} // namespace milotic_tlbmc
#pragma GCC diagnostic pop
#endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_STORE_STORE_H_