datasource_plugin.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package plugins
  2. import (
  3. "encoding/json"
  4. "os"
  5. "path/filepath"
  6. )
  7. type DataSourcePlugin struct {
  8. FrontendPluginBase
  9. Annotations bool `json:"annotations"`
  10. Metrics bool `json:"metrics"`
  11. Alerting bool `json:"alerting"`
  12. QueryOptions map[string]bool `json:"queryOptions,omitempty"`
  13. BuiltIn bool `json:"builtIn,omitempty"`
  14. Mixed bool `json:"mixed,omitempty"`
  15. HasQueryHelp bool `json:"hasQueryHelp,omitempty"`
  16. Routes []*AppPluginRoute `json:"-"`
  17. }
  18. func (p *DataSourcePlugin) Load(decoder *json.Decoder, pluginDir string) error {
  19. if err := decoder.Decode(&p); err != nil {
  20. return err
  21. }
  22. if err := p.registerPlugin(pluginDir); err != nil {
  23. return err
  24. }
  25. // look for help markdown
  26. helpPath := filepath.Join(p.PluginDir, "QUERY_HELP.md")
  27. if _, err := os.Stat(helpPath); os.IsNotExist(err) {
  28. helpPath = filepath.Join(p.PluginDir, "query_help.md")
  29. }
  30. if _, err := os.Stat(helpPath); err == nil {
  31. p.HasQueryHelp = true
  32. }
  33. DataSources[p.Id] = p
  34. return nil
  35. }