Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/beater/beater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"net/http/httptest"
"os"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -76,6 +77,9 @@ func TestStoreUsesRUMElasticsearchConfig(t *testing.T) {
)
require.NoError(t, err)
defer cancel()

time.Sleep(1 * time.Second)

// Check that the provided rum elasticsearch config was used and
// Fetch() goes to the test server.
c, err := fetcher.Fetch(context.Background(), "app", "1.0", "/bundle/path")
Expand Down
8 changes: 0 additions & 8 deletions internal/sourcemap/chained.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package sourcemap
import (
"context"
"errors"
"time"

"github.com/go-sourcemap/sourcemap"
)
Expand All @@ -44,13 +43,6 @@ func (c ChainedFetcher) Fetch(ctx context.Context, name, version, path string) (
return consumer, err
}

// previous fetcher is unavailable but the deadline expired so we cannot reuse that
if t, _ := ctx.Deadline(); t.Before(time.Now()) {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(context.Background(), 500*time.Millisecond)
defer cancel()
}

// err is errFetcherUnvailable
// store it in a tmp variable and try the next fetcher
lastErr = err
Expand Down
8 changes: 4 additions & 4 deletions internal/sourcemap/metadata_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ func (s *MetadataESFetcher) startBackgroundSync(parent context.Context) {
go func() {
s.logger.Debug("populating metadata cache")

ctx, cancel := context.WithTimeout(parent, 1*time.Second)
err := s.ping(ctx)
cancel()
// the parent ctx does not have a deadline so we
// rely on the es client timeout (default 5s).
err := s.ping(parent)

if err != nil {
// it is fine to not lock here since err will not access
Expand All @@ -112,7 +112,7 @@ func (s *MetadataESFetcher) startBackgroundSync(parent context.Context) {
s.logger.Error(s.initErr)
} else {
// First run, populate cache
ctx, cancel = context.WithTimeout(parent, syncTimeout)
ctx, cancel := context.WithTimeout(parent, syncTimeout)
err := s.sync(ctx)
cancel()

Expand Down
2 changes: 2 additions & 0 deletions internal/sourcemap/sourcemap_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func (s *SourcemapFetcher) Fetch(ctx context.Context, name, version, path string
}
case <-ctx.Done():
return nil, fmt.Errorf("error waiting for metadata fetcher to be ready: %w", ctx.Err())
default:
return nil, fmt.Errorf("metadata fetcher is not ready: %w", errFetcherUnvailable)
}

if i, ok := s.metadata.getID(original); ok {
Expand Down
6 changes: 0 additions & 6 deletions systemtest/approvals/TestNoMatchingSourcemap.approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
"line": {
"column": 18,
"number": 1
},
"sourcemap": {
"error": "unable to find sourcemap.url for service.name=apm-agent-js service.version=1.0.0 bundle.path=http://subdomain1.localhost:8000/test/e2e/general-usecase/bundle.js.map"
}
},
{
Expand All @@ -65,9 +62,6 @@
"line": {
"column": 18,
"number": 1
},
"sourcemap": {
"error": "unable to find sourcemap.url for service.name=apm-agent-js service.version=1.0.0 bundle.path=http://subdomain2.localhost:8000/test/e2e/general-usecase/bundle.js.map"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,6 @@
"line": {
"column": 9,
"number": 7662
},
"sourcemap": {
"error": "unable to find sourcemap.url for service.name=apm-a-rum-test-e2e-general-usecase service.version=0.0.1 bundle.path=http://localhost:8000/test/e2e/general-usecase/app.e2e-bundle.min.js"
}
},
{
Expand All @@ -450,9 +447,6 @@
"line": {
"column": 3,
"number": 7666
},
"sourcemap": {
"error": "unable to find sourcemap.url for service.name=apm-a-rum-test-e2e-general-usecase service.version=0.0.1 bundle.path=http://localhost:8000/test/e2e/general-usecase/app.e2e-bundle.min.js"
}
}
],
Expand Down
10 changes: 0 additions & 10 deletions systemtest/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package systemtest
import (
"context"
"net/url"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -102,15 +101,6 @@ func cleanupElasticsearch() error {
},
ExpandWildcards: "all",
}, nil)
if err != nil {
return err
}

_, err = Elasticsearch.Do(context.Background(), &esapi.DeleteByQueryRequest{
Index: []string{".apm-source-map"},
Body: strings.NewReader(`{"query": { "match_all": {}}}`),
Conflicts: "proceed",
}, nil)
return err
}

Expand Down
22 changes: 22 additions & 0 deletions systemtest/kibana.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,5 +314,27 @@ func CreateSourceMap(t testing.TB, sourcemap []byte, serviceName, serviceVersion
Value: id,
})

t.Cleanup(func() {
DeleteSourceMap(t, result.ID)
})

return result.ID
}

// DeleteSourceMap deletes a source map with the given ID.
func DeleteSourceMap(t testing.TB, id string) {
t.Helper()

url := *KibanaURL
url.Path += "/api/apm/sourcemaps/" + id
req, _ := http.NewRequest("DELETE", url.String(), nil)
req.Header.Set("kbn-xsrf", "1")

resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close()

respBody, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode, string(respBody))
}
2 changes: 2 additions & 0 deletions systemtest/sourcemap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func TestNoMatchingSourcemap(t *testing.T) {

srv := apmservertest.NewUnstartedServerTB(t)
srv.Config.RUM = &apmservertest.RUMConfig{Enabled: true}
srv.Config.Kibana.Enabled = false
err = srv.Start()
require.NoError(t, err)

Expand Down Expand Up @@ -141,6 +142,7 @@ func TestSourcemapCaching(t *testing.T) {

srv := apmservertest.NewUnstartedServerTB(t)
srv.Config.RUM = &apmservertest.RUMConfig{Enabled: true}
srv.Config.Kibana.Enabled = false
err = srv.Start()
require.NoError(t, err)

Expand Down