Improve k8s logging accuracy
parent
7ef6aeee30
commit
8e0168a0a5
|
@ -3965,13 +3965,49 @@ class KubernetesTaskRunner {
|
|||
({ shouldReadLogs, shouldCleanup, output } = follow_log_stream_service_1.FollowLogStreamService.handleIteration(message, shouldReadLogs, shouldCleanup, output));
|
||||
next();
|
||||
};
|
||||
// export interface LogOptions {
|
||||
/**
|
||||
* Follow the log stream of the pod. Defaults to false.
|
||||
*/
|
||||
// follow?: boolean;
|
||||
/**
|
||||
* If set, the number of bytes to read from the server before terminating the log output. This may not display a
|
||||
* complete final line of logging, and may return slightly more or slightly less than the specified limit.
|
||||
*/
|
||||
// limitBytes?: number;
|
||||
/**
|
||||
* If true, then the output is pretty printed.
|
||||
*/
|
||||
// pretty?: boolean;
|
||||
/**
|
||||
* Return previous terminated container logs. Defaults to false.
|
||||
*/
|
||||
// previous?: boolean;
|
||||
/**
|
||||
* A relative time in seconds before the current time from which to show logs. If this value precedes the time a
|
||||
* pod was started, only logs since the pod start will be returned. If this value is in the future, no logs will
|
||||
* be returned. Only one of sinceSeconds or sinceTime may be specified.
|
||||
*/
|
||||
// sinceSeconds?: number;
|
||||
/**
|
||||
* If set, the number of lines from the end of the logs to show. If not specified, logs are shown from the creation
|
||||
* of the container or sinceSeconds or sinceTime
|
||||
*/
|
||||
// tailLines?: number;
|
||||
/**
|
||||
* If true, add an RFC3339 or RFC3339Nano timestamp at the beginning of every line of log output. Defaults to false.
|
||||
*/
|
||||
// timestamps?: boolean;
|
||||
// }
|
||||
const logOptions = {
|
||||
follow: true,
|
||||
pretty: false,
|
||||
previous: false,
|
||||
previous: true,
|
||||
timestamps: true,
|
||||
sinceSeconds: KubernetesTaskRunner.lastReceivedTimestamp,
|
||||
};
|
||||
try {
|
||||
const resultError = yield new Promise((resolve) => new client_node_1.Log(kubeConfig).log(namespace, podName, containerName, stream, resolve, logOptions));
|
||||
const resultError = yield new client_node_1.Log(kubeConfig).log(namespace, podName, containerName, stream, logOptions);
|
||||
stream.destroy();
|
||||
if (resultError) {
|
||||
throw resultError;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -7,6 +7,7 @@ import waitUntil from 'async-wait-until';
|
|||
import { FollowLogStreamService } from '../../services/follow-log-stream-service';
|
||||
|
||||
class KubernetesTaskRunner {
|
||||
static lastReceivedTimestamp: number;
|
||||
static async runTask(
|
||||
kubeConfig: KubeConfig,
|
||||
kubeClient: CoreV1Api,
|
||||
|
@ -33,15 +34,51 @@ class KubernetesTaskRunner {
|
|||
));
|
||||
next();
|
||||
};
|
||||
|
||||
// export interface LogOptions {
|
||||
/**
|
||||
* Follow the log stream of the pod. Defaults to false.
|
||||
*/
|
||||
// follow?: boolean;
|
||||
/**
|
||||
* If set, the number of bytes to read from the server before terminating the log output. This may not display a
|
||||
* complete final line of logging, and may return slightly more or slightly less than the specified limit.
|
||||
*/
|
||||
// limitBytes?: number;
|
||||
/**
|
||||
* If true, then the output is pretty printed.
|
||||
*/
|
||||
// pretty?: boolean;
|
||||
/**
|
||||
* Return previous terminated container logs. Defaults to false.
|
||||
*/
|
||||
// previous?: boolean;
|
||||
/**
|
||||
* A relative time in seconds before the current time from which to show logs. If this value precedes the time a
|
||||
* pod was started, only logs since the pod start will be returned. If this value is in the future, no logs will
|
||||
* be returned. Only one of sinceSeconds or sinceTime may be specified.
|
||||
*/
|
||||
// sinceSeconds?: number;
|
||||
/**
|
||||
* If set, the number of lines from the end of the logs to show. If not specified, logs are shown from the creation
|
||||
* of the container or sinceSeconds or sinceTime
|
||||
*/
|
||||
// tailLines?: number;
|
||||
/**
|
||||
* If true, add an RFC3339 or RFC3339Nano timestamp at the beginning of every line of log output. Defaults to false.
|
||||
*/
|
||||
// timestamps?: boolean;
|
||||
// }
|
||||
|
||||
const logOptions = {
|
||||
follow: true,
|
||||
pretty: false,
|
||||
previous: false,
|
||||
previous: true,
|
||||
timestamps: true,
|
||||
sinceSeconds: KubernetesTaskRunner.lastReceivedTimestamp,
|
||||
};
|
||||
try {
|
||||
const resultError = await new Promise((resolve) =>
|
||||
new Log(kubeConfig).log(namespace, podName, containerName, stream, resolve, logOptions),
|
||||
);
|
||||
const resultError = await new Log(kubeConfig).log(namespace, podName, containerName, stream, logOptions);
|
||||
stream.destroy();
|
||||
if (resultError) {
|
||||
throw resultError;
|
||||
|
|
Loading…
Reference in New Issue