diff --git a/examples/grpc_vpp/stats_poller/main.go b/examples/grpc_vpp/stats_poller/main.go index bc854fac0c..fb9fe9a028 100644 --- a/examples/grpc_vpp/stats_poller/main.go +++ b/examples/grpc_vpp/stats_poller/main.go @@ -15,14 +15,18 @@ package main import ( + "context" + "errors" + "fmt" + "io" "log" "net" + "os" "time" "github.com/namsral/flag" "go.ligato.io/cn-infra/v2/agent" "go.ligato.io/cn-infra/v2/infra" - "golang.org/x/net/context" "google.golang.org/grpc" "go.ligato.io/vpp-agent/v3/proto/ligato/configurator" @@ -31,7 +35,9 @@ import ( var ( address = flag.String("address", "localhost:9111", "address of GRPC server") socketType = flag.String("socket-type", "tcp", "[tcp, tcp4, tcp6, unix, unixpacket]") - period = flag.Uint("period", 3, "Polling period (in seconds)") + + period = flag.Uint("period", 3, "Polling period (in seconds)") + polls = flag.Uint("polls", 0, "Number of pollings") ) func main() { @@ -59,7 +65,11 @@ func (p *ExamplePlugin) Init() (err error) { // Set up connection to the server. p.conn, err = grpc.Dial("unix", grpc.WithInsecure(), - grpc.WithDialer(dialer(*socketType, *address, time.Second*3))) + grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) { + return net.DialTimeout(*socketType, *address, time.Second*3) + }), + //grpc.WithContextDialer(dialer(*socketType, *address, time.Second*3)), + ) if err != nil { return err @@ -75,13 +85,14 @@ func (p *ExamplePlugin) Init() (err error) { // Get is an implementation of client-side statistics streaming. func (p *ExamplePlugin) pollStats(client configurator.StatsPollerServiceClient) { - p.Log.Infof("Polling every %v seconds..", *period) + ctx := context.Background() req := &configurator.PollStatsRequest{ PeriodSec: uint32(*period), + NumPolls: uint32(*polls), } + fmt.Printf("Polling stats: %v\n", req) - ctx := context.Background() stream, err := client.PollStats(ctx, req) if err != nil { p.Log.Fatalln("PollStats failed:", err) @@ -90,26 +101,26 @@ func (p *ExamplePlugin) pollStats(client configurator.StatsPollerServiceClient) var lastSeq uint32 for { resp, err := stream.Recv() - if err != nil { + if errors.Is(err, io.EOF) { + p.Log.Infof("Polling has completed.") + os.Exit(0) + } else if err != nil { p.Log.Fatalln("Recv failed:", err) } if resp.PollSeq != lastSeq { - p.Log.Infof(" --- Poll sequence: %-3v", resp.PollSeq) + fmt.Printf(" --- Poll sequence: %-3v\n", resp.PollSeq) } lastSeq = resp.PollSeq vppStats := resp.GetStats().GetVppStats() - p.Log.Infof("VPP stats: %v", vppStats) + fmt.Printf("VPP stats: %v\n", vppStats) } } // Dialer for unix domain socket -func dialer(socket, address string, timeoutVal time.Duration) func(string, time.Duration) (net.Conn, error) { - return func(addr string, timeout time.Duration) (net.Conn, error) { - // Pass values - addr, timeout = address, timeoutVal - // Dial with timeout - return net.DialTimeout(socket, addr, timeoutVal) +func dialer(socket, address string, timeoutVal time.Duration) func(context.Context, string) (net.Conn, error) { + return func(ctx context.Context, addr string) (net.Conn, error) { + return net.DialTimeout(socket, address, timeoutVal) } } diff --git a/plugins/telemetry/stats_poller.go b/plugins/telemetry/stats_poller.go index e10706208d..4a15c8b67d 100644 --- a/plugins/telemetry/stats_poller.go +++ b/plugins/telemetry/stats_poller.go @@ -6,6 +6,7 @@ import ( "time" govppapi "git.fd.io/govpp.git/api" + "github.com/golang/protobuf/proto" "go.ligato.io/cn-infra/v2/logging" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -25,35 +26,26 @@ type statsPollerServer struct { } func (s *statsPollerServer) PollStats(req *configurator.PollStatsRequest, svr configurator.StatsPollerService_PollStatsServer) error { - var pollSeq uint32 - - if req.PeriodSec == 0 { - return status.Error(codes.InvalidArgument, "PeriodSec must be greater than 0") + if req.GetPeriodSec() == 0 && req.GetNumPolls() > 1 { + return status.Error(codes.InvalidArgument, "period must be > 0 if number of polls is > 1") } - period := time.Duration(req.PeriodSec) * time.Second - - tick := time.NewTicker(period) - defer tick.Stop() - s.log.Debugf("starting to poll stats every %v", period) - for { - pollSeq++ - s.log.WithField("seq", pollSeq).Debugf("polling stats..") + ctx := svr.Context() - vppStatsCh := make(chan vpp.Stats) - var err error + streamStats := func(pollSeq uint32) (err error) { + vppStatsCh := make(chan *vpp.Stats) go func() { - err = s.streamVppStats(vppStatsCh) + err = s.streamVppStats(ctx, vppStatsCh) close(vppStatsCh) }() for vppStats := range vppStatsCh { - VppStats := vppStats + VppStats := proto.Clone(vppStats).(*vpp.Stats) s.log.Debugf("sending vpp stats: %v", VppStats) if err := svr.Send(&configurator.PollStatsResponse{ PollSeq: pollSeq, Stats: &configurator.Stats{ - Stats: &configurator.Stats_VppStats{VppStats: &VppStats}, + Stats: &configurator.Stats_VppStats{VppStats: VppStats}, }, }); err != nil { s.log.Errorf("sending stats failed: %v", err) @@ -64,14 +56,41 @@ func (s *statsPollerServer) PollStats(req *configurator.PollStatsRequest, svr co s.log.Errorf("polling vpp stats failed: %v", err) return err } + return nil + } - <-tick.C + if req.GetPeriodSec() == 0 { + return streamStats(0) } -} -func (s *statsPollerServer) streamVppStats(ch chan vpp.Stats) error { - ctx := context.Background() + period := time.Duration(req.GetPeriodSec()) * time.Second + s.log.Debugf("start polling stats every %v", period) + + tick := time.NewTicker(period) + defer tick.Stop() + + for pollSeq := uint32(1); ; pollSeq++ { + s.log.WithField("seq", pollSeq).Debugf("polling stats..") + if err := streamStats(pollSeq); err != nil { + return err + } + + if req.GetNumPolls() > 0 && pollSeq >= req.GetNumPolls() { + s.log.Debugf("reached %d pollings", req.GetNumPolls()) + return nil + } + + select { + case <-tick.C: + // period passed + case <-ctx.Done(): + return ctx.Err() + } + } +} + +func (s *statsPollerServer) streamVppStats(ctx context.Context, ch chan *vpp.Stats) error { ifStats, err := s.handler.GetInterfaceStats(ctx) if err != nil { return err @@ -87,7 +106,7 @@ func (s *statsPollerServer) streamVppStats(ch chan vpp.Stats) error { // fallback to internal name name = iface.InterfaceName } - vppStats := vpp.Stats{ + vppStats := &vpp.Stats{ Interface: &vpp_interfaces.InterfaceStats{ Name: name, Rx: convertInterfaceCombined(iface.Rx), @@ -109,7 +128,13 @@ func (s *statsPollerServer) streamVppStats(ch chan vpp.Stats) error { Mpls: iface.Mpls, }, } - ch <- vppStats + + select { + case ch <- vppStats: + // stats sent + case <-ctx.Done(): + return ctx.Err() + } } return nil } diff --git a/proto/ligato/configurator/statspoller.pb.go b/proto/ligato/configurator/statspoller.pb.go index 212f3498e0..f88dfcd601 100644 --- a/proto/ligato/configurator/statspoller.pb.go +++ b/proto/ligato/configurator/statspoller.pb.go @@ -25,6 +25,7 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package +// Stats defines stats data returned by StatsPollerService. type Stats struct { // Types that are valid to be assigned to Stats: // *Stats_VppStats @@ -91,8 +92,12 @@ func (*Stats) XXX_OneofWrappers() []interface{} { } type PollStatsRequest struct { - // PeriodSec defines polling period (in seconds) - PeriodSec uint32 `protobuf:"varint,1,opt,name=period_sec,json=periodSec,proto3" json:"period_sec,omitempty"` + // PeriodSec defines polling period (in seconds). Set to zero to + // return just single polling. + PeriodSec uint32 `protobuf:"varint,1,opt,name=period_sec,json=periodSec,proto3" json:"period_sec,omitempty"` + // NumPolls defines number of pollings. Set to non-zero number to + // stop the polling after specified number of pollings is reached. + NumPolls uint32 `protobuf:"varint,2,opt,name=num_polls,json=numPolls,proto3" json:"num_polls,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -130,8 +135,17 @@ func (m *PollStatsRequest) GetPeriodSec() uint32 { return 0 } +func (m *PollStatsRequest) GetNumPolls() uint32 { + if m != nil { + return m.NumPolls + } + return 0 +} + type PollStatsResponse struct { - PollSeq uint32 `protobuf:"varint,1,opt,name=poll_seq,json=pollSeq,proto3" json:"poll_seq,omitempty"` + // PollSeq defines the sequence number of this polling response. + PollSeq uint32 `protobuf:"varint,1,opt,name=poll_seq,json=pollSeq,proto3" json:"poll_seq,omitempty"` + // Stats contains polled stats data. Stats *Stats `protobuf:"bytes,2,opt,name=stats,proto3" json:"stats,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -188,25 +202,26 @@ func init() { } var fileDescriptor_a59f0470c39b77d1 = []byte{ - // 280 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0x41, 0x4b, 0xc3, 0x40, - 0x10, 0x85, 0x5b, 0xa1, 0xb6, 0x19, 0x11, 0xec, 0xea, 0xa1, 0x06, 0x04, 0x09, 0x54, 0xbc, 0x98, - 0xc4, 0xf6, 0xe8, 0x45, 0x72, 0xf2, 0x58, 0x92, 0x9b, 0x07, 0x63, 0x8c, 0x63, 0x08, 0x84, 0xec, - 0x64, 0x77, 0x9b, 0xdf, 0x2f, 0x3b, 0x1b, 0x25, 0x48, 0xc0, 0x43, 0x20, 0x33, 0x7c, 0xef, 0xcd, - 0xcc, 0x5b, 0xd8, 0x36, 0x75, 0x55, 0x18, 0x19, 0x95, 0xb2, 0xfd, 0xaa, 0xab, 0xa3, 0x2a, 0x8c, - 0x54, 0x91, 0x36, 0x85, 0xd1, 0x24, 0x9b, 0x06, 0x55, 0x48, 0x4a, 0x1a, 0x29, 0x2e, 0x1d, 0x16, - 0x8e, 0x31, 0xff, 0x6a, 0xd0, 0xf6, 0x44, 0xf6, 0x73, 0x68, 0x90, 0xc0, 0x22, 0xb3, 0x7a, 0x11, - 0x83, 0xd7, 0x13, 0xe5, 0x6c, 0xb6, 0x99, 0xdf, 0xce, 0xef, 0xcf, 0x76, 0xeb, 0x70, 0xf0, 0xb1, - 0x38, 0x53, 0x2f, 0xb3, 0x74, 0xd5, 0x13, 0xf1, 0x7f, 0xb2, 0x84, 0x05, 0xd3, 0xc1, 0x23, 0x5c, - 0x1c, 0x64, 0xd3, 0x70, 0x37, 0xc5, 0xee, 0x88, 0xda, 0x88, 0x1b, 0x00, 0x42, 0x55, 0xcb, 0xcf, - 0x5c, 0x63, 0xc9, 0x7e, 0xe7, 0xa9, 0xe7, 0x3a, 0x19, 0x96, 0xc1, 0x3b, 0xac, 0x47, 0x12, 0x4d, - 0xb2, 0xd5, 0x28, 0xae, 0x61, 0x65, 0xcf, 0xc8, 0x35, 0x76, 0x83, 0x62, 0x69, 0xeb, 0x0c, 0x3b, - 0x11, 0x0f, 0xb3, 0x36, 0x27, 0xbc, 0x99, 0x1f, 0x4e, 0x5c, 0xe8, 0x56, 0x4c, 0x1d, 0xb8, 0x33, - 0x20, 0xb8, 0x3e, 0x70, 0x30, 0x19, 0xaa, 0xbe, 0x2e, 0x51, 0xbc, 0x81, 0xf7, 0x3b, 0x57, 0x6c, - 0x27, 0x5d, 0xfe, 0x9e, 0xe2, 0xdf, 0xfd, 0x87, 0xb9, 0xf5, 0x83, 0x59, 0x3c, 0x4f, 0x92, 0xd7, - 0xe7, 0x4a, 0xfe, 0xf0, 0x35, 0x87, 0xfd, 0x50, 0x54, 0xd8, 0x9a, 0xa8, 0xdf, 0x47, 0x9c, 0x78, - 0x34, 0xf1, 0x84, 0x4f, 0xe3, 0xe2, 0xe3, 0x94, 0xb9, 0xfd, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x5d, 0xce, 0x4c, 0x70, 0xed, 0x01, 0x00, 0x00, + // 297 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0xc1, 0x4b, 0x84, 0x40, + 0x14, 0x87, 0x77, 0x83, 0x6d, 0xd7, 0xb7, 0x04, 0xed, 0xd4, 0x61, 0x33, 0x82, 0x10, 0x36, 0xba, + 0xa4, 0xe2, 0x1e, 0xbb, 0x84, 0xa7, 0x4e, 0xb1, 0xe8, 0xad, 0x43, 0x66, 0xf6, 0x12, 0xc1, 0x75, + 0xc6, 0x99, 0xd1, 0xbf, 0x3f, 0xe6, 0x8d, 0x85, 0x84, 0xd0, 0x41, 0xf0, 0x8d, 0xdf, 0xfb, 0xfc, + 0xbd, 0x79, 0xb0, 0xab, 0xab, 0x32, 0xd7, 0x3c, 0x28, 0x78, 0xf3, 0x55, 0x95, 0x9d, 0xcc, 0x35, + 0x97, 0x81, 0xd2, 0xb9, 0x56, 0x82, 0xd7, 0x35, 0x4a, 0x5f, 0x48, 0xae, 0x39, 0xbb, 0xb0, 0x98, + 0x3f, 0xc6, 0xdc, 0xcb, 0xa1, 0xb7, 0x17, 0xc2, 0x3c, 0x16, 0xf5, 0x62, 0x58, 0xa4, 0xa6, 0x9f, + 0x85, 0xe0, 0xf4, 0x42, 0x64, 0x24, 0xdb, 0xce, 0x6f, 0xe7, 0xf7, 0xeb, 0x68, 0xe3, 0x0f, 0x1e, + 0x83, 0x13, 0xf5, 0x3c, 0x4b, 0x56, 0xbd, 0x10, 0xf4, 0x1e, 0x2f, 0x61, 0x41, 0xb4, 0xf7, 0x02, + 0xe7, 0x07, 0x5e, 0xd7, 0x74, 0x9a, 0x60, 0xdb, 0xa1, 0xd2, 0xec, 0x06, 0x40, 0xa0, 0xac, 0xf8, + 0x67, 0xa6, 0xb0, 0x20, 0xdf, 0x59, 0xe2, 0xd8, 0x93, 0x14, 0x0b, 0x76, 0x0d, 0x4e, 0xd3, 0x1d, + 0x33, 0x93, 0x5a, 0x6d, 0x4f, 0xe8, 0xeb, 0xaa, 0xe9, 0x8e, 0x46, 0xa3, 0xbc, 0x77, 0xd8, 0x8c, + 0x7c, 0x4a, 0xf0, 0x46, 0x21, 0xbb, 0x82, 0x95, 0xa1, 0x33, 0x85, 0xed, 0xa0, 0x5b, 0x9a, 0x3a, + 0xc5, 0x96, 0x85, 0x43, 0x10, 0x12, 0xad, 0x23, 0xd7, 0x9f, 0x18, 0xdf, 0xe6, 0x4f, 0x2c, 0x18, + 0x69, 0x60, 0x54, 0x1f, 0xe8, 0xd6, 0x52, 0x94, 0x7d, 0x55, 0x20, 0x7b, 0x03, 0xe7, 0xf7, 0xbf, + 0x6c, 0x37, 0x69, 0xf9, 0x3b, 0xa7, 0x7b, 0xf7, 0x1f, 0x66, 0xe3, 0x7b, 0xb3, 0x70, 0x1e, 0xc7, + 0xaf, 0x4f, 0x25, 0xff, 0xe1, 0x2b, 0xda, 0xc4, 0x43, 0x5e, 0x62, 0xa3, 0x83, 0x7e, 0x1f, 0xd0, + 0x3a, 0x82, 0x89, 0xfd, 0x3e, 0x8e, 0x8b, 0x8f, 0x53, 0xe2, 0xf6, 0xdf, 0x01, 0x00, 0x00, 0xff, + 0xff, 0xb2, 0x45, 0x53, 0x57, 0x0a, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -221,7 +236,7 @@ const _ = grpc.SupportPackageIsVersion6 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type StatsPollerServiceClient interface { - // PollStats is used for polling metrics using poll period. + // PollStats is used for polling stats with specific period and number of pollings. PollStats(ctx context.Context, in *PollStatsRequest, opts ...grpc.CallOption) (StatsPollerService_PollStatsClient, error) } @@ -267,7 +282,7 @@ func (x *statsPollerServicePollStatsClient) Recv() (*PollStatsResponse, error) { // StatsPollerServiceServer is the server API for StatsPollerService service. type StatsPollerServiceServer interface { - // PollStats is used for polling metrics using poll period. + // PollStats is used for polling stats with specific period and number of pollings. PollStats(*PollStatsRequest, StatsPollerService_PollStatsServer) error } diff --git a/proto/ligato/configurator/statspoller.proto b/proto/ligato/configurator/statspoller.proto index fd0da9b859..d1307936b2 100644 --- a/proto/ligato/configurator/statspoller.proto +++ b/proto/ligato/configurator/statspoller.proto @@ -6,6 +6,7 @@ option go_package = "go.ligato.io/vpp-agent/v3/proto/ligato/configurator;configu import "ligato/vpp/vpp.proto"; +// Stats defines stats data returned by StatsPollerService. message Stats { oneof stats { vpp.Stats vpp_stats = 1; @@ -13,18 +14,24 @@ message Stats { } message PollStatsRequest { - // PeriodSec defines polling period (in seconds) + // PeriodSec defines polling period (in seconds). Set to zero to + // return just single polling. uint32 period_sec = 1; + // NumPolls defines number of pollings. Set to non-zero number to + // stop the polling after specified number of pollings is reached. + uint32 num_polls = 2; } message PollStatsResponse { + // PollSeq defines the sequence number of this polling response. uint32 poll_seq = 1; + // Stats contains polled stats data. Stats stats = 2; } // StatsPollerService provides operations for collecting statistics. service StatsPollerService { - // PollStats is used for polling metrics using poll period. + // PollStats is used for polling stats with specific period and number of pollings. rpc PollStats(PollStatsRequest) returns (stream PollStatsResponse) {}; } diff --git a/tests/e2e/200_telemetry_test.go b/tests/e2e/200_telemetry_test.go new file mode 100644 index 0000000000..9d70d9a776 --- /dev/null +++ b/tests/e2e/200_telemetry_test.go @@ -0,0 +1,196 @@ +// Copyright (c) 2020 Cisco and/or its affiliates. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package e2e + +import ( + "context" + "io" + "testing" + + . "github.com/onsi/gomega" + + "go.ligato.io/vpp-agent/v3/proto/ligato/configurator" + "go.ligato.io/vpp-agent/v3/proto/ligato/kvscheduler" + linux_interfaces "go.ligato.io/vpp-agent/v3/proto/ligato/linux/interfaces" + linux_ns "go.ligato.io/vpp-agent/v3/proto/ligato/linux/namespace" + vpp_interfaces "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces" +) + +func TestTelemetryStatsPoller(t *testing.T) { + ctx := setupE2E(t) + defer ctx.teardownE2E() + + const ( + msName = "microservice1" + fullMsName = msNamePrefix + msName + srcTapName = "vpp_span_src" + dstTapName = "vpp_span_dst" + ) + + srcTap := &vpp_interfaces.Interface{ + Name: srcTapName, + Type: vpp_interfaces.Interface_TAP, + Enabled: true, + IpAddresses: []string{ + "10.10.1.2/24", + }, + Link: &vpp_interfaces.Interface_Tap{ + Tap: &vpp_interfaces.TapLink{ + Version: 2, + }, + }, + } + srcLinuxTap := &linux_interfaces.Interface{ + Name: "linux_span_tap1", + Type: linux_interfaces.Interface_TAP_TO_VPP, + Enabled: true, + IpAddresses: []string{ + "10.10.1.1/24", + }, + HostIfName: "linux_span_tap1", + Link: &linux_interfaces.Interface_Tap{ + Tap: &linux_interfaces.TapLink{ + VppTapIfName: srcTapName, + }, + }, + } + + dstTap := &vpp_interfaces.Interface{ + Name: dstTapName, + Type: vpp_interfaces.Interface_TAP, + Enabled: true, + IpAddresses: []string{ + "10.20.1.2/24", + }, + Link: &vpp_interfaces.Interface_Tap{ + Tap: &vpp_interfaces.TapLink{ + Version: 2, + ToMicroservice: fullMsName, + }, + }, + } + dstLinuxTap := &linux_interfaces.Interface{ + Name: "linux_span_tap2", + Type: linux_interfaces.Interface_TAP_TO_VPP, + Enabled: true, + IpAddresses: []string{ + "10.20.1.1/24", + }, + HostIfName: "linux_span_tap2", + Link: &linux_interfaces.Interface_Tap{ + Tap: &linux_interfaces.TapLink{ + VppTapIfName: dstTapName, + }, + }, + Namespace: &linux_ns.NetNamespace{ + Type: linux_ns.NetNamespace_MICROSERVICE, + Reference: fullMsName, + }, + } + + spanRx := &vpp_interfaces.Span{ + InterfaceFrom: srcTapName, + InterfaceTo: dstTapName, + Direction: vpp_interfaces.Span_RX, + } + + ctx.startMicroservice(msName) + + req := ctx.grpcClient.ChangeRequest() + err := req.Update(dstTap, dstLinuxTap, spanRx).Send(context.Background()) + Expect(err).ToNot(HaveOccurred()) + + Eventually(ctx.getValueStateClb(dstTap)).Should(Equal(kvscheduler.ValueState_CONFIGURED)) + + Expect(ctx.getValueState(spanRx)).To(Equal(kvscheduler.ValueState_PENDING)) + + req = ctx.grpcClient.ChangeRequest() + err = req.Update(srcTap, srcLinuxTap).Send(context.Background()) + Expect(err).ToNot(HaveOccurred()) + + Eventually(ctx.getValueStateClb(srcTap)).Should(Equal(kvscheduler.ValueState_CONFIGURED)) + + Expect(ctx.getValueState(spanRx)).To(Equal(kvscheduler.ValueState_CONFIGURED)) + + Expect(ctx.pingFromVPP("10.20.1.1")).To(Succeed()) + Expect(ctx.pingFromMs(msName, "10.20.1.2")).To(Succeed()) + + pollerClient := configurator.NewStatsPollerServiceClient(ctx.grpcConn) + + t.Run("periodSec=0", func(tt *testing.T) { + RegisterTestingT(tt) + + stream, err := pollerClient.PollStats(context.Background(), &configurator.PollStatsRequest{ + PeriodSec: 0, + }) + Expect(err).ToNot(HaveOccurred()) + maxSeq := uint32(0) + n := 0 + for { + stats, err := stream.Recv() + if err == io.EOF { + break + } else if err != nil { + tt.Fatal("recv error:", err) + } + tt.Logf("stats: %+v", stats) + n++ + if stats.GetPollSeq() > maxSeq { + maxSeq = stats.GetPollSeq() + } + } + Expect(n).To(BeEquivalentTo(3)) + Expect(maxSeq).To(BeEquivalentTo(0)) + }) + + t.Run("numPolls=1", func(tt *testing.T) { + RegisterTestingT(tt) + + stream, err := pollerClient.PollStats(context.Background(), &configurator.PollStatsRequest{ + NumPolls: 1, + PeriodSec: 1, + }) + Expect(err).ToNot(HaveOccurred()) + maxSeq := uint32(0) + n := 0 + for { + stats, err := stream.Recv() + if err == io.EOF { + break + } else if err != nil { + tt.Fatal("recv error:", err) + } + tt.Logf("stats: %+v", stats) + n++ + if stats.GetPollSeq() > maxSeq { + maxSeq = stats.GetPollSeq() + } + } + Expect(n).To(BeEquivalentTo(3)) + Expect(maxSeq).To(BeEquivalentTo(1)) + }) + + t.Run("numPolls=2", func(tt *testing.T) { + RegisterTestingT(tt) + + stream, err := pollerClient.PollStats(context.Background(), &configurator.PollStatsRequest{ + NumPolls: 2, + }) + Expect(err).ToNot(HaveOccurred()) + _, err = stream.Recv() + Expect(err).To(HaveOccurred()) + }) + +}