Skip to content

Commit

Permalink
Modify /compiler-info to show both active and inactive compilers (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
azu-b authored Mar 29, 2022
1 parent 4764cf3 commit de05037
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/CompilerManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class CompilerManager {
*/
getAllCompilerInfo() {
const result = { compilers: {}, leastUsedCompiler: null };
Object.entries(this.activeCompilers).forEach(([name, compiler]) => {
Object.keys(this.activeCompilers).forEach((name) => {
result.compilers[name] = this.getInfoForCompiler(name);
});
result.leastUsedCompiler = this.getLeastUsedCompiler();
Expand Down
2 changes: 2 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const FIRST_BUILD = "first-build";
const BUILDING = "building";
const ERROR = "error";
const DONE = "done";
const NOT_BUILT = "not-built";

module.exports = {
PLUGIN_NAME,
Expand All @@ -14,4 +15,5 @@ module.exports = {
BUILDING,
ERROR,
DONE,
NOT_BUILT,
};
13 changes: 12 additions & 1 deletion lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const {
FIRST_BUILD,
ERROR,
DONE,
NOT_BUILT,
} = require("./constants");

// we're leaving manager detached from Kevin to keep it and its methods private
Expand Down Expand Up @@ -357,7 +358,17 @@ class Kevin {
// this endpoint shows general details about each compiler,
// particularly metrics around its use and whether it may
// be eligible for eviction
res.json(manager.getAllCompilerInfo());
// 2022 note: adding config names so this endpoint
// also shows the inactive compilers
const { compilers, leastUsedCompiler } = manager.getAllCompilerInfo();
this.configs.forEach(({ name }) => {
if (Object.prototype.hasOwnProperty.call(compilers, name)) {
return;
}
compilers[name] = { status: NOT_BUILT };
});

res.json({ compilers, leastUsedCompiler });
return;
}

Expand Down
71 changes: 70 additions & 1 deletion test/lib/CompilerManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe("getStatus", () => {
});

describe("getAllBuildStatuses", () => {
it("should show the build states of all compilers", () => {
it("should show the build states of active compilers", () => {
const manager = new CompilerManager();
manager.manageCompiler("nick", getMockCompiler(), {});
manager.manageCompiler("elback", getMockCompiler(), {}, BUILDING);
Expand All @@ -118,3 +118,72 @@ describe("getAllBuildStatuses", () => {
});
});
});

describe("getAllCompilerInfo", () => {
it("should return an object with active compilers", () => {
const manager = new CompilerManager();
// Active compilers
manager.manageCompiler("iam", getMockCompiler(), {});
manager.manageCompiler("an", getMockCompiler(), {}, BUILDING);
manager.manageCompiler("active", getMockCompiler(), {}, DONE);
manager.manageCompiler("region", getMockCompiler(), {}, ERROR);

expect(manager.getAllCompilerInfo()).toEqual(
expect.objectContaining({
compilers: {
iam: expect.objectContaining({
status: FIRST_BUILD,
}),
an: expect.objectContaining({
status: BUILDING,
}),
active: expect.objectContaining({
status: DONE,
}),
region: expect.objectContaining({
status: ERROR,
}),
},
})
);
});

it("should return more information about the active compilers", () => {
const manager = new CompilerManager();

manager.manageCompiler("iam", getMockCompiler(), {});
manager.manageCompiler("an", getMockCompiler(), {}, BUILDING);
manager.manageCompiler("active", getMockCompiler(), {}, DONE);
manager.manageCompiler("region", getMockCompiler(), {}, ERROR);

const moreInfo = {
errors: expect.any(Array),
frequency: expect.any(Number),
frecency: expect.any(Number),
frequencyChecks: expect.any(Array),
pinned: expect.any(Boolean),
};

expect(manager.getAllCompilerInfo()).toEqual({
compilers: expect.objectContaining({
iam: {
status: FIRST_BUILD,
...moreInfo,
},
an: {
status: BUILDING,
...moreInfo,
},
active: {
status: DONE,
...moreInfo,
},
region: {
status: ERROR,
...moreInfo,
},
}),
leastUsedCompiler: expect.any(String),
});
});
});

0 comments on commit de05037

Please sign in to comment.