Skip to content
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

Add logs to trace missing exit code #1059

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/adapters/src/kubernetes-instance-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ IComponent {
this.logger.error("Trying to stop non existent runner", this._runnerName);
} else {
await this.timeout(ms);
await this.kubeClient.deletePod(this._runnerName, 2);
await this.kubeClient.deletePod(this._runnerName, 2)
.catch((e) => {
this.logger.error("Error deleting pod", e, this._runnerName);
});

this._runnerName = undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/config/profileConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class ProfileConfig extends ConfigFileDefault<ProfileConfigEntity
return this.setEntry("apiUrl", normalizeUrl(apiUrl));
}
setMiddlewareApiUrl(middlewareApiUrl: string): boolean {
return this.setEntry("middlewareApiUrl", normalizeUrl(middlewareApiUrl)) as boolean;
return this.setEntry("middlewareApiUrl", normalizeUrl(middlewareApiUrl));
}
setEnv(env: configEnv): boolean {
return this.setEntry("env", env);
Expand Down
22 changes: 17 additions & 5 deletions packages/host/src/lib/csi-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,23 @@ export class CSIController extends TypedEmitter<Events> {
try {
const stopResult = await this.instanceStopped();

this.logger.debug("Stop result", stopResult);

if (stopResult) {
code = stopResult.exitcode;
code = stopResult.exitcode || code;
this.logger.trace("Instance ended with code", code);
this.status = stopResult.status;
this.setExitInfo(code, stopResult.message);

this.logger.debug("Exit info", this.terminated);
}
} catch (e: any) {
code = e.exitcode;

this.status = e.status || InstanceStatus.ERRORED;
this.setExitInfo(code, e.reason);

this.logger.error("Instance caused error", e.message, code);
this.logger.error("Instance caused error", e);
} finally {
clearInterval(interval);
}
Expand All @@ -274,7 +279,7 @@ export class CSIController extends TypedEmitter<Events> {

this.emit("terminated", code);

this.logger.trace("Finalizing...");
this.logger.trace("Finalizing...", code);

await this.finalize();

Expand All @@ -299,7 +304,7 @@ export class CSIController extends TypedEmitter<Events> {

const exitcode = await this.endOfSequence;

this.logger.trace("End of sequence");
this.logger.trace("End of sequence", exitcode);

if (exitcode > 0) {
this.status = InstanceStatus.ERRORED;
Expand All @@ -320,7 +325,10 @@ export class CSIController extends TypedEmitter<Events> {
};

this.instancePromise = instanceMain()
.then((exitcode) => mapRunnerExitCode(exitcode, this.sequence))
.then((exitcode) => {
this.logger.debug("instanceMain ExitCode", exitcode);
return mapRunnerExitCode(exitcode, this.sequence);
})
.catch((error) => {
this.logger.error("Instance promise rejected", error);
this.initResolver?.rej(error);
Expand Down Expand Up @@ -373,6 +381,8 @@ export class CSIController extends TypedEmitter<Events> {
}

instanceStopped(): CSIController["instancePromise"] {
this.logger.debug("function InstanceStopped called");

if (!this.instancePromise) {
throw new CSIControllerError("UNATTACHED_STREAMS");
}
Expand Down Expand Up @@ -766,6 +776,8 @@ export class CSIController extends TypedEmitter<Events> {
async kill(opts = { removeImmediately: false }) {
if (this.status === InstanceStatus.KILLING) {
await this.instanceAdapter.remove();

return;
}

this.status = InstanceStatus.KILLING;
Expand Down
4 changes: 3 additions & 1 deletion packages/host/src/lib/csi-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ export class CSIDispatcher extends TypedEmitter<Events> {

delete this.instanceStore[csiController.id];
})
.once("terminated", (code) => {
.on("terminated", (code) => {
this.logger.debug("Terminated event received", code);

if (csiController.requires && csiController.requires !== "") {
(this.serviceDiscovery.getData({
topic: new TopicId(csiController.requires),
Expand Down
4 changes: 3 additions & 1 deletion packages/host/src/lib/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,14 @@ export class Host implements IComponent {
* @param {DispatcherInstanceTerminatedEventData} eventData Event details.
*/
async handleDispatcherTerminatedEvent(eventData: DispatcherInstanceTerminatedEventData) {
this.logger.debug("handleDispatcherTerminatedEvent", eventData);

this.auditor.auditInstance(eventData.id, InstanceMessageCode.INSTANCE_TERMINATED);

this.pushTelemetry("Instance terminated", {
executionTime: eventData.info.executionTime.toString(),
id: eventData.id,
code: eventData.code.toString(),
code: (eventData.code || -2).toString(),
seqId: eventData.sequence.id
});
}
Expand Down
Loading