Skip to content

Commit

Permalink
Add downsampler test case to demonstrate override namespace tag
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleyk committed Nov 12, 2020
1 parent 9db9202 commit 9c3cf01
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/cmd/services/m3coordinator/downsample/downsampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,87 @@ func TestDownsamplerAggregationWithRemoteAggregatorClient(t *testing.T) {
testDownsamplerRemoteAggregation(t, testDownsampler)
}

func TestDownsamplerWithOverrideNamespace(t *testing.T) {
overrideNamespaceTag := "override_namespace_tag"

gaugeMetric := testGaugeMetric{
tags: map[string]string{
nameTag: "http_requests",
"app": "nginx_edge",
"status_code": "500",
"endpoint": "/foo/bar",
"not_rolled_up": "not_rolled_up_value",
// Set namespace tags on ingested metrics.
// The test demonstrates that overrideNamespaceTag is respected, meaning setting
// values on defaultNamespaceTag won't affect aggregation.
defaultNamespaceTag: "namespace_ignored",
},
timedSamples: []testGaugeMetricTimedSample{
{value: 42},
{value: 64, offset: 5 * time.Second},
},
}
res := 5 * time.Second
ret := 30 * 24 * time.Hour
testDownsampler := newTestDownsampler(t, testDownsamplerOptions{
rulesConfig: &RulesConfiguration{
RollupRules: []RollupRuleConfiguration{
{
Filter: fmt.Sprintf(
"%s:http_requests app:* status_code:* endpoint:*",
nameTag),
Transforms: []TransformConfiguration{
{
Transform: &TransformOperationConfiguration{
Type: transformation.PerSecond,
},
},
{
Rollup: &RollupOperationConfiguration{
MetricName: "http_requests_by_status_code",
GroupBy: []string{"app", "status_code", "endpoint"},
Aggregations: []aggregation.Type{aggregation.Sum},
},
},
},
StoragePolicies: []StoragePolicyConfiguration{
{
Resolution: res,
Retention: ret,
},
},
},
},
},
matcherConfig: MatcherConfiguration{NamespaceTag: overrideNamespaceTag},
ingest: &testDownsamplerOptionsIngest{
gaugeMetrics: []testGaugeMetric{gaugeMetric},
},
expect: &testDownsamplerOptionsExpect{
writes: []testExpectedWrite{
{
tags: map[string]string{
nameTag: "http_requests_by_status_code",
string(rollupTagName): string(rollupTagValue),
"app": "nginx_edge",
"status_code": "500",
"endpoint": "/foo/bar",
},
values: []expectedValue{{value: 4.4}},
attributes: &storagemetadata.Attributes{
MetricsType: storagemetadata.AggregatedMetricsType,
Resolution: res,
Retention: ret,
},
},
},
},
})

// Test expected output
testDownsamplerAggregation(t, testDownsampler)
}

func originalStagedMetadata(t *testing.T, testDownsampler testDownsampler) []metricpb.StagedMetadatas {
ds, ok := testDownsampler.downsampler.(*downsampler)
require.True(t, ok)
Expand Down Expand Up @@ -1751,6 +1832,7 @@ type testDownsamplerOptions struct {
sampleAppenderOpts *SampleAppenderOptions
remoteClientMock *client.MockClient
rulesConfig *RulesConfiguration
matcherConfig MatcherConfiguration

// Test ingest and expectations overrides
ingest *testDownsamplerOptionsIngest
Expand Down Expand Up @@ -1821,6 +1903,7 @@ func newTestDownsampler(t *testing.T, opts testDownsamplerOptions) testDownsampl
if opts.rulesConfig != nil {
cfg.Rules = opts.rulesConfig
}
cfg.Matcher = opts.matcherConfig

instance, err := cfg.NewDownsampler(DownsamplerOptions{
Storage: storage,
Expand Down

0 comments on commit 9c3cf01

Please sign in to comment.