blob: 0dbcff1b4507a62e914c5bf0742c06c59e87e8b1 [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 <utility>
#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 "software_metrics.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 key.
virtual std::vector<std::string> GetAllSensorKeysByConfigKey(
const std::string& board_config_key) 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 key and given sensor
// key.
virtual std::shared_ptr<const Sensor> GetSensorByConfigKeyAndSensorKey(
const std::string& board_config_key,
const std::string& sensor_key) const = 0;
// Returns the sensor devpath for the given sensor object.
virtual absl::StatusOr<const std::string&> GetDevpathFromSensor(
std::shared_ptr<const Sensor> sensor) 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_key) const = 0;
// Returns the topology config of all configs.
virtual absl::StatusOr<const TopologyConfig*> GetTopologyConfig() const = 0;
// Returns all the config keys.
virtual absl::StatusOr<std::vector<std::string>> GetAllConfigKeys() const = 0;
// Returns true if tlBMC for the given config key owns all the sensors.
// In this case, tlBMC will own the SensorCollection.
virtual bool IsConfigKeyOwningAllSensors(
absl::string_view config_key) const = 0;
// Returns the config key of the given FRU key.
virtual absl::StatusOr<std::string> GetConfigKeyByFruKey(
absl::string_view fru_key) const = 0;
virtual absl::StatusOr<std::string> GetFruKeyByConfigKey(
absl::string_view config_key) const = 0;
// Returns the fan info of the given config key. (fan_id, fan_key)
// fan_id: the name of the fan.
// fan_key: the FRU key of the fan.
virtual absl::StatusOr<std::vector<std::pair<std::string, std::string>>>
GetFanInfoByConfigKey(absl::string_view config_key) 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;
virtual SoftwareMetricsValue GetMetricValues() const = 0;
virtual SocketStatStates GetMetricSocketStatValues() const = 0;
virtual NetFilterStates GetMetricNetFilterValues() const = 0;
};
} // namespace milotic_tlbmc
#pragma GCC diagnostic pop
#endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_STORE_STORE_H_