@@ -566,14 +566,15 @@ describe('Stackdriver Stats Exporter Utils', () => {
566566 process . env . OC_RESOURCE_LABELS =
567567 'k8s.pod.name=pod-xyz-123,' +
568568 'container.name=c1,k8s.namespace.name=default,' +
569- 'cloud.zone=zone1' ;
569+ 'cloud.zone=zone1,k8s.cluster.name=cluster1 ' ;
570570 CoreResource . setup ( ) ;
571571 const monitoredResource = await getDefaultResource ( 'my-project-id' ) ;
572572 const { type, labels } = monitoredResource ;
573573
574574 assert . strictEqual ( type , 'k8s_container' ) ;
575- assert . strictEqual ( Object . keys ( labels ) . length , 5 ) ;
575+ assert . strictEqual ( Object . keys ( labels ) . length , 6 ) ;
576576 assert . deepStrictEqual ( labels , {
577+ cluster_name : 'cluster1' ,
577578 container_name : 'c1' ,
578579 namespace_name : 'default' ,
579580 pod_name : 'pod-xyz-123' ,
@@ -598,6 +599,18 @@ describe('Stackdriver Stats Exporter Utils', () => {
598599 } ) ;
599600 } ) ;
600601
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+
601614 it ( 'should return a aws MonitoredResource' , async ( ) => {
602615 process . env . OC_RESOURCE_TYPE = 'aws.com/ec2/instance' ;
603616 process . env . OC_RESOURCE_LABELS =
0 commit comments