From 278c652d6ff1a275690ed91a5e84ba6cfa001f0a Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Sat, 7 Mar 2015 07:27:35 -0700 Subject: [PATCH 01/13] send credentials if provided --- client/influxdb.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/influxdb.go b/client/influxdb.go index cb7ab54da03..d2569af488f 100644 --- a/client/influxdb.go +++ b/client/influxdb.go @@ -47,6 +47,9 @@ func (c *Client) Query(q Query) (*Results, error) { u := c.url u.Path = "query" + if c.username != "" { + u.User = url.UserPassword(c.username, c.password) + } values := u.Query() values.Set("q", q.Command) values.Set("db", q.Database) From 7c926a99348d9a39f2866c9052aac756ba18236a Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Sat, 7 Mar 2015 07:31:23 -0700 Subject: [PATCH 02/13] default and send user agent --- client/influxdb.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/client/influxdb.go b/client/influxdb.go index d2569af488f..511123e648a 100644 --- a/client/influxdb.go +++ b/client/influxdb.go @@ -12,6 +12,11 @@ import ( "github.com/influxdb/influxdb/influxql" ) +// These variables are populated via the Go linker. +var ( + version string = "0.9" +) + type Query struct { Command string Database string @@ -40,6 +45,9 @@ func NewClient(c Config) (*Client, error) { httpClient: &http.Client{}, userAgent: c.UserAgent, } + if client.userAgent == "" { + client.userAgent = "InfluxDBClient/" + version + } return &client, nil } @@ -59,9 +67,7 @@ func (c *Client) Query(q Query) (*Results, error) { if err != nil { return nil, err } - if c.userAgent != "" { - req.Header.Set("User-Agent", c.userAgent) - } + req.Header.Set("User-Agent", c.userAgent) resp, err := c.httpClient.Do(req) if err != nil { return nil, err @@ -91,9 +97,7 @@ func (c *Client) Write(bp BatchPoints) (*Results, error) { return nil, err } req.Header.Set("Content-Type", "application/json") - if c.userAgent != "" { - req.Header.Set("User-Agent", c.userAgent) - } + req.Header.Set("User-Agent", c.userAgent) resp, err := c.httpClient.Do(req) if err != nil { return nil, err @@ -124,9 +128,7 @@ func (c *Client) Ping() (time.Duration, string, error) { if err != nil { return 0, "", err } - if c.userAgent != "" { - req.Header.Set("User-Agent", c.userAgent) - } + req.Header.Set("User-Agent", c.userAgent) resp, err := c.httpClient.Do(req) if err != nil { return 0, "", err From 2b4f155407d9de5515f9efef644f41d140b0592f Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Sat, 7 Mar 2015 07:36:13 -0700 Subject: [PATCH 03/13] return no results if successful. update tests. add comments --- client/influxdb.go | 13 ++++++++++++- cmd/influxd/server_integration_test.go | 6 +++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/client/influxdb.go b/client/influxdb.go index 511123e648a..3a930355121 100644 --- a/client/influxdb.go +++ b/client/influxdb.go @@ -17,11 +17,16 @@ var ( version string = "0.9" ) +// Query is used to send a command to the server. Both Command and Database are required. type Query struct { Command string Database string } +// Config is used to specify what server to connect to. +// URL: The URL of the server connecting to. +// Username/Password are optional. They will be passed via basic auth if provided. +// UserAgent: If not provided, will default "InfluxDBClient/" + version, type Config struct { URL url.URL Username string @@ -29,6 +34,7 @@ type Config struct { UserAgent string } +// Client is used to make calls to the server. type Client struct { url url.URL username string @@ -37,6 +43,7 @@ type Client struct { userAgent string } +// NewClient will instantiate and return a connected client to issue commands to the server. func NewClient(c Config) (*Client, error) { client := Client{ url: c.URL, @@ -51,6 +58,7 @@ func NewClient(c Config) (*Client, error) { return &client, nil } +// Query sends a command to the server and returns the Results func (c *Client) Query(q Query) (*Results, error) { u := c.url @@ -84,6 +92,9 @@ func (c *Client) Query(q Query) (*Results, error) { return &results, nil } +// Write takes BatchPoints and allows for writing of multiple points with defaults +// If successful, error is nil and Results is nil +// If an error occurs, Results may contain additional information if populated. func (c *Client) Write(bp BatchPoints) (*Results, error) { c.url.Path = "write" @@ -116,7 +127,7 @@ func (c *Client) Write(bp BatchPoints) (*Results, error) { return &results, results.Error() } - return &results, nil + return nil, nil } func (c *Client) Ping() (time.Duration, string, error) { diff --git a/cmd/influxd/server_integration_test.go b/cmd/influxd/server_integration_test.go index 97653f485e9..8cd62c653c6 100644 --- a/cmd/influxd/server_integration_test.go +++ b/cmd/influxd/server_integration_test.go @@ -690,7 +690,7 @@ func TestClientLibrary(t *testing.T) { }, { name: "no points", - writeExpected: `{}`, + writeExpected: `null`, bp: client.BatchPoints{Database: "mydb"}, }, { @@ -701,7 +701,7 @@ func TestClientLibrary(t *testing.T) { {Name: "cpu", Fields: map[string]interface{}{"value": 1.1}, Timestamp: now}, }, }, - writeExpected: `{}`, + writeExpected: `null`, query: client.Query{Command: `select * from "mydb"."myrp".cpu`}, queryExpected: fmt.Sprintf(`{"results":[{"series":[{"name":"cpu","columns":["time","value"],"values":[["%s",1.1]]}]}]}`, now.Format(time.RFC3339Nano)), }, @@ -726,7 +726,7 @@ func TestClientLibrary(t *testing.T) { } if test.query.Command != "" { - time.Sleep(50 * time.Millisecond) + time.Sleep(100 * time.Millisecond) queryResult, err := c.Query(test.query) if test.queryErr != errToString(err) { t.Errorf("unexpected error. expected: %s, got %v", test.queryErr, err) From 97dc11c96d23ddc68640c6198a612400f1932927 Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Sat, 7 Mar 2015 07:43:22 -0700 Subject: [PATCH 04/13] more documenting. starting to update readme. --- client/README.md | 5 ++++- client/influxdb.go | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/client/README.md b/client/README.md index ac4840e70ec..6eec7ef75b7 100644 --- a/client/README.md +++ b/client/README.md @@ -1,4 +1,7 @@ InfluxDB Go Client Library ============ -# TODO Add links to the godoc and examples when they are written +# +# Examples + +You can see a use of the client libray in the [InfluxDB CLI](https://github.com/influxdb/influxdb/blob/master/cmd/influx/main.go). diff --git a/client/influxdb.go b/client/influxdb.go index 3a930355121..ac71ac694cb 100644 --- a/client/influxdb.go +++ b/client/influxdb.go @@ -130,6 +130,8 @@ func (c *Client) Write(bp BatchPoints) (*Results, error) { return nil, nil } +// Ping will check to see if the server is up +// Ping returns how long the requeset took, the version of the server it connected to, and an error if one occured. func (c *Client) Ping() (time.Duration, string, error) { now := time.Now() u := c.url @@ -250,6 +252,9 @@ func (a Results) Error() error { } // Point defines the fields that will be written to the database +// Name, Timestamp, and Fields are required +// Precision can be specified if the timestamp is in epoch format (integer). +// Valid values for Precision are n, u, ms, s, m, and h type Point struct { Name string Tags map[string]string @@ -357,6 +362,12 @@ func normalizeFields(fields map[string]interface{}) map[string]interface{} { } // BatchPoints is used to send batched data in a single write. +// Database and Points are required +// If no retention policy is specified, it will use the databases default retention policy. +// If tags are specified, they will be "merged" with all points. If a point already has that tag, it is ignored. +// If timestamp is specified, it will be applied to any point with an empty timestamp. +// Precision can be specified if the timestamp is in epoch format (integer). +// Valid values for Precision are n, u, ms, s, m, and h type BatchPoints struct { Points []Point `json:"points,omitempty"` Database string `json:"database,omitempty"` @@ -425,6 +436,7 @@ func (bp *BatchPoints) UnmarshalJSON(b []byte) error { // utility functions +// Addr provides the current url as a string of the server the client is connected to. func (c *Client) Addr() string { return c.url.String() } From c52210d9a5e69646fa28a48511625312314f093f Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Sat, 7 Mar 2015 07:57:20 -0700 Subject: [PATCH 05/13] fix signature and add comment --- client/influxdb.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/influxdb.go b/client/influxdb.go index ac71ac694cb..637e6cdd903 100644 --- a/client/influxdb.go +++ b/client/influxdb.go @@ -201,7 +201,8 @@ type Results struct { Err error } -func (r Results) MarshalJSON() ([]byte, error) { +// MarshalJSON encodes the result into JSON. +func (r *Results) MarshalJSON() ([]byte, error) { // Define a struct that outputs "error" as a string. var o struct { Results []Result `json:"results,omitempty"` From f1d7b3e20002b862064fceb5f75b2b8d018a48ac Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Sat, 7 Mar 2015 07:57:30 -0700 Subject: [PATCH 06/13] first pass at documenting library --- client/README.md | 176 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 175 insertions(+), 1 deletion(-) diff --git a/client/README.md b/client/README.md index 6eec7ef75b7..302fa486591 100644 --- a/client/README.md +++ b/client/README.md @@ -1,7 +1,181 @@ InfluxDB Go Client Library ============ -# +# package client + +```go + import "github.com/influxdb/influxdb/client" + ``` + + +#FUNCTIONS + +```go +func EpochToTime(epoch int64, precision string) (time.Time, error) +``` + + EpochToTime takes a unix epoch time and uses precision to return back a + time.Time + +```go +func SetPrecision(t time.Time, precision string) time.Time +``` + SetPrecision will round a time to the specified precision + +#TYPES + +```go +type BatchPoints struct { + Points []Point `json:"points,omitempty"` + Database string `json:"database,omitempty"` + RetentionPolicy string `json:"retentionPolicy,omitempty"` + Tags map[string]string `json:"tags,omitempty"` + Timestamp time.Time `json:"timestamp,omitempty"` + Precision string `json:"precision,omitempty"` +} +``` + BatchPoints is used to send batched data in a single write. Database and + Points are required If no retention policy is specified, it will use the + databases default retention policy. If tags are specified, they will be + "merged" with all points. If a point already has that tag, it is + ignored. If timestamp is specified, it will be applied to any point with + an empty timestamp. Precision can be specified if the timestamp is in + epoch format (integer). Valid values for Precision are n, u, ms, s, m, + and h + +```go +func (bp *BatchPoints) UnmarshalJSON(b []byte) error +``` + UnmarshalJSON decodes the data into the BatchPoints struct + +```go +type Client struct { + // contains filtered or unexported fields +} +``` + Client is used to make calls to the server. + +```go +func NewClient(c Config) (*Client, error) +``` + NewClient will instantiate and return a connected client to issue + commands to the server. + +```go +func (c *Client) Addr() string +``` + Addr provides the current url as a string of the server the client is + connected to. + +```go +func (c *Client) Ping() (time.Duration, string, error) +``` + Ping will check to see if the server is up Ping returns how long the + requeset took, the version of the server it connected to, and an error + if one occured. + +```go +func (c *Client) Query(q Query) (*Results, error) +``` + Query sends a command to the server and returns the Results + +```go +func (c *Client) Write(bp BatchPoints) (*Results, error) +``` + Write takes BatchPoints and allows for writing of multiple points with + defaults If successful, error is nil and Results is nil If an error + occurs, Results may contain additional information if populated. + +```go +type Config struct { + URL url.URL + Username string + Password string + UserAgent string +} +``` + Config is used to specify what server to connect to. URL: The URL of the + server connecting to. Username/Password are optional. They will be + passed via basic auth if provided. UserAgent: If not provided, will + default "InfluxDBClient/" + version, + +```go +type Point struct { + Name string + Tags map[string]string + Timestamp time.Time + Fields map[string]interface{} + Precision string +} +``` + Point defines the fields that will be written to the database Name, + Timestamp, and Fields are required Precision can be specified if the + timestamp is in epoch format (integer). Valid values for Precision are + n, u, ms, s, m, and h + +```go +func (p *Point) MarshalJSON() ([]byte, error) +``` + MarshalJSON will format the time in RFC3339Nano Precision is also + ignored as it is only used for writing, not reading Or another way to + say it is we always send back in nanosecond precision + +```go +func (p *Point) UnmarshalJSON(b []byte) error +``` + UnmarshalJSON decodes the data into the Point struct + +```go +type Query struct { + Command string + Database string +} +``` + Query is used to send a command to the server. Both Command and Database + are required. + +```go +type Result struct { + Series []influxql.Row + Err error +} +``` + Result represents a resultset returned from a single statement. + +```go +func (r *Result) MarshalJSON() ([]byte, error) +``` + MarshalJSON encodes the result into JSON. + +```go +func (r *Result) UnmarshalJSON(b []byte) error +``` + UnmarshalJSON decodes the data into the Result struct + +```go +type Results struct { + Results []Result + Err error +} +``` + Results represents a list of statement results. + +```go +func (a Results) Error() error +``` + Error returns the first error from any statement. Returns nil if no + errors occurred on any statements. + +```go +func (r *Results) MarshalJSON() ([]byte, error) +``` + MarshalJSON encodes the result into JSON. + +```go +func (r *Results) UnmarshalJSON(b []byte) error +``` + UnmarshalJSON decodes the data into the Results struct + # Examples You can see a use of the client libray in the [InfluxDB CLI](https://github.com/influxdb/influxdb/blob/master/cmd/influx/main.go). From 6afa4fb08383d0968887465542b352667228fa30 Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Sat, 7 Mar 2015 08:03:43 -0700 Subject: [PATCH 07/13] update test to expect a default user agent --- client/influxdb_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/client/influxdb_test.go b/client/influxdb_test.go index 9d870c382a2..97daea6d91a 100644 --- a/client/influxdb_test.go +++ b/client/influxdb_test.go @@ -6,6 +6,7 @@ import ( "net/http" "net/http/httptest" "net/url" + "strings" "testing" "time" @@ -134,8 +135,6 @@ func TestClient_UserAgent(t *testing.T) { t.Fatalf("unexpected error. expected %v, actual %v", nil, err) } - defaultUserAgent := receivedUserAgent - tests := []struct { name string userAgent string @@ -144,7 +143,7 @@ func TestClient_UserAgent(t *testing.T) { { name: "Empty user agent", userAgent: "", - expected: defaultUserAgent, + expected: "InfluxDBClient/", }, { name: "Custom user agent", @@ -167,7 +166,7 @@ func TestClient_UserAgent(t *testing.T) { if err != nil { t.Fatalf("unexpected error. expected %v, actual %v", nil, err) } - if receivedUserAgent != test.expected { + if !strings.HasPrefix(receivedUserAgent, test.expected) { t.Fatalf("Unexpected user agent. expected %v, actual %v", test.expected, receivedUserAgent) } @@ -177,7 +176,7 @@ func TestClient_UserAgent(t *testing.T) { if err != nil { t.Fatalf("unexpected error. expected %v, actual %v", nil, err) } - if receivedUserAgent != test.expected { + if !strings.HasPrefix(receivedUserAgent, test.expected) { t.Fatalf("Unexpected user agent. expected %v, actual %v", test.expected, receivedUserAgent) } @@ -186,7 +185,7 @@ func TestClient_UserAgent(t *testing.T) { if err != nil { t.Fatalf("unexpected error. expected %v, actual %v", nil, err) } - if receivedUserAgent != test.expected { + if !strings.HasPrefix(receivedUserAgent, test.expected) { t.Fatalf("Unexpected user agent. expected %v, actual %v", test.expected, receivedUserAgent) } } From b31ecd89ead19cb3824229020a735b05646640f4 Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Sat, 7 Mar 2015 08:09:30 -0700 Subject: [PATCH 08/13] remove indents from readme --- client/README.md | 86 ++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/client/README.md b/client/README.md index 302fa486591..cdeba587a2f 100644 --- a/client/README.md +++ b/client/README.md @@ -34,57 +34,57 @@ type BatchPoints struct { Precision string `json:"precision,omitempty"` } ``` - BatchPoints is used to send batched data in a single write. Database and - Points are required If no retention policy is specified, it will use the - databases default retention policy. If tags are specified, they will be - "merged" with all points. If a point already has that tag, it is - ignored. If timestamp is specified, it will be applied to any point with - an empty timestamp. Precision can be specified if the timestamp is in - epoch format (integer). Valid values for Precision are n, u, ms, s, m, - and h +BatchPoints is used to send batched data in a single write. Database and +Points are required If no retention policy is specified, it will use the +databases default retention policy. If tags are specified, they will be +"merged" with all points. If a point already has that tag, it is +ignored. If timestamp is specified, it will be applied to any point with +an empty timestamp. Precision can be specified if the timestamp is in +epoch format (integer). Valid values for Precision are n, u, ms, s, m, +and h ```go func (bp *BatchPoints) UnmarshalJSON(b []byte) error ``` - UnmarshalJSON decodes the data into the BatchPoints struct +UnmarshalJSON decodes the data into the BatchPoints struct ```go type Client struct { // contains filtered or unexported fields } ``` - Client is used to make calls to the server. +Client is used to make calls to the server. ```go func NewClient(c Config) (*Client, error) ``` - NewClient will instantiate and return a connected client to issue - commands to the server. +NewClient will instantiate and return a connected client to issue +commands to the server. ```go func (c *Client) Addr() string ``` - Addr provides the current url as a string of the server the client is - connected to. +Addr provides the current url as a string of the server the client is +connected to. ```go func (c *Client) Ping() (time.Duration, string, error) ``` - Ping will check to see if the server is up Ping returns how long the - requeset took, the version of the server it connected to, and an error - if one occured. +Ping will check to see if the server is up Ping returns how long the +requeset took, the version of the server it connected to, and an error +if one occured. ```go func (c *Client) Query(q Query) (*Results, error) ``` - Query sends a command to the server and returns the Results +Query sends a command to the server and returns the Results ```go func (c *Client) Write(bp BatchPoints) (*Results, error) ``` - Write takes BatchPoints and allows for writing of multiple points with - defaults If successful, error is nil and Results is nil If an error - occurs, Results may contain additional information if populated. +Write takes BatchPoints and allows for writing of multiple points with +defaults If successful, error is nil and Results is nil If an error +occurs, Results may contain additional information if populated. ```go type Config struct { @@ -94,10 +94,10 @@ type Config struct { UserAgent string } ``` - Config is used to specify what server to connect to. URL: The URL of the - server connecting to. Username/Password are optional. They will be - passed via basic auth if provided. UserAgent: If not provided, will - default "InfluxDBClient/" + version, +Config is used to specify what server to connect to. URL: The URL of the +server connecting to. Username/Password are optional. They will be +passed via basic auth if provided. UserAgent: If not provided, will +default "InfluxDBClient/" + version, ```go type Point struct { @@ -108,22 +108,22 @@ type Point struct { Precision string } ``` - Point defines the fields that will be written to the database Name, - Timestamp, and Fields are required Precision can be specified if the - timestamp is in epoch format (integer). Valid values for Precision are - n, u, ms, s, m, and h +Point defines the fields that will be written to the database Name, +Timestamp, and Fields are required Precision can be specified if the +timestamp is in epoch format (integer). Valid values for Precision are +n, u, ms, s, m, and h ```go func (p *Point) MarshalJSON() ([]byte, error) ``` - MarshalJSON will format the time in RFC3339Nano Precision is also - ignored as it is only used for writing, not reading Or another way to - say it is we always send back in nanosecond precision +MarshalJSON will format the time in RFC3339Nano Precision is also +ignored as it is only used for writing, not reading Or another way to +say it is we always send back in nanosecond precision ```go func (p *Point) UnmarshalJSON(b []byte) error ``` - UnmarshalJSON decodes the data into the Point struct +UnmarshalJSON decodes the data into the Point struct ```go type Query struct { @@ -131,8 +131,8 @@ type Query struct { Database string } ``` - Query is used to send a command to the server. Both Command and Database - are required. +Query is used to send a command to the server. Both Command and Database +are required. ```go type Result struct { @@ -140,17 +140,17 @@ type Result struct { Err error } ``` - Result represents a resultset returned from a single statement. +Result represents a resultset returned from a single statement. ```go func (r *Result) MarshalJSON() ([]byte, error) ``` - MarshalJSON encodes the result into JSON. +MarshalJSON encodes the result into JSON. ```go func (r *Result) UnmarshalJSON(b []byte) error ``` - UnmarshalJSON decodes the data into the Result struct +UnmarshalJSON decodes the data into the Result struct ```go type Results struct { @@ -158,23 +158,23 @@ type Results struct { Err error } ``` - Results represents a list of statement results. +Results represents a list of statement results. ```go func (a Results) Error() error ``` - Error returns the first error from any statement. Returns nil if no - errors occurred on any statements. +Error returns the first error from any statement. Returns nil if no +errors occurred on any statements. ```go func (r *Results) MarshalJSON() ([]byte, error) ``` - MarshalJSON encodes the result into JSON. +MarshalJSON encodes the result into JSON. ```go func (r *Results) UnmarshalJSON(b []byte) error ``` - UnmarshalJSON decodes the data into the Results struct +UnmarshalJSON decodes the data into the Results struct # Examples From abb96535ddeaf08272fe550c2d2b8702dfab3439 Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Sat, 7 Mar 2015 08:11:22 -0700 Subject: [PATCH 09/13] remove more indenting --- client/README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/client/README.md b/client/README.md index cdeba587a2f..95efc047339 100644 --- a/client/README.md +++ b/client/README.md @@ -4,7 +4,7 @@ InfluxDB Go Client Library # package client ```go - import "github.com/influxdb/influxdb/client" +import "github.com/influxdb/influxdb/client" ``` @@ -13,14 +13,13 @@ InfluxDB Go Client Library ```go func EpochToTime(epoch int64, precision string) (time.Time, error) ``` - - EpochToTime takes a unix epoch time and uses precision to return back a - time.Time +EpochToTime takes a unix epoch time and uses precision to return back a +time.Time ```go func SetPrecision(t time.Time, precision string) time.Time ``` - SetPrecision will round a time to the specified precision +SetPrecision will round a time to the specified precision #TYPES From 3172f31416bd5218bc0afb7a8423eb71b70224dd Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Mon, 9 Mar 2015 09:51:47 -0600 Subject: [PATCH 10/13] version is a lie for the client library --- client/influxdb.go | 9 ++------- client/influxdb_test.go | 4 ++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/client/influxdb.go b/client/influxdb.go index 637e6cdd903..6272cdc3680 100644 --- a/client/influxdb.go +++ b/client/influxdb.go @@ -12,11 +12,6 @@ import ( "github.com/influxdb/influxdb/influxql" ) -// These variables are populated via the Go linker. -var ( - version string = "0.9" -) - // Query is used to send a command to the server. Both Command and Database are required. type Query struct { Command string @@ -26,7 +21,7 @@ type Query struct { // Config is used to specify what server to connect to. // URL: The URL of the server connecting to. // Username/Password are optional. They will be passed via basic auth if provided. -// UserAgent: If not provided, will default "InfluxDBClient/" + version, +// UserAgent: If not provided, will default "InfluxDBClient", type Config struct { URL url.URL Username string @@ -53,7 +48,7 @@ func NewClient(c Config) (*Client, error) { userAgent: c.UserAgent, } if client.userAgent == "" { - client.userAgent = "InfluxDBClient/" + version + client.userAgent = "InfluxDBClient" } return &client, nil } diff --git a/client/influxdb_test.go b/client/influxdb_test.go index 97daea6d91a..25fd54c6dc4 100644 --- a/client/influxdb_test.go +++ b/client/influxdb_test.go @@ -143,7 +143,7 @@ func TestClient_UserAgent(t *testing.T) { { name: "Empty user agent", userAgent: "", - expected: "InfluxDBClient/", + expected: "InfluxDBClient", }, { name: "Custom user agent", @@ -185,7 +185,7 @@ func TestClient_UserAgent(t *testing.T) { if err != nil { t.Fatalf("unexpected error. expected %v, actual %v", nil, err) } - if !strings.HasPrefix(receivedUserAgent, test.expected) { + if receivedUserAgent != test.expected { t.Fatalf("Unexpected user agent. expected %v, actual %v", test.expected, receivedUserAgent) } } From 8570494552405a66cd0c8ba9f9db2cfa7a36ae0c Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Mon, 9 Mar 2015 10:47:57 -0600 Subject: [PATCH 11/13] update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71b91b622be..33989a95ce5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - [#1877](https://github.com/influxdb/influxdb/pull/1877): Broker clients track broker leader - [#1862](https://github.com/influxdb/influxdb/pull/1862): Fix memory leak in `httpd.serveWait`. Thanks @mountkin - [#1868](https://github.com/influxdb/influxdb/pull/1868): Use `BatchPoints` for `client.Write` method. Thanks @vladlopes, @georgmu, @d2g, @evanphx, @akolosov. +- [#1881](https://github.com/influxdb/influxdb/pull/1881): Update documenation for `client` package. Misc library tweaks. ## v0.9.0-rc9 [2015-03-06] From d6d21b2118cac8f79c6771c78ec17f4c75f35062 Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Mon, 9 Mar 2015 10:49:31 -0600 Subject: [PATCH 12/13] need spell checker --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33989a95ce5..1eda0b21e76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ - [#1877](https://github.com/influxdb/influxdb/pull/1877): Broker clients track broker leader - [#1862](https://github.com/influxdb/influxdb/pull/1862): Fix memory leak in `httpd.serveWait`. Thanks @mountkin - [#1868](https://github.com/influxdb/influxdb/pull/1868): Use `BatchPoints` for `client.Write` method. Thanks @vladlopes, @georgmu, @d2g, @evanphx, @akolosov. -- [#1881](https://github.com/influxdb/influxdb/pull/1881): Update documenation for `client` package. Misc library tweaks. +- [#1881](https://github.com/influxdb/influxdb/pull/1881): Update documentation for `client` package. Misc library tweaks. ## v0.9.0-rc9 [2015-03-06] From 18f159ae16e50adca46ca676b1ba86fa58c6685b Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Mon, 9 Mar 2015 13:07:50 -0600 Subject: [PATCH 13/13] point to godoc --- client/README.md | 177 +---------------------------------------------- 1 file changed, 3 insertions(+), 174 deletions(-) diff --git a/client/README.md b/client/README.md index 95efc047339..81bd9979965 100644 --- a/client/README.md +++ b/client/README.md @@ -1,180 +1,9 @@ InfluxDB Go Client Library ============ -# package client +Please refer to [http://godoc.org/github.com/influxdb/influxdb/client](http://godoc.org/github.com/influxdb/influxdb/client) +for documentation. -```go -import "github.com/influxdb/influxdb/client" - ``` - - -#FUNCTIONS - -```go -func EpochToTime(epoch int64, precision string) (time.Time, error) -``` -EpochToTime takes a unix epoch time and uses precision to return back a -time.Time - -```go -func SetPrecision(t time.Time, precision string) time.Time -``` -SetPrecision will round a time to the specified precision - -#TYPES - -```go -type BatchPoints struct { - Points []Point `json:"points,omitempty"` - Database string `json:"database,omitempty"` - RetentionPolicy string `json:"retentionPolicy,omitempty"` - Tags map[string]string `json:"tags,omitempty"` - Timestamp time.Time `json:"timestamp,omitempty"` - Precision string `json:"precision,omitempty"` -} -``` -BatchPoints is used to send batched data in a single write. Database and -Points are required If no retention policy is specified, it will use the -databases default retention policy. If tags are specified, they will be -"merged" with all points. If a point already has that tag, it is -ignored. If timestamp is specified, it will be applied to any point with -an empty timestamp. Precision can be specified if the timestamp is in -epoch format (integer). Valid values for Precision are n, u, ms, s, m, -and h - -```go -func (bp *BatchPoints) UnmarshalJSON(b []byte) error -``` -UnmarshalJSON decodes the data into the BatchPoints struct - -```go -type Client struct { - // contains filtered or unexported fields -} -``` -Client is used to make calls to the server. - -```go -func NewClient(c Config) (*Client, error) -``` -NewClient will instantiate and return a connected client to issue -commands to the server. - -```go -func (c *Client) Addr() string -``` -Addr provides the current url as a string of the server the client is -connected to. - -```go -func (c *Client) Ping() (time.Duration, string, error) -``` -Ping will check to see if the server is up Ping returns how long the -requeset took, the version of the server it connected to, and an error -if one occured. - -```go -func (c *Client) Query(q Query) (*Results, error) -``` -Query sends a command to the server and returns the Results - -```go -func (c *Client) Write(bp BatchPoints) (*Results, error) -``` -Write takes BatchPoints and allows for writing of multiple points with -defaults If successful, error is nil and Results is nil If an error -occurs, Results may contain additional information if populated. - -```go -type Config struct { - URL url.URL - Username string - Password string - UserAgent string -} -``` -Config is used to specify what server to connect to. URL: The URL of the -server connecting to. Username/Password are optional. They will be -passed via basic auth if provided. UserAgent: If not provided, will -default "InfluxDBClient/" + version, - -```go -type Point struct { - Name string - Tags map[string]string - Timestamp time.Time - Fields map[string]interface{} - Precision string -} -``` -Point defines the fields that will be written to the database Name, -Timestamp, and Fields are required Precision can be specified if the -timestamp is in epoch format (integer). Valid values for Precision are -n, u, ms, s, m, and h - -```go -func (p *Point) MarshalJSON() ([]byte, error) -``` -MarshalJSON will format the time in RFC3339Nano Precision is also -ignored as it is only used for writing, not reading Or another way to -say it is we always send back in nanosecond precision - -```go -func (p *Point) UnmarshalJSON(b []byte) error -``` -UnmarshalJSON decodes the data into the Point struct - -```go -type Query struct { - Command string - Database string -} -``` -Query is used to send a command to the server. Both Command and Database -are required. - -```go -type Result struct { - Series []influxql.Row - Err error -} -``` -Result represents a resultset returned from a single statement. - -```go -func (r *Result) MarshalJSON() ([]byte, error) -``` -MarshalJSON encodes the result into JSON. - -```go -func (r *Result) UnmarshalJSON(b []byte) error -``` -UnmarshalJSON decodes the data into the Result struct - -```go -type Results struct { - Results []Result - Err error -} -``` -Results represents a list of statement results. - -```go -func (a Results) Error() error -``` -Error returns the first error from any statement. Returns nil if no -errors occurred on any statements. - -```go -func (r *Results) MarshalJSON() ([]byte, error) -``` -MarshalJSON encodes the result into JSON. - -```go -func (r *Results) UnmarshalJSON(b []byte) error -``` -UnmarshalJSON decodes the data into the Results struct - -# Examples +# Currently Used: You can see a use of the client libray in the [InfluxDB CLI](https://github.com/influxdb/influxdb/blob/master/cmd/influx/main.go).