Repository: apache/airflow

Issue:
Bad parsing for Cloudwatch Group ARN for logging
### Apache Airflow version

2.1.3

### Operating System

All

### Versions of Apache Airflow Providers

_No response_

### Deployment

Other

### Deployment details

_No response_

### What happened

I am deploying Airflow in AWS ECS,
I am trying to send tasks logs to cloudwatch.
Usually log groups in AWS have this format /aws/name_of_service/name_of_component

I configured my env variables as follow
```
    {
      name  = "AIRFLOW__LOGGING__REMOTE_LOGGING",
      value = "true"
    },
    {
      name = "AIRFLOW__LOGGING__REMOTE_BASE_LOG_FOLDER",
      value = "cloudwatch://arn:aws:logs:aaaa:bbbbb:log-group:/aws/ecs/ccccc"
    },
    {
      name  = "AIRFLOW__LOGGING__REMOTE_LOG_CONN_ID",
      value = "aws_default"
    },
```
I am getting this error in my tasks logs
```
*** Reading remote log from Cloudwatch log_group:  log_stream: hello_airflow2/hello_task/2021-11-23T16_29_21.191922+00_00/1.log.
Could not read remote logs from log_group:  log_stream: hello_airflow2/hello_task/2021-11-23T16_29_21.191922+00_00/1.log.
```
It's throwed because the log group is empty
The reason behind this error is this line
https://github.com/apache/airflow/blob/c4fd84accd143977cba57e4daf6daef2af2ff457/airflow/config_templates/airflow_local_settings.py#L202

the result of netloc is "arn:aws:logs:aaaa:bbbbb:log-group:"
```
urlparse("cloudwatch://arn:aws:logs:aaaa:bbbbb:log-group:/aws/ecs/ccccc")
ParseResult(scheme='cloudwatch', netloc='arn:aws:logs:aaaa:bbbbb:log-group:', path='/aws/ecs/ccccc', params='', query='', fragment='')
```
and this line
https://github.com/apache/airflow/blob/86a2a19ad2bdc87a9ad14bb7fde9313b2d7489bb/airflow/providers/amazon/aws/log/cloudwatch_task_handler.py#L53
which will result an empty log group




### What you expected to happen

_No response_

### How to reproduce

_No response_

### Anything else

_No response_

### Are you willing to submit PR?

- [ ] Yes I am willing to submit a PR!

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)



Discussion:

Resolving patch:
diff --git a/airflow/config_templates/airflow_local_settings.py b/airflow/config_templates/airflow_local_settings.py
--- a/airflow/config_templates/airflow_local_settings.py
+++ b/airflow/config_templates/airflow_local_settings.py
@@ -194,12 +194,13 @@
 
         DEFAULT_LOGGING_CONFIG['handlers'].update(S3_REMOTE_HANDLERS)
     elif REMOTE_BASE_LOG_FOLDER.startswith('cloudwatch://'):
+        url_parts = urlparse(REMOTE_BASE_LOG_FOLDER)
         CLOUDWATCH_REMOTE_HANDLERS: Dict[str, Dict[str, str]] = {
             'task': {
                 'class': 'airflow.providers.amazon.aws.log.cloudwatch_task_handler.CloudwatchTaskHandler',
                 'formatter': 'airflow',
                 'base_log_folder': str(os.path.expanduser(BASE_LOG_FOLDER)),
-                'log_group_arn': urlparse(REMOTE_BASE_LOG_FOLDER).netloc,
+                'log_group_arn': url_parts.netloc + url_parts.path,
                 'filename_template': FILENAME_TEMPLATE,
             },
         }


Test patch:
diff --git a/tests/core/test_logging_config.py b/tests/core/test_logging_config.py
--- a/tests/core/test_logging_config.py
+++ b/tests/core/test_logging_config.py
@@ -26,6 +26,7 @@
 from unittest.mock import patch
 
 import pytest
+from parameterized import parameterized
 
 from airflow.configuration import conf
 from tests.test_utils.config import conf_vars
@@ -277,3 +278,40 @@ def test_loading_remote_logging_with_wasb_handler(self):
 
         logger = logging.getLogger('airflow.task')
         assert isinstance(logger.handlers[0], WasbTaskHandler)
+
+    @parameterized.expand(
+        [
+            (
+                'cloudwatch://arn:aws:logs:aaaa:bbbbb:log-group:ccccc',
+                'arn:aws:logs:aaaa:bbbbb:log-group:ccccc',
+            ),
+            (
+                'cloudwatch://arn:aws:logs:aaaa:bbbbb:log-group:aws/ccccc',
+                'arn:aws:logs:aaaa:bbbbb:log-group:aws/ccccc',
+            ),
+            (
+                'cloudwatch://arn:aws:logs:aaaa:bbbbb:log-group:/aws/ecs/ccccc',
+                'arn:aws:logs:aaaa:bbbbb:log-group:/aws/ecs/ccccc',
+            ),
+        ]
+    )
+    def test_log_group_arns_remote_logging_with_cloudwatch_handler(
+        self, remote_base_log_folder, log_group_arn
+    ):
+        """Test if the correct ARNs are configured for Cloudwatch"""
+        from airflow.config_templates import airflow_local_settings
+        from airflow.logging_config import configure_logging
+
+        with conf_vars(
+            {
+                ('logging', 'remote_logging'): 'True',
+                ('logging', 'remote_log_conn_id'): 'some_cloudwatch',
+                ('logging', 'remote_base_log_folder'): remote_base_log_folder,
+            }
+        ):
+            importlib.reload(airflow_local_settings)
+            configure_logging()
+            assert (
+                airflow_local_settings.DEFAULT_LOGGING_CONFIG['handlers']['task']['log_group_arn']
+                == log_group_arn
+            )