From 7dc69b5d80f78555be81c012054f514fd4fea9c3 Mon Sep 17 00:00:00 2001 From: Arnav Dugar Date: Wed, 22 Feb 2023 14:49:59 -0800 Subject: [PATCH] Remove logic for ingesting metrics via http in veneur-proxy. --- proxy/handlers/handlers.go | 43 --------------- proxy/handlers/handlers_test.go | 98 --------------------------------- proxy/proxy.go | 1 - 3 files changed, 142 deletions(-) diff --git a/proxy/handlers/handlers.go b/proxy/handlers/handlers.go index 64055aee3..e545c9972 100644 --- a/proxy/handlers/handlers.go +++ b/proxy/handlers/handlers.go @@ -13,7 +13,6 @@ import ( "github.com/stripe/veneur/v14/forwardrpc" "github.com/stripe/veneur/v14/proxy/connect" "github.com/stripe/veneur/v14/proxy/destinations" - "github.com/stripe/veneur/v14/proxy/json" "github.com/stripe/veneur/v14/samplers/metricpb" "github.com/stripe/veneur/v14/scopedstatsd" "github.com/stripe/veneur/v14/util/matcher" @@ -38,48 +37,6 @@ func (proxy *Handlers) HandleHealthcheck( } } -// Receives and handles metrics via HTTP requests. -func (proxy *Handlers) HandleJsonMetrics( - writer http.ResponseWriter, request *http.Request, -) { - proxy.Statsd.Count( - "veneur_proxy.ingest.request_count", 1, - []string{"protocol:http"}, 1.0) - requestStart := time.Now() - defer proxy.Statsd.Timing( - "veneur_proxy.ingest.request_latency_ms", time.Since(requestStart), - []string{"protocol:http"}, 1.0) - - jsonMetrics, err := json.ParseRequest(request) - if err != nil { - proxy.Logger.WithError(err.Err).Debug(err.Message) - http.Error(writer, fmt.Sprintf("%s: %v", err.Message, err.Err), err.Status) - proxy.Statsd.Count( - "veneur_proxy.ingest.request_error_count", 1, - []string{"protocol:http", fmt.Sprintf("status:%s", err.Tag)}, 1.0) - return - } - - proxy.Statsd.Count( - "veneur_proxy.ingest.metrics_count", - int64(len(jsonMetrics)), []string{"protocol:http"}, 1.0) - convertErrorCount := 0 - for _, jsonMetric := range jsonMetrics { - metric, err := json.ConvertJsonMetric(&jsonMetric) - if err != nil { - proxy.Logger.Debugf("error converting metric: %v", err) - convertErrorCount += 1 - continue - } - proxy.handleMetric(metric) - } - if convertErrorCount > 0 { - proxy.Statsd.Count( - "veneur_proxy.handle.metrics_count", - int64(convertErrorCount), []string{"error:json_convert"}, 1.0) - } -} - // Receives and handles metrics via individual gRPC requests. func (proxy *Handlers) SendMetrics( ctx context.Context, metricList *forwardrpc.MetricList, diff --git a/proxy/handlers/handlers_test.go b/proxy/handlers/handlers_test.go index fd595b655..00405b5a1 100644 --- a/proxy/handlers/handlers_test.go +++ b/proxy/handlers/handlers_test.go @@ -6,7 +6,6 @@ import ( "io" "net/http" "net/http/httptest" - "strings" "testing" "github.com/golang/mock/gomock" @@ -114,103 +113,6 @@ func TestHealthcheckSuccess(t *testing.T) { assert.Equal(t, http.StatusNoContent, recorder.Result().StatusCode) } -const metricsJson = "[{\"name\":\"metric-name\",\"type\":\"counter\",\"tags\":[\"tag1:value1\",\"tag2:value2\"],\"value\":[1,0,0,0,0,0,0,0]}]" - -func TestProxyJson(t *testing.T) { - ctrl := gomock.NewController(t) - defer ctrl.Finish() - - fixture := CreateTestHandlers(ctrl, []matcher.TagMatcher{}) - - fixture.Statsd.EXPECT().Count( - "veneur_proxy.ingest.request_count", - int64(1), []string{"protocol:http"}, 1.0) - fixture.Statsd.EXPECT().Timing( - "veneur_proxy.ingest.request_latency_ms", - gomock.Any(), []string{"protocol:http"}, 1.0) - fixture.Statsd.EXPECT().Count( - "veneur_proxy.ingest.metrics_count", - int64(1), []string{"protocol:http"}, 1.0) - fixture.Statsd.EXPECT().Count( - "veneur_proxy.handle.metrics_count", - int64(1), []string{"error:false"}, 1.0) - - fixture.Destinations.EXPECT(). - Get("metric-namecountertag1:value1,tag2:value2"). - Return(fixture.Destination, nil) - sendChannel := make(chan connect.SendRequest, 1) - fixture.Destination.EXPECT().SendChannel().Return(sendChannel) - closedChannel := make(chan struct{}) - fixture.Destination.EXPECT().ClosedChannel().Return(closedChannel) - - recorder := httptest.NewRecorder() - request := httptest.NewRequest( - "GET", "/import", strings.NewReader(metricsJson)) - fixture.Handlers.HandleJsonMetrics(recorder, request) - sendRequest := <-sendChannel - - assert.Equal(t, &metricpb.Metric{ - Name: "metric-name", - Tags: []string{"tag1:value1", "tag2:value2"}, - Type: metricpb.Type_Counter, - Value: &metricpb.Metric_Counter{ - Counter: &metricpb.CounterValue{ - Value: 1, - }, - }, - Scope: metricpb.Scope_Global, - }, sendRequest.Metric) - assert.Equal(t, http.StatusOK, recorder.Result().StatusCode) -} - -func TestProxyJsonBadRequest(t *testing.T) { - ctrl := gomock.NewController(t) - defer ctrl.Finish() - - fixture := CreateTestHandlers(ctrl, []matcher.TagMatcher{}) - - fixture.Statsd.EXPECT().Count( - "veneur_proxy.ingest.request_count", - int64(1), []string{"protocol:http"}, 1.0) - fixture.Statsd.EXPECT().Timing( - "veneur_proxy.ingest.request_latency_ms", - gomock.Any(), []string{"protocol:http"}, 1.0) - fixture.Statsd.EXPECT().Count( - "veneur_proxy.ingest.request_error_count", - int64(1), []string{"protocol:http", "status:error_decode"}, 1.0) - - recorder := httptest.NewRecorder() - request := httptest.NewRequest("GET", "/import", strings.NewReader("[")) - fixture.Handlers.HandleJsonMetrics(recorder, request) -} - -const metricsJsonBadType = "[{\"name\":\"metric-name\",\"type\":\"unknown\"}]" - -func TestProxyJsonConvertError(t *testing.T) { - ctrl := gomock.NewController(t) - defer ctrl.Finish() - - fixture := CreateTestHandlers(ctrl, []matcher.TagMatcher{}) - - fixture.Statsd.EXPECT().Count( - "veneur_proxy.ingest.request_count", - int64(1), []string{"protocol:http"}, 1.0) - fixture.Statsd.EXPECT().Timing( - "veneur_proxy.ingest.request_latency_ms", - gomock.Any(), []string{"protocol:http"}, 1.0) - fixture.Statsd.EXPECT().Count( - "veneur_proxy.ingest.metrics_count", - int64(1), []string{"protocol:http"}, 1.0) - fixture.Statsd.EXPECT().Count( - "veneur_proxy.handle.metrics_count", - int64(1), []string{"error:json_convert"}, 1.0) - - recorder := httptest.NewRecorder() - request := httptest.NewRequest( - "GET", "/import", strings.NewReader(metricsJsonBadType)) - fixture.Handlers.HandleJsonMetrics(recorder, request) -} - var metric = &metricpb.Metric{ Name: "metric-name", Tags: []string{"tag1:value1", "tag2:value2"}, diff --git a/proxy/proxy.go b/proxy/proxy.go index c19842630..4bc9c5d7f 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -115,7 +115,6 @@ func Create(params *CreateParams) (*Proxy, error) { params.HttpHandler.HandleFunc( "/healthcheck", proxy.handlers.HandleHealthcheck) - params.HttpHandler.HandleFunc("/import", proxy.handlers.HandleJsonMetrics) forwardrpc.RegisterForwardServer(proxy.grpcServer, proxy.handlers) forwardrpc.RegisterForwardServer(proxy.grpcTlsServer, proxy.handlers)