Add debug logging for feature flag enablement
This commit is contained in:
parent
ec298233c1
commit
d9ceda3823
3 changed files with 51 additions and 7 deletions
19
lib/feature-flags.js
generated
19
lib/feature-flags.js
generated
|
|
@ -76,6 +76,7 @@ exports.FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json";
|
||||||
*/
|
*/
|
||||||
class Features {
|
class Features {
|
||||||
constructor(gitHubVersion, repositoryNwo, tempDir, logger) {
|
constructor(gitHubVersion, repositoryNwo, tempDir, logger) {
|
||||||
|
this.logger = logger;
|
||||||
this.gitHubFeatureFlags = new GitHubFeatureFlags(gitHubVersion, repositoryNwo, path.join(tempDir, exports.FEATURE_FLAGS_FILE_NAME), logger);
|
this.gitHubFeatureFlags = new GitHubFeatureFlags(gitHubVersion, repositoryNwo, path.join(tempDir, exports.FEATURE_FLAGS_FILE_NAME), logger);
|
||||||
}
|
}
|
||||||
async getDefaultCliVersion(variant) {
|
async getDefaultCliVersion(variant) {
|
||||||
|
|
@ -100,22 +101,36 @@ class Features {
|
||||||
const envVar = (process.env[exports.featureConfig[feature].envVar] || "").toLocaleLowerCase();
|
const envVar = (process.env[exports.featureConfig[feature].envVar] || "").toLocaleLowerCase();
|
||||||
// Do not use this feature if user explicitly disables it via an environment variable.
|
// Do not use this feature if user explicitly disables it via an environment variable.
|
||||||
if (envVar === "false") {
|
if (envVar === "false") {
|
||||||
|
this.logger.debug(`Feature ${feature} is disabled via the environment variable ${exports.featureConfig[feature].envVar}.`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Never use this feature if the CLI version explicitly can't support it.
|
// Never use this feature if the CLI version explicitly can't support it.
|
||||||
const minimumVersion = exports.featureConfig[feature].minimumVersion;
|
const minimumVersion = exports.featureConfig[feature].minimumVersion;
|
||||||
if (codeql && minimumVersion) {
|
if (codeql && minimumVersion) {
|
||||||
if (!(await util.codeQlVersionAbove(codeql, minimumVersion))) {
|
if (!(await util.codeQlVersionAbove(codeql, minimumVersion))) {
|
||||||
|
this.logger.debug(`Feature ${feature} is disabled because the CodeQL CLI version is older than the minimum ` +
|
||||||
|
`version ${minimumVersion}.`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
this.logger.debug(`CodeQL CLI version ${await codeql.getVersion()} is newer than the minimum ` +
|
||||||
|
`version ${minimumVersion} for feature ${feature}.`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Use this feature if user explicitly enables it via an environment variable.
|
// Use this feature if user explicitly enables it via an environment variable.
|
||||||
if (envVar === "true") {
|
if (envVar === "true") {
|
||||||
|
this.logger.debug(`Feature ${feature} is enabled via the environment variable ${exports.featureConfig[feature].envVar}.`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Ask the GitHub API if the feature is enabled.
|
// Ask the GitHub API if the feature is enabled.
|
||||||
return ((await this.gitHubFeatureFlags.getValue(feature)) ??
|
const apiValue = await this.gitHubFeatureFlags.getValue(feature);
|
||||||
exports.featureConfig[feature].defaultValue);
|
if (apiValue !== undefined) {
|
||||||
|
this.logger.debug(`Feature ${feature} is ${apiValue ? "enabled" : "disabled"} via the GitHub API.`);
|
||||||
|
return apiValue;
|
||||||
|
}
|
||||||
|
const defaultValue = exports.featureConfig[feature].defaultValue;
|
||||||
|
this.logger.debug(`Feature ${feature} is ${defaultValue ? "enabled" : "disabled"} due to its default value.`);
|
||||||
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.Features = Features;
|
exports.Features = Features;
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -94,7 +94,7 @@ export class Features implements FeatureEnablement {
|
||||||
gitHubVersion: util.GitHubVersion,
|
gitHubVersion: util.GitHubVersion,
|
||||||
repositoryNwo: RepositoryNwo,
|
repositoryNwo: RepositoryNwo,
|
||||||
tempDir: string,
|
tempDir: string,
|
||||||
logger: Logger
|
private readonly logger: Logger
|
||||||
) {
|
) {
|
||||||
this.gitHubFeatureFlags = new GitHubFeatureFlags(
|
this.gitHubFeatureFlags = new GitHubFeatureFlags(
|
||||||
gitHubVersion,
|
gitHubVersion,
|
||||||
|
|
@ -135,6 +135,9 @@ export class Features implements FeatureEnablement {
|
||||||
|
|
||||||
// Do not use this feature if user explicitly disables it via an environment variable.
|
// Do not use this feature if user explicitly disables it via an environment variable.
|
||||||
if (envVar === "false") {
|
if (envVar === "false") {
|
||||||
|
this.logger.debug(
|
||||||
|
`Feature ${feature} is disabled via the environment variable ${featureConfig[feature].envVar}.`
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,19 +145,45 @@ export class Features implements FeatureEnablement {
|
||||||
const minimumVersion = featureConfig[feature].minimumVersion;
|
const minimumVersion = featureConfig[feature].minimumVersion;
|
||||||
if (codeql && minimumVersion) {
|
if (codeql && minimumVersion) {
|
||||||
if (!(await util.codeQlVersionAbove(codeql, minimumVersion))) {
|
if (!(await util.codeQlVersionAbove(codeql, minimumVersion))) {
|
||||||
|
this.logger.debug(
|
||||||
|
`Feature ${feature} is disabled because the CodeQL CLI version is older than the minimum ` +
|
||||||
|
`version ${minimumVersion}.`
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
|
} else {
|
||||||
|
this.logger.debug(
|
||||||
|
`CodeQL CLI version ${await codeql.getVersion()} is newer than the minimum ` +
|
||||||
|
`version ${minimumVersion} for feature ${feature}.`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use this feature if user explicitly enables it via an environment variable.
|
// Use this feature if user explicitly enables it via an environment variable.
|
||||||
if (envVar === "true") {
|
if (envVar === "true") {
|
||||||
|
this.logger.debug(
|
||||||
|
`Feature ${feature} is enabled via the environment variable ${featureConfig[feature].envVar}.`
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ask the GitHub API if the feature is enabled.
|
// Ask the GitHub API if the feature is enabled.
|
||||||
return (
|
const apiValue = await this.gitHubFeatureFlags.getValue(feature);
|
||||||
(await this.gitHubFeatureFlags.getValue(feature)) ??
|
if (apiValue !== undefined) {
|
||||||
featureConfig[feature].defaultValue
|
this.logger.debug(
|
||||||
|
`Feature ${feature} is ${
|
||||||
|
apiValue ? "enabled" : "disabled"
|
||||||
|
} via the GitHub API.`
|
||||||
|
);
|
||||||
|
return apiValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultValue = featureConfig[feature].defaultValue;
|
||||||
|
this.logger.debug(
|
||||||
|
`Feature ${feature} is ${
|
||||||
|
defaultValue ? "enabled" : "disabled"
|
||||||
|
} due to its default value.`
|
||||||
);
|
);
|
||||||
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue