forked from tensorflow/tensorboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop removing experiment related query parameters (tensorflow#5717)
* Stop removing query parameters when persisting application state to the url * simplify query param serialization logic * move feature flag overrides to feature flag metadata
- Loading branch information
1 parent
6b36a15
commit 5485907
Showing
13 changed files
with
709 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
tensorboard/webapp/feature_flag/store/feature_flag_metadata.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
==============================================================================*/ | ||
import {FeatureFlags} from '../types'; | ||
|
||
export type BaseFeatureFlagType = boolean | number | string | null | undefined; | ||
|
||
export type FeatureFlagType = BaseFeatureFlagType | Array<BaseFeatureFlagType>; | ||
|
||
export type FeatureFlagMetadata<T> = { | ||
defaultValue: T; | ||
queryParamOverride?: string; | ||
parseValue: (str: string) => T extends (infer U)[] ? U : T; // The type, or, if the type is an array, the type of the array contents | ||
isArray?: boolean; | ||
}; | ||
|
||
export type FeatureFlagMetadataMapType<T extends FeatureFlags> = { | ||
[FlagName in keyof T]: FeatureFlagMetadata<T[FlagName]>; | ||
}; | ||
|
||
export function parseBoolean(str: string): boolean { | ||
return str !== 'false'; | ||
} | ||
|
||
export function parseBooleanOrNull(str: string): boolean | null { | ||
if (str === 'null') { | ||
return null; | ||
} | ||
return parseBoolean(str); | ||
} | ||
|
||
export const FeatureFlagMetadataMap: FeatureFlagMetadataMapType<FeatureFlags> = | ||
{ | ||
scalarsBatchSize: { | ||
defaultValue: undefined, | ||
queryParamOverride: 'scalarsBatchSize', | ||
parseValue: parseInt, | ||
}, | ||
enabledColorGroup: { | ||
defaultValue: true, | ||
queryParamOverride: 'enableColorGroup', | ||
parseValue: parseBoolean, | ||
}, | ||
enabledColorGroupByRegex: { | ||
defaultValue: true, | ||
queryParamOverride: 'enableColorGroupByRegex', | ||
parseValue: parseBoolean, | ||
}, | ||
enabledExperimentalPlugins: { | ||
defaultValue: [], | ||
queryParamOverride: 'experimentalPlugin', | ||
parseValue: (str: string) => str, | ||
isArray: true, | ||
}, | ||
enabledLinkedTime: { | ||
defaultValue: false, | ||
queryParamOverride: 'enableLinkedTime', | ||
parseValue: parseBoolean, | ||
}, | ||
enabledCardWidthSetting: { | ||
defaultValue: true, | ||
queryParamOverride: 'enableCardWidthSetting', | ||
parseValue: parseBoolean, | ||
}, | ||
enabledScalarDataTable: { | ||
defaultValue: false, | ||
queryParamOverride: 'enableDataTable', | ||
parseValue: parseBoolean, | ||
}, | ||
forceSvg: { | ||
defaultValue: false, | ||
queryParamOverride: 'forceSVG', | ||
parseValue: parseBoolean, | ||
}, | ||
enableDarkModeOverride: { | ||
defaultValue: null, | ||
parseValue: parseBooleanOrNull, | ||
}, | ||
defaultEnableDarkMode: { | ||
defaultValue: false, | ||
queryParamOverride: 'darkMode', | ||
parseValue: parseBoolean, | ||
}, | ||
isAutoDarkModeAllowed: { | ||
defaultValue: true, | ||
parseValue: parseBoolean, | ||
}, | ||
inColab: { | ||
defaultValue: false, | ||
queryParamOverride: 'tensorboardColab', | ||
parseValue: parseBoolean, | ||
}, | ||
metricsImageSupportEnabled: { | ||
defaultValue: true, | ||
parseValue: parseBoolean, | ||
}, | ||
enableTimeSeriesPromotion: { | ||
defaultValue: false, | ||
parseValue: parseBoolean, | ||
}, | ||
}; | ||
|
||
/** | ||
* Gets gets just the default values of each feature flag from the provided metadata. | ||
*/ | ||
export function generateFeatureFlagDefaults<T extends FeatureFlags>( | ||
featureFlagMetadataMap: FeatureFlagMetadataMapType<T> | ||
): T { | ||
return Object.entries(featureFlagMetadataMap).reduce( | ||
(map, [key, {defaultValue}]) => { | ||
map[key] = defaultValue; | ||
return map; | ||
}, | ||
{} as Record<string, any> | ||
) as T; | ||
} |
45 changes: 45 additions & 0 deletions
45
tensorboard/webapp/feature_flag/store/feature_flag_metadata_test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import {parseBoolean, parseBooleanOrNull} from './feature_flag_metadata'; | ||
|
||
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
==============================================================================*/ | ||
describe('feature flag query parameters', () => { | ||
describe('parseBoolean', () => { | ||
it('"false" should evaluate to false', () => { | ||
expect(parseBoolean('false')).toBeFalse(); | ||
}); | ||
|
||
it('values other than "false" should evaluate to true', () => { | ||
expect(parseBoolean('true')).toBeTrue(); | ||
expect(parseBoolean('foo bar')).toBeTrue(); | ||
expect(parseBoolean('')).toBeTrue(); | ||
}); | ||
}); | ||
|
||
describe('parseBooleanOrNull', () => { | ||
it('"null" should return null', () => { | ||
expect(parseBooleanOrNull('null')).toBeNull(); | ||
}); | ||
|
||
it('"false" should evaluate to false', () => { | ||
expect(parseBooleanOrNull('false')).toBeFalse(); | ||
}); | ||
|
||
it('values other than "false" should evaluate to true', () => { | ||
expect(parseBooleanOrNull('true')).toBeTrue(); | ||
expect(parseBooleanOrNull('foo bar')).toBeTrue(); | ||
expect(parseBooleanOrNull('')).toBeTrue(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.