You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "geraj1010 (via GitHub)" <gi...@apache.org> on 2024/08/13 00:52:22 UTC

[PR] #40533 - Added logging device and logging device options [airflow]

geraj1010 opened a new pull request, #41416:
URL: https://github.com/apache/airflow/pull/41416

   <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #40533 
   related: #40533 
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   
   
   <!-- Please keep an empty line above the dashes. -->
   Updated the DockerSwarmOperator with logging device and logging device options parameters as requested. I restricted support for only 'json-file' and 'gelf', since that is all I was able to test locally. I can include support for other logging drivers (e.g. fluentd) if it makes sense. Also, I wasn't sure if I should have a check in place for valid logging options. Happy to explore if it makes sense. Here is some info on the GELF logging driver and its options, https://docs.docker.com/engine/logging/drivers/gelf/. 
   
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "geraj1010 (via GitHub)" <gi...@apache.org>.
geraj1010 commented on code in PR #41416:
URL: https://github.com/apache/airflow/pull/41416#discussion_r1722649363


##########
tests/providers/docker/operators/test_docker_swarm.py:
##########
@@ -345,3 +351,46 @@ def test_service_args_list(self, types_mock, docker_api_client_patcher):
             configs=None,
             secrets=None,
         )
+
+    @mock.patch("airflow.providers.docker.operators.docker_swarm.types")
+    def test_logging_driver(self, types_mock, docker_api_client_patcher):
+        mock_obj = mock.Mock()
+
+        client_mock = mock.Mock(spec=APIClient)
+        client_mock.create_service.return_value = {"ID": "some_id"}
+        client_mock.images.return_value = []
+        client_mock.pull.return_value = [b'{"status":"pull log"}']
+        client_mock.tasks.return_value = [{"Status": {"State": "complete"}}]
+        types_mock.TaskTemplate.return_value = mock_obj
+        types_mock.ContainerSpec.return_value = mock_obj
+        types_mock.RestartPolicy.return_value = mock_obj
+        types_mock.Resources.return_value = mock_obj
+
+        docker_api_client_patcher.return_value = client_mock
+
+        operator = DockerSwarmOperator(
+            image="", logging_driver="json-file", task_id="unittest", enable_logging=False
+        )
+        operator.execute(None)

Review Comment:
   okay, I have updated the test and confirmed that it passed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W merged PR #41416:
URL: https://github.com/apache/airflow/pull/41416


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "geraj1010 (via GitHub)" <gi...@apache.org>.
geraj1010 commented on code in PR #41416:
URL: https://github.com/apache/airflow/pull/41416#discussion_r1730474148


##########
.pre-commit-config.yaml:
##########
@@ -779,7 +779,7 @@ repos:
         files: ^\.pre-commit-config\.yaml$|^.*_installed_providers\.txt$
         pass_filenames: false
         require_serial: true
-      - id: update-spelling-wordlist-to-be-sorted
+      - id: update--wordlist-to-be-sorted

Review Comment:
   Thank you. I have updated it. I wonder why I needed to do that? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #41416:
URL: https://github.com/apache/airflow/pull/41416#discussion_r1718118927


##########
airflow/providers/docker/operators/docker_swarm.py:
##########
@@ -116,6 +126,8 @@ def __init__(
         networks: list[str | types.NetworkAttachmentConfig] | None = None,
         placement: types.Placement | list[types.Placement] | None = None,
         container_resources: types.Resources | None = None,
+        logging_driver: str | None = None,

Review Comment:
   If only `json-file` and `gelf` is supported, maybe we could use `literal` here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on PR #41416:
URL: https://github.com/apache/airflow/pull/41416#issuecomment-2293009908

   We might need to add some unit tests to this change as well


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "geraj1010 (via GitHub)" <gi...@apache.org>.
geraj1010 commented on PR #41416:
URL: https://github.com/apache/airflow/pull/41416#issuecomment-2293616313

   @Lee-W I'm not quite sure what kind of unit tests would be valid here, since this is an operator update. The operator doesn't return anything to check. I do have a test DAG if that counts, but you would need to have Docker Swarm and Graylog setup to test.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "geraj1010 (via GitHub)" <gi...@apache.org>.
geraj1010 commented on code in PR #41416:
URL: https://github.com/apache/airflow/pull/41416#discussion_r1715955116


##########
airflow/providers/docker/operators/docker_swarm.py:
##########
@@ -128,12 +140,25 @@ def __init__(
         self.networks = networks
         self.placement = placement
         self.container_resources = container_resources or types.Resources(mem_limit=self.mem_limit)
+        self.logging_driver = logging_driver
+        self.logging_driver_opts = logging_driver_opts
 
     def execute(self, context: Context) -> None:
         self.environment["AIRFLOW_TMP_DIR"] = self.tmp_dir
         return self._run_service()
 
     def _run_service(self) -> None:
+        if self.logging_driver:
+            logging_driver = self.logging_driver.lower()
+            supported_logging_drivers = ["json-file", "gelf"]
+            if logging_driver not in supported_logging_drivers:
+                raise AirflowException(
+                    f"Unsupported logging driver provided: {logging_driver}. Must be one of: [{', '.join(supported_logging_drivers)}]"
+                )
+            log_driver = types.DriverConfig(logging_driver, self.logging_driver_opts)

Review Comment:
   That's not a bad idea, since I don't think we would want the operator object to be created if there is any invalid arguments. I have made the update and moved the validation to init.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "geraj1010 (via GitHub)" <gi...@apache.org>.
geraj1010 commented on code in PR #41416:
URL: https://github.com/apache/airflow/pull/41416#discussion_r1720610991


##########
airflow/providers/docker/operators/docker_swarm.py:
##########
@@ -116,6 +126,8 @@ def __init__(
         networks: list[str | types.NetworkAttachmentConfig] | None = None,
         placement: types.Placement | list[types.Placement] | None = None,
         container_resources: types.Resources | None = None,
+        logging_driver: str | None = None,

Review Comment:
   I decided to remove `logging_driver = self.logging_driver.lower()`, which enabled me to add type `Literal`. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "geraj1010 (via GitHub)" <gi...@apache.org>.
geraj1010 commented on code in PR #41416:
URL: https://github.com/apache/airflow/pull/41416#discussion_r1719322139


##########
airflow/providers/docker/operators/docker_swarm.py:
##########
@@ -116,6 +126,8 @@ def __init__(
         networks: list[str | types.NetworkAttachmentConfig] | None = None,
         placement: types.Placement | list[types.Placement] | None = None,
         container_resources: types.Resources | None = None,
+        logging_driver: str | None = None,

Review Comment:
   It would make it more clear about which logging drivers are available. However, `mypy` doesn't like it the `Literal` type here:
   ```
   airflow/providers/docker/operators/docker_swarm.py:147: error: Incompatible
   types in assignment (expression has type "str", variable has type
   "Optional[Literal['json-file', 'gelf']]")  [assignment]
                   logging_driver = cast(str, self.logging_driver.lower())
   ```
   I think I could use an `Enum`, but then I would have to create an enum class just for logging drivers. Not sure if it's really worth the extra effort.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #41416:
URL: https://github.com/apache/airflow/pull/41416#discussion_r1719489589


##########
airflow/providers/docker/operators/docker_swarm.py:
##########
@@ -116,6 +126,8 @@ def __init__(
         networks: list[str | types.NetworkAttachmentConfig] | None = None,
         placement: types.Placement | list[types.Placement] | None = None,
         container_resources: types.Resources | None = None,
+        logging_driver: str | None = None,

Review Comment:
   I think it an ok one as this is more clear.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "geraj1010 (via GitHub)" <gi...@apache.org>.
geraj1010 commented on code in PR #41416:
URL: https://github.com/apache/airflow/pull/41416#discussion_r1724297423


##########
.pre-commit-config.yaml:
##########
@@ -779,7 +779,7 @@ repos:
         files: ^\.pre-commit-config\.yaml$|^.*_installed_providers\.txt$
         pass_filenames: false
         require_serial: true
-      - id: update-spelling-wordlist-to-be-sorted
+      - id: update--wordlist-to-be-sorted

Review Comment:
   I have pushed another update with the `pre-commit` changes.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "geraj1010 (via GitHub)" <gi...@apache.org>.
geraj1010 commented on code in PR #41416:
URL: https://github.com/apache/airflow/pull/41416#discussion_r1719920651


##########
airflow/providers/docker/operators/docker_swarm.py:
##########
@@ -116,6 +126,8 @@ def __init__(
         networks: list[str | types.NetworkAttachmentConfig] | None = None,
         placement: types.Placement | list[types.Placement] | None = None,
         container_resources: types.Resources | None = None,
+        logging_driver: str | None = None,

Review Comment:
   Okay sounds good. Would that error prevent me from pushing? I cannot seem to push the update to the repo.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "geraj1010 (via GitHub)" <gi...@apache.org>.
geraj1010 commented on code in PR #41416:
URL: https://github.com/apache/airflow/pull/41416#discussion_r1720610991


##########
airflow/providers/docker/operators/docker_swarm.py:
##########
@@ -116,6 +126,8 @@ def __init__(
         networks: list[str | types.NetworkAttachmentConfig] | None = None,
         placement: types.Placement | list[types.Placement] | None = None,
         container_resources: types.Resources | None = None,
+        logging_driver: str | None = None,

Review Comment:
   I decided to remove `logging_driver = self.logging_driver.lower()`, which enabled me to add type `Literal`. 
   
   I have also added two unit tests for checking if `logging_driver` works and for entering an invalid/unsupported `logging_driver` value.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #41416:
URL: https://github.com/apache/airflow/pull/41416#discussion_r1730203971


##########
.pre-commit-config.yaml:
##########
@@ -779,7 +779,7 @@ repos:
         files: ^\.pre-commit-config\.yaml$|^.*_installed_providers\.txt$
         pass_filenames: false
         require_serial: true
-      - id: update-spelling-wordlist-to-be-sorted
+      - id: update--wordlist-to-be-sorted

Review Comment:
   ```suggestion
         - id: update-spelling-wordlist-to-be-sorted
   ```
   
   I think this is still missed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] #40533 - Added logging device and logging device options [airflow]

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #41416:
URL: https://github.com/apache/airflow/pull/41416#issuecomment-2285144511

   Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
   Here are some useful points:
   - Pay attention to the quality of your code (ruff, mypy and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#prerequisites-for-pre-commit-hooks) will help you with that.
   - In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/docs/apache-airflow/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
   - Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
   - Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
   - Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
   - Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#coding-style-and-best-practices).
   - Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
   Apache Airflow is a community-driven project and together we are making it better 🚀.
   In case of doubts contact the developers at:
   Mailing List: dev@airflow.apache.org
   Slack: https://s.apache.org/airflow-slack
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "geraj1010 (via GitHub)" <gi...@apache.org>.
geraj1010 commented on PR #41416:
URL: https://github.com/apache/airflow/pull/41416#issuecomment-2308577331

   @Lee-W I have update the `spelling_wordlist.txt`, but the Static checks is still failing. Is there anything else I need to do?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "geraj1010 (via GitHub)" <gi...@apache.org>.
geraj1010 commented on PR #41416:
URL: https://github.com/apache/airflow/pull/41416#issuecomment-2294633490

   @Lee-W 
   I have added two unit tests for checking if `logging_driver` works and for entering an invalid/unsupported `logging_driver` value.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #41416:
URL: https://github.com/apache/airflow/pull/41416#discussion_r1723067968


##########
.pre-commit-config.yaml:
##########
@@ -779,7 +779,7 @@ repos:
         files: ^\.pre-commit-config\.yaml$|^.*_installed_providers\.txt$
         pass_filenames: false
         require_serial: true
-      - id: update-spelling-wordlist-to-be-sorted
+      - id: update--wordlist-to-be-sorted

Review Comment:
   ```suggestion
         - id: update-spelling-wordlist-to-be-sorted
   ```
   we probably don't want to change it. i guess this is an accident



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "geraj1010 (via GitHub)" <gi...@apache.org>.
geraj1010 commented on code in PR #41416:
URL: https://github.com/apache/airflow/pull/41416#discussion_r1722649363


##########
tests/providers/docker/operators/test_docker_swarm.py:
##########
@@ -345,3 +351,46 @@ def test_service_args_list(self, types_mock, docker_api_client_patcher):
             configs=None,
             secrets=None,
         )
+
+    @mock.patch("airflow.providers.docker.operators.docker_swarm.types")
+    def test_logging_driver(self, types_mock, docker_api_client_patcher):
+        mock_obj = mock.Mock()
+
+        client_mock = mock.Mock(spec=APIClient)
+        client_mock.create_service.return_value = {"ID": "some_id"}
+        client_mock.images.return_value = []
+        client_mock.pull.return_value = [b'{"status":"pull log"}']
+        client_mock.tasks.return_value = [{"Status": {"State": "complete"}}]
+        types_mock.TaskTemplate.return_value = mock_obj
+        types_mock.ContainerSpec.return_value = mock_obj
+        types_mock.RestartPolicy.return_value = mock_obj
+        types_mock.Resources.return_value = mock_obj
+
+        docker_api_client_patcher.return_value = client_mock
+
+        operator = DockerSwarmOperator(
+            image="", logging_driver="json-file", task_id="unittest", enable_logging=False
+        )
+        operator.execute(None)

Review Comment:
   Okay, I have updated the test and confirmed that it passed. I have also added `gelf` to the `docs/spelling_wordlist.txt`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "josix (via GitHub)" <gi...@apache.org>.
josix commented on code in PR #41416:
URL: https://github.com/apache/airflow/pull/41416#discussion_r1715012521


##########
airflow/providers/docker/operators/docker_swarm.py:
##########
@@ -128,12 +140,25 @@ def __init__(
         self.networks = networks
         self.placement = placement
         self.container_resources = container_resources or types.Resources(mem_limit=self.mem_limit)
+        self.logging_driver = logging_driver
+        self.logging_driver_opts = logging_driver_opts
 
     def execute(self, context: Context) -> None:
         self.environment["AIRFLOW_TMP_DIR"] = self.tmp_dir
         return self._run_service()
 
     def _run_service(self) -> None:
+        if self.logging_driver:
+            logging_driver = self.logging_driver.lower()
+            supported_logging_drivers = ["json-file", "gelf"]
+            if logging_driver not in supported_logging_drivers:
+                raise AirflowException(
+                    f"Unsupported logging driver provided: {logging_driver}. Must be one of: [{', '.join(supported_logging_drivers)}]"
+                )
+            log_driver = types.DriverConfig(logging_driver, self.logging_driver_opts)

Review Comment:
   question (non-blocking): how about moving the validation into initialization or a separate method instead of run_service? That would be helpful for avoiding mixing purposes (like setting the correct log_driver and create the service) in `_run_service`. I think It would also raise the question of whether we expect the exception to be raised at execution time or at the DAG definition phase (CMIIW).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #41416:
URL: https://github.com/apache/airflow/pull/41416#issuecomment-2312614254

   Awesome work, congrats on your first merged pull request! You are invited to check our [Issue Tracker](https://github.com/apache/airflow/issues) for additional contributions.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #41416:
URL: https://github.com/apache/airflow/pull/41416#discussion_r1721909189


##########
tests/providers/docker/operators/test_docker_swarm.py:
##########
@@ -345,3 +351,46 @@ def test_service_args_list(self, types_mock, docker_api_client_patcher):
             configs=None,
             secrets=None,
         )
+
+    @mock.patch("airflow.providers.docker.operators.docker_swarm.types")
+    def test_logging_driver(self, types_mock, docker_api_client_patcher):
+        mock_obj = mock.Mock()
+
+        client_mock = mock.Mock(spec=APIClient)
+        client_mock.create_service.return_value = {"ID": "some_id"}
+        client_mock.images.return_value = []
+        client_mock.pull.return_value = [b'{"status":"pull log"}']
+        client_mock.tasks.return_value = [{"Status": {"State": "complete"}}]
+        types_mock.TaskTemplate.return_value = mock_obj
+        types_mock.ContainerSpec.return_value = mock_obj
+        types_mock.RestartPolicy.return_value = mock_obj
+        types_mock.Resources.return_value = mock_obj
+
+        docker_api_client_patcher.return_value = client_mock
+
+        operator = DockerSwarmOperator(
+            image="", logging_driver="json-file", task_id="unittest", enable_logging=False
+        )
+        operator.execute(None)

Review Comment:
   we probably would want to assert that the logging drive is "json-file" here
   ```suggestion
           assert operator.logging_driver == "json-file"
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "geraj1010 (via GitHub)" <gi...@apache.org>.
geraj1010 commented on code in PR #41416:
URL: https://github.com/apache/airflow/pull/41416#discussion_r1719940960


##########
airflow/providers/docker/operators/docker_swarm.py:
##########
@@ -116,6 +126,8 @@ def __init__(
         networks: list[str | types.NetworkAttachmentConfig] | None = None,
         placement: types.Placement | list[types.Placement] | None = None,
         container_resources: types.Resources | None = None,
+        logging_driver: str | None = None,

Review Comment:
   I just tested with a test push and it looks like that error is preventing me from pushing the update. I don't think I can change the type unfortunately.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Added logging device and logging device options [airflow]

Posted by "geraj1010 (via GitHub)" <gi...@apache.org>.
geraj1010 commented on code in PR #41416:
URL: https://github.com/apache/airflow/pull/41416#discussion_r1724297423


##########
.pre-commit-config.yaml:
##########
@@ -779,7 +779,7 @@ repos:
         files: ^\.pre-commit-config\.yaml$|^.*_installed_providers\.txt$
         pass_filenames: false
         require_serial: true
-      - id: update-spelling-wordlist-to-be-sorted
+      - id: update--wordlist-to-be-sorted

Review Comment:
   I have pushed the `pre-commit` changes.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org