-
Notifications
You must be signed in to change notification settings - Fork 454
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
[coord] Configurable blackholed SP's back from agg #2641
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
04d3a68
[coord] Configurable blackholed SP's back from agg
schallert d76edd7
wire up to config
schallert da6796b
Merge branch 'master' into schallert/coord_sp_blackhole
schallert 6d4931f
add log message
schallert 35a8954
pass policies to handler
schallert 8489665
truncate SPs
schallert 7f95a8a
paranoid test
schallert ee729b3
array of blackhole policies
schallert 533b999
log policies
schallert f0dba2b
index -> append
schallert 0fd5198
test base policy
schallert 22b2304
Merge branch 'master' into schallert/coord_sp_blackhole
schallert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ import ( | |
"net" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/m3db/m3/src/metrics/encoding/protobuf" | ||
"github.com/m3db/m3/src/metrics/metric" | ||
|
@@ -36,13 +37,19 @@ import ( | |
"github.com/m3db/m3/src/msg/protocol/proto" | ||
"github.com/m3db/m3/src/x/instrument" | ||
"github.com/m3db/m3/src/x/server" | ||
xtime "github.com/m3db/m3/src/x/time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var ( | ||
testID = "stats.sjc1.gauges.m3+some-name+dc=sjc1,env=production,service=foo,type=gauge" | ||
validStoragePolicy = policy.MustParseStoragePolicy("1m:40d") | ||
testID = "stats.sjc1.gauges.m3+some-name+dc=sjc1,env=production,service=foo,type=gauge" | ||
|
||
// baseStoragePolicy represents what we typically define in config for SP. | ||
// precisionStoragePolicy is the same retention/resolution, but includes the | ||
// precision (which is often included with incoming writes). | ||
baseStoragePolicy = policy.MustParseStoragePolicy("1m:40d") | ||
precisionStoragePolicy = policy.NewStoragePolicy(time.Minute, xtime.Second, 40*24*time.Hour) | ||
) | ||
|
||
func TestM3MsgServerWithProtobufHandler(t *testing.T) { | ||
|
@@ -74,7 +81,7 @@ func TestM3MsgServerWithProtobufHandler(t *testing.T) { | |
Value: 1, | ||
Type: metric.GaugeType, | ||
}, | ||
StoragePolicy: validStoragePolicy, | ||
StoragePolicy: precisionStoragePolicy, | ||
} | ||
|
||
encoder := protobuf.NewAggregatedEncoder(nil) | ||
|
@@ -98,7 +105,7 @@ func TestM3MsgServerWithProtobufHandler(t *testing.T) { | |
Value: 0, | ||
Type: metric.UnknownType, | ||
}, | ||
StoragePolicy: validStoragePolicy, | ||
StoragePolicy: precisionStoragePolicy, | ||
} | ||
require.NoError(t, encoder.Encode(m2, 3000)) | ||
enc = proto.NewEncoder(opts.EncoderOptions()) | ||
|
@@ -127,6 +134,74 @@ func TestM3MsgServerWithProtobufHandler(t *testing.T) { | |
require.Equal(t, m2.StoragePolicy, payload.sp) | ||
} | ||
|
||
func TestM3MsgServerWithProtobufHandler_Blackhole(t *testing.T) { | ||
l, err := net.Listen("tcp", "127.0.0.1:0") | ||
require.NoError(t, err) | ||
|
||
w := &mockWriter{m: make(map[string]payload)} | ||
hOpts := Options{ | ||
WriteFn: w.write, | ||
InstrumentOptions: instrument.NewOptions(), | ||
BlockholePolicies: []policy.StoragePolicy{baseStoragePolicy}, | ||
} | ||
opts := consumer.NewOptions(). | ||
SetAckBufferSize(1). | ||
SetConnectionWriteBufferSize(1) | ||
|
||
s := server.NewServer( | ||
"a", | ||
consumer.NewMessageHandler(newProtobufProcessor(hOpts), opts), | ||
server.NewOptions(), | ||
) | ||
s.Serve(l) | ||
|
||
conn, err := net.Dial("tcp", l.Addr().String()) | ||
require.NoError(t, err) | ||
m1 := aggregated.MetricWithStoragePolicy{ | ||
Metric: aggregated.Metric{ | ||
ID: []byte(testID), | ||
TimeNanos: 1000, | ||
Value: 1, | ||
Type: metric.GaugeType, | ||
}, | ||
StoragePolicy: precisionStoragePolicy, | ||
} | ||
|
||
encoder := protobuf.NewAggregatedEncoder(nil) | ||
require.NoError(t, encoder.Encode(m1, 2000)) | ||
enc := proto.NewEncoder(opts.EncoderOptions()) | ||
require.NoError(t, enc.Encode(&msgpb.Message{ | ||
Value: encoder.Buffer().Bytes(), | ||
})) | ||
_, err = conn.Write(enc.Bytes()) | ||
require.NoError(t, err) | ||
|
||
var a msgpb.Ack | ||
dec := proto.NewDecoder(conn, opts.DecoderOptions(), 10) | ||
require.NoError(t, dec.Decode(&a)) | ||
require.Equal(t, 0, w.ingested()) | ||
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. Worth adding a test with |
||
|
||
// Ensure a metric with a difference policy still gets ingested. | ||
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: different policy |
||
m2 := aggregated.MetricWithStoragePolicy{ | ||
Metric: aggregated.Metric{ | ||
ID: []byte{}, | ||
TimeNanos: 0, | ||
Value: 0, | ||
Type: metric.UnknownType, | ||
}, | ||
StoragePolicy: policy.MustParseStoragePolicy("5m:180d"), | ||
} | ||
require.NoError(t, encoder.Encode(m2, 3000)) | ||
enc = proto.NewEncoder(opts.EncoderOptions()) | ||
require.NoError(t, enc.Encode(&msgpb.Message{ | ||
Value: encoder.Buffer().Bytes(), | ||
})) | ||
_, err = conn.Write(enc.Bytes()) | ||
require.NoError(t, err) | ||
require.NoError(t, dec.Decode(&a)) | ||
require.Equal(t, 1, w.ingested()) | ||
} | ||
|
||
type mockWriter struct { | ||
sync.Mutex | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: using append instead of indexed insert is a little more future proof