diff --git a/sdk/filter/filter.go b/sdk/filter/filter.go index 6a9e672..f1fa31d 100644 --- a/sdk/filter/filter.go +++ b/sdk/filter/filter.go @@ -7,12 +7,6 @@ import ( // Filter evaluates whether request should be blocked, `true` blocks the request and `false` continues it. type Filter interface { - // EvaluateURLAndHeaders can be used to evaluate both URL and headers - EvaluateURLAndHeaders(span sdk.Span, url string, headers map[string][]string) result.FilterResult - - // EvaluateBody can be used to evaluate the body content - EvaluateBody(span sdk.Span, body []byte, headers map[string][]string) result.FilterResult - // Evaluate can be used to evaluate URL, headers and body content in one call - Evaluate(span sdk.Span, url string, body []byte, headers map[string][]string) result.FilterResult + Evaluate(span sdk.Span) result.FilterResult } diff --git a/sdk/filter/multifilter.go b/sdk/filter/multifilter.go index 38add9c..55242e1 100644 --- a/sdk/filter/multifilter.go +++ b/sdk/filter/multifilter.go @@ -17,32 +17,10 @@ func NewMultiFilter(filter ...Filter) *MultiFilter { return &MultiFilter{filters: filter} } -// EvaluateURLAndHeaders runs URL and headers evaluation for each filter until one returns true -func (m *MultiFilter) EvaluateURLAndHeaders(span sdk.Span, url string, headers map[string][]string) result.FilterResult { - for _, f := range (*m).filters { - filterResult := f.EvaluateURLAndHeaders(span, url, headers) - if filterResult.Block { - return filterResult - } - } - return result.FilterResult{} -} - -// EvaluateBody runs body evaluators for each filter until one returns true -func (m *MultiFilter) EvaluateBody(span sdk.Span, body []byte, headers map[string][]string) result.FilterResult { - for _, f := range (*m).filters { - filterResult := f.EvaluateBody(span, body, headers) - if filterResult.Block { - return filterResult - } - } - return result.FilterResult{} -} - // Evaluate runs body evaluators for each filter until one returns true -func (m *MultiFilter) Evaluate(span sdk.Span, url string, body []byte, headers map[string][]string) result.FilterResult { +func (m *MultiFilter) Evaluate(span sdk.Span) result.FilterResult { for _, f := range (*m).filters { - filterResult := f.Evaluate(span, url, body, headers) + filterResult := f.Evaluate(span) if filterResult.Block { return filterResult } diff --git a/sdk/filter/multifilter_test.go b/sdk/filter/multifilter_test.go index 8309694..a94b430 100644 --- a/sdk/filter/multifilter_test.go +++ b/sdk/filter/multifilter_test.go @@ -15,7 +15,7 @@ func TestMultiFilterEmpty(t *testing.T) { assert.False(t, res.Block) res = f.EvaluateBody(nil, nil, nil) assert.False(t, res.Block) - res = f.Evaluate(nil, "", nil, nil) + res = f.Evaluate(nil) assert.False(t, res.Block) } @@ -99,7 +99,7 @@ func TestMultiFilterStopsAfterTrue(t *testing.T) { assert.Equal(t, tCase.expectedURLAndHeadersFilterResult, res.Block) res = tCase.multiFilter.EvaluateBody(nil, nil, nil) assert.Equal(t, tCase.expectedBodyFilterResult, res.Block) - res = tCase.multiFilter.Evaluate(nil, "", nil, nil) + res = tCase.multiFilter.Evaluate(nil) assert.Equal(t, tCase.expectedFilterResult, res.Block) }) } diff --git a/sdk/filter/noop.go b/sdk/filter/noop.go index 1e165dc..12372b7 100644 --- a/sdk/filter/noop.go +++ b/sdk/filter/noop.go @@ -10,17 +10,7 @@ type NoopFilter struct{} var _ Filter = NoopFilter{} -// EvaluateURLAndHeaders that always returns false -func (NoopFilter) EvaluateURLAndHeaders(span sdk.Span, url string, headers map[string][]string) result.FilterResult { - return result.FilterResult{} -} - -// EvaluateBody that always returns false -func (NoopFilter) EvaluateBody(span sdk.Span, body []byte, headers map[string][]string) result.FilterResult { - return result.FilterResult{} -} - // Evaluate that always returns false -func (NoopFilter) Evaluate(span sdk.Span, url string, body []byte, headers map[string][]string) result.FilterResult { +func (NoopFilter) Evaluate(span sdk.Span) result.FilterResult { return result.FilterResult{} } diff --git a/sdk/filter/noop_test.go b/sdk/filter/noop_test.go index db58b82..43264b4 100644 --- a/sdk/filter/noop_test.go +++ b/sdk/filter/noop_test.go @@ -12,6 +12,6 @@ func TestNoopFilter(t *testing.T) { assert.False(t, res.Block) res = f.EvaluateBody(nil, nil, nil) assert.False(t, res.Block) - res = f.Evaluate(nil, "", nil, nil) + res = f.Evaluate(nil) assert.False(t, res.Block) } diff --git a/sdk/instrumentation/google.golang.org/grpc/server.go b/sdk/instrumentation/google.golang.org/grpc/server.go index cc406e2..a656849 100644 --- a/sdk/instrumentation/google.golang.org/grpc/server.go +++ b/sdk/instrumentation/google.golang.org/grpc/server.go @@ -12,7 +12,6 @@ import ( internalconfig "github.com/hypertrace/goagent/sdk/internal/config" "github.com/hypertrace/goagent/sdk/internal/container" "google.golang.org/grpc" - "google.golang.org/grpc/metadata" "google.golang.org/grpc/peer" "google.golang.org/grpc/stats" "google.golang.org/grpc/status" @@ -99,27 +98,19 @@ func wrapHandler( len(reqBody) > 0 && err == nil { setTruncatedBodyAttribute("request", reqBody, int(dataCaptureConfig.BodyMaxSizeBytes.Value), span) - if md, ok := metadata.FromIncomingContext(ctx); ok { - processingBody := reqBody - if int(dataCaptureConfig.BodyMaxProcessingSizeBytes.Value) < len(reqBody) { - processingBody = reqBody[:dataCaptureConfig.BodyMaxProcessingSizeBytes.Value] - } - filterResult := filter.EvaluateBody(span, processingBody, md) - if filterResult.Block { - return nil, status.Error(StatusCode(int(filterResult.ResponseStatusCode)), StatusText(int(filterResult.ResponseStatusCode))) - } + filterResult := filter.Evaluate(span) + if filterResult.Block { + return nil, status.Error(StatusCode(int(filterResult.ResponseStatusCode)), StatusText(int(filterResult.ResponseStatusCode))) } } if dataCaptureConfig.RpcMetadata.Request.Value { setAttributesFromRequestIncomingMetadata(ctx, span) - if md, ok := metadata.FromIncomingContext(ctx); ok { - // TODO: decide what should be passed as URL in GRPC - filterResult := filter.EvaluateURLAndHeaders(span, "", md) - if filterResult.Block { - return nil, status.Error(StatusCode(int(filterResult.ResponseStatusCode)), StatusText(int(filterResult.ResponseStatusCode))) - } + // TODO: decide what should be passed as URL in GRPC + filterResult := filter.Evaluate(span) + if filterResult.Block { + return nil, status.Error(StatusCode(int(filterResult.ResponseStatusCode)), StatusText(int(filterResult.ResponseStatusCode))) } } diff --git a/sdk/instrumentation/net/http/handler.go b/sdk/instrumentation/net/http/handler.go index 646530b..d34dae7 100644 --- a/sdk/instrumentation/net/http/handler.go +++ b/sdk/instrumentation/net/http/handler.go @@ -2,7 +2,6 @@ package http // import "github.com/hypertrace/goagent/sdk/instrumentation/net/ht import ( "bytes" - "encoding/base64" "io" "io/ioutil" "net/http" @@ -72,14 +71,13 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { host := r.Host span.SetAttribute("http.request.header.host", host) - headers := r.Header // Sets an attribute per each request header. if h.dataCaptureConfig.HttpHeaders.Request.Value { SetAttributesFromHeaders("request", NewHeaderMapAccessor(r.Header), span) } // run filters on headers - filterResult := h.filter.EvaluateURLAndHeaders(span, url, headers) + filterResult := h.filter.Evaluate(span) if filterResult.Block { w.WriteHeader(int(filterResult.ResponseStatusCode)) return @@ -103,19 +101,8 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { isMultipartFormDataBody) } - processingBody := body - if int(h.dataCaptureConfig.BodyMaxProcessingSizeBytes.Value) < len(body) { - processingBody = body[:h.dataCaptureConfig.BodyMaxProcessingSizeBytes.Value] - } - // if body is multipart/form-data, base64 encode it before passing it on to the filter - if isMultipartFormDataBody { - origProcessingBody := processingBody - processingBody = make([]byte, base64.RawStdEncoding.EncodedLen(len(origProcessingBody))) - base64.RawStdEncoding.Encode(processingBody, origProcessingBody) - } - // run body filters - filterResult := h.filter.EvaluateBody(span, processingBody, headers) + filterResult := h.filter.Evaluate(span) if filterResult.Block { w.WriteHeader(int(filterResult.ResponseStatusCode)) return diff --git a/sdk/internal/mock/filter.go b/sdk/internal/mock/filter.go index 2b4aef1..4722112 100644 --- a/sdk/internal/mock/filter.go +++ b/sdk/internal/mock/filter.go @@ -6,26 +6,10 @@ import ( ) type Filter struct { - URLAndHeadersEvaluator func(span sdk.Span, url string, headers map[string][]string) result.FilterResult - BodyEvaluator func(span sdk.Span, body []byte, headers map[string][]string) result.FilterResult - Evaluator func(span sdk.Span, url string, body []byte, headers map[string][]string) result.FilterResult + Evaluator func(span sdk.Span, url string, body []byte, headers map[string][]string) result.FilterResult } -func (f Filter) EvaluateURLAndHeaders(span sdk.Span, url string, headers map[string][]string) result.FilterResult { - if f.URLAndHeadersEvaluator == nil { - return result.FilterResult{} - } - return f.URLAndHeadersEvaluator(span, url, headers) -} - -func (f Filter) EvaluateBody(span sdk.Span, body []byte, headers map[string][]string) result.FilterResult { - if f.BodyEvaluator == nil { - return result.FilterResult{} - } - return f.BodyEvaluator(span, body, headers) -} - -func (f Filter) Evaluate(span sdk.Span, url string, body []byte, headers map[string][]string) result.FilterResult { +func (f Filter) Evaluate(span sdk.Span) result.FilterResult { if f.Evaluator == nil { return result.FilterResult{} }