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
a7c816c6
Commit
a7c816c6
authored
Dec 19, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Datasource proxy, switch to lookup by id
parent
a2a0e039
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
12 additions
and
13 deletions
+12
-13
pkg/api/api.go
+1
-1
pkg/api/api_config.go
+2
-1
pkg/api/api_dataproxy.go
+4
-6
pkg/models/datasource.go
+2
-2
pkg/stores/sqlstore/sqlstore_datasource.go
+3
-3
No files found.
pkg/api/api.go
View file @
a7c816c6
...
@@ -33,7 +33,7 @@ func Register(m *macaron.Macaron) {
...
@@ -33,7 +33,7 @@ func Register(m *macaron.Macaron) {
m
.
Delete
(
"/api/admin/datasources/:id"
,
auth
,
DeleteDataSource
)
m
.
Delete
(
"/api/admin/datasources/:id"
,
auth
,
DeleteDataSource
)
// data source proxy
// data source proxy
m
.
Any
(
"/api/datasources/proxy/:
name
/*"
,
auth
,
ProxyDataSourceRequest
)
m
.
Any
(
"/api/datasources/proxy/:
id
/*"
,
auth
,
ProxyDataSourceRequest
)
// user register
// user register
m
.
Get
(
"/register/*_"
,
Index
)
m
.
Get
(
"/register/*_"
,
Index
)
...
...
pkg/api/api_config.go
View file @
a7c816c6
...
@@ -2,6 +2,7 @@ package api
...
@@ -2,6 +2,7 @@ package api
import
(
import
(
"encoding/json"
"encoding/json"
"strconv"
"strings"
"strings"
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/bus"
...
@@ -27,7 +28,7 @@ func renderConfig(data *configJsTmplModel) string {
...
@@ -27,7 +28,7 @@ func renderConfig(data *configJsTmplModel) string {
for
_
,
ds
:=
range
data
.
DataSources
{
for
_
,
ds
:=
range
data
.
DataSources
{
url
:=
ds
.
Url
url
:=
ds
.
Url
if
ds
.
Access
==
m
.
DS_ACCESS_PROXY
{
if
ds
.
Access
==
m
.
DS_ACCESS_PROXY
{
url
=
"/api/datasources/proxy/"
+
ds
.
Name
url
=
"/api/datasources/proxy/"
+
strconv
.
FormatInt
(
ds
.
Id
,
10
)
}
}
datasources
[
ds
.
Name
]
=
map
[
string
]
interface
{}{
datasources
[
ds
.
Name
]
=
map
[
string
]
interface
{}{
"type"
:
ds
.
Type
,
"type"
:
ds
.
Type
,
...
...
pkg/api/api_dataproxy.go
View file @
a7c816c6
...
@@ -7,7 +7,6 @@ import (
...
@@ -7,7 +7,6 @@ import (
"strings"
"strings"
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/log"
"github.com/torkelo/grafana-pro/pkg/middleware"
"github.com/torkelo/grafana-pro/pkg/middleware"
m
"github.com/torkelo/grafana-pro/pkg/models"
m
"github.com/torkelo/grafana-pro/pkg/models"
)
)
...
@@ -36,18 +35,17 @@ func NewReverseProxy(target *url.URL, proxyPath string) *httputil.ReverseProxy {
...
@@ -36,18 +35,17 @@ func NewReverseProxy(target *url.URL, proxyPath string) *httputil.ReverseProxy {
}
else
{
}
else
{
req
.
URL
.
RawQuery
=
targetQuery
+
"&"
+
req
.
URL
.
RawQuery
req
.
URL
.
RawQuery
=
targetQuery
+
"&"
+
req
.
URL
.
RawQuery
}
}
log
.
Info
(
"Proxy: %v"
,
req
.
URL
.
Path
)
}
}
return
&
httputil
.
ReverseProxy
{
Director
:
director
}
return
&
httputil
.
ReverseProxy
{
Director
:
director
}
}
}
// TODO: need to cache datasources
// TODO: need to cache datasources
func
ProxyDataSourceRequest
(
c
*
middleware
.
Context
)
{
func
ProxyDataSourceRequest
(
c
*
middleware
.
Context
)
{
name
:=
c
.
Params
(
":name
"
)
id
:=
c
.
ParamsInt64
(
":id
"
)
query
:=
m
.
GetDataSourceBy
Name
Query
{
query
:=
m
.
GetDataSourceBy
Id
Query
{
Name
:
name
,
Id
:
id
,
AccountId
:
c
.
GetAccountId
(),
AccountId
:
c
.
GetAccountId
(),
}
}
...
...
pkg/models/datasource.go
View file @
a7c816c6
...
@@ -42,8 +42,8 @@ type GetDataSourcesQuery struct {
...
@@ -42,8 +42,8 @@ type GetDataSourcesQuery struct {
Result
[]
*
DataSource
Result
[]
*
DataSource
}
}
type
GetDataSourceBy
Name
Query
struct
{
type
GetDataSourceBy
Id
Query
struct
{
Name
string
Id
int64
AccountId
int64
AccountId
int64
Result
DataSource
Result
DataSource
}
}
...
...
pkg/stores/sqlstore/sqlstore_datasource.go
View file @
a7c816c6
...
@@ -14,11 +14,11 @@ func init() {
...
@@ -14,11 +14,11 @@ func init() {
bus
.
AddHandler
(
"sql"
,
AddDataSource
)
bus
.
AddHandler
(
"sql"
,
AddDataSource
)
bus
.
AddHandler
(
"sql"
,
DeleteDataSource
)
bus
.
AddHandler
(
"sql"
,
DeleteDataSource
)
bus
.
AddHandler
(
"sql"
,
UpdateDataSource
)
bus
.
AddHandler
(
"sql"
,
UpdateDataSource
)
bus
.
AddHandler
(
"sql"
,
GetDataSourceBy
Name
)
bus
.
AddHandler
(
"sql"
,
GetDataSourceBy
Id
)
}
}
func
GetDataSourceBy
Name
(
query
*
m
.
GetDataSourceByName
Query
)
error
{
func
GetDataSourceBy
Id
(
query
*
m
.
GetDataSourceById
Query
)
error
{
sess
:=
x
.
Limit
(
100
,
0
)
.
Where
(
"account_id=? AND
name=?"
,
query
.
AccountId
,
query
.
Name
)
sess
:=
x
.
Limit
(
100
,
0
)
.
Where
(
"account_id=? AND
id=?"
,
query
.
AccountId
,
query
.
Id
)
has
,
err
:=
sess
.
Get
(
&
query
.
Result
)
has
,
err
:=
sess
.
Get
(
&
query
.
Result
)
if
!
has
{
if
!
has
{
...
...
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