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
20284f77
Commit
20284f77
authored
Dec 20, 2017
by
Carl Bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge backend datasources and datasources
parent
8b37e27d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
97 deletions
+23
-97
pkg/plugins/backend_datasource.go
+0
-85
pkg/plugins/datasource_plugin.go
+15
-2
pkg/plugins/plugins.go
+8
-10
No files found.
pkg/plugins/backend_datasource.go
deleted
100644 → 0
View file @
8b37e27d
package
plugins
import
(
"context"
"encoding/json"
"os/exec"
"path"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/plugins/backend"
"github.com/grafana/grafana/pkg/tsdb"
"github.com/grafana/grafana/pkg/log"
proto
"github.com/grafana/grafana/pkg/tsdb/models"
shared
"github.com/grafana/grafana/pkg/tsdb/models/proxy"
plugin
"github.com/hashicorp/go-plugin"
)
type
BackendDatasource
struct
{
*
PluginBase
Executable
string
log
log
.
Logger
client
*
plugin
.
Client
}
var
handshakeConfig
=
plugin
.
HandshakeConfig
{
ProtocolVersion
:
1
,
MagicCookieKey
:
"GRAFANA_BACKEND_DATASOURCE"
,
MagicCookieValue
:
"55d2200a-6492-493a-9353-73b728d468aa"
,
}
func
(
p
*
BackendDatasource
)
initBackendPlugin
(
log
log
.
Logger
)
error
{
p
.
log
=
log
.
New
(
"plugin-id"
,
p
.
Id
)
p
.
client
=
plugin
.
NewClient
(
&
plugin
.
ClientConfig
{
HandshakeConfig
:
handshakeConfig
,
Plugins
:
map
[
string
]
plugin
.
Plugin
{
p
.
Id
:
&
shared
.
TsdbPluginImpl
{}},
Cmd
:
exec
.
Command
(
path
.
Join
(
p
.
PluginDir
,
p
.
Executable
)),
AllowedProtocols
:
[]
plugin
.
Protocol
{
plugin
.
ProtocolGRPC
},
Logger
:
backend
.
LogWrapper
{
Logger
:
p
.
log
},
})
rpcClient
,
err
:=
p
.
client
.
Client
()
if
err
!=
nil
{
return
err
}
raw
,
err
:=
rpcClient
.
Dispense
(
p
.
Id
)
if
err
!=
nil
{
return
err
}
plugin
:=
raw
.
(
shared
.
TsdbPlugin
)
response
,
err
:=
plugin
.
Query
(
context
.
Background
(),
&
proto
.
TsdbQuery
{})
if
err
!=
nil
{
p
.
log
.
Error
(
"Response from plugin. "
,
"response"
,
response
)
}
else
{
p
.
log
.
Info
(
"Response from plugin. "
,
"response"
,
response
)
}
tsdb
.
RegisterTsdbQueryEndpoint
(
p
.
Id
,
func
(
dsInfo
*
models
.
DataSource
)
(
tsdb
.
TsdbQueryEndpoint
,
error
)
{
return
&
shared
.
TsdbWrapper
{
TsdbPlugin
:
plugin
},
nil
})
return
nil
}
func
(
p
*
BackendDatasource
)
Kill
()
{
p
.
client
.
Kill
()
}
func
(
p
*
BackendDatasource
)
Load
(
decoder
*
json
.
Decoder
,
pluginDir
string
)
error
{
if
err
:=
decoder
.
Decode
(
&
p
);
err
!=
nil
{
return
err
}
if
err
:=
p
.
registerPlugin
(
pluginDir
);
err
!=
nil
{
return
err
}
BackendDatasources
[
p
.
Id
]
=
p
return
nil
}
pkg/plugins/datasource_plugin.go
View file @
20284f77
...
...
@@ -2,10 +2,13 @@ package plugins
import
(
"encoding/json"
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strings"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/models"
...
...
@@ -55,13 +58,21 @@ func (p *DataSourcePlugin) Load(decoder *json.Decoder, pluginDir string) error {
return
nil
}
var
handshakeConfig
=
plugin
.
HandshakeConfig
{
ProtocolVersion
:
1
,
MagicCookieKey
:
"GRAFANA_BACKEND_DATASOURCE"
,
MagicCookieValue
:
"55d2200a-6492-493a-9353-73b728d468aa"
,
}
func
(
p
*
DataSourcePlugin
)
initBackendPlugin
(
log
log
.
Logger
)
error
{
p
.
log
=
log
.
New
(
"plugin-id"
,
p
.
Id
)
cmd
:=
path
.
Join
(
p
.
PluginDir
,
fmt
.
Sprintf
(
"%s_%s_%s"
,
p
.
Executable
,
strings
.
ToLower
(
runtime
.
GOOS
),
strings
.
ToLower
(
runtime
.
GOARCH
)))
p
.
client
=
plugin
.
NewClient
(
&
plugin
.
ClientConfig
{
HandshakeConfig
:
handshakeConfig
,
Plugins
:
map
[
string
]
plugin
.
Plugin
{
p
.
Id
:
&
shared
.
TsdbPluginImpl
{}},
Cmd
:
exec
.
Command
(
path
.
Join
(
p
.
PluginDir
,
p
.
Executable
)
),
Cmd
:
exec
.
Command
(
cmd
),
AllowedProtocols
:
[]
plugin
.
Protocol
{
plugin
.
ProtocolGRPC
},
Logger
:
backend
.
LogWrapper
{
Logger
:
p
.
log
},
})
...
...
@@ -86,5 +97,7 @@ func (p *DataSourcePlugin) initBackendPlugin(log log.Logger) error {
}
func
(
p
*
DataSourcePlugin
)
Kill
()
{
p
.
client
.
Kill
()
if
p
.
client
!=
nil
{
p
.
client
.
Kill
()
}
}
pkg/plugins/plugins.go
View file @
20284f77
...
...
@@ -18,13 +18,13 @@ import (
)
var
(
DataSources
map
[
string
]
*
DataSourcePlugin
Panels
map
[
string
]
*
PanelPlugin
StaticRoutes
[]
*
PluginStaticRoute
Apps
map
[
string
]
*
AppPlugin
Plugins
map
[
string
]
*
PluginBase
BackendDatasources
map
[
string
]
*
BackendDatasource
PluginTypes
map
[
string
]
interface
{}
DataSources
map
[
string
]
*
DataSourcePlugin
Panels
map
[
string
]
*
PanelPlugin
StaticRoutes
[]
*
PluginStaticRoute
Apps
map
[
string
]
*
AppPlugin
Plugins
map
[
string
]
*
PluginBase
//
BackendDatasources map[string]*BackendDatasource
PluginTypes
map
[
string
]
interface
{}
GrafanaLatestVersion
string
GrafanaHasUpdate
bool
...
...
@@ -52,7 +52,7 @@ func NewPluginManager() (*PluginManager, error) {
func
(
p
*
PluginManager
)
Run
(
ctx
context
.
Context
)
error
{
<-
ctx
.
Done
()
for
_
,
p
:=
range
BackendDatas
ources
{
for
_
,
p
:=
range
DataS
ources
{
p
.
Kill
()
}
...
...
@@ -68,12 +68,10 @@ func Init() error {
Panels
=
make
(
map
[
string
]
*
PanelPlugin
)
Apps
=
make
(
map
[
string
]
*
AppPlugin
)
Plugins
=
make
(
map
[
string
]
*
PluginBase
)
BackendDatasources
=
make
(
map
[
string
]
*
BackendDatasource
)
PluginTypes
=
map
[
string
]
interface
{}{
"panel"
:
PanelPlugin
{},
"datasource"
:
DataSourcePlugin
{},
"app"
:
AppPlugin
{},
//"backend-datasource": BackendDatasource{},
}
plog
.
Info
(
"Starting plugin search"
)
...
...
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