30 lines
1.1 KiB
Go
30 lines
1.1 KiB
Go
package metrics
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestMetricsHandlerExportsOnlyAggregateGatewayState(t *testing.T) {
|
|
ObserveSubmit(true, 20*time.Millisecond)
|
|
request := httptest.NewRequest(http.MethodGet, "/metrics", nil)
|
|
response := httptest.NewRecorder()
|
|
Handler(func(context.Context) Snapshot {
|
|
return Snapshot{UpstreamDesired: 2, UpstreamConnected: 1, DownstreamConnected: 3, SubmitWorkerUp: true, QueueAvailable: true, QueuePending: 4, QueueLag: 5, QueueOldestAgeSeconds: 12}
|
|
}).ServeHTTP(response, request)
|
|
|
|
body := response.Body.String()
|
|
if response.Code != http.StatusOK || !strings.Contains(body, "cmpp_gateway_submit_queue_pending 4") || !strings.Contains(body, "cmpp_gateway_upstream_connections{state=\"connected\"} 1") {
|
|
t.Fatalf("unexpected metrics response: code=%d body=%s", response.Code, body)
|
|
}
|
|
for _, forbidden := range []string{"phone_number", "message_id", "channel_id"} {
|
|
if strings.Contains(body, forbidden) {
|
|
t.Fatalf("metrics expose forbidden label %q", forbidden)
|
|
}
|
|
}
|
|
}
|