Skip to content

Commit

Permalink
Disable sourcemapping config (#2488) (#2491)
Browse files Browse the repository at this point in the history
  • Loading branch information
graphaelli authored Aug 6, 2019
1 parent 32fa814 commit ee24fea
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 16 deletions.
3 changes: 3 additions & 0 deletions _meta/beat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ apm-server:
# to all error and transaction documents sent to the RUM endpoint.
#source_mapping:

# Sourcemapping is enabled by default for RUM events
#enabled: true

# Source maps are always fetched from Elasticsearch, by default using the output.elasticsearch configuration.
# A different instance must be configured when using any other output.
# This setting only affects sourcemap reads - the output determines where sourcemaps are written.
Expand Down
3 changes: 3 additions & 0 deletions apm-server.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ apm-server:
# to all error and transaction documents sent to the RUM endpoint.
#source_mapping:

# Sourcemapping is enabled by default for RUM events
#enabled: true

# Source maps are always fetched from Elasticsearch, by default using the output.elasticsearch configuration.
# A different instance must be configured when using any other output.
# This setting only affects sourcemap reads - the output determines where sourcemaps are written.
Expand Down
3 changes: 3 additions & 0 deletions apm-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ apm-server:
# to all error and transaction documents sent to the RUM endpoint.
#source_mapping:

# Sourcemapping is enabled by default for RUM events
#enabled: true

# Source maps are always fetched from Elasticsearch, by default using the output.elasticsearch configuration.
# A different instance must be configured when using any other output.
# This setting only affects sourcemap reads - the output determines where sourcemaps are written.
Expand Down
7 changes: 6 additions & 1 deletion beater/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type agentConfig struct {

type SourceMapping struct {
Cache *Cache `config:"cache"`
Enabled *bool `config:"enabled"`
IndexPattern string `config:"index_pattern"`

EsConfig *common.Config `config:"elasticsearch"`
Expand Down Expand Up @@ -188,6 +189,10 @@ func (c *rumConfig) isEnabled() bool {
return c != nil && (c.Enabled != nil && *c.Enabled)
}

func (s *SourceMapping) isEnabled() bool {
return s == nil || s.Enabled == nil || *s.Enabled
}

func (s *SourceMapping) isSetup() bool {
return s != nil && (s.EsConfig != nil)
}
Expand All @@ -201,7 +206,7 @@ func (c *pipelineConfig) shouldOverwrite() bool {
}

func (c *rumConfig) memoizedSmapMapper() (sourcemap.Mapper, error) {
if !c.isEnabled() || !c.SourceMapping.isSetup() {
if !c.isEnabled() || !c.SourceMapping.isEnabled() || !c.SourceMapping.isSetup() {
return nil, nil
}
if c.SourceMapping.mapper != nil {
Expand Down
2 changes: 1 addition & 1 deletion beater/route_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func rumHandler(beaterConfig *Config, h http.Handler) http.Handler {

func sourcemapHandler(beaterConfig *Config, h http.Handler) http.Handler {
return logHandler(
killSwitchHandler(beaterConfig.RumConfig.isEnabled(),
killSwitchHandler(beaterConfig.RumConfig.isEnabled() && beaterConfig.RumConfig.SourceMapping.isEnabled(),
authHandler(beaterConfig.SecretToken, h)))
}

Expand Down
1 change: 1 addition & 0 deletions changelogs/7.4.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ https://github.com/elastic/apm-server/compare/v7.3.0\...v7.4.0[View commits]
[float]
==== Added
- Upgrade Go to 1.12.7 {pull}2483[2483].
- Add config option to disable sourcemapping {pull}2488[2488].
10 changes: 2 additions & 8 deletions tests/system/apmserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ class ClientSideBaseTest(ServerBaseTest):
sourcemap_url = 'http://localhost:8200/assets/v1/sourcemaps'
intake_url = 'http://localhost:8200/intake/v2/rum/events'
backend_intake_url = 'http://localhost:8200/intake/v2/events'
config_overrides = {}

@classmethod
def setUpClass(cls):
Expand All @@ -269,6 +270,7 @@ def config(self):
cfg = super(ClientSideBaseTest, self).config()
cfg.update({"enable_rum": "true",
"smap_cache_expiration": "200"})
cfg.update(self.config_overrides)
return cfg

def get_backend_error_payload_path(self, name="errors_2.ndjson"):
Expand Down Expand Up @@ -367,20 +369,12 @@ def tearDown(self):


class CorsBaseTest(ClientSideBaseTest):

def config(self):
cfg = super(CorsBaseTest, self).config()
cfg.update({"allow_origins": ["http://www.elastic.co"]})
return cfg


class SmapCacheBaseTest(ClientSideElasticTest):
def config(self):
cfg = super(SmapCacheBaseTest, self).config()
cfg.update({"smap_cache_expiration": "1"})
return cfg


class ExpvarBaseTest(ServerBaseTest):
config_overrides = {}

Expand Down
8 changes: 6 additions & 2 deletions tests/system/config/apm-server.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ apm-server:
rum.exclude_from_grouping: "~/test"
rum.event_rate.limit: 16

{% if smap_cache_expiration%}
{% if rum_sourcemapping_disabled %}
rum.source_mapping.enabled: false
{% endif %}

{% if smap_cache_expiration %}
rum.source_mapping.cache.expiration: {{ smap_cache_expiration}}
{% endif %}
{% if smap_index_pattern%}
{% if smap_index_pattern %}
rum.source_mapping.index_pattern: {{ smap_index_pattern}}
{% endif %}

Expand Down
37 changes: 33 additions & 4 deletions tests/system/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import unittest

from apmserver import ElasticTest, ExpvarBaseTest
from apmserver import ClientSideElasticTest, SmapCacheBaseTest
from apmserver import ClientSideElasticTest
from apmserver import OverrideIndicesTest, OverrideIndicesFailureTest
from beat.beat import INTEGRATION_TESTS
from sets import Set
Expand Down Expand Up @@ -505,8 +505,6 @@ def test_sourcemap_mapping_cache_usage(self):
self.assert_no_logged_warnings()
self.check_rum_error_sourcemap(True)


class SourcemappingIntegrationChangedConfigTest(ClientSideElasticTest):
@unittest.skipUnless(INTEGRATION_TESTS, "integration test")
def test_rum_error_changed_index(self):
# use an uncleaned path to test that path is cleaned in upload
Expand All @@ -524,7 +522,9 @@ def test_rum_error_changed_index(self):
self.check_rum_error_sourcemap(True)


class SourcemappingCacheIntegrationTest(SmapCacheBaseTest):
class SourcemappingCacheIntegrationTest(ClientSideElasticTest):
config_overrides = {"smap_cache_expiration": "1"}

@unittest.skipUnless(INTEGRATION_TESTS, "integration test")
def test_sourcemap_cache_expiration(self):
path = 'http://localhost:8000/test/e2e/general-usecase/bundle.js.map'
Expand Down Expand Up @@ -556,6 +556,35 @@ def test_sourcemap_cache_expiration(self):
self.check_rum_error_sourcemap(False, expected_err="No Sourcemap available for")


class SourcemappingDisabledIntegrationTest(ClientSideElasticTest):
config_overrides = {
"rum_sourcemapping_disabled": True,
}

@unittest.skipUnless(INTEGRATION_TESTS, "integration test")
def test_rum_transaction(self):
path = 'http://localhost:8000/test/e2e/general-usecase/bundle.js.map'
r = self.upload_sourcemap(file_name='bundle.js.map',
bundle_filepath=path,
service_version='1.0.0')
assert r.status_code == 403, r.status_code

self.load_docs_with_template(self.get_transaction_payload_path(),
self.intake_url,
'transaction',
2)
rs = self.es.search(index=self.index_span, params={"rest_total_hits_as_int": "true"})
assert rs['hits']['total'] == 1, "found {} documents, expected {}".format(
rs['hits']['total'], 1)
frames_checked = 0
for doc in rs['hits']['hits']:
span = doc["_source"]["span"]
for frame in span["stacktrace"]:
frames_checked += 1
assert "sourcemap" not in frame, frame
assert frames_checked > 0, "no frames checked"


class ExpvarDisabledIntegrationTest(ExpvarBaseTest):
config_overrides = {"expvar_enabled": "false"}

Expand Down

0 comments on commit ee24fea

Please sign in to comment.