@@ -1274,6 +1274,87 @@ func TestDownsamplerAggregationWithRemoteAggregatorClient(t *testing.T) {
1274
1274
testDownsamplerRemoteAggregation (t , testDownsampler )
1275
1275
}
1276
1276
1277
+ func TestDownsamplerWithOverrideNamespace (t * testing.T ) {
1278
+ overrideNamespaceTag := "override_namespace_tag"
1279
+
1280
+ gaugeMetric := testGaugeMetric {
1281
+ tags : map [string ]string {
1282
+ nameTag : "http_requests" ,
1283
+ "app" : "nginx_edge" ,
1284
+ "status_code" : "500" ,
1285
+ "endpoint" : "/foo/bar" ,
1286
+ "not_rolled_up" : "not_rolled_up_value" ,
1287
+ // Set namespace tags on ingested metrics.
1288
+ // The test demonstrates that overrideNamespaceTag is respected, meaning setting
1289
+ // values on defaultNamespaceTag won't affect aggregation.
1290
+ defaultNamespaceTag : "namespace_ignored" ,
1291
+ },
1292
+ timedSamples : []testGaugeMetricTimedSample {
1293
+ {value : 42 },
1294
+ {value : 64 , offset : 5 * time .Second },
1295
+ },
1296
+ }
1297
+ res := 5 * time .Second
1298
+ ret := 30 * 24 * time .Hour
1299
+ testDownsampler := newTestDownsampler (t , testDownsamplerOptions {
1300
+ rulesConfig : & RulesConfiguration {
1301
+ RollupRules : []RollupRuleConfiguration {
1302
+ {
1303
+ Filter : fmt .Sprintf (
1304
+ "%s:http_requests app:* status_code:* endpoint:*" ,
1305
+ nameTag ),
1306
+ Transforms : []TransformConfiguration {
1307
+ {
1308
+ Transform : & TransformOperationConfiguration {
1309
+ Type : transformation .PerSecond ,
1310
+ },
1311
+ },
1312
+ {
1313
+ Rollup : & RollupOperationConfiguration {
1314
+ MetricName : "http_requests_by_status_code" ,
1315
+ GroupBy : []string {"app" , "status_code" , "endpoint" },
1316
+ Aggregations : []aggregation.Type {aggregation .Sum },
1317
+ },
1318
+ },
1319
+ },
1320
+ StoragePolicies : []StoragePolicyConfiguration {
1321
+ {
1322
+ Resolution : res ,
1323
+ Retention : ret ,
1324
+ },
1325
+ },
1326
+ },
1327
+ },
1328
+ },
1329
+ matcherConfig : MatcherConfiguration {NamespaceTag : overrideNamespaceTag },
1330
+ ingest : & testDownsamplerOptionsIngest {
1331
+ gaugeMetrics : []testGaugeMetric {gaugeMetric },
1332
+ },
1333
+ expect : & testDownsamplerOptionsExpect {
1334
+ writes : []testExpectedWrite {
1335
+ {
1336
+ tags : map [string ]string {
1337
+ nameTag : "http_requests_by_status_code" ,
1338
+ string (rollupTagName ): string (rollupTagValue ),
1339
+ "app" : "nginx_edge" ,
1340
+ "status_code" : "500" ,
1341
+ "endpoint" : "/foo/bar" ,
1342
+ },
1343
+ values : []expectedValue {{value : 4.4 }},
1344
+ attributes : & storagemetadata.Attributes {
1345
+ MetricsType : storagemetadata .AggregatedMetricsType ,
1346
+ Resolution : res ,
1347
+ Retention : ret ,
1348
+ },
1349
+ },
1350
+ },
1351
+ },
1352
+ })
1353
+
1354
+ // Test expected output
1355
+ testDownsamplerAggregation (t , testDownsampler )
1356
+ }
1357
+
1277
1358
func originalStagedMetadata (t * testing.T , testDownsampler testDownsampler ) []metricpb.StagedMetadatas {
1278
1359
ds , ok := testDownsampler .downsampler .(* downsampler )
1279
1360
require .True (t , ok )
@@ -1751,6 +1832,7 @@ type testDownsamplerOptions struct {
1751
1832
sampleAppenderOpts * SampleAppenderOptions
1752
1833
remoteClientMock * client.MockClient
1753
1834
rulesConfig * RulesConfiguration
1835
+ matcherConfig MatcherConfiguration
1754
1836
1755
1837
// Test ingest and expectations overrides
1756
1838
ingest * testDownsamplerOptionsIngest
@@ -1821,6 +1903,7 @@ func newTestDownsampler(t *testing.T, opts testDownsamplerOptions) testDownsampl
1821
1903
if opts .rulesConfig != nil {
1822
1904
cfg .Rules = opts .rulesConfig
1823
1905
}
1906
+ cfg .Matcher = opts .matcherConfig
1824
1907
1825
1908
instance , err := cfg .NewDownsampler (DownsamplerOptions {
1826
1909
Storage : storage ,
0 commit comments