Skip configuring sensors that have failed creation.
The sensor collector will now also skip reconfiguration of sampling for sensors with status CREATION_PENDING or CREATION_FAILED. These statuses will be logged. In either case, this indicates that the sensor is present in the tlBMC store, but has a bad status. With the previous logic, this causes the HFT stream to immediately terminate since it will attempt to access the sensor in the `sensor_key_to_task_id` map, causing a segfault.
Instead of ending the HFT stream, this change will allow us to detect the sensor as STATUS_MISSING in the HFT stream and allow debugging from the status message. Other valid sensors in the subscription will stream their readings as expected.
#tlbmc-hft
PiperOrigin-RevId: 826647508
Change-Id: Idc91966165deb3f0bf2aee6f9564352a7632da3d
diff --git a/tlbmc/collector/sensor_collector.cc b/tlbmc/collector/sensor_collector.cc
index 840ba8d..70b0ead 100644
--- a/tlbmc/collector/sensor_collector.cc
+++ b/tlbmc/collector/sensor_collector.cc
@@ -735,10 +735,13 @@
// board config.
if (config.key.empty()) {
for (auto& [key, sensor] : key_to_sensor) {
- if (sensor->GetSensorAttributesDynamic().state().status() ==
- STATUS_CREATION_PENDING) {
+ if (Status sensor_status =
+ sensor->GetSensorAttributesDynamic().state().status();
+ sensor_status == STATUS_CREATION_PENDING ||
+ sensor_status == STATUS_CREATION_FAILED) {
LOG(WARNING) << "Skipping configuration for sensor " << key
- << " because it is pending creation.";
+ << " because sensor status is: "
+ << Status_Name(sensor_status);
continue;
}
absl::Duration interval = get_sampling_interval(sensor, config);
@@ -759,10 +762,13 @@
// given key.
auto it = key_to_sensor.find(config.key);
if (it != key_to_sensor.end()) {
- if (it->second->GetSensorAttributesDynamic().state().status() ==
- STATUS_CREATION_PENDING) {
+ if (Status sensor_status =
+ it->second->GetSensorAttributesDynamic().state().status();
+ sensor_status == STATUS_CREATION_PENDING ||
+ sensor_status == STATUS_CREATION_FAILED) {
LOG(WARNING) << "Skipping configuration for sensor " << config.key
- << " because it is pending creation.";
+ << " because sensor status is: "
+ << Status_Name(sensor_status);
return absl::OkStatus();
}
absl::Duration interval = get_sampling_interval(it->second, config);