@@ -328,6 +328,51 @@ func TestServiceSummaryMetricsAggregation(t *testing.T) {
328328 systemtest .ApproveEvents (t , t .Name (), result .Hits .Hits )
329329}
330330
331+ func TestServiceSummaryMetricsAggregationOverflow (t * testing.T ) {
332+ systemtest .CleanupElasticsearch (t )
333+ srv := apmservertest .NewUnstartedServerTB (t )
334+ srv .Config .Aggregation = & apmservertest.AggregationConfig {
335+ ServiceTransactionMaxGroups : 2 ,
336+ }
337+ require .NoError (t , srv .Start ())
338+
339+ f := func (env string ) {
340+ t .Setenv ("ELASTIC_APM_ENVIRONMENT" , env )
341+ timestamp , _ := time .Parse (time .RFC3339Nano , "2006-01-02T15:04:05.999999999Z" ) // should be truncated to 1s
342+ tracer := srv .Tracer ()
343+ tx := tracer .StartTransactionOptions ("name" , "type" , apm.TransactionOptions {Start : timestamp })
344+ tx .Duration = time .Second
345+ tx .End ()
346+ tracer .Flush (nil )
347+ }
348+ f ("dev" )
349+ f ("staging" )
350+ f ("prod" )
351+ f ("test" )
352+
353+ // Wait for the transaction to be indexed, indicating that Elasticsearch
354+ // indices have been setup and we should not risk triggering the shutdown
355+ // timeout while waiting for the aggregated metrics to be indexed.
356+ systemtest .Elasticsearch .ExpectMinDocs (t , 4 , "traces-apm*" ,
357+ estest.TermQuery {Field : "processor.event" , Value : "transaction" },
358+ )
359+ // Stop server to ensure metrics are flushed on shutdown.
360+ assert .NoError (t , srv .Close ())
361+ systemtest .Elasticsearch .ExpectMinDocs (t , 3 , "metrics-apm.service_summary*" ,
362+ estest.BoolQuery {
363+ Must : []interface {}{
364+ estest.TermQuery {Field : "metricset.name" , Value : "service_summary" },
365+ estest.TermQuery {Field : "service.name" , Value : "_other" },
366+ },
367+ },
368+ )
369+ result := systemtest .Elasticsearch .ExpectMinDocs (t , 9 , "metrics-apm.service_summary*" ,
370+ estest.TermQuery {Field : "metricset.name" , Value : "service_summary" },
371+ )
372+ // Ignore timestamp because overflow bucket uses time.Now()
373+ systemtest .ApproveEvents (t , t .Name (), result .Hits .Hits , "@timestamp" )
374+ }
375+
331376func TestNonDefaultRollupIntervalHiddenDataStream (t * testing.T ) {
332377 systemtest .CleanupElasticsearch (t )
333378 srv := apmservertest .NewServerTB (t )
0 commit comments