MCPcopy Create free account
hub / github.com/InferCore/InferCore / TestMetrics_Success200

Function TestMetrics_Success200

internal/server/server_test.go:738–779  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

736}
737
738func TestMetrics_Success200(t *testing.T) {
739 srv := New(testConfig(100, true))
740 ts := httptest.NewServer(srv.Routes())
741 defer ts.Close()
742
743 // Generate one non-metrics request so labeled HTTP counter is populated.
744 _, _ = http.Get(ts.URL + "/health")
745
746 resp, err := http.Get(ts.URL + "/metrics")
747 if err != nil {
748 t.Fatalf("metrics request failed: %v", err)
749 }
750 defer resp.Body.Close()
751
752 if resp.StatusCode != http.StatusOK {
753 t.Fatalf("expected 200, got %d", resp.StatusCode)
754 }
755 if !strings.Contains(resp.Header.Get("Content-Type"), "text/plain") {
756 t.Fatalf("expected text/plain content type, got %s", resp.Header.Get("Content-Type"))
757 }
758
759 raw, err := io.ReadAll(resp.Body)
760 if err != nil {
761 t.Fatalf("read metrics body: %v", err)
762 }
763 metricsBody := string(raw)
764 if !strings.Contains(metricsBody, "infercore_requests_total") {
765 t.Fatalf("expected infercore_requests_total metric")
766 }
767 if !strings.Contains(metricsBody, "infercore_http_requests_total") {
768 t.Fatalf("expected infercore_http_requests_total metric")
769 }
770 if !strings.Contains(metricsBody, "infercore_scaling_ttft_degradation_ratio") {
771 t.Fatalf("expected infercore_scaling_ttft_degradation_ratio metric")
772 }
773 if !strings.Contains(metricsBody, "path=\"/health\"") {
774 t.Fatalf("expected /health labeled metric entry")
775 }
776 if !strings.Contains(metricsBody, "method=\"GET\"") {
777 t.Fatalf("expected GET method labeled metric entry")
778 }
779}
780
781func TestInfer_EmitsTraceRecord(t *testing.T) {
782 exporter := &captureTelemetryExporter{}

Callers

nothing calls this directly

Calls 4

RoutesMethod · 0.80
NewFunction · 0.70
testConfigFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected