Skip to content

Commit

Permalink
index the url path only of the sourcemaps (elastic#1661)
Browse files Browse the repository at this point in the history
* Index the url path only of the sourcemaps, so that sourcemapping works eg. with many subdomains

* Skip flaky test
  • Loading branch information
jalvz committed Jan 16, 2019
1 parent 870234a commit 79066ed
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 3 deletions.
1 change: 1 addition & 0 deletions beater/server_test.go
Expand Up @@ -425,6 +425,7 @@ func TestServerSourcemapElasticsearch(t *testing.T) {
}

func TestServerSSL(t *testing.T) {
t.Skip("flaky test in go 1.11")
tests := []struct {
label string
domain string
Expand Down
1 change: 1 addition & 0 deletions changelogs/head.asciidoc
Expand Up @@ -12,6 +12,7 @@ https://github.com/elastic/apm-server/compare/6.5\...6.x[View commits]
- Add `transaction.sampled` to errors {pull}1662[1662].
- Remove formatting of `duration.us` to milliseconds in index pattern pull{1717}[1717].
- Allow numbers and boolean values for `transaction.tags`, `span.tags`, `metricset.tags` {pull}1712[1712].
- Lookup sourcemaps by full URL and URL path only {pull}1661[1661].

[float]
==== Removed
Expand Down
2 changes: 1 addition & 1 deletion model/sourcemap/payload.go
Expand Up @@ -78,7 +78,7 @@ func (pa *Sourcemap) Transform(tctx *transform.Context) []beat.Event {
Fields: common.MapStr{
"processor": processorEntry,
smapDocType: common.MapStr{
"bundle_filepath": pa.BundleFilepath,
"bundle_filepath": utility.UrlPath(pa.BundleFilepath),
"service": common.MapStr{"name": pa.ServiceName, "version": pa.ServiceVersion},
"sourcemap": pa.Sourcemap,
},
Expand Down
18 changes: 17 additions & 1 deletion sourcemap/elasticsearch.go
Expand Up @@ -22,6 +22,8 @@ import (
"fmt"
"sync"

"github.com/elastic/apm-server/utility"

"github.com/go-sourcemap/sourcemap"

"github.com/elastic/beats/libbeat/common"
Expand Down Expand Up @@ -104,14 +106,28 @@ func query(id Id) map[string]interface{} {
"bool": map[string]interface{}{
"must": []map[string]interface{}{
{"term": map[string]interface{}{"processor.name": "sourcemap"}},
{"term": map[string]interface{}{"sourcemap.bundle_filepath": id.Path}},
{"term": map[string]interface{}{"sourcemap.service.name": id.ServiceName}},
{"term": map[string]interface{}{"sourcemap.service.version": id.ServiceVersion}},
{"bool": map[string]interface{}{
"should": []map[string]interface{}{
{"term": map[string]interface{}{"sourcemap.bundle_filepath": map[string]interface{}{
"value": id.Path,
// prefer full url match
"boost": 2.0,
}}},
{"term": map[string]interface{}{"sourcemap.bundle_filepath": utility.UrlPath(id.Path)}},
},
}},
},
},
},
"size": 1,
"sort": []map[string]interface{}{
{
"_score": map[string]interface{}{
"order": "desc",
},
},
{
"@timestamp": map[string]interface{}{
"order": "desc",
Expand Down
5 changes: 4 additions & 1 deletion tests/system/apmserver.py
Expand Up @@ -226,11 +226,14 @@ def get_elasticsearch_url(self):
)

def load_docs_with_template(self, data_path, url, endpoint, expected_events_count, query_index=None):
payload = json.loads(open(data_path).read())
return self.load_payload_with_template(payload, url, endpoint, expected_events_count, query_index)

def load_payload_with_template(self, payload, url, endpoint, expected_events_count, query_index=None):

if query_index is None:
query_index = self.index_name

payload = json.loads(open(data_path).read())
r = requests.post(url, json=payload)
assert r.status_code == 202

Expand Down
21 changes: 21 additions & 0 deletions tests/system/test_integration.py
Expand Up @@ -366,6 +366,27 @@ def test_rum_transaction(self):
self.assert_no_logged_warnings()
self.check_rum_transaction_sourcemap(True)

@unittest.skipUnless(INTEGRATION_TESTS, "integration test")
def test_rum_transaction_different_subdomain(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 == 202, r.status_code
self.wait_for_sourcemaps()

payload = json.loads(open(self.get_transaction_payload_path()).read())
for idx, stacktrace in enumerate(payload['transactions'][0]['spans'][0]['stacktrace']):
stacktrace['abs_path'] = stacktrace['abs_path'].replace("localhost", "subdomain.localhost")
payload['transactions'][0]['spans'][0]['stacktrace'][idx] = stacktrace

self.load_payload_with_template(payload,
self.transactions_url,
'transaction',
2)
self.assert_no_logged_warnings()
self.check_rum_transaction_sourcemap(True)

@unittest.skipUnless(INTEGRATION_TESTS, "integration test")
def test_no_sourcemap(self):
self.load_docs_with_template(self.get_error_payload_path(),
Expand Down
8 changes: 8 additions & 0 deletions utility/common.go
Expand Up @@ -22,6 +22,14 @@ import (
"path"
)

func UrlPath(p string) string {
url, err := url.Parse(p)
if err != nil {
return p
}
return url.Path
}

func CleanUrlPath(p string) string {
url, err := url.Parse(p)
if err != nil {
Expand Down

0 comments on commit 79066ed

Please sign in to comment.