Migrate CollectionEntityId to Entity in Feed collector infra.
No reason to have both and Entity is more robust w/ enum typing.
PiperOrigin-RevId: 826607927
Change-Id: I7f59d281eb5d8f480918c77ce8697db861426e6a
diff --git a/tlbmc/entity.proto b/tlbmc/entity.proto
new file mode 100644
index 0000000..0275823
--- /dev/null
+++ b/tlbmc/entity.proto
@@ -0,0 +1,31 @@
+edition = "2023";
+
+package platforms_syshealth.collection.feed;
+
+message MachineNodeEntity {
+ string machine_name = 1;
+ string hostname = 2;
+ string node_entity_tag = 3;
+}
+
+message Entity {
+ message Metadata {
+ // The hostname of the entity.
+ string hostname = 1;
+ }
+ enum Type {
+ UNKNOWN = 0;
+ MACHINE = 1;
+ MACHINE_NODE = 2;
+ NETWORK_DEVICE = 3;
+ }
+ Type type = 1;
+ Metadata metadata = 2;
+ oneof entity_id {
+ // Simple name identifier. Suitable for machines and network devices.
+ string name = 3;
+ // Identifier for a machine node which also must include the hostname
+ // and node entity tag.
+ MachineNodeEntity machine_node_entity = 4;
+ }
+}
diff --git a/tlbmc/feed_payload.proto b/tlbmc/feed_payload.proto
index 18da6c3..6ef66b6 100644
--- a/tlbmc/feed_payload.proto
+++ b/tlbmc/feed_payload.proto
@@ -2,7 +2,7 @@
package platforms_syshealth.collection.feed;
-import "collection_entity.proto";
+import "entity.proto";
import "payload.proto";
message HftPayload {
@@ -11,7 +11,7 @@
message Metadata {
// The entity that produced the data.
- CollectionEntityId entity_id = 1;
+ Entity entity = 1;
}
// Central payload for collect data types we support.
diff --git a/tlbmc/meson.build b/tlbmc/meson.build
index d4db712..5d51c71 100644
--- a/tlbmc/meson.build
+++ b/tlbmc/meson.build
@@ -9,6 +9,7 @@
'client_subscription.proto',
'collection_entity.proto',
'data_sink_service.proto',
+ 'entity.proto',
'entity_common_config.proto',
'fan_controller_config.proto',
'fan_pwm_config.proto',
diff --git a/tlbmc/service_messages.proto b/tlbmc/service_messages.proto
index 8b6df5c..611fc07 100644
--- a/tlbmc/service_messages.proto
+++ b/tlbmc/service_messages.proto
@@ -2,12 +2,12 @@
package platforms_syshealth.collection.feed;
+import "entity.proto";
import "feed_payload.proto";
-import "collection_entity.proto";
import "client_subscription.proto";
message MetricSet {
- optional CollectionEntityId entity_id = 1;
+ optional Entity entity = 1;
optional string policy_id = 2;
// Payload depends on the source type, needs a flexible structure.
@@ -38,7 +38,7 @@
}
message GetPoliciesRequest {
- optional CollectionEntityId entity_id = 1;
+ optional Entity entity = 1;
optional EndpointIdentifier endpoint_identifier = 2;
}
diff --git a/tlbmc/subscription/manager_impl.cc b/tlbmc/subscription/manager_impl.cc
index c5a2d25..c8fef51 100644
--- a/tlbmc/subscription/manager_impl.cc
+++ b/tlbmc/subscription/manager_impl.cc
@@ -13,7 +13,6 @@
#include <vector>
#include "tlbmc/feed_payload.pb.h"
-#include "tlbmc/collection_entity.pb.h"
#include "tlbmc/feed_client_interface.h"
#include "tlbmc/hft_subscription.pb.h"
#include "tlbmc/client_subscription.pb.h"
@@ -291,14 +290,14 @@
SubscriptionManagerImpl::SubscriptionManagerImpl(
std::unique_ptr<DataSource> data_source, FeedClientInterface* feed_client,
const Options& options,
- const platforms_syshealth::collection::feed::NodeEntityId& node_entity_id)
+ const platforms_syshealth::collection::feed::Entity& entity)
: next_subscription_id_(0),
task_scheduler_(std::make_unique<milotic_tlbmc::TaskScheduler>()),
data_source_(std::move(data_source)),
feed_client_(feed_client),
get_policies_interval_(options.get_policies_interval),
endpoint_type_(options.endpoint_type),
- node_entity_id_(node_entity_id) {
+ entity_(entity) {
if (feed_client_ != nullptr) {
get_policies_task_id_ = task_scheduler_->ScheduleAsync(
[this](absl::AnyInvocable<void()> on_done) {
@@ -323,7 +322,7 @@
LOG(INFO) << "Getting policies from agent config service";
GetPoliciesRequest request;
request.mutable_endpoint_identifier()->set_endpoint_type(endpoint_type_);
- *request.mutable_entity_id()->mutable_node_entity() = node_entity_id_;
+ *request.mutable_entity() = entity_;
absl::StatusOr<GetPoliciesResponse> response =
feed_client_->GetPolicies(request);
if (!response.ok()) {
diff --git a/tlbmc/subscription/manager_impl.h b/tlbmc/subscription/manager_impl.h
index c79f3a1..9f5c923 100644
--- a/tlbmc/subscription/manager_impl.h
+++ b/tlbmc/subscription/manager_impl.h
@@ -9,7 +9,7 @@
#include <string>
#include <utility>
-#include "tlbmc/collection_entity.pb.h"
+#include "tlbmc/entity.pb.h"
#include "tlbmc/feed_client_interface.h"
#include "tlbmc/service_messages.pb.h"
#include "one/offline_node_entities.pb.h"
@@ -181,7 +181,9 @@
std::unique_ptr<DataSource> data_source,
platforms_syshealth::collection::feed::FeedClientInterface* feed_client,
const Options& options) {
- platforms_syshealth::collection::feed::NodeEntityId node_entity_id;
+ platforms_syshealth::collection::feed::Entity entity;
+ entity.set_type(
+ platforms_syshealth::collection::feed::Entity::MACHINE_NODE);
absl::StatusOr<
production_msv::node_entities_proto::OfflineNodeEntityInformation>
node_entity_info;
@@ -198,18 +200,25 @@
<< node_entity_info.status();
return nullptr;
}
- node_entity_id.set_machine_name(
- node_entity_info->resolved_config().machine_name());
- node_entity_id.set_entity_tag(node_entity_info->entity_tag());
- if (node_entity_info->resolved_config().entities().contains(
- node_entity_info->entity_tag())) {
- node_entity_id.set_hostname(node_entity_info->resolved_config()
- .entities()
- .at(node_entity_info->entity_tag())
- .hostname());
- }
+ entity.mutable_machine_node_entity()->set_machine_name(
+ node_entity_info->resolved_config().machine_name());
+ entity.mutable_machine_node_entity()->set_node_entity_tag(
+ node_entity_info->entity_tag());
+ if (node_entity_info->resolved_config().entities().contains(
+ node_entity_info->entity_tag())) {
+ entity.mutable_machine_node_entity()->set_hostname(
+ node_entity_info->resolved_config()
+ .entities()
+ .at(node_entity_info->entity_tag())
+ .hostname());
+ entity.mutable_metadata()->set_hostname(
+ node_entity_info->resolved_config()
+ .entities()
+ .at(node_entity_info->entity_tag())
+ .hostname());
+ }
return absl::WrapUnique(new SubscriptionManagerImpl(
- std::move(data_source), feed_client, options, node_entity_id));
+ std::move(data_source), feed_client, options, entity));
}
absl::StatusOr<SubscriptionId> AddSubscription(
@@ -228,8 +237,7 @@
std::unique_ptr<DataSource> data_source,
platforms_syshealth::collection::feed::FeedClientInterface* feed_client,
const Options& options,
- const platforms_syshealth::collection::feed::NodeEntityId&
- node_entity_id);
+ const platforms_syshealth::collection::feed::Entity& entity);
void PullAgentPoliciesAndUpdateSubscriptions();
SubscriptionId GenerateSubscriptionId();
@@ -261,7 +269,7 @@
const platforms_syshealth::collection::feed::EndpointIdentifier::EndpointType
endpoint_type_ = platforms_syshealth::collection::feed::
EndpointIdentifier::ENDPOINT_TYPE_UNSPECIFIED;
- platforms_syshealth::collection::feed::NodeEntityId node_entity_id_;
+ platforms_syshealth::collection::feed::Entity entity_;
};
} // namespace milotic_hft