@@ -559,6 +559,58 @@ func TestReporterResetTagsAfterReturnToPool(t *testing.T) {
559
559
require .Equal (t , 0 , len (filtered [1 ].GetTags ()))
560
560
}
561
561
562
+ func TestReporterCommmonTagsInternal (t * testing.T ) {
563
+ var wg sync.WaitGroup
564
+ server := newFakeM3Server (t , & wg , false , Compact )
565
+ go server .Serve ()
566
+ defer server .Close ()
567
+
568
+ internalTags := map [string ]string {
569
+ "internal1" : "test1" ,
570
+ "internal2" : "test2" ,
571
+ }
572
+
573
+ r , err := NewReporter (Options {
574
+ HostPorts : []string {server .Addr },
575
+ Service : "test-service" ,
576
+ CommonTags : defaultCommonTags ,
577
+ MaxQueueSize : queueSize ,
578
+ IncludeHost : true ,
579
+ MaxPacketSizeBytes : maxPacketSize ,
580
+ InternalTags : internalTags ,
581
+ })
582
+ require .NoError (t , err )
583
+ defer r .Close ()
584
+
585
+ c := r .AllocateCounter ("testCounter1" , nil )
586
+ c .ReportCount (1 )
587
+ wg .Add (internalMetrics + 1 )
588
+ r .Flush ()
589
+ wg .Wait ()
590
+
591
+ numInternalMetricsActual := 0
592
+ metrics := server .Service .getMetrics ()
593
+ require .Equal (t , internalMetrics + 1 , len (metrics ))
594
+ for _ , metric := range metrics {
595
+ if strings .HasPrefix (metric .Name , "tally.internal" ) {
596
+ numInternalMetricsActual ++
597
+ for k , v := range internalTags {
598
+ require .True (t , tagEquals (metric .Tags , k , v ))
599
+ }
600
+ } else {
601
+ require .Equal (t , "testCounter1" , metric .Name )
602
+ require .False (t , tagIncluded (metric .Tags , "internal1" ))
603
+ require .False (t , tagIncluded (metric .Tags , "internal2" ))
604
+ }
605
+ // The following tags should not be present as part of the individual metrics
606
+ // as they are common tags.
607
+ require .False (t , tagIncluded (metric .Tags , "host" ))
608
+ require .False (t , tagIncluded (metric .Tags , "instance" ))
609
+ require .False (t , tagIncluded (metric .Tags , "service" ))
610
+ }
611
+ require .Equal (t , internalMetrics , numInternalMetricsActual )
612
+ }
613
+
562
614
func TestReporterHasReportingAndTaggingCapability (t * testing.T ) {
563
615
r , err := NewReporter (Options {
564
616
HostPorts : []string {"127.0.0.1:9052" },
@@ -587,6 +639,13 @@ type fakeM3ServerPackets struct {
587
639
values [][]byte
588
640
}
589
641
642
+ // newFakeM3Server creates a new fake M3 server that listens on a random port
643
+ // and returns the server.
644
+ // The server will wait for the given wait group to be done before returning.
645
+ // If countBatches is true, the server will wait consider the wg.Add()s to be
646
+ // representing batches and will do a eg.Done() for each encountered batch.
647
+ // But if countBatches is false, the server will do the same thing but for individual
648
+ // metrics instead of batches.
590
649
func newFakeM3Server (t * testing.T , wg * sync.WaitGroup , countBatches bool , protocol Protocol ) * fakeM3Server {
591
650
service := newFakeM3Service (wg , countBatches )
592
651
processor := m3thrift .NewM3Processor (service )
0 commit comments