Agent Package (internal/agent/): - Agent struct with all collectors and memory-efficient pooling - Run loop with configurable collection interval - Graceful shutdown with context cancellation - Auto-reconnection callback for re-registration gRPC Client (internal/agent/client.go): - mTLS support with CA, agent cert, and key - Bidirectional streaming for metrics - Heartbeat fallback when streaming fails - Exponential backoff with jitter for reconnection - Concurrent reconnection handling with mutex Protocol Buffers (proto/tyto.proto): - AgentService with Stream, Register, Heartbeat RPCs - MetricsReport with summary fields for aggregation - ConfigUpdate and Command messages for server control - RegisterStatus enum for registration workflow CLI Integration (cmd/tyto/main.go): - Full agent subcommand with flag parsing - Support for --id, --server, --interval, --ca-cert, etc. - Environment variable overrides (TYTO_AGENT_*) - Signal handling for graceful shutdown Build System (Makefile): - Cross-compilation for linux/amd64, arm64, armv7 - Stripped binaries with version info - Proto generation target - Test and coverage targets Config Updates: - DefaultConfig() and LoadFromPath() functions - Agent config properly parsed from YAML 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
203 lines
8.1 KiB
Go
203 lines
8.1 KiB
Go
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
|
// versions:
|
|
// - protoc-gen-go-grpc v1.6.0
|
|
// - protoc v6.33.1
|
|
// source: tyto.proto
|
|
|
|
package proto
|
|
|
|
import (
|
|
context "context"
|
|
grpc "google.golang.org/grpc"
|
|
codes "google.golang.org/grpc/codes"
|
|
status "google.golang.org/grpc/status"
|
|
)
|
|
|
|
// This is a compile-time assertion to ensure that this generated file
|
|
// is compatible with the grpc package it is being compiled against.
|
|
// Requires gRPC-Go v1.64.0 or later.
|
|
const _ = grpc.SupportPackageIsVersion9
|
|
|
|
const (
|
|
AgentService_Stream_FullMethodName = "/tyto.AgentService/Stream"
|
|
AgentService_Register_FullMethodName = "/tyto.AgentService/Register"
|
|
AgentService_Heartbeat_FullMethodName = "/tyto.AgentService/Heartbeat"
|
|
)
|
|
|
|
// AgentServiceClient is the client API for AgentService service.
|
|
//
|
|
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
|
//
|
|
// AgentService handles communication between agents and the central server.
|
|
type AgentServiceClient interface {
|
|
// Stream establishes a bidirectional stream for metrics and control messages.
|
|
Stream(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[AgentMessage, ServerMessage], error)
|
|
// Register allows an agent to request registration with the server.
|
|
Register(ctx context.Context, in *RegisterRequest, opts ...grpc.CallOption) (*RegisterResponse, error)
|
|
// Heartbeat is a simple health check (alternative to streaming).
|
|
Heartbeat(ctx context.Context, in *HeartbeatRequest, opts ...grpc.CallOption) (*HeartbeatResponse, error)
|
|
}
|
|
|
|
type agentServiceClient struct {
|
|
cc grpc.ClientConnInterface
|
|
}
|
|
|
|
func NewAgentServiceClient(cc grpc.ClientConnInterface) AgentServiceClient {
|
|
return &agentServiceClient{cc}
|
|
}
|
|
|
|
func (c *agentServiceClient) Stream(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[AgentMessage, ServerMessage], error) {
|
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
|
stream, err := c.cc.NewStream(ctx, &AgentService_ServiceDesc.Streams[0], AgentService_Stream_FullMethodName, cOpts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
x := &grpc.GenericClientStream[AgentMessage, ServerMessage]{ClientStream: stream}
|
|
return x, nil
|
|
}
|
|
|
|
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
|
|
type AgentService_StreamClient = grpc.BidiStreamingClient[AgentMessage, ServerMessage]
|
|
|
|
func (c *agentServiceClient) Register(ctx context.Context, in *RegisterRequest, opts ...grpc.CallOption) (*RegisterResponse, error) {
|
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
|
out := new(RegisterResponse)
|
|
err := c.cc.Invoke(ctx, AgentService_Register_FullMethodName, in, out, cOpts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (c *agentServiceClient) Heartbeat(ctx context.Context, in *HeartbeatRequest, opts ...grpc.CallOption) (*HeartbeatResponse, error) {
|
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
|
out := new(HeartbeatResponse)
|
|
err := c.cc.Invoke(ctx, AgentService_Heartbeat_FullMethodName, in, out, cOpts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// AgentServiceServer is the server API for AgentService service.
|
|
// All implementations must embed UnimplementedAgentServiceServer
|
|
// for forward compatibility.
|
|
//
|
|
// AgentService handles communication between agents and the central server.
|
|
type AgentServiceServer interface {
|
|
// Stream establishes a bidirectional stream for metrics and control messages.
|
|
Stream(grpc.BidiStreamingServer[AgentMessage, ServerMessage]) error
|
|
// Register allows an agent to request registration with the server.
|
|
Register(context.Context, *RegisterRequest) (*RegisterResponse, error)
|
|
// Heartbeat is a simple health check (alternative to streaming).
|
|
Heartbeat(context.Context, *HeartbeatRequest) (*HeartbeatResponse, error)
|
|
mustEmbedUnimplementedAgentServiceServer()
|
|
}
|
|
|
|
// UnimplementedAgentServiceServer must be embedded to have
|
|
// forward compatible implementations.
|
|
//
|
|
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
|
// pointer dereference when methods are called.
|
|
type UnimplementedAgentServiceServer struct{}
|
|
|
|
func (UnimplementedAgentServiceServer) Stream(grpc.BidiStreamingServer[AgentMessage, ServerMessage]) error {
|
|
return status.Error(codes.Unimplemented, "method Stream not implemented")
|
|
}
|
|
func (UnimplementedAgentServiceServer) Register(context.Context, *RegisterRequest) (*RegisterResponse, error) {
|
|
return nil, status.Error(codes.Unimplemented, "method Register not implemented")
|
|
}
|
|
func (UnimplementedAgentServiceServer) Heartbeat(context.Context, *HeartbeatRequest) (*HeartbeatResponse, error) {
|
|
return nil, status.Error(codes.Unimplemented, "method Heartbeat not implemented")
|
|
}
|
|
func (UnimplementedAgentServiceServer) mustEmbedUnimplementedAgentServiceServer() {}
|
|
func (UnimplementedAgentServiceServer) testEmbeddedByValue() {}
|
|
|
|
// UnsafeAgentServiceServer may be embedded to opt out of forward compatibility for this service.
|
|
// Use of this interface is not recommended, as added methods to AgentServiceServer will
|
|
// result in compilation errors.
|
|
type UnsafeAgentServiceServer interface {
|
|
mustEmbedUnimplementedAgentServiceServer()
|
|
}
|
|
|
|
func RegisterAgentServiceServer(s grpc.ServiceRegistrar, srv AgentServiceServer) {
|
|
// If the following call panics, it indicates UnimplementedAgentServiceServer was
|
|
// embedded by pointer and is nil. This will cause panics if an
|
|
// unimplemented method is ever invoked, so we test this at initialization
|
|
// time to prevent it from happening at runtime later due to I/O.
|
|
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
|
t.testEmbeddedByValue()
|
|
}
|
|
s.RegisterService(&AgentService_ServiceDesc, srv)
|
|
}
|
|
|
|
func _AgentService_Stream_Handler(srv interface{}, stream grpc.ServerStream) error {
|
|
return srv.(AgentServiceServer).Stream(&grpc.GenericServerStream[AgentMessage, ServerMessage]{ServerStream: stream})
|
|
}
|
|
|
|
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
|
|
type AgentService_StreamServer = grpc.BidiStreamingServer[AgentMessage, ServerMessage]
|
|
|
|
func _AgentService_Register_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
in := new(RegisterRequest)
|
|
if err := dec(in); err != nil {
|
|
return nil, err
|
|
}
|
|
if interceptor == nil {
|
|
return srv.(AgentServiceServer).Register(ctx, in)
|
|
}
|
|
info := &grpc.UnaryServerInfo{
|
|
Server: srv,
|
|
FullMethod: AgentService_Register_FullMethodName,
|
|
}
|
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
return srv.(AgentServiceServer).Register(ctx, req.(*RegisterRequest))
|
|
}
|
|
return interceptor(ctx, in, info, handler)
|
|
}
|
|
|
|
func _AgentService_Heartbeat_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
|
in := new(HeartbeatRequest)
|
|
if err := dec(in); err != nil {
|
|
return nil, err
|
|
}
|
|
if interceptor == nil {
|
|
return srv.(AgentServiceServer).Heartbeat(ctx, in)
|
|
}
|
|
info := &grpc.UnaryServerInfo{
|
|
Server: srv,
|
|
FullMethod: AgentService_Heartbeat_FullMethodName,
|
|
}
|
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
return srv.(AgentServiceServer).Heartbeat(ctx, req.(*HeartbeatRequest))
|
|
}
|
|
return interceptor(ctx, in, info, handler)
|
|
}
|
|
|
|
// AgentService_ServiceDesc is the grpc.ServiceDesc for AgentService service.
|
|
// It's only intended for direct use with grpc.RegisterService,
|
|
// and not to be introspected or modified (even as a copy)
|
|
var AgentService_ServiceDesc = grpc.ServiceDesc{
|
|
ServiceName: "tyto.AgentService",
|
|
HandlerType: (*AgentServiceServer)(nil),
|
|
Methods: []grpc.MethodDesc{
|
|
{
|
|
MethodName: "Register",
|
|
Handler: _AgentService_Register_Handler,
|
|
},
|
|
{
|
|
MethodName: "Heartbeat",
|
|
Handler: _AgentService_Heartbeat_Handler,
|
|
},
|
|
},
|
|
Streams: []grpc.StreamDesc{
|
|
{
|
|
StreamName: "Stream",
|
|
Handler: _AgentService_Stream_Handler,
|
|
ServerStreams: true,
|
|
ClientStreams: true,
|
|
},
|
|
},
|
|
Metadata: "tyto.proto",
|
|
}
|