MCPcopy Index your code
hub / github.com/coder/coder / TestServer_Metrics

Function TestServer_Metrics

agent/boundarylogproxy/proxy_test.go:679–812  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

677}
678
679func 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")

Callers

nothing calls this directly

Calls 15

StartMethod · 0.95
CloseMethod · 0.95
RunForwarderMethod · 0.95
getLogsMethod · 0.95
TempDirUnixSocketFunction · 0.92
NewServerFunction · 0.92
LoggerFunction · 0.92
sendLogsFunction · 0.85
getCounterVecValueFunction · 0.85
getCounterValueFunction · 0.85
sendStatusFunction · 0.85
FatalMethod · 0.80

Tested by

no test coverage detected