-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fix crash with logs view #4376
Conversation
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.
Nice improvement and overall cleaning! However, found couple of issues:
-
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:
-
If the viewed pod has suddenly disappeared, maybe it's better to show sibling pod if any? Instead of this message:
-
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:
Fair enough, I agree that we shouldn't have this limitation.
Sounds good
Sounds good
I will try and fix this in this PR anyway |
69a3583
to
0b0ae6e
Compare
@aleksfront Resolved, can you PTALA? |
/** | ||
* Get a set of namespaces which pod tabs care about | ||
*/ | ||
public getNamespaces(): string[] { |
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 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()
?
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.
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?
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, | ||
]; |
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.
Not obvious why this is needed?
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'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
@Nokel81 Most of the issues are gone, thanks for fixing those.
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
|
I think it would be better to keep it here because the fix it to move out the |
Oh, I thought I fixed that...
Sounds good about the naming.
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. |
Additional observations:
placeholder.blink.mov
unstyles.placeholder.mov
2.different.spinners.mov |
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.
Problems solved, looking good!
.PodLogs { | ||
.pod-not-found { | ||
margin: auto; | ||
color: var(--terminalBrightWhite); | ||
} | ||
} |
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.
Minor thing, but it's better to stick with css modules to properly isolate styles.
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'll make a follow up PR to move pod logs to modules.
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
5aa2084
to
bc9a350
Compare
Conflicts have been resolved. A maintainer will review the pull request shortly. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
bc9a350
to
a6e307c
Compare
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]>
a6e307c
to
cea7a34
Compare
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.
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 |
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 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 ?? []; |
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.
Global shared state, fixed elsewhere.
|
||
namespaces ??= KubeWatchApi.context?.contextNamespaces ?? []; | ||
|
||
if (isNamespaceFilterWatch && this.#watch.inc(store) > 1) { |
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.
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) { |
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.
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(); |
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.
Notice: Multiple expects in a test is very bad.
get lines(): number { | ||
return this.logs.length; | ||
} | ||
getLogs(tabId: TabId, { showTimestamps }: LogTabData): string[] { |
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.
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 ""; |
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.
Empty string should be null when possible. Future improvement.
], { | ||
namespaces: logTabStore.getNamespaces(), | ||
}), | ||
when(() => this.canLoad, () => this.load(true)), |
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.
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) => { |
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.
Preventable reaction
. Use action.
@@ -50,8 +51,11 @@ export function createStorage<T>(key: string, defaultValue: T) { | |||
|
|||
try { | |||
storage.data = await fse.readJson(filePath); |
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.
Notice: explicit access to filesystem! Explicit side-effect.
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
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