Skip to content
This repository has been archived by the owner on Dec 21, 2021. It is now read-only.

Container logs can be retrieved #135

Merged
merged 12 commits into from
Apr 29, 2021
Merged

Container logs can be retrieved #135

merged 12 commits into from
Apr 29, 2021

Conversation

siegfriedweber
Copy link
Member

Closes #37

@siegfriedweber siegfriedweber requested a review from a team April 22, 2021 13:30
@siegfriedweber siegfriedweber self-assigned this Apr 22, 2021
soenkeliebau
soenkeliebau previously approved these changes Apr 28, 2021
Copy link
Member

@soenkeliebau soenkeliebau left a comment

Choose a reason for hiding this comment

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

I've left some comments, nothing that I'd consider a blocker though, so I'll approve this, but am happy to discuss the comments of course.
Regarding the "missing" timestamp issue I've opened krustlet/krustlet#591 to make processing of additional parameters possible.


if let Some(line_count) = sender.tail() {
journal.seek_tail()?;
let skipped = journal.previous_skip(line_count as u64 + 1)?;
Copy link
Member

Choose a reason for hiding this comment

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

More a question out of interest, what happens to the reader when we skip more lines than there are in the log here? Is that defined behavior? If so, can we potentially get rid of the conditional seek_head() ?

Copy link
Member Author

Choose a reason for hiding this comment

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

If line_count is greater than the number of journal entries then previous_skip sets the cursor to the first entry. The following code assumes that the cursor is set to one position before the next entry. Therefore if the beginning of the journal is reached then the cursor must be set to one position before the first entry which is done by seek_head.

I will try to make this more clear in the code.

Copy link
Member Author

Choose a reason for hiding this comment

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

I hope it is clearer now.

src/provider/systemdmanager/journal_reader.rs Show resolved Hide resolved
src/provider/systemdmanager/journal_reader.rs Show resolved Hide resolved
src/provider/systemdmanager/journal_reader.rs Show resolved Hide resolved
) -> Result<()> {
let mut sent = 0;
let mut message_available = true;
while sent != count && message_available {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason you are using != instead of < ?
I agree with you that this should never break, but out of instinct usually take the "safe" route..

Copy link
Member Author

@siegfriedweber siegfriedweber Apr 28, 2021

Choose a reason for hiding this comment

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

If sent could become greater then count then it would be a programming error. If I would use < instead of != the programming error would be masked and a potentially incorrect program state would be propagated. If an error occurs further down the line then it would be difficult to find the root cause. Therefore I prefer offensive programming over defensive programming.

If we decide to go the other way, I am also okay.

Actually I am not happy with this code:

  • I did not use (somehow) the type system to make the state where sent > count unrepresentable.
  • I use a counter.
  • The reading and sending of messages is intertwined.

But this is probably how it is done in Rust without overcomplicating things.

src/provider/states/pod/terminated.rs Show resolved Hide resolved
src/provider/states/pod/starting.rs Show resolved Hide resolved
@@ -45,10 +49,116 @@ mod systemdmanager;
/// Provider-level state shared between all pods
#[derive(Clone)]
pub struct ProviderState {
handles: Arc<RwLock<PodHandleMap>>,
Copy link
Member

Choose a reason for hiding this comment

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

It might just be me, so this is really just a note, feel free to leave as is.
I found it very hard to grok what exactly a PodHandleMap is due to the mixture of structs and types that are defined here as well as in the kubelet.
It might make sense to insert a brief comment that shows this..or at least explains it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I extended the documentation of PodHandleMap.

) -> anyhow::Result<()> {
debug!("Logs requested");
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add pod and container information to the log message?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

src/provider/mod.rs Show resolved Hide resolved
Copy link
Member

@soenkeliebau soenkeliebau left a comment

Choose a reason for hiding this comment

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

LGTM

@siegfriedweber siegfriedweber merged commit 62a8546 into stackabletech:main Apr 29, 2021
@siegfriedweber siegfriedweber deleted the logs branch April 29, 2021 07:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add functionality to tail logs via kubectl (or similar tools)
2 participants