@@ -452,7 +452,6 @@ describe('AwsEcsResourceDetector', () => {
452452 } ) ;
453453 } ) ;
454454 } ) ;
455- } ) ;
456455
457456 describe ( 'Container ID extraction' , ( ) => {
458457 const testMetadataUri = 'http://169.254.170.2/v4/test' ;
@@ -491,246 +490,47 @@ describe('AwsEcsResourceDetector', () => {
491490 } ) ;
492491 }
493492
494- describe ( 'new AWS ECS Fargate cgroup format' , ( ) => {
495- it ( 'should extract full container ID from new Fargate format' , async ( ) => {
496- const taskId = 'c23e5f76c09d438aa1824ca4058bdcab' ;
497- const containerId = '1234567890abcdef' ;
498- const cgroupData = `/ecs/${ taskId } /${ taskId } -${ containerId } ` ;
499-
500- setupMocks ( cgroupData ) ;
501- const nockScope = setupMetadataNock ( ) ;
502-
503- const resource = detectResources ( { detectors : [ awsEcsDetector ] } ) ;
504- await resource . waitForAsyncAttributes ?.( ) ;
505-
506- sinon . assert . calledOnce ( readStub ) ;
507- assert . ok ( resource ) ;
508- assertEcsResource ( resource , { } ) ;
509- assertContainerResource ( resource , {
510- name : testHostname ,
511- id : `${ taskId } -${ containerId } ` ,
512- } ) ;
513-
514- nockScope . done ( ) ;
515- } ) ;
516-
517- it ( 'should extract container ID from long cgroup path without truncation' , async ( ) => {
518- const longTaskId = 'abcdefgh12345678abcdefgh12345678abcdefgh12345678' ;
519- const containerId = '1234567890abcdef' ;
520- const cgroupData = `/ecs/${ longTaskId } /${ longTaskId } -${ containerId } ` ;
521-
522- setupMocks ( cgroupData ) ;
523- const nockScope = setupMetadataNock ( ) ;
524-
525- const resource = detectResources ( { detectors : [ awsEcsDetector ] } ) ;
526- await resource . waitForAsyncAttributes ?.( ) ;
527-
528- sinon . assert . calledOnce ( readStub ) ;
529- assert . ok ( resource ) ;
530- assertEcsResource ( resource , { } ) ;
531- assertContainerResource ( resource , {
532- name : testHostname ,
533- id : `${ longTaskId } -${ containerId } ` ,
534- } ) ;
535-
536- nockScope . done ( ) ;
537- } ) ;
538-
539- it ( 'should handle multiple cgroup lines and pick the valid one' , async ( ) => {
540- const taskId = 'c23e5f76c09d438aa1824ca4058bdcab' ;
541- const containerId = '1234567890abcdef' ;
542- const cgroupData = [
543- '12:memory:/ecs' ,
544- '11:cpu:/ecs/task-id' ,
545- `10:devices:/ecs/${ taskId } /${ taskId } -${ containerId } ` ,
546- '9:freezer:/ecs' ,
547- ] . join ( '\n' ) ;
548-
549- setupMocks ( cgroupData ) ;
550- const nockScope = setupMetadataNock ( ) ;
551-
552- const resource = detectResources ( { detectors : [ awsEcsDetector ] } ) ;
553- await resource . waitForAsyncAttributes ?.( ) ;
554-
555- sinon . assert . calledOnce ( readStub ) ;
556- assert . ok ( resource ) ;
557- assertEcsResource ( resource , { } ) ;
558- assertContainerResource ( resource , {
559- name : testHostname ,
560- id : `${ taskId } -${ containerId } ` ,
561- } ) ;
562-
563- nockScope . done ( ) ;
564- } ) ;
565- } ) ;
566-
567- describe ( 'alternative container runtime formats' , ( ) => {
568- it ( 'should handle containerd format with colon separators' , async ( ) => {
569- const taskId = 'c23e5f76c09d438aa1824ca4058bdcab' ;
570- const containerId = '1234567890abcdef' ;
571- const cgroupData = `0::/system.slice/containerd.service/kubepods-burstable-pod.slice:cri-containerd:${ taskId } -${ containerId } ` ;
493+ it ( 'should extract full container ID from new ECS Fargate format' , async ( ) => {
494+ const taskId = 'c23e5f76c09d438aa1824ca4058bdcab' ;
495+ const containerId = '1234567890abcdef' ;
496+ const cgroupData = `/ecs/${ taskId } /${ taskId } -${ containerId } ` ;
572497
573- setupMocks ( cgroupData ) ;
574- const nockScope = setupMetadataNock ( ) ;
498+ setupMocks ( cgroupData ) ;
499+ const nockScope = setupMetadataNock ( ) ;
575500
576- const resource = detectResources ( { detectors : [ awsEcsDetector ] } ) ;
577- await resource . waitForAsyncAttributes ?.( ) ;
578-
579- sinon . assert . calledOnce ( readStub ) ;
580- assert . ok ( resource ) ;
581- assertEcsResource ( resource , { } ) ;
582- assertContainerResource ( resource , {
583- name : testHostname ,
584- id : `${ taskId } -${ containerId } ` ,
585- } ) ;
501+ const resource = detectResources ( { detectors : [ awsEcsDetector ] } ) ;
502+ await resource . waitForAsyncAttributes ?.( ) ;
586503
587- nockScope . done ( ) ;
504+ sinon . assert . calledOnce ( readStub ) ;
505+ assert . ok ( resource ) ;
506+ assertEcsResource ( resource , { } ) ;
507+ assertContainerResource ( resource , {
508+ name : testHostname ,
509+ id : `${ taskId } -${ containerId } ` ,
588510 } ) ;
589511
590- it ( 'should handle docker prefix and scope suffix' , async ( ) => {
591- const taskId = 'c23e5f76c09d438aa1824ca4058bdcab' ;
592- const containerId = '1234567890abcdef' ;
593- const cgroupData = `/docker/docker-${ taskId } -${ containerId } .scope` ;
594-
595- setupMocks ( cgroupData ) ;
596- const nockScope = setupMetadataNock ( ) ;
597-
598- const resource = detectResources ( { detectors : [ awsEcsDetector ] } ) ;
599- await resource . waitForAsyncAttributes ?.( ) ;
600-
601- sinon . assert . calledOnce ( readStub ) ;
602- assert . ok ( resource ) ;
603- assertEcsResource ( resource , { } ) ;
604- assertContainerResource ( resource , {
605- name : testHostname ,
606- id : `${ taskId } -${ containerId } ` ,
607- } ) ;
608-
609- nockScope . done ( ) ;
610- } ) ;
512+ nockScope . done ( ) ;
611513 } ) ;
612514
613- describe ( 'invalid container ID scenarios' , ( ) => {
614- it ( 'should return resource without container ID for invalid format' , async ( ) => {
615- const invalidCgroupData = '/invalid/path/with/non-hex-characters!!!' ;
616-
617- setupMocks ( invalidCgroupData ) ;
618- const nockScope = setupMetadataNock ( ) ;
619-
620- const resource = detectResources ( { detectors : [ awsEcsDetector ] } ) ;
621- await resource . waitForAsyncAttributes ?.( ) ;
622-
623- sinon . assert . calledOnce ( readStub ) ;
624- assert . ok ( resource ) ;
625- assertEcsResource ( resource , { } ) ;
626- assertContainerResource ( resource , {
627- name : testHostname ,
628- } ) ;
629-
630- nockScope . done ( ) ;
631- } ) ;
632-
633- it ( 'should return resource without container ID when too short' , async ( ) => {
634- const shortContainerId = 'short' ;
635- const cgroupData = `/ecs/task/${ shortContainerId } ` ;
636-
637- setupMocks ( cgroupData ) ;
638- const nockScope = setupMetadataNock ( ) ;
639-
640- const resource = detectResources ( { detectors : [ awsEcsDetector ] } ) ;
641- await resource . waitForAsyncAttributes ?.( ) ;
642-
643- sinon . assert . calledOnce ( readStub ) ;
644- assert . ok ( resource ) ;
645- assertEcsResource ( resource , { } ) ;
646- assertContainerResource ( resource , {
647- name : testHostname ,
648- } ) ;
649-
650- nockScope . done ( ) ;
651- } ) ;
652-
653- it ( 'should return resource without container ID when too long' , async ( ) => {
654- const tooLongContainerId = 'a' . repeat ( 129 ) ;
655- const cgroupData = `/ecs/task/${ tooLongContainerId } ` ;
656-
657- setupMocks ( cgroupData ) ;
658- const nockScope = setupMetadataNock ( ) ;
659-
660- const resource = detectResources ( { detectors : [ awsEcsDetector ] } ) ;
661- await resource . waitForAsyncAttributes ?.( ) ;
662-
663- sinon . assert . calledOnce ( readStub ) ;
664- assert . ok ( resource ) ;
665- assertEcsResource ( resource , { } ) ;
666- assertContainerResource ( resource , {
667- name : testHostname ,
668- } ) ;
669-
670- nockScope . done ( ) ;
671- } ) ;
672-
673- it ( 'should return resource without container ID with invalid characters' , async ( ) => {
674- const invalidContainerId = 'invalid@#$%container' ;
675- const cgroupData = `/ecs/task/${ invalidContainerId } ` ;
676-
677- setupMocks ( cgroupData ) ;
678- const nockScope = setupMetadataNock ( ) ;
515+ it ( 'should handle backward compatibility with legacy format' , async ( ) => {
516+ const legacyContainerId =
517+ 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm' ;
679518
680- const resource = detectResources ( { detectors : [ awsEcsDetector ] } ) ;
681- await resource . waitForAsyncAttributes ?. ( ) ;
519+ setupMocks ( legacyContainerId ) ;
520+ const nockScope = setupMetadataNock ( ) ;
682521
683- sinon . assert . calledOnce ( readStub ) ;
684- assert . ok ( resource ) ;
685- assertEcsResource ( resource , { } ) ;
686- assertContainerResource ( resource , {
687- name : testHostname ,
688- } ) ;
522+ const resource = detectResources ( { detectors : [ awsEcsDetector ] } ) ;
523+ await resource . waitForAsyncAttributes ?.( ) ;
689524
690- nockScope . done ( ) ;
525+ sinon . assert . calledOnce ( readStub ) ;
526+ assert . ok ( resource ) ;
527+ assertEcsResource ( resource , { } ) ;
528+ assertContainerResource ( resource , {
529+ name : testHostname ,
530+ id : 'bcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm' ,
691531 } ) ;
692532
693- it ( 'should return resource without container ID for empty processed segment' , async ( ) => {
694- const cgroupData = '/ecs/task/docker-.scope' ;
695-
696- setupMocks ( cgroupData ) ;
697- const nockScope = setupMetadataNock ( ) ;
698-
699- const resource = detectResources ( { detectors : [ awsEcsDetector ] } ) ;
700- await resource . waitForAsyncAttributes ?.( ) ;
701-
702- sinon . assert . calledOnce ( readStub ) ;
703- assert . ok ( resource ) ;
704- assertEcsResource ( resource , { } ) ;
705- assertContainerResource ( resource , {
706- name : testHostname ,
707- } ) ;
708-
709- nockScope . done ( ) ;
710- } ) ;
711- } ) ;
712-
713- describe ( 'backward compatibility' , ( ) => {
714- it ( 'should handle legacy 64-character container ID format' , async ( ) => {
715- const legacyContainerId =
716- 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm' ;
717-
718- setupMocks ( legacyContainerId ) ;
719- const nockScope = setupMetadataNock ( ) ;
720-
721- const resource = detectResources ( { detectors : [ awsEcsDetector ] } ) ;
722- await resource . waitForAsyncAttributes ?.( ) ;
723-
724- sinon . assert . calledOnce ( readStub ) ;
725- assert . ok ( resource ) ;
726- assertEcsResource ( resource , { } ) ;
727- assertContainerResource ( resource , {
728- name : testHostname ,
729- id : 'bcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklm' ,
730- } ) ;
731-
732- nockScope . done ( ) ;
733- } ) ;
533+ nockScope . done ( ) ;
734534 } ) ;
735535 } ) ;
736-
536+ } ) ;
0 commit comments