-
Notifications
You must be signed in to change notification settings - Fork 17.3k
KPO write_logs does not need to use complicated pod logs reader #36228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -625,7 +625,7 @@ def execute_complete(self, context: Context, event: dict, **kwargs): | |
| if event["status"] in ("error", "failed", "timeout"): | ||
| # fetch some logs when pod is failed | ||
| if self.get_logs: | ||
| self.write_logs(pod) | ||
| self._write_logs(pod) | ||
| if "stack_trace" in event: | ||
| message = f"{event['message']}\n{event['stack_trace']}" | ||
| else: | ||
|
|
@@ -634,7 +634,7 @@ def execute_complete(self, context: Context, event: dict, **kwargs): | |
| elif event["status"] == "success": | ||
| # fetch some logs when pod is executed successfully | ||
| if self.get_logs: | ||
| self.write_logs(pod) | ||
| self._write_logs(pod) | ||
|
|
||
| if self.do_xcom_push: | ||
| xcom_sidecar_output = self.extract_xcom(pod=pod) | ||
|
|
@@ -651,22 +651,21 @@ def execute_complete(self, context: Context, event: dict, **kwargs): | |
| remote_pod=pod, | ||
| ) | ||
|
|
||
| def write_logs(self, pod: k8s.V1Pod): | ||
| def _write_logs(self, pod: k8s.V1Pod): | ||
| try: | ||
| logs = self.pod_manager.read_pod_logs( | ||
| pod=pod, | ||
| logs = self.client.read_namespaced_pod_log( | ||
| name=pod.metadata.name, | ||
| namespace=pod.metadata.namespace, | ||
| container_name=self.base_container_name, | ||
| timestamps=False, | ||
| follow=False, | ||
| _preload_content=False, | ||
| ) | ||
| for raw_line in logs: | ||
| line = raw_line.decode("utf-8", errors="backslashreplace").rstrip("\n") | ||
| self.log.info("Container logs: %s", line) | ||
| self.log.info("[%s] %s", self.base_container_name, line) | ||
| except HTTPError as e: | ||
| self.log.warning( | ||
| "Reading of logs interrupted with error %r; will retry. " | ||
| "Set log level to DEBUG for traceback.", | ||
| e, | ||
| ) | ||
| self.log.warning("Reading of logs interrupted with error %r;", e) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it retry? We should mention in the warning in that case. |
||
|
|
||
| def post_complete_action(self, *, pod, remote_pod, **kwargs): | ||
| """Actions that must be done after operator finishes logic of the deferrable_execution.""" | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this considered a breaking change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to consider it breaking. This is a method that realistically no one would ever override. It's used in one place. I think of it as "bugfix" that it wasn't marked private.
Really this also connects to something we've discussed before. That our operators should not be published as "base classes" to be extended. I think they should be end products whose behavior is governed by semver but not whose structure is governed by semver. Personally I think we ought to update our "public interface" doc to reflect this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool yeah I see the discussion in #36767
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked the discussion in #36767, seems about right to me that no one "should" ever override the write_logs method, it is something that should not be changed. Seems like a non breaking change