Repository: cloud-custodian/cloud-custodian

Issue:
AWS-Metric filter on log-group is failing
I  am writing a policy to  with  metric  filter on log groups. The  policy is
```
policies:   
    - name: logs-incoming-bytes
      resource: log-group
      comment: |
        Ingested logs size 
      filters:
        - type: metrics
          namespace: AWS/Logs
          name: IncomingBytes          
          value: 0         
          statistics: Sum
```
This is failing with below error,

```
2020-07-09 17:21:54,198: custodian.filters:WARNING CW Retrieval error: 'LogGroupName'
2020-07-09 17:21:54,199: custodian.policy:INFO policy:logs-incoming-bytes resource:log-group region:us-east-1 count:0 time:4.81
```
Please look into this.

Background (please complete the following information):**
 - OS: OSX 10.15.5
 - Python Version: python 3.7.7
 - Custodian Version: 0.8.44.2
 - Tool Version: [if applicable]
 - Cloud Provider: aws
 


Discussion:
kapilt: this doesn't actually make a metrics filter work, implementing a unit test will demonstrate that

Patch:
diff --git a/c7n/resources/cw.py b/c7n/resources/cw.py
index b0ccf6e14..6c8655a52 100644
--- a/c7n/resources/cw.py
+++ b/c7n/resources/cw.py
@@ -176,6 +176,13 @@ class LogGroup(QueryResourceManager):
         return [r['arn'][:-2] for r in resources]
 
 
+@LogGroup.filter_registry.register('metrics')
+class LogGroupMetrics(MetricsFilter):
+
+    def get_dimensions(self, resource):
+        return [{'Name': 'LogGroupName', 'Value': resource['logGroupName']}]
+
+
 @LogGroup.action_registry.register('retention')
 class Retention(BaseAction):
     """Action to set the retention period (in days) for CloudWatch log groups


Test patch:
diff --git a/tests/data/placebo/test_log_group_metric/logs.DescribeLogGroups_1.json b/tests/data/placebo/test_log_group_metric/logs.DescribeLogGroups_1.json
new file mode 100644
index 000000000..fcbcc6f18
--- /dev/null
+++ b/tests/data/placebo/test_log_group_metric/logs.DescribeLogGroups_1.json
@@ -0,0 +1,22 @@
+{
+    "status_code": 200,
+    "data": {
+        "logGroups": [
+            {
+                "logGroupName": "/aws/lambda/myIOTFunction",
+                "creationTime": 6441605581965,
+                "metricFilterCount": 0,
+                "arn": "arn:aws:logs:us-west-2:644160558196:log-group:/aws/lambda/myIOTFunction:*",
+                "storedBytes": 857324
+            },
+            {
+                "logGroupName": "devlog",
+                "creationTime": 6441605581968,
+                "metricFilterCount": 0,
+                "arn": "arn:aws:logs:us-west-2:644160558196:log-group:devlog:*",
+                "storedBytes": 0
+            }
+        ],
+        "ResponseMetadata": {}
+    }
+}
\ No newline at end of file
diff --git a/tests/data/placebo/test_log_group_metric/monitoring.GetMetricStatistics_1.json b/tests/data/placebo/test_log_group_metric/monitoring.GetMetricStatistics_1.json
new file mode 100644
index 000000000..5478a41ce
--- /dev/null
+++ b/tests/data/placebo/test_log_group_metric/monitoring.GetMetricStatistics_1.json
@@ -0,0 +1,23 @@
+{
+    "status_code": 200,
+    "data": {
+        "Label": "IncomingBytes",
+        "Datapoints": [
+            {
+                "Timestamp": {
+                    "hour": 11, 
+                    "__class__": "datetime", 
+                    "month": 8, 
+                    "second": 0, 
+                    "microsecond": 0, 
+                    "year": 2016, 
+                    "day": 8, 
+                    "minute": 46
+                }, 
+                "Average": 107.0, 
+                "Unit": "Bytes"
+            }  
+        ],
+        "ResponseMetadata": {}
+    }
+}
\ No newline at end of file
diff --git a/tests/data/placebo/test_log_group_metric/tagging.GetResources_1.json b/tests/data/placebo/test_log_group_metric/tagging.GetResources_1.json
new file mode 100644
index 000000000..8b704d185
--- /dev/null
+++ b/tests/data/placebo/test_log_group_metric/tagging.GetResources_1.json
@@ -0,0 +1,8 @@
+{
+    "status_code": 200,
+    "data": {
+        "PaginationToken": "",
+        "ResourceTagMappingList": [],
+        "ResponseMetadata": {}
+    }
+}
\ No newline at end of file
diff --git a/tests/test_cwl.py b/tests/test_cwl.py
index ff2525d45..8ba8ec007 100644
--- a/tests/test_cwl.py
+++ b/tests/test_cwl.py
@@ -161,3 +161,20 @@ class LogGroupTest(BaseTest):
         self.assertEqual(
             results[0]['kmsKeyId'],
             'arn:aws:kms:us-west-2:644160558196:key/6f13fc53-8da0-46f2-9c69-c1f9fbf471d7')
+
+    def test_metrics(self):
+        session_factory = self.replay_flight_data('test_log_group_metric')
+        p = self.load_policy(
+            {'name': 'metric-log-group',
+             'resource': 'log-group',
+             'filters': [
+                 {"logGroupName": "/aws/lambda/myIOTFunction"},
+                 {"type": "metrics",
+                  "name": "IncomingBytes",
+                  "value": 1,
+                  "op": "greater-than"}]},
+            config={'region': 'us-west-2'},
+            session_factory=session_factory)
+        resources = p.run()
+        self.assertEqual(len(resources), 1)
+        self.assertIn('c7n.metrics', resources[0])