From 9d9fa826b5683f9ce213949c51facfdd533be6d3 Mon Sep 17 00:00:00 2001 From: Joel Takvorian Date: Thu, 21 Feb 2019 12:30:15 +0100 Subject: [PATCH 1/2] KIALI-2426 Get serverConfig from static env.js So this is removed from redux (lot of changes) and used instead as a standard constant. This constant is written in 'window' object, in env.js, by the server. File is imported in index.html as static js. Valid durations are now computed statically once for all. --- public/env.js | 16 +- src/actions/GraphDataThunkActions.ts | 2 +- src/actions/KialiAppAction.ts | 2 - src/actions/LoginThunkActions.ts | 33 +- src/actions/ServerConfigActions.ts | 13 - .../__tests__/ServerConfigAction.test.ts | 20 - src/app/History.ts | 4 +- src/components/GraphFilter/GraphRefresh.tsx | 27 +- src/components/IstioWizards/IstioWizard.tsx | 2 +- .../IstioWizards/IstioWizardDropdown.tsx | 4 +- src/components/Metrics/CustomMetrics.tsx | 4 +- src/components/Metrics/Helper.ts | 2 +- src/components/Metrics/IstioMetrics.tsx | 4 +- .../Metrics/__tests__/CustomMetrics.test.tsx | 12 - .../Metrics/__tests__/IstioMetrics.test.tsx | 16 - .../MetricsOptions/MetricsDuration.tsx | 36 +- .../__tests__/ToolbarDropdown.test.tsx | 7 +- .../ToolbarDropdown.test.tsx.snap | 600 ------------------ src/config/config.ts | 14 - src/config/serverConfig.ts | 93 ++- src/pages/Graph/SummaryPanelCommon.tsx | 2 +- src/pages/Graph/SummaryPanelEdge.tsx | 6 +- src/pages/Graph/SummaryPanelGroup.tsx | 4 +- src/pages/Graph/SummaryPanelNode.tsx | 10 +- src/pages/Overview/OverviewToolbar.tsx | 33 +- .../Overview/__tests__/OverviewPage.test.tsx | 12 - .../WorkloadDetails/WorkloadDetailsPage.tsx | 5 +- src/reducers/ServerConfigState.ts | 21 - src/reducers/index.ts | 2 - src/services/Api.ts | 6 +- src/services/Prometheus.ts | 3 +- src/services/__tests__/Prometheus.test.ts | 13 - src/store/ConfigStore.ts | 11 +- src/store/Selectors.ts | 7 - src/store/Store.ts | 12 - src/utils/RateIntervals.ts | 9 +- 36 files changed, 141 insertions(+), 926 deletions(-) delete mode 100644 src/actions/ServerConfigActions.ts delete mode 100644 src/actions/__tests__/ServerConfigAction.test.ts delete mode 100644 src/reducers/ServerConfigState.ts diff --git a/public/env.js b/public/env.js index e0fbdece9c..39ba547d09 100644 --- a/public/env.js +++ b/public/env.js @@ -1,2 +1,14 @@ -// This file is intentionally left bank. -// Kiali server may re-generate this file with configuration variables. +// This file is setup for development mode (such as using "yarn start") +// Make sure it always matches definition in kiali/config/public_config.go +// !! WARNING !! KIALI SERVER WILL RE-GENERATE THIS FILE ON STARTUP +window.serverConfig = { + istioNamespace: 'istio-system', + istioLabels: { + appLabelName: 'app', + versionLabelName: 'version' + }, + prometheus: { + globalScrapeInterval: 15, + storageTsdbRetention: 21600 + } +}; diff --git a/src/actions/GraphDataThunkActions.ts b/src/actions/GraphDataThunkActions.ts index 2dd4734dc5..f4dee5799d 100644 --- a/src/actions/GraphDataThunkActions.ts +++ b/src/actions/GraphDataThunkActions.ts @@ -43,7 +43,7 @@ const GraphDataThunkActions = { graphType: graphType, injectServiceNodes: injectServiceNodes }; - if (namespaces.find(namespace => namespace.name === serverConfig().istioNamespace)) { + if (namespaces.find(namespace => namespace.name === serverConfig.istioNamespace)) { restParams['includeIstio'] = true; } diff --git a/src/actions/KialiAppAction.ts b/src/actions/KialiAppAction.ts index 91058cde83..9415978c46 100644 --- a/src/actions/KialiAppAction.ts +++ b/src/actions/KialiAppAction.ts @@ -8,7 +8,6 @@ import { LoginAction } from './LoginActions'; import { MessageCenterAction } from './MessageCenterActions'; import { NamespaceAction } from './NamespaceAction'; import { UserSettingsAction } from './UserSettingsActions'; -import { ServerConfigAction } from './ServerConfigActions'; import { JaegerAction } from './JaegerActions'; export type KialiAppAction = @@ -21,6 +20,5 @@ export type KialiAppAction = | LoginAction | MessageCenterAction | NamespaceAction - | ServerConfigAction | UserSettingsAction | JaegerAction; diff --git a/src/actions/LoginThunkActions.ts b/src/actions/LoginThunkActions.ts index 9f241dce15..882e92e884 100644 --- a/src/actions/LoginThunkActions.ts +++ b/src/actions/LoginThunkActions.ts @@ -1,12 +1,10 @@ import { ThunkDispatch } from 'redux-thunk'; -import { HTTP_CODES } from '../types/Common'; -import { KialiAppState, Token, ServerConfig } from '../store/Store'; +import { KialiAppState, Token } from '../store/Store'; import { KialiAppAction } from './KialiAppAction'; import HelpDropdownThunkActions from './HelpDropdownThunkActions'; import GrafanaThunkActions from './GrafanaThunkActions'; import { LoginActions } from './LoginActions'; import * as API from '../services/Api'; -import { ServerConfigActions } from './ServerConfigActions'; const ANONYMOUS: string = 'anonymous'; @@ -19,31 +17,12 @@ const completeLogin = ( timeout?: number ) => { const auth = `Bearer ${token['token']}`; - API.getServerConfig(auth).then( - response => { - // set the serverConfig before completing login so that it is available for - // anything needing it to render properly. - const serverConfig: ServerConfig = { - istioNamespace: response.data.istioNamespace, - istioLabels: response.data.istioLabels, - prometheus: response.data.prometheus - }; - dispatch(ServerConfigActions.setServerConfig(serverConfig)); + // complete the login process + dispatch(LoginActions.loginSuccess(token, username, timeout)); - // complete the login process - dispatch(LoginActions.loginSuccess(token, username, timeout)); - - // dispatch requests to be done now but not necessarily requiring immediate completion - dispatch(HelpDropdownThunkActions.refresh()); - dispatch(GrafanaThunkActions.getInfo(auth)); - }, - error => { - /** Logout user */ - if (error.response && error.response.status === HTTP_CODES.UNAUTHORIZED) { - dispatch(LoginActions.logoutSuccess()); - } - } - ); + // dispatch requests to be done now but not necessarily requiring immediate completion + dispatch(HelpDropdownThunkActions.refresh()); + dispatch(GrafanaThunkActions.getInfo(auth)); }; // performLogin performs only the authentication part of login. If successful diff --git a/src/actions/ServerConfigActions.ts b/src/actions/ServerConfigActions.ts deleted file mode 100644 index d48d4ca507..0000000000 --- a/src/actions/ServerConfigActions.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { ActionType, createStandardAction } from 'typesafe-actions'; -import { ServerConfig } from '../store/Store'; - -enum ServerConfigActionKeys { - SET_SERVER_CONFIG = 'SET_SERVER_CONFIG' -} - -// synchronous action creators -export const ServerConfigActions = { - setServerConfig: createStandardAction(ServerConfigActionKeys.SET_SERVER_CONFIG)() -}; - -export type ServerConfigAction = ActionType; diff --git a/src/actions/__tests__/ServerConfigAction.test.ts b/src/actions/__tests__/ServerConfigAction.test.ts deleted file mode 100644 index f1d3be1290..0000000000 --- a/src/actions/__tests__/ServerConfigAction.test.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { ServerConfigActions } from '../ServerConfigActions'; -import { ServerConfig } from '../../store/Store'; -import { serverConfig } from '../../config/serverConfig'; -import { store } from '../../store/ConfigStore'; - -const config: ServerConfig = { - istioNamespace: 'istio-system', - istioLabels: { appLabelName: 'app', versionLabelName: 'version' }, - prometheus: { globalScrapeInterval: 15, storageTsdbRetention: 21600 } -}; - -describe('ServerConfigActions', () => { - it('Set ServerConfig action success', () => { - store.dispatch(ServerConfigActions.setServerConfig(config)); - expect(serverConfig().istioNamespace).toEqual(config.istioNamespace); - expect(serverConfig().istioLabels).toEqual(config.istioLabels); - expect(serverConfig().prometheus.globalScrapeInterval).toEqual(config.prometheus.globalScrapeInterval); - expect(serverConfig().prometheus.storageTsdbRetention).toEqual(config.prometheus.storageTsdbRetention); - }); -}); diff --git a/src/app/History.ts b/src/app/History.ts index d145c64422..074ac63a0a 100644 --- a/src/app/History.ts +++ b/src/app/History.ts @@ -1,8 +1,8 @@ import { createBrowserHistory } from 'history'; import createMemoryHistory from 'history/createMemoryHistory'; +import { serverConfig } from '../config/serverConfig'; -const webRoot = (window as any).WEB_ROOT ? (window as any).WEB_ROOT : undefined; -const baseName = webRoot && webRoot !== '/' ? webRoot + '/console' : '/console'; +const baseName = serverConfig.webRoot && serverConfig.webRoot !== '/' ? serverConfig.webRoot + '/console' : '/console'; const history = process.env.TEST_RUNNER ? createMemoryHistory() : createBrowserHistory({ basename: baseName }); export default history; diff --git a/src/components/GraphFilter/GraphRefresh.tsx b/src/components/GraphFilter/GraphRefresh.tsx index 3493d3b3af..14a8d961b1 100644 --- a/src/components/GraphFilter/GraphRefresh.tsx +++ b/src/components/GraphFilter/GraphRefresh.tsx @@ -5,8 +5,8 @@ import { connect } from 'react-redux'; import { ThunkDispatch } from 'redux-thunk'; import { bindActionCreators } from 'redux'; -import { KialiAppState, ServerConfig } from '../../store/Store'; -import { durationSelector, refreshIntervalSelector, serverConfigSelector } from '../../store/Selectors'; +import { KialiAppState } from '../../store/Store'; +import { durationSelector, refreshIntervalSelector } from '../../store/Selectors'; import { KialiAppAction } from '../../actions/KialiAppAction'; import { UserSettingsActions } from '../../actions/UserSettingsActions'; @@ -16,7 +16,7 @@ import { config } from '../../config/config'; import { HistoryManager, URLParams } from '../../app/History'; import { ListPagesHelper } from '../../components/ListPage/ListPagesHelper'; import ToolbarDropdown from '../ToolbarDropdown/ToolbarDropdown'; -import { getValidDurations, getValidDuration } from '../../config/serverConfig'; +import { serverConfig } from '../../config/serverConfig'; // // GraphRefresh actually handles the Duration dropdown, the RefreshInterval dropdown and the Refresh button. @@ -25,7 +25,6 @@ import { getValidDurations, getValidDuration } from '../../config/serverConfig'; type ReduxProps = { duration: DurationInSeconds; refreshInterval: PollIntervalInMs; - serverConfig: ServerConfig; setDuration: (duration: DurationInSeconds) => void; setRefreshInterval: (refreshInterval: PollIntervalInMs) => void; @@ -38,7 +37,6 @@ type GraphRefreshProps = ReduxProps & { }; export class GraphRefresh extends React.PureComponent { - static readonly DURATION_LIST = config.toolbar.intervalDuration; static readonly POLL_INTERVAL_LIST = config.toolbar.pollInterval; static readonly durationLabelStyle = style({ @@ -73,20 +71,16 @@ export class GraphRefresh extends React.PureComponent { } render() { - const retention = this.props.serverConfig.prometheus.storageTsdbRetention; - const validDurations = getValidDurations(GraphRefresh.DURATION_LIST, retention); - const validDuration = getValidDuration(validDurations, this.props.duration); - return ( <> this.props.setDuration(Number(key))} + value={this.props.duration} + label={String(serverConfig.durations[this.props.duration])} + options={serverConfig.durations} /> { ); } - - private handleDurationChange = (duration: string) => { - this.props.setDuration(Number(duration)); - }; } const mapStateToProps = (state: KialiAppState) => ({ duration: durationSelector(state), - refreshInterval: refreshIntervalSelector(state), - serverConfig: serverConfigSelector(state) + refreshInterval: refreshIntervalSelector(state) }); const mapDispatchToProps = (dispatch: ThunkDispatch) => { diff --git a/src/components/IstioWizards/IstioWizard.tsx b/src/components/IstioWizards/IstioWizard.tsx index 094c43d260..b5c212dc96 100644 --- a/src/components/IstioWizards/IstioWizard.tsx +++ b/src/components/IstioWizards/IstioWizard.tsx @@ -137,7 +137,7 @@ class IstioWizard extends React.Component { host: this.props.serviceName, subsets: this.props.workloads.map(workload => { // Using version - const versionLabelName = serverConfig().istioLabels.versionLabelName; + const versionLabelName = serverConfig.istioLabels.versionLabelName; const versionValue = workload.labels![versionLabelName]; const labels: { [key: string]: string } = {}; labels[versionLabelName] = versionValue; diff --git a/src/components/IstioWizards/IstioWizardDropdown.tsx b/src/components/IstioWizards/IstioWizardDropdown.tsx index 14bf81abf1..0d88b4a0ff 100644 --- a/src/components/IstioWizards/IstioWizardDropdown.tsx +++ b/src/components/IstioWizards/IstioWizardDropdown.tsx @@ -132,8 +132,8 @@ class IstioWizardDropdown extends React.Component { namespace={this.props.namespace} serviceName={this.props.serviceName} workloads={this.props.workloads.filter(workload => { - const appLabelName = serverConfig().istioLabels.versionLabelName; - const versionLabelName = serverConfig().istioLabels.versionLabelName; + const appLabelName = serverConfig.istioLabels.versionLabelName; + const versionLabelName = serverConfig.istioLabels.versionLabelName; return workload.labels && workload.labels[appLabelName] && workload.labels[versionLabelName]; })} onClose={this.onClose} diff --git a/src/components/Metrics/CustomMetrics.tsx b/src/components/Metrics/CustomMetrics.tsx index 2a60352d6c..2eb0ff5149 100644 --- a/src/components/Metrics/CustomMetrics.tsx +++ b/src/components/Metrics/CustomMetrics.tsx @@ -16,7 +16,7 @@ import { Dashboard } from './Dashboard'; import MetricsHelper from './Helper'; import { MetricsSettingsDropdown, MetricsSettings } from '../MetricsOptions/MetricsSettings'; import MetricsRawAggregation from '../MetricsOptions/MetricsRawAggregation'; -import MetricsDurationContainer from '../MetricsOptions/MetricsDuration'; +import MetricsDuration from '../MetricsOptions/MetricsDuration'; type MetricsState = { dashboard?: M.MonitoringDashboard; @@ -129,7 +129,7 @@ class CustomMetrics extends React.Component { - + diff --git a/src/components/Metrics/Helper.ts b/src/components/Metrics/Helper.ts index bff20d8c84..de6b8d286b 100644 --- a/src/components/Metrics/Helper.ts +++ b/src/components/Metrics/Helper.ts @@ -11,7 +11,7 @@ import { } from '../../types/Metrics'; import { BaseMetricsOptions } from '../../types/MetricsOptions'; import { MetricsSettingsDropdown, MetricsSettings } from '../MetricsOptions/MetricsSettings'; -import { MetricsDuration } from '../MetricsOptions/MetricsDuration'; +import MetricsDuration from '../MetricsOptions/MetricsDuration'; import { DurationInSeconds } from '../../types/Common'; import { computePrometheusRateParams } from '../../services/Prometheus'; diff --git a/src/components/Metrics/IstioMetrics.tsx b/src/components/Metrics/IstioMetrics.tsx index e912150b90..076388ec5c 100644 --- a/src/components/Metrics/IstioMetrics.tsx +++ b/src/components/Metrics/IstioMetrics.tsx @@ -15,7 +15,7 @@ import { Dashboard } from './Dashboard'; import MetricsHelper from './Helper'; import { MetricsSettings, MetricsSettingsDropdown } from '../MetricsOptions/MetricsSettings'; import MetricsReporter from '../MetricsOptions/MetricsReporter'; -import MetricsDurationContainer from '../MetricsOptions/MetricsDuration'; +import MetricsDuration from '../MetricsOptions/MetricsDuration'; type MetricsState = { dashboard?: M.MonitoringDashboard; @@ -176,7 +176,7 @@ class IstioMetrics extends React.Component { )} - + diff --git a/src/components/Metrics/__tests__/CustomMetrics.test.tsx b/src/components/Metrics/__tests__/CustomMetrics.test.tsx index 7301f2a5ec..75ab3317b4 100644 --- a/src/components/Metrics/__tests__/CustomMetrics.test.tsx +++ b/src/components/Metrics/__tests__/CustomMetrics.test.tsx @@ -7,8 +7,6 @@ import CustomMetrics from '../CustomMetrics'; import * as API from '../../../services/Api'; import { MonitoringDashboard } from '../../../types/Metrics'; import { store } from '../../../store/ConfigStore'; -import { ServerConfig } from '../../../store/Store'; -import { ServerConfigActions } from '../../../actions/ServerConfigActions'; window['SVGPathElement'] = a => a; let mounted: ReactWrapper | null; @@ -34,15 +32,6 @@ const mockCustomDashboard = (dashboard: MonitoringDashboard): Promise => { return mockAPIToPromise('getCustomDashboard', dashboard); }; -const mockServerConfig = () => { - const config: ServerConfig = { - istioNamespace: 'istio-system', - istioLabels: { appLabelName: 'app', versionLabelName: 'version' }, - prometheus: { storageTsdbRetention: 31 * 24 * 60 * 60 } - }; - store.dispatch(ServerConfigActions.setServerConfig(config)); -}; - describe('Custom metrics', () => { beforeEach(() => { mounted = null; @@ -54,7 +43,6 @@ describe('Custom metrics', () => { }); it('mounts and loads empty metrics', done => { - mockServerConfig(); mockCustomDashboard({ title: 'foo', aggregations: [], charts: [] }) .then(() => { mounted!.update(); diff --git a/src/components/Metrics/__tests__/IstioMetrics.test.tsx b/src/components/Metrics/__tests__/IstioMetrics.test.tsx index 7259c93a44..a19e16fc2a 100644 --- a/src/components/Metrics/__tests__/IstioMetrics.test.tsx +++ b/src/components/Metrics/__tests__/IstioMetrics.test.tsx @@ -7,8 +7,6 @@ import IstioMetrics from '../IstioMetrics'; import * as API from '../../../services/Api'; import { MetricsObjectTypes, MonitoringDashboard, Chart } from '../../../types/Metrics'; import { store } from '../../../store/ConfigStore'; -import { ServerConfig } from '../../../store/Store'; -import { ServerConfigActions } from '../../../actions/ServerConfigActions'; window['SVGPathElement'] = a => a; let mounted: ReactWrapper | null; @@ -42,15 +40,6 @@ const mockGrafanaInfo = (info: any): Promise => { return mockAPIToPromise('getGrafanaInfo', info); }; -const mockServerConfig = () => { - const config: ServerConfig = { - istioNamespace: 'istio-system', - istioLabels: { appLabelName: 'app', versionLabelName: 'version' }, - prometheus: { storageTsdbRetention: 31 * 24 * 60 * 60 } - }; - store.dispatch(ServerConfigActions.setServerConfig(config)); -}; - const createMetricChart = (name: string): Chart => { return { name: name, @@ -125,7 +114,6 @@ describe('Metrics for a service', () => { }); it('renders initial layout', () => { - mockServerConfig(); mockGrafanaInfo({}); const wrapper = shallow( @@ -157,7 +145,6 @@ describe('Metrics for a service', () => { it('mounts and loads empty metrics', done => { const allMocksDone = [ - mockServerConfig(), mockServiceDashboard({ title: 'foo', aggregations: [], charts: [] }) .then(() => { mounted!.update(); @@ -196,7 +183,6 @@ describe('Metrics for a service', () => { it('mounts and loads full metrics', done => { const allMocksDone = [ - mockServerConfig(), mockServiceDashboard({ title: 'foo', aggregations: [], @@ -281,7 +267,6 @@ describe('Inbound Metrics for a workload', () => { it('mounts and loads empty metrics', done => { const allMocksDone = [ - mockServerConfig(), mockWorkloadDashboard({ title: 'foo', aggregations: [], charts: [] }) .then(() => { mounted!.update(); @@ -320,7 +305,6 @@ describe('Inbound Metrics for a workload', () => { it('mounts and loads full metrics', done => { const allMocksDone = [ - mockServerConfig(), mockWorkloadDashboard({ title: 'foo', aggregations: [], diff --git a/src/components/MetricsOptions/MetricsDuration.tsx b/src/components/MetricsOptions/MetricsDuration.tsx index b7620a7133..2ad7149615 100644 --- a/src/components/MetricsOptions/MetricsDuration.tsx +++ b/src/components/MetricsOptions/MetricsDuration.tsx @@ -1,24 +1,15 @@ import * as React from 'react'; import history, { URLParams, HistoryManager } from '../../app/History'; -import { config } from '../../config'; import { DurationInSeconds } from '../../types/Common'; import { ToolbarDropdown } from '../ToolbarDropdown/ToolbarDropdown'; -import { KialiAppState, ServerConfig } from '../../store/Store'; -import { serverConfigSelector } from '../../store/Selectors'; -import { connect } from 'react-redux'; -import { getValidDurations, getValidDuration } from '../../config/serverConfig'; +import { serverConfig } from '../../config/serverConfig'; -type ReduxProps = { - serverConfig: ServerConfig; -}; - -type Props = ReduxProps & { +type Props = { onChanged: (duration: DurationInSeconds) => void; }; -export class MetricsDuration extends React.Component { - static Durations = config.toolbar.intervalDuration; +export default class MetricsDuration extends React.Component { // Default to 10 minutes. Showing timeseries to only 1 minute doesn't make so much sense. static DefaultDuration = 600; @@ -54,19 +45,15 @@ export class MetricsDuration extends React.Component { render() { this.processUrlParams(); - const retention = this.props.serverConfig.prometheus.storageTsdbRetention; - const validDurations = getValidDurations(MetricsDuration.Durations, retention); - const validDuration = getValidDuration(validDurations, this.duration); - return ( ); } @@ -77,14 +64,3 @@ export class MetricsDuration extends React.Component { this.duration = duration; } } - -const mapStateToProps = (state: KialiAppState) => ({ - serverConfig: serverConfigSelector(state) -}); - -const MetricsDurationContainer = connect( - mapStateToProps, - null -)(MetricsDuration); - -export default MetricsDurationContainer; diff --git a/src/components/ToolbarDropdown/__tests__/ToolbarDropdown.test.tsx b/src/components/ToolbarDropdown/__tests__/ToolbarDropdown.test.tsx index f6080186d2..d5831ebd1f 100644 --- a/src/components/ToolbarDropdown/__tests__/ToolbarDropdown.test.tsx +++ b/src/components/ToolbarDropdown/__tests__/ToolbarDropdown.test.tsx @@ -3,6 +3,7 @@ import { mount, shallow } from 'enzyme'; import ToolbarDropdown from '../ToolbarDropdown'; import { config } from '../../../config'; +import { serverConfig } from '../../../config/serverConfig'; const optionsChanged = jest.fn(); @@ -10,7 +11,7 @@ const data = [ { id: 'graph_filter_interval_duration', default: config.toolbar.defaultDuration, - options: config.toolbar.intervalDuration + options: serverConfig.durations }, { id: 'metrics_filter_poll_interval', @@ -63,8 +64,8 @@ describe('ToolbarDropdown', () => { handleSelect={optionsChanged} nameDropdown={'Duration'} initialValue={config.toolbar.defaultDuration} - initialLabel={config.toolbar.intervalDuration[config.toolbar.defaultDuration]} - options={config.toolbar.intervalDuration} + initialLabel={serverConfig.durations[config.toolbar.defaultDuration]} + options={serverConfig.durations} /> ); const elt = wrapper diff --git a/src/components/ToolbarDropdown/__tests__/__snapshots__/ToolbarDropdown.test.tsx.snap b/src/components/ToolbarDropdown/__tests__/__snapshots__/ToolbarDropdown.test.tsx.snap index 19c24b52e4..295894a54f 100644 --- a/src/components/ToolbarDropdown/__tests__/__snapshots__/ToolbarDropdown.test.tsx.snap +++ b/src/components/ToolbarDropdown/__tests__/__snapshots__/ToolbarDropdown.test.tsx.snap @@ -15,14 +15,10 @@ ShallowWrapper { "10800": "Last 3 hours", "1800": "Last 30 min", "21600": "Last 6 hours", - "2592000": "Last 30 days", "300": "Last 5 min", "3600": "Last hour", - "43200": "Last 12 hours", "60": "Last min", "600": "Last 10 min", - "604800": "Last 7 days", - "86400": "Last day", } } />, @@ -127,46 +123,6 @@ ShallowWrapper { > Last 6 hours - - Last 12 hours - - - Last day - - - Last 7 days - - - Last 30 days - , ], }, @@ -263,46 +219,6 @@ ShallowWrapper { > Last 6 hours , - - Last 12 hours - , - - Last day - , - - Last 7 days - , - - Last 30 days - , ], "disabled": false, "id": "graph_filter_interval_duration", @@ -431,74 +347,6 @@ ShallowWrapper { "rendered": "Last 6 hours", "type": [Function], }, - Object { - "instance": null, - "key": "43200", - "nodeType": "class", - "props": Object { - "active": false, - "bsClass": "dropdown", - "children": "Last 12 hours", - "disabled": false, - "divider": false, - "eventKey": "43200", - "header": false, - }, - "ref": null, - "rendered": "Last 12 hours", - "type": [Function], - }, - Object { - "instance": null, - "key": "86400", - "nodeType": "class", - "props": Object { - "active": false, - "bsClass": "dropdown", - "children": "Last day", - "disabled": false, - "divider": false, - "eventKey": "86400", - "header": false, - }, - "ref": null, - "rendered": "Last day", - "type": [Function], - }, - Object { - "instance": null, - "key": "604800", - "nodeType": "class", - "props": Object { - "active": false, - "bsClass": "dropdown", - "children": "Last 7 days", - "disabled": false, - "divider": false, - "eventKey": "604800", - "header": false, - }, - "ref": null, - "rendered": "Last 7 days", - "type": [Function], - }, - Object { - "instance": null, - "key": "2592000", - "nodeType": "class", - "props": Object { - "active": false, - "bsClass": "dropdown", - "children": "Last 30 days", - "disabled": false, - "divider": false, - "eventKey": "2592000", - "header": false, - }, - "ref": null, - "rendered": "Last 30 days", - "type": [Function], - }, ], "type": [Function], }, @@ -599,46 +447,6 @@ ShallowWrapper { > Last 6 hours - - Last 12 hours - - - Last day - - - Last 7 days - - - Last 30 days - , ], }, @@ -735,46 +543,6 @@ ShallowWrapper { > Last 6 hours , - - Last 12 hours - , - - Last day - , - - Last 7 days - , - - Last 30 days - , ], "disabled": false, "id": "graph_filter_interval_duration", @@ -903,74 +671,6 @@ ShallowWrapper { "rendered": "Last 6 hours", "type": [Function], }, - Object { - "instance": null, - "key": "43200", - "nodeType": "class", - "props": Object { - "active": false, - "bsClass": "dropdown", - "children": "Last 12 hours", - "disabled": false, - "divider": false, - "eventKey": "43200", - "header": false, - }, - "ref": null, - "rendered": "Last 12 hours", - "type": [Function], - }, - Object { - "instance": null, - "key": "86400", - "nodeType": "class", - "props": Object { - "active": false, - "bsClass": "dropdown", - "children": "Last day", - "disabled": false, - "divider": false, - "eventKey": "86400", - "header": false, - }, - "ref": null, - "rendered": "Last day", - "type": [Function], - }, - Object { - "instance": null, - "key": "604800", - "nodeType": "class", - "props": Object { - "active": false, - "bsClass": "dropdown", - "children": "Last 7 days", - "disabled": false, - "divider": false, - "eventKey": "604800", - "header": false, - }, - "ref": null, - "rendered": "Last 7 days", - "type": [Function], - }, - Object { - "instance": null, - "key": "2592000", - "nodeType": "class", - "props": Object { - "active": false, - "bsClass": "dropdown", - "children": "Last 30 days", - "disabled": false, - "divider": false, - "eventKey": "2592000", - "header": false, - }, - "ref": null, - "rendered": "Last 30 days", - "type": [Function], - }, ], "type": [Function], }, @@ -2183,14 +1883,10 @@ ShallowWrapper { "10800": "Last 3 hours", "1800": "Last 30 min", "21600": "Last 6 hours", - "2592000": "Last 30 days", "300": "Last 5 min", "3600": "Last hour", - "43200": "Last 12 hours", "60": "Last min", "600": "Last 10 min", - "604800": "Last 7 days", - "86400": "Last day", } } value={60} @@ -2296,46 +1992,6 @@ ShallowWrapper { > Last 6 hours - - Last 12 hours - - - Last day - - - Last 7 days - - - Last 30 days - , ], }, @@ -2432,46 +2088,6 @@ ShallowWrapper { > Last 6 hours , - - Last 12 hours - , - - Last day - , - - Last 7 days - , - - Last 30 days - , ], "disabled": false, "id": "graph_filter_interval_duration", @@ -2600,74 +2216,6 @@ ShallowWrapper { "rendered": "Last 6 hours", "type": [Function], }, - Object { - "instance": null, - "key": "43200", - "nodeType": "class", - "props": Object { - "active": false, - "bsClass": "dropdown", - "children": "Last 12 hours", - "disabled": false, - "divider": false, - "eventKey": "43200", - "header": false, - }, - "ref": null, - "rendered": "Last 12 hours", - "type": [Function], - }, - Object { - "instance": null, - "key": "86400", - "nodeType": "class", - "props": Object { - "active": false, - "bsClass": "dropdown", - "children": "Last day", - "disabled": false, - "divider": false, - "eventKey": "86400", - "header": false, - }, - "ref": null, - "rendered": "Last day", - "type": [Function], - }, - Object { - "instance": null, - "key": "604800", - "nodeType": "class", - "props": Object { - "active": false, - "bsClass": "dropdown", - "children": "Last 7 days", - "disabled": false, - "divider": false, - "eventKey": "604800", - "header": false, - }, - "ref": null, - "rendered": "Last 7 days", - "type": [Function], - }, - Object { - "instance": null, - "key": "2592000", - "nodeType": "class", - "props": Object { - "active": false, - "bsClass": "dropdown", - "children": "Last 30 days", - "disabled": false, - "divider": false, - "eventKey": "2592000", - "header": false, - }, - "ref": null, - "rendered": "Last 30 days", - "type": [Function], - }, ], "type": [Function], }, @@ -2768,46 +2316,6 @@ ShallowWrapper { > Last 6 hours - - Last 12 hours - - - Last day - - - Last 7 days - - - Last 30 days - , ], }, @@ -2904,46 +2412,6 @@ ShallowWrapper { > Last 6 hours , - - Last 12 hours - , - - Last day - , - - Last 7 days - , - - Last 30 days - , ], "disabled": false, "id": "graph_filter_interval_duration", @@ -3072,74 +2540,6 @@ ShallowWrapper { "rendered": "Last 6 hours", "type": [Function], }, - Object { - "instance": null, - "key": "43200", - "nodeType": "class", - "props": Object { - "active": false, - "bsClass": "dropdown", - "children": "Last 12 hours", - "disabled": false, - "divider": false, - "eventKey": "43200", - "header": false, - }, - "ref": null, - "rendered": "Last 12 hours", - "type": [Function], - }, - Object { - "instance": null, - "key": "86400", - "nodeType": "class", - "props": Object { - "active": false, - "bsClass": "dropdown", - "children": "Last day", - "disabled": false, - "divider": false, - "eventKey": "86400", - "header": false, - }, - "ref": null, - "rendered": "Last day", - "type": [Function], - }, - Object { - "instance": null, - "key": "604800", - "nodeType": "class", - "props": Object { - "active": false, - "bsClass": "dropdown", - "children": "Last 7 days", - "disabled": false, - "divider": false, - "eventKey": "604800", - "header": false, - }, - "ref": null, - "rendered": "Last 7 days", - "type": [Function], - }, - Object { - "instance": null, - "key": "2592000", - "nodeType": "class", - "props": Object { - "active": false, - "bsClass": "dropdown", - "children": "Last 30 days", - "disabled": false, - "divider": false, - "eventKey": "2592000", - "header": false, - }, - "ref": null, - "rendered": "Last 30 days", - "type": [Function], - }, ], "type": [Function], }, diff --git a/src/config/config.ts b/src/config/config.ts index 38ae7d6b08..345c6eeb33 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -16,20 +16,6 @@ const conf = { toolbar: { /** Duration default in 1 minute */ defaultDuration: 1 * UNIT_TIME.MINUTE, - /** Options in interval duration */ - intervalDuration: { - 60: 'Last min', - 300: 'Last 5 min', - 600: 'Last 10 min', - 1800: 'Last 30 min', - 3600: 'Last hour', - 10800: 'Last 3 hours', - 21600: 'Last 6 hours', - 43200: 'Last 12 hours', - 86400: 'Last day', - 604800: 'Last 7 days', - 2592000: 'Last 30 days' - }, /** By default refresh is 15 seconds */ defaultPollInterval: 15 * MILLISECONDS, /** Options in refresh */ diff --git a/src/config/serverConfig.ts b/src/config/serverConfig.ts index cb6e88ae0f..5550b4c78c 100644 --- a/src/config/serverConfig.ts +++ b/src/config/serverConfig.ts @@ -1,42 +1,67 @@ import deepFreeze from 'deep-freeze'; -import { store } from '../store/ConfigStore'; -import { KialiAppState, ServerConfig } from '../store/Store'; -import { PersistPartial } from 'redux-persist'; import { DurationInSeconds } from '../types/Common'; -import { forOwn, pickBy } from 'lodash'; -// It's not great to access the store directly for convenience but the alternative is -// a huge code ripple just to access some server config. better to just have this one utility. -export const serverConfig = (): ServerConfig => { - const actualState = store.getState() || ({} as KialiAppState & PersistPartial); - return deepFreeze(actualState.serverConfig); -}; +export type IstioLabelKey = 'appLabelName' | 'versionLabelName'; +export type Durations = { [key: number]: string }; + +export interface ServerConfig { + istioNamespace: string; + istioLabels: { [key in IstioLabelKey]: string }; + prometheus: { + globalScrapeInterval?: DurationInSeconds; + storageTsdbRetention?: DurationInSeconds; + }; + webRoot?: string; + durations: Durations; +} -// getValidDurations returns a new object with only the durations <= retention -export const getValidDurations = ( - durations: { [key: number]: string }, - retention?: DurationInSeconds -): { [key: number]: string } => { - const validDurations = pickBy(durations, (_, key: number) => { - return !retention || key <= retention; +const toDurations = (tupleArray: [number, string][]): Durations => { + const obj = {}; + tupleArray.forEach(tuple => { + obj[tuple[0]] = tuple[1]; }); - return validDurations as { [key: number]: string }; + return obj; }; -// getValidDuration returns duration if it is a valid property key in durations, otherwise it return the first property -// key in durations. It is assumed that durations has at least one property. -export const getValidDuration = ( - durations: { [key: number]: string }, - duration: DurationInSeconds -): DurationInSeconds => { - let validDuration = 0; - forOwn(durations, (_, key) => { - const d = Number(key); - if (d === duration) { - validDuration = d; - } else if (!validDuration) { - validDuration = d; - } - }); - return validDuration; +const computeValidDurations = (cfg: ServerConfig) => { + const defaultDurations: [number, string][] = [ + [60, 'Last min'], + [300, 'Last 5 min'], + [600, 'Last 10 min'], + [1800, 'Last 30 min'], + [3600, 'Last hour'], + [10800, 'Last 3 hours'], + [21600, 'Last 6 hours'], + [43200, 'Last 12 hours'], + [86400, 'Last day'], + [604800, 'Last 7 days'], + [2592000, 'Last 30 days'] + ]; + if (cfg.prometheus.storageTsdbRetention) { + const filtered = defaultDurations.filter(d => d[0] <= cfg.prometheus.storageTsdbRetention!); + cfg.durations = toDurations(filtered); + } else { + cfg.durations = toDurations(defaultDurations); + } }; + +const tmpConfig: ServerConfig = process.env.TEST_RUNNER + ? { + istioNamespace: 'istio-system', + istioLabels: { + appLabelName: 'app', + versionLabelName: 'version' + }, + prometheus: { + globalScrapeInterval: 15, + storageTsdbRetention: 21600 + }, + durations: {} + } + : (window as any).serverConfig; +if (tmpConfig) { + computeValidDurations(tmpConfig); +} else { + console.error('serverConfig object is missing'); +} +export const serverConfig: ServerConfig = deepFreeze(tmpConfig); diff --git a/src/pages/Graph/SummaryPanelCommon.tsx b/src/pages/Graph/SummaryPanelCommon.tsx index 5935acfdb2..89e4009702 100644 --- a/src/pages/Graph/SummaryPanelCommon.tsx +++ b/src/pages/Graph/SummaryPanelCommon.tsx @@ -178,7 +178,7 @@ export const renderLabels = (data: NodeData) => { <>
{hasNamespace &&
); diff --git a/src/pages/Graph/SummaryPanelEdge.tsx b/src/pages/Graph/SummaryPanelEdge.tsx index 65d0e0b7cf..8b6cf82f5e 100644 --- a/src/pages/Graph/SummaryPanelEdge.tsx +++ b/src/pages/Graph/SummaryPanelEdge.tsx @@ -231,8 +231,8 @@ export default class SummaryPanelEdge extends React.Component (