Skip to content
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

Capture log to error when executing command #1947

Merged
merged 5 commits into from
May 15, 2023

Conversation

e-sumin
Copy link
Contributor

@e-sumin e-sumin commented Mar 9, 2023

Change Overview

When executing command in pod, we'd like to have generalized errors handling.
As a high level of execution error, we will have error with last log lines.
Callers who does know what are they execute, are able to produce more specific error basing on data containing in logs.

Pull request type

Please check the type of change your PR introduces:

  • 🚧 Work in Progress
  • 🌈 Refactoring (no functional changes, no api changes)
  • 🐹 Trivial/Minor
  • 🐛 Bugfix
  • 🌻 Feature
  • 🗺️ Documentation
  • 🤖 Test

Test Plan

  • 💪 Manual
  • ⚡ Unit test
  • 💚 E2E

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2023

Thanks for submitting this pull request 🎉. The team will review it soon and get back to you.

If you haven't already, please take a moment to review our project contributing guideline and Code of Conduct document.

@infraq infraq added this to In Progress in Kanister Mar 9, 2023
@e-sumin e-sumin force-pushed the pod_command_executor_exec_error branch from 873d704 to defd856 Compare March 21, 2023 12:14
@e-sumin e-sumin requested a review from pavannd1 March 22, 2023 11:12
@e-sumin e-sumin marked this pull request as ready for review March 24, 2023 15:15
@denisvmedia denisvmedia self-requested a review March 24, 2023 15:15
@e-sumin
Copy link
Contributor Author

e-sumin commented Apr 19, 2023

@pavannd1 @PrasadG193 could you please review ?

@@ -20,6 +20,8 @@ import (
"strings"
)

const LogTailDefaultLength = 10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const LogTailDefaultLength = 10
const logTailDefaultLength = 10

No need to export unless required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done !

@@ -100,7 +102,6 @@ func (s *PodCommandExecutorTestSuite) TestPodRunnerExec(c *C) {
ctx := context.Background()
cli := fake.NewSimpleClientset()

//simulatedError := errors.New("SimulatedError")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed removing commented lines during code cleanup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, seems so.

@e-sumin e-sumin force-pushed the pod_command_executor_exec_error branch from 539ea68 to 4b2e41d Compare May 12, 2023 09:24
Kanister automation moved this from In Progress to Reviewer approved May 15, 2023
@e-sumin
Copy link
Contributor Author

e-sumin commented May 15, 2023

@PrasadG193 @pavannd1 could you please check the changes ?

@viveksinghggits
Copy link
Contributor

Hi @e-sumin,
The PR looks good. I just wanted to know, do we not use this way to execing a command into a pod when we use kube.Exec API?

Stdout: stdout,
Stderr: stderr,
Stdout: stdoutTail,
Stderr: stderrTail,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I don't have previous context in this task. What happens if we don't specify stdout, where exactly NewLogTail writes the logs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LogTail collects only last lines of log, and keeps them internally. If error occurs, we create error which contains log tail. Thus, whether or not the caller passed the stdout/stderr writers, in case of error he will get an access to last log lines.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you. What about

I just wanted to know, do we not use this way to execing a command into a pod when we use kube.Exec API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, forgot to answer this part - nope, currently we are not using and it's only part of PodController / PodCommandExecutor way of execution. Because for proper utilization of such error handling, the invoker should be prepared for such kind of error. But of course we can extend kube.Exec invokers and handle such erros.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I think we should do the same kind of handling even for kube.exec to make sure we are not seeing diff kinds of behaviour between creating a new pod and executing command in that and executing command in an already created pod.
Should we create an issue to track this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably you are right. Should I create an issue or you will do it ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@e-sumin e-sumin added the kueue label May 15, 2023
@mergify mergify bot merged commit 15140cc into master May 15, 2023
Kanister automation moved this from Reviewer approved to Done May 15, 2023
@mergify mergify bot deleted the pod_command_executor_exec_error branch May 15, 2023 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants