mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Logging: sourcemap transform asset urls from CDN in logged stacktraces (#31115)
This commit is contained in:
parent
3303e28b38
commit
5c9a10d423
@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -45,8 +46,12 @@ func logSentryEventScenario(t *testing.T, desc string, event frontendlogging.Fro
|
|||||||
|
|
||||||
sc := setupScenarioContext(t, "/log")
|
sc := setupScenarioContext(t, "/log")
|
||||||
|
|
||||||
|
cdnRootURL, e := url.Parse("https://storage.googleapis.com/grafana-static-assets")
|
||||||
|
require.NoError(t, e)
|
||||||
|
|
||||||
cfg := &setting.Cfg{
|
cfg := &setting.Cfg{
|
||||||
StaticRootPath: "/staticroot",
|
StaticRootPath: "/staticroot",
|
||||||
|
CDNRootURL: cdnRootURL,
|
||||||
}
|
}
|
||||||
|
|
||||||
readSourceMap := func(dir string, path string) ([]byte, error) {
|
readSourceMap := func(dir string, path string) ([]byte, error) {
|
||||||
@ -252,6 +257,12 @@ func TestFrontendLoggingEndpoint(t *testing.T) {
|
|||||||
Lineno: 3,
|
Lineno: 3,
|
||||||
Colno: 10,
|
Colno: 10,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Function: "cdn",
|
||||||
|
Filename: "https://storage.googleapis.com/grafana-static-assets/grafana-oss/pre-releases/7.5.0-11925pre/public/build/foo.js", // source map found and mapped
|
||||||
|
Lineno: 3,
|
||||||
|
Colno: 10,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -268,8 +279,9 @@ func TestFrontendLoggingEndpoint(t *testing.T) {
|
|||||||
at explode (http://localhost:3000/public/build/error.js:3:10)
|
at explode (http://localhost:3000/public/build/error.js:3:10)
|
||||||
at wat (http://localhost:3000/public/build/bar.js:3:10)
|
at wat (http://localhost:3000/public/build/bar.js:3:10)
|
||||||
at nope (http://localhost:3000/baz.js:3:10)
|
at nope (http://localhost:3000/baz.js:3:10)
|
||||||
at fake (http://localhost:3000/public/build/../../secrets.txt:3:10)`)
|
at fake (http://localhost:3000/public/build/../../secrets.txt:3:10)
|
||||||
assert.Len(t, sourceMapReads, 5)
|
at ? (core|webpack:///./some_source.ts:3:2)`)
|
||||||
|
assert.Len(t, sourceMapReads, 6)
|
||||||
assert.Equal(t, "/staticroot", sourceMapReads[0].dir)
|
assert.Equal(t, "/staticroot", sourceMapReads[0].dir)
|
||||||
assert.Equal(t, "build/moo/foo.js.map", sourceMapReads[0].path)
|
assert.Equal(t, "build/moo/foo.js.map", sourceMapReads[0].path)
|
||||||
assert.Equal(t, "/usr/local/telepathic-panel", sourceMapReads[1].dir)
|
assert.Equal(t, "/usr/local/telepathic-panel", sourceMapReads[1].dir)
|
||||||
@ -280,6 +292,8 @@ func TestFrontendLoggingEndpoint(t *testing.T) {
|
|||||||
assert.Equal(t, "build/bar.js.map", sourceMapReads[3].path)
|
assert.Equal(t, "build/bar.js.map", sourceMapReads[3].path)
|
||||||
assert.Equal(t, "/staticroot", sourceMapReads[4].dir)
|
assert.Equal(t, "/staticroot", sourceMapReads[4].dir)
|
||||||
assert.Equal(t, "secrets.txt.map", sourceMapReads[4].path)
|
assert.Equal(t, "secrets.txt.map", sourceMapReads[4].path)
|
||||||
|
assert.Equal(t, "/staticroot", sourceMapReads[5].dir)
|
||||||
|
assert.Equal(t, "build/foo.js.map", sourceMapReads[5].path)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -68,13 +68,16 @@ func (store *SourceMapStore) guessSourceMapLocation(sourceURL string) (*sourceMa
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine if source comes from grafana core, look in public build dir
|
// determine if source comes from grafana core, locally or CDN, look in public build dir on fs
|
||||||
if strings.HasPrefix(u.Path, "/public/build/") {
|
if strings.HasPrefix(u.Path, "/public/build/") || (store.cfg.CDNRootURL != nil && strings.HasPrefix(sourceURL, store.cfg.CDNRootURL.String()) && strings.Contains(u.Path, "/public/build/")) {
|
||||||
return &sourceMapLocation{
|
pathParts := strings.SplitN(u.Path, "/public/build/", 2)
|
||||||
dir: store.cfg.StaticRootPath,
|
if len(pathParts) == 2 {
|
||||||
path: filepath.Join("build", u.Path[len("/public/build/"):]) + ".map",
|
return &sourceMapLocation{
|
||||||
pluginID: "",
|
dir: store.cfg.StaticRootPath,
|
||||||
}, nil
|
path: filepath.Join("build", pathParts[1]+".map"),
|
||||||
|
pluginID: "",
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
// if source comes from a plugin, look in plugin dir
|
// if source comes from a plugin, look in plugin dir
|
||||||
} else if strings.HasPrefix(u.Path, "/public/plugins/") {
|
} else if strings.HasPrefix(u.Path, "/public/plugins/") {
|
||||||
for _, route := range plugins.StaticRoutes {
|
for _, route := range plugins.StaticRoutes {
|
||||||
|
Loading…
Reference in New Issue
Block a user