Merge branch 'metrics-tab-v3'

This commit is contained in:
Torkel Ödegaard
2017-09-04 13:27:44 +02:00
35 changed files with 404 additions and 383 deletions
+1 -1
View File
@@ -209,7 +209,7 @@ func (hs *HttpServer) registerRoutes() {
r.Get("/plugins", wrap(GetPluginList))
r.Get("/plugins/:pluginId/settings", wrap(GetPluginSettingById))
r.Get("/plugins/:pluginId/readme", wrap(GetPluginReadme))
r.Get("/plugins/:pluginId/markdown/:name", wrap(GetPluginMarkdown))
r.Group("/plugins", func() {
r.Get("/:pluginId/dashboards/", wrap(GetPluginDashboards))
+4 -3
View File
@@ -147,15 +147,16 @@ func GetPluginDashboards(c *middleware.Context) Response {
}
}
func GetPluginReadme(c *middleware.Context) Response {
func GetPluginMarkdown(c *middleware.Context) Response {
pluginId := c.Params(":pluginId")
name := c.Params(":name")
if content, err := plugins.GetPluginReadme(pluginId); err != nil {
if content, err := plugins.GetPluginMarkdown(pluginId, name); err != nil {
if notfound, ok := err.(plugins.PluginNotFoundError); ok {
return ApiError(404, notfound.Error(), nil)
}
return ApiError(500, "Could not get readme", err)
return ApiError(500, "Could not get markdown file", err)
} else {
return Respond(200, content)
}
+23 -7
View File
@@ -1,15 +1,22 @@
package plugins
import "encoding/json"
import (
"encoding/json"
"os"
"path/filepath"
)
type DataSourcePlugin struct {
FrontendPluginBase
Annotations bool `json:"annotations"`
Metrics bool `json:"metrics"`
Alerting bool `json:"alerting"`
BuiltIn bool `json:"builtIn"`
Mixed bool `json:"mixed"`
Routes []*AppPluginRoute `json:"routes"`
Annotations bool `json:"annotations"`
Metrics bool `json:"metrics"`
Alerting bool `json:"alerting"`
QueryOptions map[string]bool `json:"queryOptions,omitempty"`
BuiltIn bool `json:"builtIn,omitempty"`
Mixed bool `json:"mixed,omitempty"`
HasQueryHelp bool `json:"hasQueryHelp,omitempty"`
Routes []*AppPluginRoute `json:"-"`
}
func (p *DataSourcePlugin) Load(decoder *json.Decoder, pluginDir string) error {
@@ -21,6 +28,15 @@ func (p *DataSourcePlugin) Load(decoder *json.Decoder, pluginDir string) error {
return err
}
// look for help markdown
helpPath := filepath.Join(p.PluginDir, "QUERY_HELP.md")
if _, err := os.Stat(helpPath); os.IsNotExist(err) {
helpPath = filepath.Join(p.PluginDir, "query_help.md")
}
if _, err := os.Stat(helpPath); err == nil {
p.HasQueryHelp = true
}
DataSources[p.Id] = p
return nil
}
+2 -5
View File
@@ -38,8 +38,8 @@ type PluginBase struct {
Includes []*PluginInclude `json:"includes"`
Module string `json:"module"`
BaseUrl string `json:"baseUrl"`
HideFromList bool `json:"hideFromList"`
State string `json:"state"`
HideFromList bool `json:"hideFromList,omitempty"`
State string `json:"state,omitempty"`
IncludedInAppId string `json:"-"`
PluginDir string `json:"-"`
@@ -48,9 +48,6 @@ type PluginBase struct {
GrafanaNetVersion string `json:"-"`
GrafanaNetHasUpdate bool `json:"-"`
// cache for readme file contents
Readme []byte `json:"-"`
}
func (pb *PluginBase) registerPlugin(pluginDir string) error {
+9 -14
View File
@@ -3,6 +3,7 @@ package plugins
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path"
@@ -166,30 +167,24 @@ func (scanner *PluginScanner) loadPluginJson(pluginJsonFilePath string) error {
return loader.Load(jsonParser, currentDir)
}
func GetPluginReadme(pluginId string) ([]byte, error) {
func GetPluginMarkdown(pluginId string, name string) ([]byte, error) {
plug, exists := Plugins[pluginId]
if !exists {
return nil, PluginNotFoundError{pluginId}
}
if plug.Readme != nil {
return plug.Readme, nil
path := filepath.Join(plug.PluginDir, fmt.Sprintf("%s.md", strings.ToUpper(name)))
if _, err := os.Stat(path); os.IsNotExist(err) {
path = filepath.Join(plug.PluginDir, fmt.Sprintf("%s.md", strings.ToLower(name)))
}
readmePath := filepath.Join(plug.PluginDir, "README.md")
if _, err := os.Stat(readmePath); os.IsNotExist(err) {
readmePath = filepath.Join(plug.PluginDir, "readme.md")
if _, err := os.Stat(path); os.IsNotExist(err) {
return make([]byte, 0), nil
}
if _, err := os.Stat(readmePath); os.IsNotExist(err) {
plug.Readme = make([]byte, 0)
return plug.Readme, nil
}
if readmeBytes, err := ioutil.ReadFile(readmePath); err != nil {
if data, err := ioutil.ReadFile(path); err != nil {
return nil, err
} else {
plug.Readme = readmeBytes
return plug.Readme, nil
return data, nil
}
}