Implement target selection, autodiscovery via aggregator, implement listTargets
This commit is contained in:
@@ -14,12 +14,13 @@ import (
|
||||
// Server implements pb.LogtailServiceServer backed by the aggregator Cache.
|
||||
type Server struct {
|
||||
pb.UnimplementedLogtailServiceServer
|
||||
cache *Cache
|
||||
source string
|
||||
cache *Cache
|
||||
source string
|
||||
registry *TargetRegistry
|
||||
}
|
||||
|
||||
func NewServer(cache *Cache, source string) *Server {
|
||||
return &Server{cache: cache, source: source}
|
||||
func NewServer(cache *Cache, source string, registry *TargetRegistry) *Server {
|
||||
return &Server{cache: cache, source: source, registry: registry}
|
||||
}
|
||||
|
||||
func (srv *Server) TopN(_ context.Context, req *pb.TopNRequest) (*pb.TopNResponse, error) {
|
||||
@@ -53,6 +54,16 @@ func (srv *Server) Trend(_ context.Context, req *pb.TrendRequest) (*pb.TrendResp
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (srv *Server) ListTargets(_ context.Context, _ *pb.ListTargetsRequest) (*pb.ListTargetsResponse, error) {
|
||||
resp := &pb.ListTargetsResponse{}
|
||||
if srv.registry != nil {
|
||||
for _, t := range srv.registry.Targets() {
|
||||
resp.Targets = append(resp.Targets, &pb.TargetInfo{Name: t.Name, Addr: t.Addr})
|
||||
}
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (srv *Server) StreamSnapshots(_ *pb.SnapshotRequest, stream grpc.ServerStreamingServer[pb.Snapshot]) error {
|
||||
ch := srv.cache.Subscribe()
|
||||
defer srv.cache.Unsubscribe(ch)
|
||||
|
||||
Reference in New Issue
Block a user