@@ -566,14 +566,15 @@ describe('Stackdriver Stats Exporter Utils', () => {
566
566
process . env . OC_RESOURCE_LABELS =
567
567
'k8s.pod.name=pod-xyz-123,' +
568
568
'container.name=c1,k8s.namespace.name=default,' +
569
- 'cloud.zone=zone1' ;
569
+ 'cloud.zone=zone1,k8s.cluster.name=cluster1 ' ;
570
570
CoreResource . setup ( ) ;
571
571
const monitoredResource = await getDefaultResource ( 'my-project-id' ) ;
572
572
const { type, labels } = monitoredResource ;
573
573
574
574
assert . strictEqual ( type , 'k8s_container' ) ;
575
- assert . strictEqual ( Object . keys ( labels ) . length , 5 ) ;
575
+ assert . strictEqual ( Object . keys ( labels ) . length , 6 ) ;
576
576
assert . deepStrictEqual ( labels , {
577
+ cluster_name : 'cluster1' ,
577
578
container_name : 'c1' ,
578
579
namespace_name : 'default' ,
579
580
pod_name : 'pod-xyz-123' ,
@@ -598,6 +599,18 @@ describe('Stackdriver Stats Exporter Utils', () => {
598
599
} ) ;
599
600
} ) ;
600
601
602
+ it ( 'should fallback to global type is any of the label is missing' , async ( ) => {
603
+ process . env . OC_RESOURCE_TYPE = 'cloud.google.com/gce/instance' ;
604
+ process . env . OC_RESOURCE_LABELS = 'cloud.zone=zone1' ;
605
+ CoreResource . setup ( ) ;
606
+ const monitoredResource = await getDefaultResource ( 'my-project-id' ) ;
607
+ const { type, labels } = monitoredResource ;
608
+
609
+ assert . strictEqual ( type , 'global' ) ;
610
+ assert . strictEqual ( Object . keys ( labels ) . length , 1 ) ;
611
+ assert . deepStrictEqual ( labels , { project_id : 'my-project-id' } ) ;
612
+ } ) ;
613
+
601
614
it ( 'should return a aws MonitoredResource' , async ( ) => {
602
615
process . env . OC_RESOURCE_TYPE = 'aws.com/ec2/instance' ;
603
616
process . env . OC_RESOURCE_LABELS =
0 commit comments