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

Fix crash with logs view #4376

Closed
wants to merge 1 commit into from
Closed

Fix crash with logs view #4376

wants to merge 1 commit into from

Conversation

Nokel81
Copy link
Collaborator

@Nokel81 Nokel81 commented Nov 17, 2021

  • Switch to saving only IDs of pods, owners, and containers instead of
    whole objects

  • Add more checks about data integrety

Signed-off-by: Sebastian Malton [email protected]

Fixes secondary crash reported in #3782

@Nokel81 Nokel81 added the bug Something isn't working label Nov 17, 2021
@Nokel81 Nokel81 requested a review from a team as a code owner November 17, 2021 22:07
@Nokel81 Nokel81 requested review from jweak and jakolehm and removed request for a team November 17, 2021 22:07
@Nokel81 Nokel81 marked this pull request as draft November 18, 2021 04:07
@Nokel81 Nokel81 marked this pull request as ready for review November 18, 2021 14:04
@Nokel81 Nokel81 requested a review from aleksfront November 18, 2021 14:04
@Nokel81 Nokel81 mentioned this pull request Nov 29, 2021
@Nokel81 Nokel81 linked an issue Nov 29, 2021 that may be closed by this pull request
Copy link
Contributor

@aleksfront aleksfront left a comment

Choose a reason for hiding this comment

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

Nice improvement and overall cleaning! However, found couple of issues:

  1. Do we actually need to prevent logs to show up if pod doesn't have any owners? I'm not sure how often pods can be created directly, but nothing blocks us to open logs for them? For example, here's what I see if created raw Pod from Create Resource tab:
    pod without owner

  2. If the viewed pod has suddenly disappeared, maybe it's better to show sibling pod if any? Instead of this message:
    pod not found

  3. For pods without (?) logs I don't see any message like "No logs available", just empty log area. Create a deployment from template dropdown to reproduce:

no message

  1. This probably not affected by current PR, but it's annoying: search box is changing its width if some elements found:
    jumping search

src/renderer/components/dock/log-list.tsx Outdated Show resolved Hide resolved
src/renderer/components/dock/log-resource-selector.tsx Outdated Show resolved Hide resolved
@Nokel81
Copy link
Collaborator Author

Nokel81 commented Nov 30, 2021

Nice improvement and overall cleaning! However, found couple of issues:

1. Do we actually need to prevent logs to show up if pod doesn't have any owners? I'm not sure how often pods can be created directly, but nothing blocks us to open logs for them? For example, here's what I see if created raw Pod from `Create Resource` tab:

Fair enough, I agree that we shouldn't have this limitation.

2. If the viewed pod has suddenly disappeared, maybe it's better to show sibling pod if any? Instead of this message:

Sounds good

3. For pods without (?) logs I don't see any message like "No logs available", just empty log area. Create a deployment from template dropdown to reproduce:

Sounds good

4. This probably not affected by current PR, but it's annoying: search box is changing its width if some elements found:

I will try and fix this in this PR anyway

@Nokel81 Nokel81 linked an issue Dec 2, 2021 that may be closed by this pull request
@Nokel81 Nokel81 force-pushed the fix/pod-logs-storage branch from 69a3583 to 0b0ae6e Compare December 2, 2021 19:10
@Nokel81 Nokel81 requested a review from aleksfront December 2, 2021 19:14
@Nokel81
Copy link
Collaborator Author

Nokel81 commented Dec 2, 2021

@aleksfront Resolved, can you PTALA?

src/renderer/components/dock/log-tab.store.ts Outdated Show resolved Hide resolved
src/renderer/components/dock/log-tab.store.ts Outdated Show resolved Hide resolved
/**
* Get a set of namespaces which pod tabs care about
*/
public getNamespaces(): string[] {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get why we should get namespaces in some way and watch them in logs.tsx. The pod which logs we're looking at (as well as it's "sibling" pods with same owner) could have only 1 namespace. So why we need to collect more than one? Isn't it enough to pick namespace attribute from the previewed pod like pod.getNs()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is, however, this gets the namespaces for all tabs not just the currently open one.

This is needed for when we reopen Lens and the pods view might not be open yet. So the Logs component needs to register a watch for pods in all of these namespaces.

I guess I could watch pods in a single namespace for each tab. WDYT?

Comment on lines 276 to 291
if (merge) {
const namespaces = partialItems.map(item => item.getNs());
const uids = new Set(partialItems.map(item => item.getId()));

items = [
...this.items.filter(existingItem => !namespaces.includes(existingItem.getNs())),
...this.items.filter(existingItem => !uids.has(existingItem.getId())),
...partialItems,
];
Copy link
Contributor

Choose a reason for hiding this comment

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

Not obvious why this is needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll add a comment then, but the main gist is that stores cannot assume that a given call to mergeItems represents all namespaces being watched.

Specifically, a Logs tab might be viewing logs from a pod in default while the pods view is showing only the ones in kube-system

@aleksfront
Copy link
Contributor

@Nokel81 Most of the issues are gone, thanks for fixing those.

  1. This is still an issue:

If the viewed pod has suddenly disappeared, maybe it's better to show sibling pod if any? Instead of this message:
removed pod issue

  1. Suggestions about tab naming. First, I doubt we should add namespace before workload name. It makes impossible to get meaningful information from tab because ns will always be long enough to cover all available space.
    long space names

Maybe it's just me, but kind of strange to see titles like "ReplicaSet logs..." if you just just looking at the Pod logs:

job.logs.mov
  1. You've marked this PR as a candidate to fix Blank Screen when accessing one (out of three) clusters #4018 (Blank Screen when accessing one (out of three) clusters #4018 (comment)). Maybe to move things forward, extract needed parts for 4018 and pull a separate PR? Or it's better to keep with current one?

@Nokel81
Copy link
Collaborator Author

Nokel81 commented Dec 6, 2021

Or it's better to keep with current one?

I think it would be better to keep it here because the fix it to move out the reloadLogs call in render but that requires some other changes I think too.

@Nokel81
Copy link
Collaborator Author

Nokel81 commented Dec 6, 2021

  1. This is still an issue:

Oh, I thought I fixed that...

  1. Suggestions about tab naming. First, I doubt we should add namespace before workload name. It makes impossible to get meaningful information from tab because ns will always be long enough to cover all available space.

Sounds good about the naming.

Maybe it's just me, but kind of strange to see titles like "ReplicaSet logs..." if you just just looking at the Pod logs:

I can revert that change but let me explain why I made it. I made it because I felt that each tab was both about logs and about switching between pods and containers. And to be honest we aren't really even viewing pod logs, but instead viewing container logs.

src/common/utils/comparer.ts Outdated Show resolved Hide resolved
src/common/utils/reactions.ts Show resolved Hide resolved
src/main/cluster.ts Show resolved Hide resolved
src/renderer/components/cluster-manager/cluster-status.tsx Outdated Show resolved Hide resolved
src/renderer/components/dock/logs.tsx Outdated Show resolved Hide resolved
src/renderer/components/dock/logs.tsx Show resolved Hide resolved
src/renderer/components/dock/logs.tsx Outdated Show resolved Hide resolved
@aleksfront
Copy link
Contributor

Additional observations:

  1. We have blink of unstyled placeholder on cluster connect / window reload:
placeholder.blink.mov
  1. Lets revert tab title to have "Pod Logs" names:
    renamed titles

  2. Need to style this placeholder a bit, make it white and put into center, wdyt?

unstyles.placeholder.mov
  1. For some reason now we have 2 separate spinners around:
2.different.spinners.mov

aleksfront
aleksfront previously approved these changes Dec 10, 2021
Copy link
Contributor

@aleksfront aleksfront left a comment

Choose a reason for hiding this comment

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

Problems solved, looking good!

Comment on lines +22 to +27
.PodLogs {
.pod-not-found {
margin: auto;
color: var(--terminalBrightWhite);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor thing, but it's better to stick with css modules to properly isolate styles.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll make a follow up PR to move pod logs to modules.

@Nokel81 Nokel81 requested a review from aleksfront December 14, 2021 15:43
@github-actions
Copy link
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions
Copy link
Contributor

Conflicts have been resolved. A maintainer will review the pull request shortly.

@Nokel81 Nokel81 added this to the 5.4.0 milestone Jan 5, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2022

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2022

Conflicts have been resolved. A maintainer will review the pull request shortly.

- Switch to saving only IDs of pods, owners, and containers instead of
  whole objects

- Add more checks about data integrety

Signed-off-by: Sebastian Malton <[email protected]>
@Nokel81 Nokel81 force-pushed the fix/pod-logs-storage branch from a6e307c to cea7a34 Compare January 7, 2022 21:10
Copy link
Contributor

@Iku-turso Iku-turso left a comment

Choose a reason for hiding this comment

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

Uh. To be blunt, there are too many problems with this PR to approve. We propose live session to cover all more efficiently. Also PR #4653 (ie. a big splash) makes significant improvements in code touched here. The improvements include getting rid of global shared state and involuntary re-renders which also cause side-effects.

@@ -34,7 +34,9 @@ const electronRemote = (() => {
if (ipcRenderer) {
try {
return require("@electron/remote");
} catch {}
} catch {
// ignore temp
Copy link
Contributor

Choose a reason for hiding this comment

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

I can see that there is a wild-card try-catch, but the code does not explain why. If the try/catch is indeed an absolute necessity, I would like to know why. Better comment, or preferrably lovingly named function, would be better. Future improvement.

if (this.#watch.inc(store) > 1) {
const isNamespaceFilterWatch = !namespaces;

namespaces ??= KubeWatchApi.context?.contextNamespaces ?? [];
Copy link
Contributor

Choose a reason for hiding this comment

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

Global shared state, fixed elsewhere.


namespaces ??= KubeWatchApi.context?.contextNamespaces ?? [];

if (isNamespaceFilterWatch && this.#watch.inc(store) > 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Named function required. Future improvement.

@@ -167,7 +172,7 @@ export class KubeWatchApi {
: noop; // don't watch namespaces if namespaces were provided

return () => {
if (this.#watch.dec(store) === 0) {
if (!isNamespaceFilterWatch || this.#watch.dec(store) === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Named function required. Future improvement.

const tabData = getOnePodTabData();
const { getByText } = render(getComponent(tabData));
const props = getOnePodTabProps();
const { getByText } = render(<LogResourceSelector {...props} />);

expect(getByText("dockerExporter")).toBeInTheDocument();
Copy link
Contributor

Choose a reason for hiding this comment

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

Notice: Multiple expects in a test is very bad.

get lines(): number {
return this.logs.length;
}
getLogs(tabId: TabId, { showTimestamps }: LogTabData): string[] {
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be reactive. The big-splash makes this reactive, among other things. The big-splash needs to be merged first because this.

if (!extraction || extraction.length < 3) {
return ["", logs];
if (!timestamps) {
return "";
Copy link
Contributor

Choose a reason for hiding this comment

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

Empty string should be null when possible. Future improvement.

], {
namespaces: logTabStore.getNamespaces(),
}),
when(() => this.canLoad, () => this.load(true)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Initialization in wrong place (component). State should be ready when rendering. Future improvement.

* Only used in `componentDidMount`
*/
private changeSelectedPodWhenCurrentDisappears() {
return reaction(() => this.getPods(this.tabData), (data) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Preventable reaction. Use action.

@@ -50,8 +51,11 @@ export function createStorage<T>(key: string, defaultValue: T) {

try {
storage.data = await fse.readJson(filePath);
Copy link
Contributor

Choose a reason for hiding this comment

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

Notice: explicit access to filesystem! Explicit side-effect.

@github-actions
Copy link
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@Nokel81
Copy link
Collaborator Author

Nokel81 commented Jan 24, 2022

Closing this PR as the commit 9d33fff fixes a lot of the issues that this did as well.

I will recreate the changes to the storage layer in a new PR (for 5.5) once #3738 is merged.

@Nokel81 Nokel81 closed this Jan 24, 2022
@Nokel81 Nokel81 deleted the fix/pod-logs-storage branch January 24, 2022 15:10
@Nokel81 Nokel81 restored the fix/pod-logs-storage branch January 25, 2022 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants