Commit ce4beb73 by bergquist

Review tsdb protobuf contract

parent 1fd40a48
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{},
}
......
......@@ -3,39 +3,35 @@ option go_package = "proto";
package plugins;
import "google/protobuf/timestamp.proto";
message TsdbQuery {
Timerange timerange = 1;
TimeRange timeRange = 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 {
......
......@@ -11,14 +11,14 @@ func NewTimeRange(from, to string) *TimeRange {
return &TimeRange{
From: from,
To: to,
Now: time.Now(),
now: time.Now(),
}
}
type TimeRange struct {
From string
To string
Now time.Time
now time.Time
}
func (tr *TimeRange) GetFromAsMsEpoch() int64 {
......@@ -65,12 +65,12 @@ func (tr *TimeRange) ParseFrom() (time.Time, error) {
return time.Time{}, err
}
return tr.Now.Add(diff), nil
return tr.now.Add(diff), nil
}
func (tr *TimeRange) ParseTo() (time.Time, error) {
if tr.To == "now" {
return tr.Now, nil
return tr.now, 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.Now.Add(diff), nil
return tr.now.Add(diff), nil
}
if res, ok := tryParseUnixMsEpoch(tr.To); ok {
......
......@@ -16,7 +16,7 @@ func TestTimeRange(t *testing.T) {
tr := TimeRange{
From: "5m",
To: "now",
Now: now,
now: now,
}
Convey("5m ago ", func() {
......@@ -39,7 +39,7 @@ func TestTimeRange(t *testing.T) {
tr := TimeRange{
From: "5h",
To: "now-10m",
Now: now,
now: now,
}
Convey("5h ago ", func() {
......@@ -65,7 +65,7 @@ func TestTimeRange(t *testing.T) {
tr := TimeRange{
From: "1474973725473",
To: "1474975757930",
Now: now,
now: now,
}
res, err := tr.ParseFrom()
......@@ -82,7 +82,7 @@ func TestTimeRange(t *testing.T) {
tr := TimeRange{
From: "asdf",
To: "asdf",
Now: now,
now: now,
}
_, err = tr.ParseFrom()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment