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
ce4beb73
Commit
ce4beb73
authored
Jan 11, 2018
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Review tsdb protobuf contract
parent
1fd40a48
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
54 deletions
+36
-54
pkg/plugins/datasource/tsdb/datasource_plugin_wrapper.go
+11
-21
pkg/tsdb/models/tsdb_plugin.pb.go
+0
-0
pkg/tsdb/models/tsdb_plugin.proto
+16
-24
pkg/tsdb/time_range.go
+5
-5
pkg/tsdb/time_range_test.go
+4
-4
No files found.
pkg/plugins/datasource/tsdb/datasource_plugin_wrapper.go
View file @
ce4beb73
package
tsdb
import
(
"github.com/golang/protobuf/ptypes"
"github.com/grafana/grafana/pkg/components/null"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/tsdb"
...
...
@@ -19,28 +18,20 @@ func (tw *DatasourcePluginWrapper) Query(ctx context.Context, ds *models.DataSou
return
nil
,
err
}
now
,
err
:=
ptypes
.
TimestampProto
(
query
.
TimeRange
.
Now
)
if
err
!=
nil
{
return
nil
,
err
}
pbQuery
:=
&
proto
.
TsdbQuery
{
Datasource
:
&
proto
.
DatasourceInfo
{
Access
:
string
(
ds
.
Access
),
BasicAuth
:
ds
.
BasicAuth
,
BasicAuthUser
:
ds
.
BasicAuthUser
,
BasicAuthPassword
:
ds
.
BasicAuthPassword
,
JsonData
:
string
(
jsonData
),
Name
:
ds
.
Name
,
Type
:
ds
.
Type
,
Url
:
ds
.
Url
,
Id
:
ds
.
Id
,
OrgId
:
ds
.
OrgId
,
JsonData
:
string
(
jsonData
),
Name
:
ds
.
Name
,
Type
:
ds
.
Type
,
Url
:
ds
.
Url
,
Id
:
ds
.
Id
,
OrgId
:
ds
.
OrgId
,
},
Timerange
:
&
proto
.
Timerange
{
From
:
query
.
TimeRange
.
From
,
To
:
query
.
TimeRange
.
To
,
Now
:
now
,
TimeRange
:
&
proto
.
TimeRange
{
FromRaw
:
query
.
TimeRange
.
From
,
ToRaw
:
query
.
TimeRange
.
To
,
ToEpochMs
:
query
.
TimeRange
.
GetToAsMsEpoch
(),
FromEpochMs
:
query
.
TimeRange
.
GetFromAsMsEpoch
(),
},
Queries
:
[]
*
proto
.
Query
{},
}
...
...
@@ -63,7 +54,6 @@ func (tw *DatasourcePluginWrapper) Query(ctx context.Context, ds *models.DataSou
}
res
:=
&
tsdb
.
Response
{
Message
:
pbres
.
Message
,
Results
:
map
[
string
]
*
tsdb
.
QueryResult
{},
}
...
...
pkg/tsdb/models/tsdb_plugin.pb.go
View file @
ce4beb73
This diff is collapsed.
Click to expand it.
pkg/tsdb/models/tsdb_plugin.proto
View file @
ce4beb73
...
...
@@ -3,39 +3,35 @@ option go_package = "proto";
package
plugins
;
import
"google/protobuf/timestamp.proto"
;
message
TsdbQuery
{
Time
range
timer
ange
=
1
;
Time
Range
timeR
ange
=
1
;
DatasourceInfo
datasource
=
2
;
repeated
Query
queries
=
3
;
}
message
Query
{
string
refId
=
1
;
string
modelJson
=
2
;
int64
MaxDataPoints
=
3
;
int64
intervalMs
=
4
;
// dont repeat. DatasourceInfo datasource = 5;
int64
maxDataPoints
=
2
;
int64
intervalMs
=
3
;
string
modelJson
=
4
;
}
message
Timerange
{
string
from
=
1
;
string
to
=
2
;
google.protobuf.Timestamp
now
=
3
;
message
TimeRange
{
string
fromRaw
=
1
;
string
toRaw
=
2
;
int64
fromEpochMs
=
3
;
int64
toEpochMs
=
4
;
}
message
Response
{
string
message
=
1
;
map
<
string
,
QueryResult
>
results
=
2
;
repeated
QueryResult
results
=
1
;
}
message
QueryResult
{
string
error
=
1
;
string
errorString
=
2
;
string
refId
=
3
;
string
metaJson
=
4
;
repeated
TimeSeries
series
=
5
;
string
refId
=
2
;
string
metaJson
=
3
;
repeated
TimeSeries
series
=
4
;
//repeat Table tables = x;
}
...
...
@@ -45,13 +41,9 @@ message DatasourceInfo {
int64
orgId
=
2
;
string
name
=
3
;
string
type
=
4
;
string
access
=
5
;
string
url
=
6
;
bool
basicAuth
=
7
;
string
basicAuthUser
=
8
;
string
basicAuthPassword
=
9
;
string
jsonData
=
10
;
string
secureJsonData
=
11
;
string
url
=
5
;
string
jsonData
=
6
;
string
secureJsonData
=
7
;
}
message
TimeSeries
{
...
...
pkg/tsdb/time_range.go
View file @
ce4beb73
...
...
@@ -11,14 +11,14 @@ func NewTimeRange(from, to string) *TimeRange {
return
&
TimeRange
{
From
:
from
,
To
:
to
,
N
ow
:
time
.
Now
(),
n
ow
:
time
.
Now
(),
}
}
type
TimeRange
struct
{
From
string
To
string
N
ow
time
.
Time
n
ow
time
.
Time
}
func
(
tr
*
TimeRange
)
GetFromAsMsEpoch
()
int64
{
...
...
@@ -65,12 +65,12 @@ func (tr *TimeRange) ParseFrom() (time.Time, error) {
return
time
.
Time
{},
err
}
return
tr
.
N
ow
.
Add
(
diff
),
nil
return
tr
.
n
ow
.
Add
(
diff
),
nil
}
func
(
tr
*
TimeRange
)
ParseTo
()
(
time
.
Time
,
error
)
{
if
tr
.
To
==
"now"
{
return
tr
.
N
ow
,
nil
return
tr
.
n
ow
,
nil
}
else
if
strings
.
HasPrefix
(
tr
.
To
,
"now-"
)
{
withoutNow
:=
strings
.
Replace
(
tr
.
To
,
"now-"
,
""
,
1
)
...
...
@@ -79,7 +79,7 @@ func (tr *TimeRange) ParseTo() (time.Time, error) {
return
time
.
Time
{},
nil
}
return
tr
.
N
ow
.
Add
(
diff
),
nil
return
tr
.
n
ow
.
Add
(
diff
),
nil
}
if
res
,
ok
:=
tryParseUnixMsEpoch
(
tr
.
To
);
ok
{
...
...
pkg/tsdb/time_range_test.go
View file @
ce4beb73
...
...
@@ -16,7 +16,7 @@ func TestTimeRange(t *testing.T) {
tr
:=
TimeRange
{
From
:
"5m"
,
To
:
"now"
,
N
ow
:
now
,
n
ow
:
now
,
}
Convey
(
"5m ago "
,
func
()
{
...
...
@@ -39,7 +39,7 @@ func TestTimeRange(t *testing.T) {
tr
:=
TimeRange
{
From
:
"5h"
,
To
:
"now-10m"
,
N
ow
:
now
,
n
ow
:
now
,
}
Convey
(
"5h ago "
,
func
()
{
...
...
@@ -65,7 +65,7 @@ func TestTimeRange(t *testing.T) {
tr
:=
TimeRange
{
From
:
"1474973725473"
,
To
:
"1474975757930"
,
N
ow
:
now
,
n
ow
:
now
,
}
res
,
err
:=
tr
.
ParseFrom
()
...
...
@@ -82,7 +82,7 @@ func TestTimeRange(t *testing.T) {
tr
:=
TimeRange
{
From
:
"asdf"
,
To
:
"asdf"
,
N
ow
:
now
,
n
ow
:
now
,
}
_
,
err
=
tr
.
ParseFrom
()
...
...
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