Skip to content

Commit

Permalink
Showing 6 changed files with 28 additions and 37 deletions.
8 changes: 5 additions & 3 deletions lib/feature-flags.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/feature-flags.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 7 additions & 11 deletions lib/feature-flags.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/feature-flags.test.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 8 additions & 17 deletions src/feature-flags.test.ts
@@ -5,6 +5,7 @@ import * as sinon from "sinon";
import * as apiClient from "./api-client";
import { GitHubApiDetails } from "./api-client";
import { GitHubFeatureFlags } from "./feature-flags";
import { getRunnerLogger } from "./logging";
import {
getRecordingLogger,
LoggedMessage,
@@ -135,31 +136,22 @@ test("Feature flags are disabled if they're not returned in API response", async
});
});

test("All feature flags are disabled if the API request errors", async (t) => {
test("Feature flags exception is propagated if the API request errors", async (t) => {
await withTmpDir(async (tmpDir) => {
setupActionsVars(tmpDir, tmpDir);

const loggedMessages = [];
const featureFlags = new GitHubFeatureFlags(
{ type: GitHubVariant.DOTCOM },
testApiDetails,
getRecordingLogger(loggedMessages)
getRunnerLogger(true)
);

mockHttpRequests(500, {});

t.assert((await featureFlags.getDatabaseUploadsEnabled()) === false);
t.assert((await featureFlags.getMlPoweredQueriesEnabled()) === false);
t.assert((await featureFlags.getUploadsDomainEnabled()) === false);

t.assert(
loggedMessages.find(
(v: LoggedMessage) =>
v.type === "info" &&
v.message ===
"Disabling all feature flags due to unknown error: Error: some error message"
) !== undefined
);
await t.throwsAsync(async () => featureFlags.preloadFeatureFlags(), {
message:
"Encountered an error while trying to load feature flags: Error: some error message",
});
});
});

@@ -174,11 +166,10 @@ for (const featureFlag of FEATURE_FLAGS) {
await withTmpDir(async (tmpDir) => {
setupActionsVars(tmpDir, tmpDir);

const loggedMessages = [];
const featureFlags = new GitHubFeatureFlags(
{ type: GitHubVariant.DOTCOM },
testApiDetails,
getRecordingLogger(loggedMessages)
getRunnerLogger(true)
);

const expectedFeatureFlags = {};
10 changes: 6 additions & 4 deletions src/feature-flags.ts
@@ -75,11 +75,13 @@ export class GitHubFeatureFlags implements FeatureFlags {
);
return response.data;
} catch (e) {
console.log(e);
this.logger.info(
`Disabling all feature flags due to unknown error: ${e}`
// Some feature flags, such as `ml_powered_queries_enabled` affect the produced alerts.
// Considering these feature flags disabled in the event of a transient error could
// therefore lead to alert churn. As a result, we crash if we cannot determine the value of
// the feature flags.
throw new Error(
`Encountered an error while trying to load feature flags: ${e}`
);
return {};
}
};

0 comments on commit 621e079

Please sign in to comment.