Skip to content

Commit

Permalink
CIRC-9872: Fix tests and default timeouts (#97)
Browse files Browse the repository at this point in the history
* CIRC-9872: Fix tests and default timeouts

* CIRC-9694: Improve PromQLResponse data values
  • Loading branch information
dhaifley authored Feb 24, 2023
1 parent 8270a7d commit 9fb88eb
Show file tree
Hide file tree
Showing 26 changed files with 136 additions and 101 deletions.
8 changes: 8 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ to [Semantic Versioning](http://semver.org/) rules.

## [Next Release]

## [v1.13.1] - 2023-02-23

* upd: Modifies the PromQLResponse and PromQLError types to support more types
of PromQL data values.
* upd: Updates unit tests and examples to use NewClient().
* upd: Ensures default values are set for snowth client timeouts.

## [v1.13.0] - 2023-02-23

* fix: Corrects a bug that could cause snowth client creation to fail if a
Expand Down Expand Up @@ -453,6 +460,7 @@ writing to histogram endpoints.
any delay, once started. Created: 2019-03-12. Fixed: 2019-03-13.

[Next Release]: https://github.com/circonus-labs/gosnowth
[v1.13.1]: https://github.com/circonus-labs/gosnowth/releases/tag/v1.13.1
[v1.13.0]: https://github.com/circonus-labs/gosnowth/releases/tag/v1.13.0
[v1.12.5]: https://github.com/circonus-labs/gosnowth/releases/tag/v1.12.5
[v1.12.4]: https://github.com/circonus-labs/gosnowth/releases/tag/v1.12.4
Expand Down
3 changes: 2 additions & 1 deletion activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ func TestRebuildActivity(t *testing.T) {

defer ms.Close()

sc, err := NewSnowthClient(false, ms.URL)
sc, err := NewClient(context.Background(),
&Config{Servers: []string{ms.URL}})
if err != nil {
t.Fatal("Unable to create snowth client", err)
}
Expand Down
4 changes: 3 additions & 1 deletion caql_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gosnowth

import (
"context"
"io"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -86,7 +87,8 @@ func TestGetCAQLQuery(t *testing.T) {

defer ms.Close()

sc, err := NewSnowthClient(false, ms.URL)
sc, err := NewClient(context.Background(),
&Config{Servers: []string{ms.URL}})
if err != nil {
t.Fatal("Unable to create snowth client", err)
}
Expand Down
8 changes: 8 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ type SnowthClient struct {
func NewClient(ctx context.Context, cfg *Config,
logs ...Logger,
) (*SnowthClient, error) {
if cfg.Timeout == 0 {
cfg.Timeout = time.Second * 10
}

if cfg.DialTimeout == 0 {
cfg.DialTimeout = time.Millisecond * 500
}

client := &http.Client{
Timeout: cfg.Timeout,
Transport: &http.Transport{
Expand Down
23 changes: 7 additions & 16 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@ func TestSnowthNode(t *testing.T) {
}
}

func TestNewSnowthClient(t *testing.T) {
t.Parallel()

// crude test to ensure err is returned for invalid snowth url
badAddr := "foobar"

_, err := NewSnowthClient(false, badAddr)
if err == nil {
t.Errorf("Error not encountered on invalid snowth addr %v", badAddr)
}
}

func TestNewClientTimeout(t *testing.T) {
t.Parallel()

Expand All @@ -59,7 +47,7 @@ func TestNewClientTimeout(t *testing.T) {
t.Error("Error expected for new client timeout test")
}

if !strings.Contains(err.Error(), "context deadline exceeded") {
if !strings.Contains(err.Error(), "no snowth nodes could be activated") {
t.Errorf("Expected context error, got: %v", err.Error())
}
}
Expand Down Expand Up @@ -95,7 +83,8 @@ func TestSnowthClientRequest(t *testing.T) {

defer ms.Close()

sc, err := NewSnowthClient(false, ms.URL)
sc, err := NewClient(context.Background(),
&Config{Servers: []string{ms.URL}})
if err != nil {
t.Fatal("Unable to create snowth client", err)
}
Expand Down Expand Up @@ -195,7 +184,8 @@ func TestSnowthClientDiscoverNodesWatch(t *testing.T) {

defer ms.Close()

sc, err := NewSnowthClient(true, ms.URL)
sc, err := NewClient(context.Background(),
&Config{Servers: []string{ms.URL}})
if err != nil {
t.Fatal("Unable to create snowth client", err)
}
Expand Down Expand Up @@ -324,7 +314,8 @@ func TestSnowthClientLog(t *testing.T) {

defer ms.Close()

sc, err := NewSnowthClient(true, ms.URL)
sc, err := NewClient(context.Background(),
&Config{Servers: []string{ms.URL}})
if err != nil {
t.Fatal("Unable to create snowth client", err)
}
Expand Down
22 changes: 0 additions & 22 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package gosnowth
import (
"bytes"
"encoding/xml"
"fmt"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -43,27 +42,6 @@ func TestResolveURL(t *testing.T) {
}
}

func TestMultiError(t *testing.T) {
t.Parallel()

me := newMultiError()
if me.HasError() {
t.Error("Should have no errors yet")
}

me.Add(fmt.Errorf("error 1"))
me.Add(fmt.Errorf("error 2"))
me.Add(nil)

if !me.HasError() {
t.Error("Should have errors")
}

if res, exp := me.Error(), "error 1; error 2"; res != exp {
t.Errorf("Expected result: %v, got: %v", exp, res)
}
}

func TestDecodeJSON(t *testing.T) {
t.Parallel()

Expand Down
14 changes: 8 additions & 6 deletions examples/retrieval.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
func ExampleReadNNT() {
// Create a new client.
cfg := gosnowth.NewConfig(SnowthServers...)
cfg.Discover = true

client, err := gosnowth.NewClient(context.Background(), cfg)
if err != nil {
Expand Down Expand Up @@ -61,7 +60,6 @@ func ExampleReadNNT() {
func ExampleReadText() {
// Create a new client.
cfg := gosnowth.NewConfig(SnowthServers...)
cfg.Discover = true

client, err := gosnowth.NewClient(context.Background(), cfg)
if err != nil {
Expand Down Expand Up @@ -94,7 +92,8 @@ func ExampleFetchQuery() {
return
}

sc, err := gosnowth.NewSnowthClient(false, host)
sc, err := gosnowth.NewClient(context.Background(),
&gosnowth.Config{Servers: []string{host}})
if err != nil {
log.Fatal("Unable to create snowth client", err)
}
Expand Down Expand Up @@ -144,7 +143,8 @@ func ExampleFetchQueryMultiStream() {
return
}

sc, err := gosnowth.NewSnowthClient(false, host)
sc, err := gosnowth.NewClient(context.Background(),
&gosnowth.Config{Servers: []string{host}})
if err != nil {
log.Fatal("Unable to create snowth client", err)
}
Expand Down Expand Up @@ -182,7 +182,8 @@ func ExampleCAQLQuery() {
return
}

sc, err := gosnowth.NewSnowthClient(false, host)
sc, err := gosnowth.NewClient(context.Background(),
&gosnowth.Config{Servers: []string{host}})
if err != nil {
log.Fatal("Unable to create snowth client", err)
}
Expand Down Expand Up @@ -216,7 +217,8 @@ func ExampleGetCheckTags() {
return
}

sc, err := gosnowth.NewSnowthClient(false, host)
sc, err := gosnowth.NewClient(context.Background(),
&gosnowth.Config{Servers: []string{host}})
if err != nil {
log.Fatal("Unable to create snowth client", err)
}
Expand Down
3 changes: 0 additions & 3 deletions examples/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
func ExampleGetNodeState() {
// Create a new client.
cfg := gosnowth.NewConfig(SnowthServers...)
cfg.Discover = true

client, err := gosnowth.NewClient(context.Background(), cfg)
if err != nil {
Expand All @@ -34,7 +33,6 @@ func ExampleGetNodeState() {
func ExampleGetNodeGossip() {
// Create a new client.
cfg := gosnowth.NewConfig(SnowthServers...)
cfg.Discover = true

client, err := gosnowth.NewClient(context.Background(), cfg)
if err != nil {
Expand All @@ -56,7 +54,6 @@ func ExampleGetNodeGossip() {
func ExampleGetTopology() {
// Create a new client.
cfg := gosnowth.NewConfig(SnowthServers...)
cfg.Discover = true

client, err := gosnowth.NewClient(context.Background(), cfg)
if err != nil {
Expand Down
9 changes: 4 additions & 5 deletions examples/submission.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
func ExampleSubmitText() {
// Create a new client.
cfg := gosnowth.NewConfig(SnowthServers...)
cfg.Discover = true

client, err := gosnowth.NewClient(context.Background(), cfg)
if err != nil {
Expand All @@ -43,7 +42,6 @@ func ExampleSubmitText() {
func ExampleSubmitNNT() {
// Create a new client.
cfg := gosnowth.NewConfig(SnowthServers...)
cfg.Discover = true

client, err := gosnowth.NewClient(context.Background(), cfg)
if err != nil {
Expand Down Expand Up @@ -76,7 +74,6 @@ func ExampleSubmitNNT() {
func ExampleSubmitHistogram() {
// Create a new client.
cfg := gosnowth.NewConfig(SnowthServers...)
cfg.Discover = true

client, err := gosnowth.NewClient(context.Background(), cfg)
if err != nil {
Expand Down Expand Up @@ -113,7 +110,8 @@ func ExampleWriteRawMetricList(b *testing.B) {
return
}

sc, err := gosnowth.NewSnowthClient(false, host)
sc, err := gosnowth.NewClient(context.Background(),
&gosnowth.Config{Servers: []string{host}})
if err != nil {
log.Fatal("Unable to create snowth client", err)
}
Expand Down Expand Up @@ -160,7 +158,8 @@ func ExampleBulkWriteRawMetricList(b *testing.B) {
return
}

sc, err := gosnowth.NewSnowthClient(false, host)
sc, err := gosnowth.NewClient(context.Background(),
&gosnowth.Config{Servers: []string{host}})
if err != nil {
log.Fatal("Unable to create snowth client", err)
}
Expand Down
4 changes: 3 additions & 1 deletion fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gosnowth

import (
"bytes"
"context"
"encoding/json"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -115,7 +116,8 @@ func TestFetchQuery(t *testing.T) {

defer ms.Close()

sc, err := NewSnowthClient(false, ms.URL)
sc, err := NewClient(context.Background(),
&Config{Servers: []string{ms.URL}})
if err != nil {
t.Fatal("Unable to create snowth client", err)
}
Expand Down
3 changes: 2 additions & 1 deletion gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ func TestGetGossipInfo(t *testing.T) {

defer ms.Close()

sc, err := NewSnowthClient(false, ms.URL)
sc, err := NewClient(context.Background(),
&Config{Servers: []string{ms.URL}})
if err != nil {
t.Fatal("Unable to create snowth client", err)
}
Expand Down
10 changes: 7 additions & 3 deletions graphite_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gosnowth

import (
"context"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -62,7 +63,8 @@ func TestGraphiteFindMetrics(t *testing.T) {

defer ms.Close()

sc, err := NewSnowthClient(false, ms.URL)
sc, err := NewClient(context.Background(),
&Config{Servers: []string{ms.URL}})
if err != nil {
t.Fatal("Unable to create snowth client", err)
}
Expand Down Expand Up @@ -118,7 +120,8 @@ func TestGraphiteFindTags(t *testing.T) {

defer ms.Close()

sc, err := NewSnowthClient(false, ms.URL)
sc, err := NewClient(context.Background(),
&Config{Servers: []string{ms.URL}})
if err != nil {
t.Fatal("Unable to create snowth client", err)
}
Expand Down Expand Up @@ -174,7 +177,8 @@ func TestGraphiteGetDatapoints(t *testing.T) {

defer ms.Close()

sc, err := NewSnowthClient(false, ms.URL)
sc, err := NewClient(context.Background(),
&Config{Servers: []string{ms.URL}})
if err != nil {
t.Fatal("Unable to create snowth client", err)
}
Expand Down
7 changes: 5 additions & 2 deletions histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gosnowth

import (
"bytes"
"context"
"encoding/json"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -112,7 +113,8 @@ func TestReadHistogramValues(t *testing.T) {

defer ms.Close()

sc, err := NewSnowthClient(false, ms.URL)
sc, err := NewClient(context.Background(),
&Config{Servers: []string{ms.URL}})
if err != nil {
t.Fatal("Unable to create snowth client", err)
}
Expand Down Expand Up @@ -199,7 +201,8 @@ func TestWriteHistogram(t *testing.T) {

defer ms.Close()

sc, err := NewSnowthClient(false, ms.URL)
sc, err := NewClient(context.Background(),
&Config{Servers: []string{ms.URL}})
if err != nil {
t.Fatal("Unable to create snowth client", err)
}
Expand Down
Loading

0 comments on commit 9fb88eb

Please sign in to comment.