Skip to content

Commit 3e41f8d

Browse files
committed
[db] Add meta back to client interface
- it is needed by generator in xephon-b
1 parent c0f702d commit 3e41f8d

File tree

7 files changed

+149
-8
lines changed

7 files changed

+149
-8
lines changed

database/akumuli/client/pkg.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
package client
22

33
import (
4+
"github.com/libtsdb/libtsdb-go/database"
5+
"github.com/libtsdb/libtsdb-go/database/akumuli"
46
"github.com/libtsdb/libtsdb-go/database/akumuli/config"
57
"github.com/libtsdb/libtsdb-go/protocol"
68
)
79

8-
func NewAkumuliClient(cfg config.AkumuliClientConfig) (*protocol.TCPClient, error) {
9-
return protocol.NewTCPClient(NewAkumuliEncoder(), cfg.Addr, cfg.Timeout)
10+
type AkumuliClient struct {
11+
*protocol.TCPClient
12+
meta database.Meta
13+
}
14+
15+
func (c *AkumuliClient) Meta() database.Meta {
16+
return c.meta
17+
}
18+
19+
func NewAkumuliClient(cfg config.AkumuliClientConfig) (*AkumuliClient, error) {
20+
p, err := protocol.NewTCPClient(NewAkumuliEncoder(), cfg.Addr, cfg.Timeout)
21+
if err != nil {
22+
return nil, err
23+
}
24+
return &AkumuliClient{TCPClient: p, meta: akumuli.Meta()}, nil
1025
}

database/akumuli/meta.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package akumuli
2+
3+
import (
4+
"time"
5+
6+
"github.com/libtsdb/libtsdb-go/database"
7+
)
8+
9+
const (
10+
name = "akumuli"
11+
precision = time.Nanosecond
12+
)
13+
14+
var meta = database.Meta{
15+
Name: name,
16+
TimePrecision: time.Nanosecond,
17+
SupportTag: true,
18+
SupportInt: true, // TODO: the protocol support int, but is it stored as float?
19+
SupportDouble: true,
20+
SupportBatchSeries: true,
21+
SupportBatchPoints: false,
22+
}
23+
24+
func Meta() database.Meta {
25+
return meta
26+
}
27+
28+
func init() {
29+
database.RegisterMeta(name, meta)
30+
}

database/client.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
// TSBClient returns meta of the database including its protocol, data type support
1111
type TSDBClient interface {
12+
Meta() Meta
1213
Close() error
1314
}
1415

database/influxdb/client/pkg.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,22 @@ import (
55
"net/url"
66

77
"github.com/dyweb/gommon/errors"
8+
"github.com/libtsdb/libtsdb-go/database"
9+
"github.com/libtsdb/libtsdb-go/database/influxdb"
810
"github.com/libtsdb/libtsdb-go/database/influxdb/config"
911
"github.com/libtsdb/libtsdb-go/protocol"
1012
)
1113

12-
func NewInfluxDBClient(cfg config.InfluxdbClientConfig) (*protocol.HTTPClient, error) {
14+
type InfluxDBClient struct {
15+
*protocol.HTTPClient
16+
meta database.Meta
17+
}
18+
19+
func (c *InfluxDBClient) Meta() database.Meta {
20+
return c.meta
21+
}
22+
23+
func NewInfluxDBClient(cfg config.InfluxdbClientConfig) (*InfluxDBClient, error) {
1324
u, err := url.Parse(cfg.Addr)
1425
if err != nil {
1526
return nil, errors.Wrap(err, "can't parse server address")
@@ -23,5 +34,5 @@ func NewInfluxDBClient(cfg config.InfluxdbClientConfig) (*protocol.HTTPClient, e
2334
baseReq.URL.RawQuery = params.Encode()
2435
baseReq.Header.Set("User-Agent", "libtsdb")
2536
c := protocol.NewHTTPClient(NewInfluxDBEncoder(), baseReq)
26-
return c, nil
37+
return &InfluxDBClient{HTTPClient: c, meta: influxdb.Meta()}, nil
2738
}

database/influxdb/meta.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package influxdb
2+
3+
import (
4+
"time"
5+
6+
"github.com/libtsdb/libtsdb-go/database"
7+
)
8+
9+
const (
10+
name = "influxdb"
11+
precision = time.Nanosecond
12+
)
13+
14+
var meta = database.Meta{
15+
Name: name,
16+
TimePrecision: precision,
17+
SupportTag: true,
18+
SupportInt: true,
19+
SupportDouble: true,
20+
SupportBatchSeries: true,
21+
SupportBatchPoints: false,
22+
}
23+
24+
func Meta() database.Meta {
25+
return meta
26+
}
27+
28+
func init() {
29+
database.RegisterMeta(name, meta)
30+
}

database/kairosdb/client/pkg.go

+28-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,31 @@ import (
55
"net/url"
66

77
"github.com/dyweb/gommon/errors"
8+
"github.com/libtsdb/libtsdb-go/database"
9+
"github.com/libtsdb/libtsdb-go/database/kairosdb"
810
"github.com/libtsdb/libtsdb-go/database/kairosdb/config"
911
"github.com/libtsdb/libtsdb-go/protocol"
1012
)
1113

12-
func NewKairosDBHTTPClient(cfg config.KairosdbClientConfig) (*protocol.HTTPClient, error) {
14+
type KairosDBHTTPClient struct {
15+
*protocol.HTTPClient
16+
meta database.Meta
17+
}
18+
19+
func (c *KairosDBHTTPClient) Meta() database.Meta {
20+
return c.meta
21+
}
22+
23+
type KairosDBTCPCLient struct {
24+
*protocol.TCPClient
25+
meta database.Meta
26+
}
27+
28+
func (c *KairosDBTCPCLient) Meta() database.Meta {
29+
return c.meta
30+
}
31+
32+
func NewKairosDBHTTPClient(cfg config.KairosdbClientConfig) (*KairosDBHTTPClient, error) {
1333
u, err := url.Parse(cfg.Addr)
1434
if err != nil {
1535
return nil, errors.Wrap(err, "can't parse server address")
@@ -19,9 +39,13 @@ func NewKairosDBHTTPClient(cfg config.KairosdbClientConfig) (*protocol.HTTPClien
1939
return nil, errors.Wrap(err, "can't create base query")
2040
}
2141
c := protocol.NewHTTPClient(NewKairosDBJSONEncoder(), baseReq)
22-
return c, nil
42+
return &KairosDBHTTPClient{HTTPClient: c, meta: kairosdb.Meta()}, nil
2343
}
2444

25-
func NewKairosDBTCPClient(cfg config.KairosdbClientConfig) (*protocol.TCPClient, error) {
26-
return protocol.NewTCPClient(NewKaiorsDBTelnetEncoder(), cfg.TelnetAddr, cfg.Timeout)
45+
func NewKairosDBTCPClient(cfg config.KairosdbClientConfig) (*KairosDBTCPCLient, error) {
46+
p, err := protocol.NewTCPClient(NewKaiorsDBTelnetEncoder(), cfg.TelnetAddr, cfg.Timeout)
47+
if err != nil {
48+
return nil, err
49+
}
50+
return &KairosDBTCPCLient{TCPClient: p, meta: kairosdb.Meta()}, nil
2751
}

database/kairosdb/meta.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package kairosdb
2+
3+
import (
4+
"time"
5+
6+
"github.com/libtsdb/libtsdb-go/database"
7+
)
8+
9+
const (
10+
name = "kairosdb"
11+
precision = time.Millisecond
12+
)
13+
14+
var meta = database.Meta{
15+
Name: name,
16+
TimePrecision: precision,
17+
SupportTag: true,
18+
SupportInt: true,
19+
SupportDouble: true,
20+
SupportBatchSeries: true,
21+
SupportBatchPoints: true,
22+
}
23+
24+
func Meta() database.Meta {
25+
return meta
26+
}
27+
28+
func init() {
29+
database.RegisterMeta(name, meta)
30+
}

0 commit comments

Comments
 (0)