Skip to content

Commit

Permalink
Merge branch 'master' into linasn/read-handler-hooks
Browse files Browse the repository at this point in the history
* master:
  [dbnode] Update series metadata type name. (#2946)
  [aggregator/client] Include instance ID in write errors (#2945)
  Revert "[dbnode] Properly rebuild index segments if they fail verification. (#2879)" (#2944)
  [dbnode] Add DocRef() to NS and multiple series metadata types  (#2931)
  [dbnode] Remove dead code in fs package (#2932)
  [query] Fix incorrect content type in m3query/ error response (#2917)
  [query] Graphite query timeout propagation and add per endpoint status/latency metrics (#2880)
  [query] Allow Graphite variadic functions to omit variadic args (#2882)
  [aggregator] Return NaN instead of 0 for NaN gauge values (#2930)
  [aggregator] Use NaN instead of math.MaxFloat64 and add sentinel guards (#2929)

# Conflicts:
#	src/query/api/v1/handler/prom/read.go
#	src/query/api/v1/handler/prom/read_instant.go
#	src/query/api/v1/handler/prom/read_test.go
#	src/query/api/v1/httpd/handler_test.go
  • Loading branch information
soundvibe committed Nov 24, 2020
2 parents a50265a + c8326e3 commit 2314219
Show file tree
Hide file tree
Showing 81 changed files with 1,689 additions and 2,238 deletions.
2 changes: 2 additions & 0 deletions site/.htmltest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ IgnoreURLs:
- "youtu.be"
- "youtube.com"
- "cassandra.apache.org"
- "slideshare.net"
- "meetup.com"
- "github.com/m3db/m3/tree/docs-test/site/content/docs"
- "github.com/m3db/m3/tree/master/site/content/docs"
27 changes: 16 additions & 11 deletions src/aggregator/aggregation/gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ import (
"github.com/m3db/m3/src/metrics/aggregation"
)

const (
minFloat64 = -math.MaxFloat64
)

// Gauge aggregates gauge values.
type Gauge struct {
Options
Expand All @@ -48,8 +44,8 @@ type Gauge struct {
func NewGauge(opts Options) Gauge {
return Gauge{
Options: opts,
max: minFloat64,
min: math.MaxFloat64,
max: math.NaN(),
min: math.NaN(),
}
}

Expand All @@ -65,12 +61,17 @@ func (g *Gauge) Update(timestamp time.Time, value float64) {
g.Options.Metrics.Gauge.IncValuesOutOfOrder()
}

g.sum += value
g.count++
if g.max < value {

if math.IsNaN(value) {
return
}

g.sum += value
if math.IsNaN(g.max) || g.max < value {
g.max = value
}
if g.min > value {
if math.IsNaN(g.min) || g.min > value {
g.min = value
}

Expand Down Expand Up @@ -108,10 +109,14 @@ func (g *Gauge) Stdev() float64 {
}

// Min returns the minimum gauge value.
func (g *Gauge) Min() float64 { return g.min }
func (g *Gauge) Min() float64 {
return g.min
}

// Max returns the maximum gauge value.
func (g *Gauge) Max() float64 { return g.max }
func (g *Gauge) Max() float64 {
return g.max
}

// ValueOf returns the value for the aggregation type.
func (g *Gauge) ValueOf(aggType aggregation.Type) float64 {
Expand Down
39 changes: 39 additions & 0 deletions src/aggregator/aggregation/gauge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package aggregation

import (
"math"
"testing"
"time"

Expand All @@ -42,6 +43,17 @@ func TestGaugeDefaultAggregationType(t *testing.T) {
require.Equal(t, 100.0, g.ValueOf(aggregation.Count))
require.Equal(t, 50.5, g.ValueOf(aggregation.Mean))
require.Equal(t, 0.0, g.ValueOf(aggregation.SumSq))
require.Equal(t, 100.0, g.ValueOf(aggregation.Max))
require.Equal(t, 1.0, g.ValueOf(aggregation.Min))

g = NewGauge(NewOptions(instrument.NewOptions()))
require.Equal(t, 0.0, g.Last())
require.Equal(t, 0.0, g.ValueOf(aggregation.Last))
require.Equal(t, 0.0, g.ValueOf(aggregation.Count))
require.Equal(t, 0.0, g.ValueOf(aggregation.Mean))
require.Equal(t, 0.0, g.ValueOf(aggregation.SumSq))
require.True(t, math.IsNaN(g.ValueOf(aggregation.Max)))
require.True(t, math.IsNaN(g.ValueOf(aggregation.Min)))
}

func TestGaugeCustomAggregationType(t *testing.T) {
Expand Down Expand Up @@ -80,6 +92,33 @@ func TestGaugeCustomAggregationType(t *testing.T) {
require.False(t, aggType.IsValidForGauge())
}
}

g = NewGauge(opts)
require.Equal(t, 0.0, g.Last())
for aggType := range aggregation.ValidTypes {
v := g.ValueOf(aggType)
switch aggType {
case aggregation.Last:
require.Equal(t, 0.0, v)
case aggregation.Min:
require.True(t, math.IsNaN(v))
case aggregation.Max:
require.True(t, math.IsNaN(v))
case aggregation.Mean:
require.Equal(t, 0.0, v)
case aggregation.Count:
require.Equal(t, 0.0, v)
case aggregation.Sum:
require.Equal(t, 0.0, v)
case aggregation.SumSq:
require.Equal(t, 0.0, v)
case aggregation.Stdev:
require.InDelta(t, 0.0, v, 0.0)
default:
require.Equal(t, 0.0, v)
require.False(t, aggType.IsValidForGauge())
}
}
}

func TestGaugeLastOutOfOrderValues(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions src/aggregator/client/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ func (q *queue) writeAndReset() {
if err := q.writeFn(q.buf); err != nil {
q.log.Error("error writing data",
zap.Int("buffer_size", len(q.buf)),
zap.String("target_instance_id", q.instance.ID()),
zap.String("target_instance", q.instance.Endpoint()),
zap.Error(err),
)
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/tools/dtest/docker/harness/carbon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
)

func findVerifier(expected string) resources.ResponseVerifier {
return func(status int, s string, err error) error {
return func(status int, _ map[string][]string, s string, err error) error {
if err != nil {
return err
}
Expand All @@ -55,7 +55,7 @@ func renderVerifier(v float64) resources.ResponseVerifier {
Datapoints [][]float64 `json:"datapoints"`
}

return func(status int, s string, err error) error {
return func(status int, _ map[string][]string, s string, err error) error {
if err != nil {
return err
}
Expand Down
12 changes: 9 additions & 3 deletions src/cmd/tools/dtest/docker/harness/query_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func testInvalidQueryReturns400(t *testing.T, tests []urlTest) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.NoError(t, coord.RunQuery(verifyStatus(400), tt.url), "for query '%v'", tt.url)
assert.NoError(t, coord.RunQuery(verifyResponse(400), tt.url), "for query '%v'", tt.url)
})
}
}
Expand Down Expand Up @@ -129,8 +129,8 @@ func queryString(params map[string]string) string {
return strings.Join(p, "&")
}

func verifyStatus(expectedStatus int) resources.ResponseVerifier {
return func(status int, resp string, err error) error {
func verifyResponse(expectedStatus int) resources.ResponseVerifier {
return func(status int, headers map[string][]string, resp string, err error) error {
if err != nil {
return err
}
Expand All @@ -139,6 +139,12 @@ func verifyStatus(expectedStatus int) resources.ResponseVerifier {
return fmt.Errorf("expeceted %v status code, got %v", expectedStatus, status)
}

if contentType, ok := headers["Content-Type"]; !ok {
return fmt.Errorf("missing Content-Type header")
} else if len(contentType) != 1 || contentType[0] != "application/json" {
return fmt.Errorf("expected json content type, got %v", contentType)
}

return nil
}
}
4 changes: 2 additions & 2 deletions src/cmd/tools/dtest/docker/harness/resources/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var (
)

// ResponseVerifier is a function that checks if the query response is valid.
type ResponseVerifier func(int, string, error) error
type ResponseVerifier func(int, map[string][]string, string, error) error

// Coordinator is a wrapper for a coordinator. It provides a wrapper on HTTP
// endpoints that expose cluster management APIs as well as read and write
Expand Down Expand Up @@ -363,7 +363,7 @@ func (c *coordinator) query(
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)

return verifier(resp.StatusCode, string(b), err)
return verifier(resp.StatusCode, resp.Header, string(b), err)
}

func (c *coordinator) RunQuery(
Expand Down
2 changes: 1 addition & 1 deletion src/dbnode/generated/mocks/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

// mockgen rules for generating mocks for exported interfaces (reflection mode)

//go:generate sh -c "mockgen -package=fs $PACKAGE/src/dbnode/persist/fs CrossBlockReader,CrossBlockIterator,DataFileSetWriter,DataFileSetReader,DataFileSetSeeker,IndexFileSetWriter,IndexFileSetReader,IndexSegmentFileSetWriter,IndexSegmentFileSet,IndexSegmentFile,SnapshotMetadataFileWriter,DataFileSetSeekerManager,ConcurrentDataFileSetSeeker,MergeWith,StreamingWriter | genclean -pkg $PACKAGE/src/dbnode/persist/fs -out $GOPATH/src/$PACKAGE/src/dbnode/persist/fs/fs_mock.go"
//go:generate sh -c "mockgen -package=fs $PACKAGE/src/dbnode/persist/fs DataFileSetWriter,DataFileSetReader,DataFileSetSeeker,IndexFileSetWriter,IndexFileSetReader,IndexSegmentFileSetWriter,IndexSegmentFileSet,IndexSegmentFile,SnapshotMetadataFileWriter,DataFileSetSeekerManager,ConcurrentDataFileSetSeeker,MergeWith,StreamingWriter | genclean -pkg $PACKAGE/src/dbnode/persist/fs -out $GOPATH/src/$PACKAGE/src/dbnode/persist/fs/fs_mock.go"
//go:generate sh -c "mockgen -package=xio $PACKAGE/src/dbnode/x/xio SegmentReader,SegmentReaderPool | genclean -pkg $PACKAGE/src/dbnode/x/xio -out $GOPATH/src/$PACKAGE/src/dbnode/x/xio/io_mock.go"
//go:generate sh -c "mockgen -package=digest -destination=$GOPATH/src/$PACKAGE/src/dbnode/digest/digest_mock.go $PACKAGE/src/dbnode/digest ReaderWithDigest"
//go:generate sh -c "mockgen -package=series $PACKAGE/src/dbnode/storage/series DatabaseSeries,QueryableBlockRetriever | genclean -pkg $PACKAGE/src/dbnode/storage/series -out $GOPATH/src/$PACKAGE/src/dbnode/storage/series/series_mock.go"
Expand Down
94 changes: 0 additions & 94 deletions src/dbnode/persist/fs/cross_block_iterator.go

This file was deleted.

Loading

0 comments on commit 2314219

Please sign in to comment.