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

timeseries: show spinner when tags load #5271

Merged
merged 1 commit into from
Aug 27, 2021
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
12 changes: 7 additions & 5 deletions tensorboard/webapp/metrics/effects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
import {
getCardLoadState,
getCardMetadata,
getMetricsTagMetadataLoaded,
getMetricsTagMetadataLoadState,
} from '../store';
import {CardId, CardMetadata} from '../types';

Expand Down Expand Up @@ -98,12 +98,12 @@ export class MetricsEffects implements OnInitEffects {
ofType(initAction, coreActions.changePlugin, routingActions.navigated),
withLatestFrom(
this.store.select(getActivePlugin),
this.store.select(getMetricsTagMetadataLoaded)
this.store.select(getMetricsTagMetadataLoadState)
),
filter(([, activePlugin, tagLoadState]) => {
return (
activePlugin === METRICS_PLUGIN_ID &&
tagLoadState === DataLoadState.NOT_LOADED
tagLoadState.state === DataLoadState.NOT_LOADED
);
})
);
Expand All @@ -121,15 +121,17 @@ export class MetricsEffects implements OnInitEffects {
this.reloadRequestedWhileShown$
).pipe(
withLatestFrom(
this.store.select(getMetricsTagMetadataLoaded),
this.store.select(getMetricsTagMetadataLoadState),
this.store.select(selectors.getExperimentIdsFromRoute)
),
filter(([, tagLoadState, experimentIds]) => {
/**
* When `experimentIds` is null, the actual ids have not
* appeared in the store yet.
*/
return tagLoadState !== DataLoadState.LOADING && experimentIds !== null;
return (
tagLoadState.state !== DataLoadState.LOADING && experimentIds !== null
);
}),
tap(() => {
this.store.dispatch(actions.metricsTagMetadataRequested());
Expand Down
58 changes: 29 additions & 29 deletions tensorboard/webapp/metrics/effects/metrics_effects_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
TagMetadata,
TimeSeriesResponse,
} from '../data_source';
import {getMetricsTagMetadataLoaded} from '../store';
import {getMetricsTagMetadataLoadState} from '../store';
import {
appStateFromMetricsState,
buildDataSourceTagMetadata,
Expand Down Expand Up @@ -109,10 +109,10 @@ describe('metrics effects', () => {

it('loads TagMetadata on dashboard open if data is not loaded', () => {
store.overrideSelector(selectors.getExperimentIdsFromRoute, null);
store.overrideSelector(
getMetricsTagMetadataLoaded,
DataLoadState.NOT_LOADED
);
store.overrideSelector(getMetricsTagMetadataLoadState, {
state: DataLoadState.NOT_LOADED,
lastLoadedTimeInMs: null,
});
store.overrideSelector(getActivePlugin, null);
store.refreshState();

Expand Down Expand Up @@ -145,10 +145,10 @@ describe('metrics effects', () => {

it('loads TagMetadata when switching to dashboard with experiment', () => {
store.overrideSelector(selectors.getExperimentIdsFromRoute, ['exp1']);
store.overrideSelector(
getMetricsTagMetadataLoaded,
DataLoadState.NOT_LOADED
);
store.overrideSelector(getMetricsTagMetadataLoadState, {
state: DataLoadState.NOT_LOADED,
lastLoadedTimeInMs: null,
});
store.overrideSelector(getActivePlugin, null);
store.refreshState();

Expand All @@ -172,10 +172,10 @@ describe('metrics effects', () => {
});

it('does not fetch TagMetadata if data was loaded when opening', () => {
store.overrideSelector(
getMetricsTagMetadataLoaded,
DataLoadState.LOADED
);
store.overrideSelector(getMetricsTagMetadataLoadState, {
state: DataLoadState.LOADED,
lastLoadedTimeInMs: 1,
});
store.overrideSelector(getActivePlugin, METRICS_PLUGIN_ID);
store.refreshState();
actions$.next(TEST_ONLY.initAction());
Expand All @@ -187,10 +187,10 @@ describe('metrics effects', () => {
});

it('does not fetch TagMetadata if data was loading when opening', () => {
store.overrideSelector(
getMetricsTagMetadataLoaded,
DataLoadState.LOADING
);
store.overrideSelector(getMetricsTagMetadataLoadState, {
state: DataLoadState.LOADING,
lastLoadedTimeInMs: null,
});
store.overrideSelector(getActivePlugin, METRICS_PLUGIN_ID);
store.refreshState();
actions$.next(TEST_ONLY.initAction());
Expand Down Expand Up @@ -252,10 +252,10 @@ describe('metrics effects', () => {
for (const {reloadAction, reloadName} of reloadSpecs) {
it(`re-fetches data on ${reloadName}, while dashboard is open`, () => {
store.overrideSelector(selectors.getExperimentIdsFromRoute, ['exp1']);
store.overrideSelector(
getMetricsTagMetadataLoaded,
DataLoadState.LOADED
);
store.overrideSelector(getMetricsTagMetadataLoadState, {
state: DataLoadState.LOADED,
lastLoadedTimeInMs: 1,
});
store.overrideSelector(getActivePlugin, METRICS_PLUGIN_ID);
store.overrideSelector(
selectors.getVisibleCardIdSet,
Expand Down Expand Up @@ -304,10 +304,10 @@ describe('metrics effects', () => {

it(`re-fetches data on ${reloadName}, only for non-loading cards`, () => {
store.overrideSelector(selectors.getExperimentIdsFromRoute, ['exp1']);
store.overrideSelector(
getMetricsTagMetadataLoaded,
DataLoadState.LOADING
);
store.overrideSelector(getMetricsTagMetadataLoadState, {
state: DataLoadState.LOADING,
lastLoadedTimeInMs: null,
});
store.overrideSelector(getActivePlugin, METRICS_PLUGIN_ID);
store.overrideSelector(
selectors.getVisibleCardIdSet,
Expand Down Expand Up @@ -343,10 +343,10 @@ describe('metrics effects', () => {
}

it('does not re-fetch data on reload, if open and already loading', () => {
store.overrideSelector(
getMetricsTagMetadataLoaded,
DataLoadState.LOADING
);
store.overrideSelector(getMetricsTagMetadataLoadState, {
state: DataLoadState.LOADING,
lastLoadedTimeInMs: null,
});
store.overrideSelector(getActivePlugin, METRICS_PLUGIN_ID);
store.overrideSelector(
selectors.getVisibleCardIdSet,
Expand Down
27 changes: 21 additions & 6 deletions tensorboard/webapp/metrics/store/metrics_reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ const {initialState, reducers: routeContextReducer} = createRouteContextedState<
>(
{
// Backend data.
tagMetadataLoaded: DataLoadState.NOT_LOADED,
tagMetadataLoadState: {
state: DataLoadState.NOT_LOADED,
lastLoadedTimeInMs: null,
},
tagMetadata: {
scalars: {
tagDescriptions: {},
Expand Down Expand Up @@ -400,7 +403,7 @@ const reducer = createReducer(
}),
on(coreActions.reload, coreActions.manualReload, (state) => {
const nextTagMetadataLoaded =
state.tagMetadataLoaded === DataLoadState.LOADING
state.tagMetadataLoadState.state === DataLoadState.LOADING
? DataLoadState.LOADING
: DataLoadState.NOT_LOADED;

Expand All @@ -420,7 +423,10 @@ const reducer = createReducer(

return {
...state,
tagMetadataLoaded: nextTagMetadataLoaded,
tagMetadataLoadState: {
...state.tagMetadataLoadState,
state: nextTagMetadataLoaded,
},
timeSeriesData: nextTimeSeriesData,
};
}),
Expand All @@ -429,7 +435,10 @@ const reducer = createReducer(
(state: MetricsState): MetricsState => {
return {
...state,
tagMetadataLoaded: DataLoadState.LOADING,
tagMetadataLoadState: {
...state.tagMetadataLoadState,
state: DataLoadState.LOADING,
},
};
}
),
Expand All @@ -438,7 +447,10 @@ const reducer = createReducer(
(state: MetricsState): MetricsState => {
return {
...state,
tagMetadataLoaded: DataLoadState.FAILED,
tagMetadataLoadState: {
...state.tagMetadataLoadState,
state: DataLoadState.FAILED,
},
};
}
),
Expand Down Expand Up @@ -483,7 +495,10 @@ const reducer = createReducer(
return {
...state,
...resolvedResult,
tagMetadataLoaded: DataLoadState.LOADED,
tagMetadataLoadState: {
state: DataLoadState.LOADED,
lastLoadedTimeInMs: Date.now(),
},
tagMetadata: nextTagMetadata,
cardList: nextCardList,
};
Expand Down
63 changes: 50 additions & 13 deletions tensorboard/webapp/metrics/store/metrics_reducers_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,34 @@ describe('metrics reducers', () => {
action: actions.metricsTagMetadataRequested(),
actionName: 'metricsTagMetadataRequested',
beforeState: buildMetricsState({
tagMetadataLoaded: DataLoadState.NOT_LOADED,
tagMetadataLoadState: {
state: DataLoadState.NOT_LOADED,
lastLoadedTimeInMs: null,
},
}),
expectedState: buildMetricsState({
tagMetadataLoaded: DataLoadState.LOADING,
tagMetadataLoadState: {
state: DataLoadState.LOADING,
lastLoadedTimeInMs: null,
},
tagMetadata: buildTagMetadata(),
}),
},
{
action: actions.metricsTagMetadataFailed(),
actionName: 'metricsTagMetadataFailed',
beforeState: buildMetricsState({
tagMetadataLoaded: DataLoadState.LOADING,
tagMetadataLoadState: {
state: DataLoadState.LOADING,
lastLoadedTimeInMs: null,
},
tagMetadata: tagMetadataSample.storeForm,
}),
expectedState: buildMetricsState({
tagMetadataLoaded: DataLoadState.FAILED,
tagMetadataLoadState: {
state: DataLoadState.FAILED,
lastLoadedTimeInMs: null,
},
tagMetadata: tagMetadataSample.storeForm,
}),
},
Expand All @@ -156,19 +168,29 @@ describe('metrics reducers', () => {
}),
actionName: 'metricsTagMetadataLoaded',
beforeState: buildMetricsState({
tagMetadataLoaded: DataLoadState.LOADING,
tagMetadataLoadState: {
state: DataLoadState.LOADING,
lastLoadedTimeInMs: null,
},
}),
expectedState: buildMetricsState({
tagMetadataLoaded: DataLoadState.LOADED,
tagMetadataLoadState: {
state: DataLoadState.LOADED,
lastLoadedTimeInMs: 3,
},
tagMetadata: tagMetadataSample.storeForm,
}),
},
].forEach((metaSpec) => {
describe(metaSpec.actionName, () => {
beforeEach(() => {
spyOn(Date, 'now').and.returnValue(3);
});

it(`sets the loadState on ${metaSpec.actionName}`, () => {
const nextState = reducers(metaSpec.beforeState, metaSpec.action);
expect(nextState.tagMetadataLoaded).toEqual(
metaSpec.expectedState.tagMetadataLoaded
expect(nextState.tagMetadataLoadState).toEqual(
metaSpec.expectedState.tagMetadataLoadState
);
expect(nextState.tagMetadata).toEqual(
metaSpec.expectedState.tagMetadata
Expand Down Expand Up @@ -465,22 +487,34 @@ describe('metrics reducers', () => {

it(`marks loaded tag metadata as stale`, () => {
const prevState = buildMetricsState({
tagMetadataLoaded: DataLoadState.LOADED,
tagMetadataLoadState: {
state: DataLoadState.LOADED,
lastLoadedTimeInMs: 3,
},
tagMetadata: buildTagMetadata(),
});

const nextState = reducers(prevState, reloadAction);
expect(nextState.tagMetadataLoaded).toBe(DataLoadState.NOT_LOADED);
expect(nextState.tagMetadataLoadState).toEqual({
state: DataLoadState.NOT_LOADED,
lastLoadedTimeInMs: 3,
});
});

it(`does not change tag load state if already loading`, () => {
const prevState = buildMetricsState({
tagMetadataLoaded: DataLoadState.LOADING,
tagMetadataLoadState: {
state: DataLoadState.LOADING,
lastLoadedTimeInMs: 3,
},
tagMetadata: buildTagMetadata(),
});

const nextState = reducers(prevState, reloadAction);
expect(nextState.tagMetadataLoaded).toBe(DataLoadState.LOADING);
expect(nextState.tagMetadataLoadState).toEqual({
state: DataLoadState.LOADING,
lastLoadedTimeInMs: 3,
});
});

it(
Expand Down Expand Up @@ -1587,7 +1621,10 @@ describe('metrics reducers', () => {
cardMetadataMap: {
card1: fakeMetadata,
},
tagMetadataLoaded: DataLoadState.LOADED,
tagMetadataLoadState: {
state: DataLoadState.LOADED,
lastLoadedTimeInMs: 1,
},
tagMetadata: {
...buildTagMetadata(),
[PluginType.SCALARS]: {
Expand Down
7 changes: 3 additions & 4 deletions tensorboard/webapp/metrics/store/metrics_selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
import {createFeatureSelector, createSelector} from '@ngrx/store';

import {State} from '../../app_state';
import {DataLoadState} from '../../types/data';
import {DataLoadState, LoadState} from '../../types/data';
import {ElementId} from '../../util/dom';
import {DeepReadonly} from '../../util/types';
import {
Expand All @@ -38,7 +38,6 @@ import {
MetricsState,
METRICS_FEATURE_KEY,
RunToSeries,
StoreInternalLinkedTime,
TagMetadata,
} from './metrics_types';

Expand All @@ -48,9 +47,9 @@ const selectMetricsState = createFeatureSelector<State, MetricsState>(
METRICS_FEATURE_KEY
);

export const getMetricsTagMetadataLoaded = createSelector(
export const getMetricsTagMetadataLoadState = createSelector(
selectMetricsState,
(state: MetricsState): DataLoadState => state.tagMetadataLoaded
(state: MetricsState): LoadState => state.tagMetadataLoadState
);

export const getMetricsTagMetadata = createSelector(
Expand Down
Loading