Skip to content

Add an initial logs utility class. #87

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

Merged
merged 2 commits into from
Oct 23, 2017

Conversation

brendandburns
Copy link
Contributor

Adds capability to get logs as a stream, not just as a string.

if (!response.isSuccessful()) {
throw new ApiException("Logs request failed: " + response.code());
}
return response.body().byteStream();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we always know what this content-type will be? (for decoding)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added JavaDoc (it's text/plain)


// Important note. You must close this stream or else you can leak connections.
public InputStream streamNamespacedPodLog(String namespace, String name, String container,
Integer sinceSeconds, Integer tailLines, boolean timestamps) throws ApiException, IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is sinceSeconds since epoch, or when the container started?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added JavaDoc (stolen from Swagger docs)

* Utility class offering streaming access to Pod logs.
*/
public class Logs {
private ApiClient apiClient;
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: I would make apiClient public final and remove setter and getter for it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why public?

Copy link
Contributor

@mbohlool mbohlool Oct 12, 2017

Choose a reason for hiding this comment

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

That means you don't need a getter for it. It is a common practice I guess with pros and cons. But now that I think more about it, maybe having getter is not a bad idea. But I still suggest we remove setter for this and make it private final.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah was just curious since the rest of the generated code uses getters in favor of public final. Agreed that a setter probably shouldn't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the setter.

* @param pod The Pod to get logs for, uses the first container in the pod for logs
* @return A UTF-8 encoded InputStream
*/
public InputStream streamNamespacedPodLog(V1Pod pod) throws ApiException, IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we just call this streamPodLog?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is done for consistency, all the generated api methods seem to follow <verb>Namespaced<resource> for this kind of stuff

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this was for consistency...

/**
* Utility class offering streaming access to Pod logs.
*/
public class Logs {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this be confused with a Logger? When I saw the topic for this PR, I though this is a special logger. I suggest we call it something like PodLogs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed.

@brendandburns
Copy link
Contributor Author

Comments addressed, please re-check.

Thanks!
--brendan

@mbohlool
Copy link
Contributor

/LGTM

@mbohlool mbohlool merged commit bc382e2 into kubernetes-client:master Oct 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants