| #include "tlbmc/feed_client_grpc.h" |
| |
| #include <climits> |
| #include <memory> |
| #include <string> |
| |
| #include "tlbmc/feed_client.pb.h" |
| #include "agent_config_service.grpc.pb.h" |
| #include "data_sink_service.grpc.pb.h" |
| #include "absl/log/log.h" |
| #include "absl/status/status.h" |
| #include "grpc/grpc.h" |
| #include "grpcpp/client_context.h" |
| #include "grpcpp/security/credentials.h" |
| #include "grpcpp/support/channel_arguments.h" |
| #include "grpcpp/support/status.h" |
| |
| namespace platforms_syshealth::collection::feed { |
| |
| FeedClientGrpc::FeedClientGrpc( |
| const FeedClientConfig& config, |
| const std::shared_ptr<::grpc::ChannelCredentials>& credentials) |
| : config_(config) { |
| ::grpc::ChannelArguments args; |
| args.SetInt(GRPC_ARG_KEEPALIVE_TIME_MS, INT_MAX); |
| args.SetInt(GRPC_ARG_KEEPALIVE_TIMEOUT_MS, 20 * 1000 /*20 sec*/); |
| args.SetInt(GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS, 0); |
| std::shared_ptr<::grpc::Channel> channel = |
| ::grpc::CreateCustomChannel(config_.target_address(), credentials, args); |
| stub_ = DataSinkService::NewStub(channel); |
| agent_config_stub_ = AgentConfigService::NewStub(channel); |
| } |
| |
| absl::StatusOr<WriteMetricsResponse> FeedClientGrpc::WriteMetrics( |
| const WriteMetricsRequest& request) { |
| if (!stub_) { |
| return absl::InternalError("gRPC stub not initialized"); |
| } |
| ::grpc::ClientContext context; |
| WriteMetricsResponse response; |
| ::grpc::Status status = stub_->WriteMetrics(&context, request, &response); |
| if (!status.ok()) { |
| return absl::InternalError(status.error_message()); |
| } |
| return response; |
| } |
| |
| absl::StatusOr<GetPoliciesResponse> FeedClientGrpc::GetPolicies( |
| const GetPoliciesRequest& request) { |
| if (!agent_config_stub_) { |
| return absl::InternalError("gRPC config stub not initialized"); |
| } |
| ::grpc::ClientContext context; |
| GetPoliciesResponse response; |
| ::grpc::Status status = |
| agent_config_stub_->GetPolicies(&context, request, &response); |
| if (!status.ok()) { |
| return absl::InternalError(status.error_message()); |
| } |
| return response; |
| } |
| |
| } // namespace platforms_syshealth::collection::feed |