Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

Trace Filtering #309

Merged
merged 4 commits into from
Aug 22, 2017
Merged

Trace Filtering #309

merged 4 commits into from
Aug 22, 2017

Conversation

p-lambert
Copy link
Member

@p-lambert p-lambert commented Aug 15, 2017

This PR enables filtering out certain traces based on their root resource name. The underlying motivation for it is to prevent traces such as those originated from heartbeat requests to be sent to the backend services.

Usage

A blacklist of regular expressions can be set through the agent configuration file or through the environment variable DD_IGNORE_RESOURCE.

Entries must surrounded by double quotes and separated by comas.

INI File

[trace.ignore]
resource: "(GET|POST) /heartbeat", "another_entry", "SELECT COUNT\\(\\*\\) FROM BAR"

ENV variable

DD_IGNORE_RESOURCE='"(GET|POST) /heartbeat", "another_entry"'

The regular expressions are evaluated using the RE2 engine. Accepted syntax is described here.

Performance impact

The performance impact of this feature was measured against two scenarios:

  • running the agent with a set of filters that match some traces – rather than degrading the performance this turned out to improve it since we avoid computation when we drop a trace;
  • running the agent with a set of filters that don't match any traces – this is the worst case scenario since we have the overhead of filtering without dropping any trace;

In both cases the impact seems to be negligibe:

BenchmarkAgentTraceProcessing                         	   10000	    120873 ns/op	   50970 B/op	     706 allocs/op
BenchmarkAgentTraceProcessingWithFiltering            	   10000	    114600 ns/op	   45879 B/op	     633 allocs/op
BenchmarkAgentTraceProcessingWithWorstCaseFiltering   	   10000	    125369 ns/op	   51124 B/op	     706 allocs/op

@p-lambert p-lambert force-pushed the trace-filtering branch 4 times, most recently from a040b7c to 41348fc Compare August 16, 2017 14:25
agent/agent.go Outdated
func (a *Agent) countAsDropped(t model.Trace) {
// We get the address of the struct holding the stats associated to the tags
ts := a.Receiver.stats.getTagStats(Tags{})
atomic.AddInt64(&ts.TracesDropped, 1)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think traces discarded to comply with a user request should be counted separately from those discarded for being badly formatted. i.e. let's count TracesFiltered as a distinct thing from TracesDropped.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it also bothers me the amount of coupling between the Agent and the Receiver. This seems to be a classic example of feature envy. Maybe we should abstract this away? @talwai

agent/agent.go Outdated
@@ -35,6 +35,7 @@ func (pt *processedTrace) weight() float64 {
type Agent struct {
Receiver *HTTPReceiver
Concentrator *Concentrator
Filter Filter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe take a []Filter here so it can accommodate several blacklists that check against different fields (name service etc.)

agent/agent.go Outdated
@@ -56,6 +57,7 @@ func NewAgent(conf *config.AgentConfig) *Agent {
conf.ExtraAggregators,
conf.BucketInterval.Nanoseconds(),
)
f := NewResourceFilter(conf)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per above, call this NewFilters so that it is more generalized. implementing a name- and service- blacklist can be out of the scope PR, but let's make it easy for us to add this in the future

config/agent.go Outdated
@@ -65,6 +65,8 @@ type AgentConfig struct {

// http/s proxying
Proxy *ProxySettings

ResourceBlacklist []string
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe Blacklist map[string][]string and have the current implementation only populate blacklist["resource"]

agent/agent.go Outdated

if !a.Filter.Keep(root) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the new "general" scheme, loop over a.Filters and check against each. As of now there'll be only one

filters/base.go Outdated
)

// Interface handles Span filtering
type Interface interface {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just call it Filter

f.blacklist = blacklist

return f
}
Copy link

@talwai talwai Aug 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just do func NewResource() *Resource

then in filters/base you can do return []Filter{NewResource(conf)}

)

// Resource implements a resource-based filter
type Resource struct {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call this ResourceFilter

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it shouldn't be exported?

@p-lambert p-lambert force-pushed the trace-filtering branch 7 times, most recently from 5bd9879 to 219c31b Compare August 17, 2017 18:43
@p-lambert p-lambert force-pushed the trace-filtering branch 2 times, most recently from 32d7386 to 1b78231 Compare August 21, 2017 15:00
@talwai talwai merged commit 9772170 into master Aug 22, 2017
@dtilghman dtilghman deleted the trace-filtering branch August 23, 2017 05:14
@DataDog DataDog deleted a comment from p-lambert Aug 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants