Merge pull request #4299 from arussellsaw/feature/client-reject-uint64
Reject uint64 Client.Point.Field valuespull/5387/merge
commit
dc74bb53d0
|
@ -28,6 +28,7 @@ This release also changes how clusters are setup. The config file has changed so
|
|||
- [#5522](https://github.com/influxdata/influxdb/pull/5522): Optimize tsm1 cache to reduce memory consumption and GC scan time.
|
||||
|
||||
### Bugfixes
|
||||
- [#4299](https://github.com/influxdata/influxdb/pull/4299): Reject uint64 Client.Point.Field values
|
||||
- [#5129](https://github.com/influxdata/influxdb/pull/5129): Ensure precision flag is respected by CLI. Thanks @e-dard
|
||||
- [#5042](https://github.com/influxdb/influxdb/issues/5042): Count with fill(none) will drop 0 valued intervals.
|
||||
- [#4735](https://github.com/influxdb/influxdb/issues/4735): Fix panic when merging empty results.
|
||||
|
|
|
@ -206,6 +206,10 @@ func (c *Client) Write(bp BatchPoints) (*Response, error) {
|
|||
|
||||
var b bytes.Buffer
|
||||
for _, p := range bp.Points {
|
||||
err := checkPointTypes(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if p.Raw != "" {
|
||||
if _, err := b.WriteString(p.Raw); err != nil {
|
||||
return nil, err
|
||||
|
@ -652,6 +656,19 @@ func (c *Client) Addr() string {
|
|||
return c.url.String()
|
||||
}
|
||||
|
||||
// checkPointTypes ensures no unsupported types are submitted to influxdb, returning error if they are found.
|
||||
func checkPointTypes(p Point) error {
|
||||
for _, v := range p.Fields {
|
||||
switch v.(type) {
|
||||
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, float32, float64, bool, string, nil:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("unsupported point type: %T", v)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// helper functions
|
||||
|
||||
// EpochToTime takes a unix epoch time and uses precision to return back a time.Time
|
||||
|
|
|
@ -17,6 +17,36 @@ import (
|
|||
"github.com/influxdb/influxdb/client"
|
||||
)
|
||||
|
||||
func BenchmarkWrite(b *testing.B) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var data client.Response
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
_ = json.NewEncoder(w).Encode(data)
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
u, _ := url.Parse(ts.URL)
|
||||
config := client.Config{URL: *u}
|
||||
c, err := client.NewClient(config)
|
||||
if err != nil {
|
||||
b.Fatalf("unexpected error. expected %v, actual %v", nil, err)
|
||||
}
|
||||
|
||||
bp := client.BatchPoints{
|
||||
Points: []client.Point{
|
||||
{Fields: map[string]interface{}{"value": 101}}},
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
r, err := c.Write(bp)
|
||||
if err != nil {
|
||||
b.Fatalf("unexpected error. expected %v, actual %v", nil, err)
|
||||
}
|
||||
if r != nil {
|
||||
b.Fatalf("unexpected response. expected %v, actual %v", nil, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkUnmarshalJSON2Tags(b *testing.B) {
|
||||
var bp client.BatchPoints
|
||||
data := []byte(`
|
||||
|
@ -550,6 +580,36 @@ func TestClient_NoTimeout(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestClient_WriteUint64(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var data client.Response
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
_ = json.NewEncoder(w).Encode(data)
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
u, _ := url.Parse(ts.URL)
|
||||
config := client.Config{URL: *u}
|
||||
c, err := client.NewClient(config)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error. expected %v, actual %v", nil, err)
|
||||
}
|
||||
bp := client.BatchPoints{
|
||||
Points: []client.Point{
|
||||
{
|
||||
Fields: map[string]interface{}{"value": uint64(10)},
|
||||
},
|
||||
},
|
||||
}
|
||||
r, err := c.Write(bp)
|
||||
if err == nil {
|
||||
t.Fatalf("unexpected error. expected err, actual %v", err)
|
||||
}
|
||||
if r != nil {
|
||||
t.Fatalf("unexpected response. expected %v, actual %v", nil, r)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_ParseConnectionString_IPv6(t *testing.T) {
|
||||
path := "[fdf5:9ede:1875:0:a9ee:a600:8fe3:d495]:8086"
|
||||
u, err := client.ParseConnectionString(path, false)
|
||||
|
|
Loading…
Reference in New Issue