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
9fc91b7a
Commit
9fc91b7a
authored
Oct 08, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed gofmt issue
parent
04eefb84
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
28 deletions
+30
-28
pkg/api/cloudwatch/metrics.go
+0
-0
pkg/api/dataproxy.go
+20
-7
pkg/middleware/logger.go
+10
-21
No files found.
pkg/api/cloudwatch/metrics.go
View file @
9fc91b7a
This diff is collapsed.
Click to expand it.
pkg/api/dataproxy.go
View file @
9fc91b7a
...
...
@@ -64,17 +64,30 @@ func NewReverseProxy(ds *m.DataSource, proxyPath string, targetUrl *url.URL) *ht
return
&
httputil
.
ReverseProxy
{
Director
:
director
}
}
//ProxyDataSourceRequest TODO need to cache datasources
func
ProxyDataSourceRequest
(
c
*
middleware
.
Context
)
{
id
:=
c
.
ParamsInt64
(
":id"
)
query
:=
m
.
GetDataSourceByIdQuery
{
Id
:
id
,
OrgId
:
c
.
OrgId
}
var
dsMap
map
[
int64
]
*
m
.
DataSource
=
make
(
map
[
int64
]
*
m
.
DataSource
)
func
getDatasource
(
id
int64
,
orgId
int64
)
(
*
m
.
DataSource
,
error
)
{
// ds, exists := dsMap[id]
// if exists && ds.OrgId == orgId {
// return ds, nil
// }
query
:=
m
.
GetDataSourceByIdQuery
{
Id
:
id
,
OrgId
:
orgId
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
nil
,
err
}
dsMap
[
id
]
=
&
query
.
Result
return
&
query
.
Result
,
nil
}
func
ProxyDataSourceRequest
(
c
*
middleware
.
Context
)
{
ds
,
err
:=
getDatasource
(
c
.
ParamsInt64
(
":id"
),
c
.
OrgId
)
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Unable to load datasource meta data"
,
err
)
return
}
ds
:=
query
.
Result
targetUrl
,
_
:=
url
.
Parse
(
ds
.
Url
)
if
len
(
setting
.
DataProxyWhiteList
)
>
0
{
if
_
,
exists
:=
setting
.
DataProxyWhiteList
[
targetUrl
.
Host
];
!
exists
{
...
...
@@ -83,11 +96,11 @@ func ProxyDataSourceRequest(c *middleware.Context) {
}
}
if
query
.
Result
.
Type
==
m
.
DS_CLOUDWATCH
{
if
ds
.
Type
==
m
.
DS_CLOUDWATCH
{
cloudwatch
.
HandleRequest
(
c
)
}
else
{
proxyPath
:=
c
.
Params
(
"*"
)
proxy
:=
NewReverseProxy
(
&
ds
,
proxyPath
,
targetUrl
)
proxy
:=
NewReverseProxy
(
ds
,
proxyPath
,
targetUrl
)
proxy
.
Transport
=
dataProxyTransport
proxy
.
ServeHTTP
(
c
.
RW
(),
c
.
Req
.
Request
)
}
...
...
pkg/middleware/logger.go
View file @
9fc91b7a
...
...
@@ -18,20 +18,12 @@ package middleware
import
(
"fmt"
"net/http"
"runtime"
"time"
"github.com/Unknwon/macaron"
"github.com/grafana/grafana/pkg/log"
)
var
isWindows
bool
func
init
()
{
isWindows
=
runtime
.
GOOS
==
"windows"
}
// Logger returns a middleware handler that logs the request as it goes in and the response as it goes out.
func
Logger
()
macaron
.
Handler
{
return
func
(
res
http
.
ResponseWriter
,
req
*
http
.
Request
,
c
*
macaron
.
Context
)
{
start
:=
time
.
Now
()
...
...
@@ -40,20 +32,17 @@ func Logger() macaron.Handler {
c
.
Next
()
content
:=
fmt
.
Sprintf
(
"Completed %s %v %s in %v"
,
req
.
URL
.
Path
,
rw
.
Status
(),
http
.
StatusText
(
rw
.
Status
()),
time
.
Since
(
start
))
if
!
isWindows
{
switch
rw
.
Status
()
{
case
200
:
content
=
fmt
.
Sprintf
(
"
\0
33[1;32m%s
\0
33[0m"
,
content
)
return
case
304
:
//content = fmt.Sprintf("\033[1;33m%s\033[0m", content)
return
case
404
:
content
=
fmt
.
Sprintf
(
"
\0
33[1;31m%s
\0
33[0m"
,
content
)
case
500
:
content
=
fmt
.
Sprintf
(
"
\0
33[1;36m%s
\0
33[0m"
,
content
)
}
switch
rw
.
Status
()
{
case
200
,
304
:
content
=
fmt
.
Sprintf
(
"%s"
,
content
)
return
case
404
:
content
=
fmt
.
Sprintf
(
"%s"
,
content
)
case
500
:
content
=
fmt
.
Sprintf
(
"%s"
,
content
)
}
log
.
Info
(
content
)
}
}
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