Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
5c9a10d4
Unverified
Commit
5c9a10d4
authored
Feb 11, 2021
by
Domas
Committed by
GitHub
Feb 11, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Logging: sourcemap transform asset urls from CDN in logged stacktraces (#31115)
parent
3303e28b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
9 deletions
+26
-9
pkg/api/frontend_logging_test.go
+16
-2
pkg/api/frontendlogging/source_maps.go
+10
-7
No files found.
pkg/api/frontend_logging_test.go
View file @
5c9a10d4
...
...
@@ -4,6 +4,7 @@ import (
"errors"
"io/ioutil"
"net/http"
"net/url"
"os"
"strings"
"testing"
...
...
@@ -45,8 +46,12 @@ func logSentryEventScenario(t *testing.T, desc string, event frontendlogging.Fro
sc
:=
setupScenarioContext
(
t
,
"/log"
)
cdnRootURL
,
e
:=
url
.
Parse
(
"https://storage.googleapis.com/grafana-static-assets"
)
require
.
NoError
(
t
,
e
)
cfg
:=
&
setting
.
Cfg
{
StaticRootPath
:
"/staticroot"
,
CDNRootURL
:
cdnRootURL
,
}
readSourceMap
:=
func
(
dir
string
,
path
string
)
([]
byte
,
error
)
{
...
...
@@ -252,6 +257,12 @@ func TestFrontendLoggingEndpoint(t *testing.T) {
Lineno
:
3
,
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 wat (http://localhost:3000/public/build/bar.js:3:10)
at nope (http://localhost:3000/baz.js:3:10)
at fake (http://localhost:3000/public/build/../../secrets.txt:3:10)`
)
assert
.
Len
(
t
,
sourceMapReads
,
5
)
at fake (http://localhost:3000/public/build/../../secrets.txt:3:10)
at ? (core|webpack:///./some_source.ts:3:2)`
)
assert
.
Len
(
t
,
sourceMapReads
,
6
)
assert
.
Equal
(
t
,
"/staticroot"
,
sourceMapReads
[
0
]
.
dir
)
assert
.
Equal
(
t
,
"build/moo/foo.js.map"
,
sourceMapReads
[
0
]
.
path
)
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
,
"/staticroot"
,
sourceMapReads
[
4
]
.
dir
)
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
)
})
})
}
...
...
pkg/api/frontendlogging/source_maps.go
View file @
5c9a10d4
...
...
@@ -68,13 +68,16 @@ func (store *SourceMapStore) guessSourceMapLocation(sourceURL string) (*sourceMa
return
nil
,
err
}
// determine if source comes from grafana core, look in public build dir
if
strings
.
HasPrefix
(
u
.
Path
,
"/public/build/"
)
{
return
&
sourceMapLocation
{
dir
:
store
.
cfg
.
StaticRootPath
,
path
:
filepath
.
Join
(
"build"
,
u
.
Path
[
len
(
"/public/build/"
)
:
])
+
".map"
,
pluginID
:
""
,
},
nil
// determine if source comes from grafana core, locally or CDN, look in public build dir on fs
if
strings
.
HasPrefix
(
u
.
Path
,
"/public/build/"
)
||
(
store
.
cfg
.
CDNRootURL
!=
nil
&&
strings
.
HasPrefix
(
sourceURL
,
store
.
cfg
.
CDNRootURL
.
String
())
&&
strings
.
Contains
(
u
.
Path
,
"/public/build/"
))
{
pathParts
:=
strings
.
SplitN
(
u
.
Path
,
"/public/build/"
,
2
)
if
len
(
pathParts
)
==
2
{
return
&
sourceMapLocation
{
dir
:
store
.
cfg
.
StaticRootPath
,
path
:
filepath
.
Join
(
"build"
,
pathParts
[
1
]
+
".map"
),
pluginID
:
""
,
},
nil
}
// if source comes from a plugin, look in plugin dir
}
else
if
strings
.
HasPrefix
(
u
.
Path
,
"/public/plugins/"
)
{
for
_
,
route
:=
range
plugins
.
StaticRoutes
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment