Skip to content

Commit

Permalink
Remove logic for ingesting metrics via http in veneur-proxy.
Browse files Browse the repository at this point in the history
  • Loading branch information
arnavdugar-stripe committed Feb 22, 2023
1 parent 62ac5d5 commit 7dc69b5
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 142 deletions.
43 changes: 0 additions & 43 deletions proxy/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down
98 changes: 0 additions & 98 deletions proxy/handlers/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"

"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -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"},
Expand Down
1 change: 0 additions & 1 deletion proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 7dc69b5

Please sign in to comment.