-
Notifications
You must be signed in to change notification settings - Fork 540
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
Fixes #82 Add a client for the pod read-log endpoint #83
Conversation
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
@@ -87,7 +88,7 @@ export class WebSocketHandler { | |||
textHandler(message.utf8Data); | |||
} | |||
} else if (message.type === 'binary') { | |||
if (binaryHandler) { | |||
if (binaryHandler && message.binaryData.length > 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.
On my Kubernetes cluster, the first message received is an empty one.
node-client/src/log.ts
Outdated
const promise = this.handler.connect(path, null, (streamNum: number, buff: Buffer) => { | ||
const charBuff = Buffer.allocUnsafe(1) | ||
charBuff.writeInt8(streamNum, 0) | ||
stream.write(Buffer.concat([charBuff, buff])); |
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.
Little bit ugly trick, but this allows to re-use the code from WebSocketHandler
without having to it in a way that could break the other consumers of it (Attach
, Exec
).
A single write()
call is issued on the stream because that tends to correspond to a line in the logs (although this is probably not guaranteed).
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.
Sorry can you explain why this is needed? This is probably a bug in WebSocketHandler
that should be fixed instead of doing this here...
(and it's probably my bug :)
47d5225
to
4e8676c
Compare
There is a flaky error while reading the logs:
This is already fixed upstream in this commit theturtle32/WebSocket-Node@12ed73d All we need is to update to the latest release 1.0.26, which indeed solves this problem. |
node-client/package.json
Outdated
@@ -38,7 +38,7 @@ | |||
"request": "^2.72.0", | |||
"shelljs": "^0.7.8 ", | |||
"underscore": "^1.8.3", | |||
"websocket": "^1.0.25" | |||
"websocket": "^1.0.26" |
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.
The diff on the auto-generated package-lock.json
is pretty huge, unsure what to do with that, so I'm excluding it for the time being from this PR
node-client/src/log.ts
Outdated
} | ||
|
||
// TODO add support for limitBytes, previous, sinceSeconds and tailLines | ||
public log(namespace: string, podName: string, containerName: 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.
indentation is weird here, can you run this through tslint?
node-client/src/log.ts
Outdated
public 'handler': WebSocketHandler; | ||
|
||
public constructor(config: KubeConfig) { | ||
this.handler = new WebSocketHandler(config); |
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.
Does the log endpoint even use WebSockets? I thought it was a standard hanging GET, that's what we do in Java:
Thanks for the PR! Do we really need WebSockets here? I think in other clients this is implemented as a straight GET... Thanks! |
@dbolkensteyn friendly ping on this, I'd love to get it merged, but I have some thoughts. Thanks! |
And I thank you for the valuable feedback @brendandburns - I'll come back to this during the week. |
Friendly ping on this if you still have time I'd love to get this merged. Thanks! |
@dbolkensteyn Friendly ping on this. Thanks! |
Final ping, otherwise I'm going to close and build a different implementation of this functionality. Thanks! |
428bff4
to
a649a15
Compare
Sorry for the late follow-up @brendandburns , I've just forced-pushed a new implementation that incorporates all of your feedback and the one from #214 which actually implements the same feature (but hard-codes |
} | ||
}).on('response', (response) => { | ||
if (response.statusCode === 200) { | ||
req.pipe(stream); |
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.
unlike #214 this will only start to pipe the "logs" when a 200 response is returned (else Kubernetes error jsons might get treated as logs)
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.
@dbolkensteyn How to stop piping? I am successfully able to open the logs (follow option) but what is the right way to terminate underlying request?
public log( | ||
namespace: string, | ||
podName: string, | ||
containerName: 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.
containerName
is mandatory
/** | ||
* Follow the log stream of the pod. Defaults to false. | ||
*/ | ||
follow?: boolean; |
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.
follow
is taken as a parameter and not hard-coded
|
||
import { KubeConfig } from './config'; | ||
|
||
export interface LogOptions { |
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 is taken over from #214 as it seems as a nice way to avoid overly-parameterized methods
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: brendandburns, dbolkensteyn The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Does anyone have an example of using this code? I tried to use it to stream logs but have not gotten it to work. |
@abierbaum You could use something like
|
How could i close the log? Iv'e tried to call logStream.destroy() but the program still keeps running. |
Hi guys, I use this class with |
This PR adds the ability to read the logs of a pod. Fixes #82