From 65fb3f099e15c8ba9a070df4c4ef354846286372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20=C3=81lvarez?= Date: Tue, 1 Sep 2020 11:07:23 +0200 Subject: [PATCH] Deprecate IGNORE_URLS and replace with TRANSACTION_IGNORE_URLS (#811) Closes #792 --- docs/configuration.asciidoc | 9 ++++++--- module/apmhttp/ignorer.go | 8 ++++++-- module/apmhttp/ignorer_test.go | 15 ++++++++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/docs/configuration.asciidoc b/docs/configuration.asciidoc index 6eab42ed4..b9754e4de 100644 --- a/docs/configuration.asciidoc +++ b/docs/configuration.asciidoc @@ -258,12 +258,12 @@ server versions. [float] [[config-ignore-urls]] -=== `ELASTIC_APM_IGNORE_URLS` +=== `ELASTIC_APM_TRANSACTION_IGNORE_URLS` [options="header"] |============ -| Environment | Default | Example -| `ELASTIC_APM_IGNORE_URLS` | | `/heartbeat*, *.jpg` +| Environment | Default | Example +| `ELASTIC_APM_TRANSACTION_IGNORE_URLS` | | `/heartbeat*, *.jpg` |============ A list of patterns to match HTTP requests to ignore. An incoming HTTP request @@ -273,6 +273,9 @@ This option supports the wildcard `*`, which matches zero or more characters. Examples: `/foo/*/bar/*/baz*`, `*foo*`. Matching is case insensitive by default. Prefixing a pattern with `(?-i)` makes the matching case sensitive. +NOTE: this configuration was previously known as `ELASTIC_APM_IGNORE_URLS`, which has been deprecated and will be removed in a future major +version of the agent. + [float] [[config-sanitize-field-names]] === `ELASTIC_APM_SANITIZE_FIELD_NAMES` diff --git a/module/apmhttp/ignorer.go b/module/apmhttp/ignorer.go index 6ec56dd50..10ed81def 100644 --- a/module/apmhttp/ignorer.go +++ b/module/apmhttp/ignorer.go @@ -27,7 +27,8 @@ import ( ) const ( - envIgnoreURLs = "ELASTIC_APM_IGNORE_URLS" + envIgnoreURLs = "ELASTIC_APM_TRANSACTION_IGNORE_URLS" + deprecatedEnvIgnoreURLs = "ELASTIC_APM_IGNORE_URLS" ) var ( @@ -36,12 +37,15 @@ var ( ) // DefaultServerRequestIgnorer returns the default RequestIgnorer to use in -// handlers. If ELASTIC_APM_IGNORE_URLS is set, it will be treated as a +// handlers. If ELASTIC_APM_TRANSACTION_IGNORE_URLS is set, it will be treated as a // comma-separated list of wildcard patterns; requests that match any of the // patterns will be ignored. func DefaultServerRequestIgnorer() RequestIgnorerFunc { defaultServerRequestIgnorerOnce.Do(func() { matchers := configutil.ParseWildcardPatternsEnv(envIgnoreURLs, nil) + if len(matchers) == 0 { + matchers = configutil.ParseWildcardPatternsEnv(deprecatedEnvIgnoreURLs, nil) + } if len(matchers) != 0 { defaultServerRequestIgnorer = NewWildcardPatternsRequestIgnorer(matchers) } diff --git a/module/apmhttp/ignorer_test.go b/module/apmhttp/ignorer_test.go index b93caa9b8..26973a95d 100644 --- a/module/apmhttp/ignorer_test.go +++ b/module/apmhttp/ignorer_test.go @@ -61,7 +61,7 @@ func testDefaultServerRequestIgnorer(t *testing.T, ignoreURLs string, r *http.Re if os.Getenv("_INSIDE_TEST") != "1" { cmd := exec.Command(os.Args[0], "-test.run=^"+regexp.QuoteMeta(t.Name())+"$") cmd.Env = append(os.Environ(), "_INSIDE_TEST=1") - cmd.Env = append(cmd.Env, "ELASTIC_APM_IGNORE_URLS="+ignoreURLs) + cmd.Env = append(cmd.Env, "ELASTIC_APM_TRANSACTION_IGNORE_URLS="+ignoreURLs) assert.NoError(t, cmd.Run()) return } @@ -69,3 +69,16 @@ func testDefaultServerRequestIgnorer(t *testing.T, ignoreURLs string, r *http.Re assert.Equal(t, expect, ignorer(r)) }) } + +func TestFallbackDeprecatedRequestIgnorer(t *testing.T) { + if os.Getenv("_INSIDE_TEST") != "1" { + cmd := exec.Command(os.Args[0], "-test.run=^"+regexp.QuoteMeta(t.Name())+"$") + cmd.Env = append(os.Environ(), "_INSIDE_TEST=1") + cmd.Env = append(cmd.Env, "ELASTIC_APM_IGNORE_URLS=*/foo*") + assert.NoError(t, cmd.Run()) + return + } + req := &http.Request{URL: &url.URL{Path: "/foo"}} + ignorer := apmhttp.DefaultServerRequestIgnorer() + assert.Equal(t, true, ignorer(req)) +}