@@ -44,6 +44,7 @@ const (
4444 nonComplianceMessageField = "non_compliance_message"
4545 custodianWatchInterval = 30 * time .Second
4646 custodianOutputTailBytes = 4096
47+ custodianLogTailMaxSections = 5
4748)
4849
4950var lookPath = exec .LookPath
@@ -1116,12 +1117,18 @@ func processSocketInodes(pid int) (map[string]bool, error) {
11161117 fdDir := filepath .Join ("/proc" , strconv .Itoa (pid ), "fd" )
11171118 entries , err := os .ReadDir (fdDir )
11181119 if err != nil {
1120+ if errors .Is (err , fs .ErrNotExist ) || errors .Is (err , os .ErrNotExist ) {
1121+ return map [string ]bool {}, nil
1122+ }
11191123 return nil , err
11201124 }
11211125 inodes := map [string ]bool {}
11221126 for _ , entry := range entries {
11231127 target , err := os .Readlink (filepath .Join (fdDir , entry .Name ()))
11241128 if err != nil {
1129+ if errors .Is (err , fs .ErrNotExist ) || errors .Is (err , os .ErrNotExist ) {
1130+ continue
1131+ }
11251132 continue
11261133 }
11271134 if strings .HasPrefix (target , "socket:[" ) && strings .HasSuffix (target , "]" ) {
@@ -1255,8 +1262,13 @@ func readCustodianLogArtifactsForPaths(logPaths []string, maxBytes int) ([]strin
12551262 return nil , "" , nil
12561263 }
12571264
1258- sections := make ([]string , 0 , len (logPaths ))
1259- for _ , logPath := range logPaths {
1265+ sections := make ([]string , 0 , min (len (logPaths ), custodianLogTailMaxSections ))
1266+ for i , logPath := range logPaths {
1267+ if i >= custodianLogTailMaxSections {
1268+ remaining := len (logPaths ) - custodianLogTailMaxSections
1269+ sections = append (sections , fmt .Sprintf ("custodian log tail truncated: %d additional custodian-run.log file(s) omitted" , remaining ))
1270+ break
1271+ }
12601272 content , err := readFileTail (logPath , maxBytes )
12611273 if err != nil {
12621274 return logPaths , "" , fmt .Errorf ("failed to read custodian log %s: %w" , logPath , err )
@@ -2828,16 +2840,18 @@ func awsResourceExplorerURLWithReason(payload *StandardizedResourcePayload) (str
28282840 return "" , reason
28292841 }
28302842
2843+ partition := awsPartitionFromARN (resourceARN )
28312844 region := awsRegionFromARN (resourceARN )
2832- if region == "" && payload .Resource .Region != "" && payload .Resource .Region != "global" {
2845+ if region == "" && payload .Resource .Region != "" && payload .Resource .Region != "global" && awsPartitionForRegion ( payload . Resource . Region ) == partition {
28332846 region = payload .Resource .Region
28342847 }
28352848 if region == "" {
2836- region = "us-east-1"
2849+ region = awsDefaultConsoleRegionForPartition ( partition )
28372850 }
28382851
28392852 query := "id:" + resourceARN
2840- return "https://console.aws.amazon.com/resource-explorer/home?region=" + url .QueryEscape (region ) + "#/search?query=" + url .QueryEscape (query ), ""
2853+ consoleDomain := awsConsoleDomainForPartition (partition )
2854+ return "https://" + consoleDomain + "/resource-explorer/home?region=" + url .QueryEscape (region ) + "#/search?query=" + url .QueryEscape (query ), ""
28412855}
28422856
28432857func awsResourceExplorerResourceARN (payload * StandardizedResourcePayload ) (string , string ) {
@@ -2880,6 +2894,28 @@ func awsPartitionFromARN(arnValue string) string {
28802894 return ""
28812895}
28822896
2897+ func awsConsoleDomainForPartition (partition string ) string {
2898+ switch partition {
2899+ case "aws-cn" :
2900+ return "console.amazonaws.cn"
2901+ case "aws-us-gov" :
2902+ return "console.amazonaws-us-gov.com"
2903+ default :
2904+ return "console.aws.amazon.com"
2905+ }
2906+ }
2907+
2908+ func awsDefaultConsoleRegionForPartition (partition string ) string {
2909+ switch partition {
2910+ case "aws-cn" :
2911+ return "cn-north-1"
2912+ case "aws-us-gov" :
2913+ return "us-gov-west-1"
2914+ default :
2915+ return "us-east-1"
2916+ }
2917+ }
2918+
28832919func awsPartitionForRegion (region string ) string {
28842920 region = strings .TrimSpace (strings .ToLower (region ))
28852921 switch {
0 commit comments