forked from mpobrien/perf
/
perf.go
67 lines (59 loc) · 1.85 KB
/
perf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package git
import (
"fmt"
"github.com/evergreen-ci/evergreen/plugin"
"github.com/evergreen-ci/evergreen/util"
"github.com/mitchellh/mapstructure"
"html/template"
"io/ioutil"
"net/http"
)
func init() {
plugin.Publish(&PerfPlugin{})
}
var includes = []template.HTML{
`<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3.min.js"></script>`,
`<script src="//cdnjs.cloudflare.com/ajax/libs/rickshaw/1.5.1/rickshaw.js"></script>`,
`<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/rickshaw/1.5.1/rickshaw.css">`,
`<script type="text/javascript" src="/plugin/perf/static/js/perf.js"></script>`,
}
// PerfPlugin displays performance statistics in the UI.
type PerfPlugin struct {
Projects []string `yaml:"string"`
}
// Name implements Plugin Interface.
func (pp *PerfPlugin) Name() string {
return "perf"
}
func (pp *PerfPlugin) GetUIHandler() http.Handler { return nil }
func (pp *PerfPlugin) Configure(params map[string]interface{}) error {
err := mapstructure.Decode(params, pp)
if err != nil {
return fmt.Errorf("error decoding %v params: %v", pp.Name(), err)
}
return nil
}
func (pp *PerfPlugin) GetPanelConfig() (*plugin.PanelConfig, error) {
root := plugin.StaticWebRootFromSourceFile()
panelHTML, err := ioutil.ReadFile(root + "/task_perf_data.html")
if err != nil {
return nil, fmt.Errorf("Can't load panel html file: %v", err)
}
return &plugin.PanelConfig{
StaticRoot: plugin.StaticWebRootFromSourceFile(),
Panels: []plugin.UIPanel{
{
Includes: includes,
Page: plugin.TaskPage,
Position: plugin.PageCenter,
PanelHTML: template.HTML(panelHTML),
DataFunc: func(context plugin.UIContext) (interface{}, error) {
return struct {
Enabled bool `json:"enabled"`
}{util.SliceContains(pp.Projects, context.ProjectRef.Identifier)}, nil
},
},
},
}, nil
return nil, nil
}