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
c7c5730c
Commit
c7c5730c
authored
Jul 31, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'v4.4.x'
parents
61d8eb1f
34cda659
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
16 deletions
+24
-16
pkg/api/render.go
+6
-2
pkg/components/renderer/renderer.go
+9
-6
vendor/phantomjs/render.js
+9
-8
No files found.
pkg/api/render.go
View file @
c7c5730c
...
...
@@ -18,14 +18,18 @@ func RenderToPng(c *middleware.Context) {
Width
:
queryReader
.
Get
(
"width"
,
"800"
),
Height
:
queryReader
.
Get
(
"height"
,
"400"
),
OrgId
:
c
.
OrgId
,
Timeout
:
queryReader
.
Get
(
"timeout"
,
"
3
0"
),
Timeout
:
queryReader
.
Get
(
"timeout"
,
"
6
0"
),
Timezone
:
queryReader
.
Get
(
"tz"
,
""
),
}
pngPath
,
err
:=
renderer
.
RenderToPng
(
renderOpts
)
if
err
!=
nil
{
c
.
Handle
(
500
,
"Failed to render to png"
,
err
)
if
err
==
renderer
.
ErrTimeout
{
c
.
Handle
(
500
,
err
.
Error
(),
err
)
}
c
.
Handle
(
500
,
"Rendering failed."
,
err
)
return
}
...
...
pkg/components/renderer/renderer.go
View file @
c7c5730c
package
renderer
import
(
"errors"
"fmt"
"io"
"os"
...
...
@@ -28,6 +29,7 @@ type RenderOpts struct {
Timezone
string
}
var
ErrTimeout
=
errors
.
New
(
"Timeout error. You can set timeout in seconds with &timeout url parameter"
)
var
rendererLog
log
.
Logger
=
log
.
New
(
"png-renderer"
)
func
isoTimeOffsetToPosixTz
(
isoOffset
string
)
string
{
...
...
@@ -75,6 +77,11 @@ func RenderToPng(params *RenderOpts) (string, error) {
renderKey
:=
middleware
.
AddRenderAuthKey
(
params
.
OrgId
)
defer
middleware
.
RemoveRenderAuthKey
(
renderKey
)
timeout
,
err
:=
strconv
.
Atoi
(
params
.
Timeout
)
if
err
!=
nil
{
timeout
=
15
}
cmdArgs
:=
[]
string
{
"--ignore-ssl-errors=true"
,
"--web-security=false"
,
...
...
@@ -84,6 +91,7 @@ func RenderToPng(params *RenderOpts) (string, error) {
"height="
+
params
.
Height
,
"png="
+
pngPath
,
"domain="
+
localDomain
,
"timeout="
+
strconv
.
Itoa
(
timeout
),
"renderKey="
+
renderKey
,
}
...
...
@@ -117,17 +125,12 @@ func RenderToPng(params *RenderOpts) (string, error) {
close
(
done
)
}()
timeout
,
err
:=
strconv
.
Atoi
(
params
.
Timeout
)
if
err
!=
nil
{
timeout
=
15
}
select
{
case
<-
time
.
After
(
time
.
Duration
(
timeout
)
*
time
.
Second
)
:
if
err
:=
cmd
.
Process
.
Kill
();
err
!=
nil
{
rendererLog
.
Error
(
"failed to kill"
,
"error"
,
err
)
}
return
""
,
fmt
.
Errorf
(
"PhantomRenderer::renderToPng timeout (>%vs)"
,
timeout
)
return
""
,
ErrTimeout
case
<-
done
:
}
...
...
vendor/phantomjs/render.js
View file @
c7c5730c
...
...
@@ -30,10 +30,12 @@
height
:
params
.
height
||
'400'
};
var
tries
=
0
;
var
timeoutMs
=
(
parseInt
(
params
.
timeout
)
||
10
)
*
1000
;
var
waitBetweenReadyCheckMs
=
50
;
var
totalWaitMs
=
0
;
page
.
open
(
params
.
url
,
function
(
status
)
{
// console.log('Loading a web page: ' + params.url + ' status: ' + statu
s);
console
.
log
(
'Loading a web page: '
+
params
.
url
+
' status: '
+
status
,
timeoutM
s
);
page
.
onError
=
function
(
msg
,
trace
)
{
var
msgStack
=
[
'ERROR: '
+
msg
];
...
...
@@ -59,7 +61,7 @@
return
rootScope
.
panelsRendered
>=
panels
;
});
if
(
panelsRendered
||
t
ries
===
1000
)
{
if
(
panelsRendered
||
t
otalWaitMs
>
timeoutMs
)
{
var
bb
=
page
.
evaluate
(
function
()
{
return
document
.
getElementsByClassName
(
"main-view"
)[
0
].
getBoundingClientRect
();
});
...
...
@@ -73,13 +75,12 @@
page
.
render
(
params
.
png
);
phantom
.
exit
();
}
else
{
tries
++
;
setTimeout
(
checkIsReady
,
10
);
}
else
{
totalWaitMs
+=
waitBetweenReadyCheckMs
;
setTimeout
(
checkIsReady
,
waitBetweenReadyCheckMs
);
}
}
setTimeout
(
checkIsReady
,
200
);
setTimeout
(
checkIsReady
,
waitBetweenReadyCheckMs
);
});
})();
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