(t *testing.T)
| 677 | } |
| 678 | |
| 679 | func TestServer_Metrics(t *testing.T) { |
| 680 | t.Parallel() |
| 681 | |
| 682 | makeReq := func(n int) *agentproto.ReportBoundaryLogsRequest { |
| 683 | logs := make([]*agentproto.BoundaryLog, n) |
| 684 | for i := range n { |
| 685 | logs[i] = &agentproto.BoundaryLog{ |
| 686 | Allowed: true, |
| 687 | Time: timestamppb.Now(), |
| 688 | Resource: &agentproto.BoundaryLog_HttpRequest_{ |
| 689 | HttpRequest: &agentproto.BoundaryLog_HttpRequest{ |
| 690 | Method: "GET", |
| 691 | Url: "https://example.com", |
| 692 | }, |
| 693 | }, |
| 694 | } |
| 695 | } |
| 696 | return &agentproto.ReportBoundaryLogsRequest{Logs: logs} |
| 697 | } |
| 698 | |
| 699 | // BufferFull needs its own setup because it intentionally does not run |
| 700 | // a forwarder so the channel fills up. |
| 701 | t.Run("BufferFull", func(t *testing.T) { |
| 702 | t.Parallel() |
| 703 | |
| 704 | reg := prometheus.NewRegistry() |
| 705 | socketPath := filepath.Join(testutil.TempDirUnixSocket(t), "boundary.sock") |
| 706 | srv := boundarylogproxy.NewServer(testutil.Logger(t), socketPath, reg) |
| 707 | |
| 708 | err := srv.Start() |
| 709 | require.NoError(t, err) |
| 710 | t.Cleanup(func() { require.NoError(t, srv.Close()) }) |
| 711 | |
| 712 | conn, err := net.Dial("unix", socketPath) |
| 713 | require.NoError(t, err) |
| 714 | defer conn.Close() |
| 715 | |
| 716 | // Fill the buffer (size 100) without running a forwarder so nothing |
| 717 | // drains. Then send one more to trigger the drop path. |
| 718 | for range 101 { |
| 719 | sendLogs(t, conn, makeReq(1)) |
| 720 | } |
| 721 | |
| 722 | require.Eventually(t, func() bool { |
| 723 | return getCounterVecValue(t, reg, "agent_boundary_log_proxy_batches_dropped_total", "buffer_full") >= 1 |
| 724 | }, testutil.WaitShort, testutil.IntervalFast) |
| 725 | require.GreaterOrEqual(t, |
| 726 | getCounterVecValue(t, reg, "agent_boundary_log_proxy_logs_dropped_total", "buffer_full"), |
| 727 | float64(1)) |
| 728 | }) |
| 729 | |
| 730 | // The remaining metrics share one server, forwarder, and connection. The |
| 731 | // phases run sequentially so metrics accumulate. |
| 732 | t.Run("Forwarding", func(t *testing.T) { |
| 733 | t.Parallel() |
| 734 | |
| 735 | reg := prometheus.NewRegistry() |
| 736 | socketPath := filepath.Join(testutil.TempDirUnixSocket(t), "boundary.sock") |
nothing calls this directly
no test coverage detected