-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[query] Fix graphite functions, aggregation bug #2549
Changes from 16 commits
57c9985
ed90f14
1f16a8f
4c26204
c340f1b
218b671
fcc9c80
83aeabb
33ed9b8
31f5999
ab97310
2427b12
f7e8e2b
0d658d5
8923dca
70faf7e
efa6a97
117bf9a
62dfe0d
1093151
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,14 +22,17 @@ package downsample | |
|
||
import ( | ||
"bytes" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/m3db/m3/src/metrics/metric/aggregated" | ||
"github.com/m3db/m3/src/metrics/metric/id" | ||
"github.com/m3db/m3/src/metrics/policy" | ||
"github.com/m3db/m3/src/query/models" | ||
"github.com/m3db/m3/src/query/storage/mock" | ||
"github.com/m3db/m3/src/x/ident" | ||
"github.com/m3db/m3/src/x/instrument" | ||
"github.com/m3db/m3/src/x/pool" | ||
"github.com/m3db/m3/src/x/serialize" | ||
xsync "github.com/m3db/m3/src/x/sync" | ||
xtest "github.com/m3db/m3/src/x/test" | ||
|
@@ -41,7 +44,7 @@ import ( | |
) | ||
|
||
func TestDownsamplerFlushHandlerCopiesTags(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
ctrl := xtest.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
store := mock.NewMockStorage() | ||
|
@@ -104,3 +107,105 @@ func TestDownsamplerFlushHandlerCopiesTags(t *testing.T) { | |
assert.False(t, xtest.ByteSlicesBackedBySameData(tagName, tag.Name)) | ||
assert.False(t, xtest.ByteSlicesBackedBySameData(tagValue, tag.Value)) | ||
} | ||
|
||
func mustEncodedTags(first string, encPool serialize.TagEncoderPool) []byte { | ||
enc := encPool.Get() | ||
defer enc.Finalize() | ||
|
||
if err := enc.Encode(ident.MustNewTagStringsIterator( | ||
"__g0__", first, | ||
"__g1__", "y", | ||
"__g2__", "z", | ||
string(MetricsOptionIDSchemeTagName), string(GraphiteIDSchemeTagValue), | ||
)); err != nil { | ||
panic(err.Error()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of panic, why not remove the “must” prefix and make the test take a “t *testing.T” as first arg and then “require.NoError(t, err)” like we do with some other test methods? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main motivation here was it already using a call to |
||
} | ||
|
||
data, _ := enc.Data() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Perhaps take a “t *testing.T” and check that second arg “ok” is true? data, ok := enc.Data() |
||
return append(make([]byte, 0, data.Len()), data.Bytes()...) | ||
} | ||
|
||
func TestDownsamplerFlushHandlerHighConcurrencyNoTagMixing(t *testing.T) { | ||
ctrl := xtest.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
store := mock.NewMockStorage() | ||
|
||
size := 10 | ||
decodeOpts := serialize.NewTagDecoderOptions(serialize.TagDecoderOptionsConfig{ | ||
CheckBytesWrapperPoolSize: &size, | ||
}) | ||
|
||
poolOpts := pool.NewObjectPoolOptions() | ||
tagDecoderPool := serialize.NewTagDecoderPool(decodeOpts, poolOpts) | ||
tagDecoderPool.Init() | ||
|
||
pool := serialize.NewMetricTagsIteratorPool(tagDecoderPool, poolOpts) | ||
pool.Init() | ||
|
||
workers := xsync.NewWorkerPool(1) | ||
workers.Init() | ||
|
||
instrumentOpts := instrument.NewOptions() | ||
|
||
handler := newDownsamplerFlushHandler(store, pool, | ||
workers, models.NewTagOptions(), instrumentOpts) | ||
writer, err := handler.NewWriter(tally.NoopScope) | ||
require.NoError(t, err) | ||
|
||
encodeOpts := serialize.NewTagEncoderOptions() | ||
encPool := serialize.NewTagEncoderPool(encodeOpts, poolOpts) | ||
encPool.Init() | ||
|
||
xBytes := mustEncodedTags("x", encPool) | ||
fooBytes := mustEncodedTags("foo", encPool) | ||
|
||
var wg sync.WaitGroup | ||
for i := 0; i < 100; i++ { | ||
wg.Add(1) | ||
xData := append(make([]byte, 0, len(xBytes)), xBytes...) | ||
fooData := append(make([]byte, 0, len(fooBytes)), fooBytes...) | ||
go func() { | ||
defer wg.Done() | ||
err := writer.Write(aggregated.ChunkedMetricWithStoragePolicy{ | ||
ChunkedMetric: aggregated.ChunkedMetric{ | ||
ChunkedID: id.ChunkedID{Data: xData}, | ||
TimeNanos: 123, | ||
Value: 42.42, | ||
}, | ||
StoragePolicy: policy.MustParseStoragePolicy("1s:1d"), | ||
}) | ||
require.NoError(t, err) | ||
|
||
err = writer.Write(aggregated.ChunkedMetricWithStoragePolicy{ | ||
ChunkedMetric: aggregated.ChunkedMetric{ | ||
ChunkedID: id.ChunkedID{Data: fooData}, | ||
TimeNanos: 123, | ||
Value: 42.42, | ||
}, | ||
StoragePolicy: policy.MustParseStoragePolicy("1s:1d"), | ||
}) | ||
require.NoError(t, err) | ||
}() | ||
} | ||
|
||
wg.Wait() | ||
// Wait for flush | ||
err = writer.Flush() | ||
require.NoError(t, err) | ||
|
||
// Inspect the write | ||
writes := store.Writes() | ||
require.Equal(t, 200, len(writes)) | ||
|
||
seenMap := make(map[string]int, 10) | ||
for _, w := range writes { | ||
str := w.Tags().String() | ||
seenMap[str] = seenMap[str] + 1 | ||
} | ||
|
||
assert.Equal(t, map[string]int{ | ||
"__g0__: foo, __g1__: y, __g2__: z": 100, | ||
"__g0__: x, __g1__: y, __g2__: z": 100, | ||
}, seenMap) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Name “mustGraphiteEncodedTags(...)” to be clear it’s forming graphite set of tags?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sg, nothing really special about them being graphite here, was just working off the repro for test data :p