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

Bug 1807210: added Time Range & Refresh Interval dropdowns in monitoring dashboard #4519

Merged
merged 1 commit into from Mar 2, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -5,7 +5,7 @@ import { HorizontalNav, PageHeading, history } from '@console/internal/component
import { TechPreviewBadge, ALL_NAMESPACES_KEY } from '@console/shared';
import NamespacedPage, { NamespacedPageVariants } from '../NamespacedPage';
import ProjectListPage from '../projects/ProjectListPage';
import MonitoringDashboard from './dashboard/MonitoringDashboard';
import ConnectedMonitoringDashboard from './dashboard/MonitoringDashboard';
import ConnectedMonitoringMetrics from './metrics/MonitoringMetrics';
import MonitoringEvents from './events/MonitoringEvents';

Expand Down Expand Up @@ -44,7 +44,7 @@ export const MonitoringPage: React.FC<MonitoringPageProps> = ({ match }) => {
{
href: '',
name: 'Dashboard',
component: MonitoringDashboard,
component: ConnectedMonitoringDashboard,
},
{
href: 'metrics',
Expand Down
@@ -0,0 +1,7 @@
.odc-monitoring-dashboard__dropdown-options {
display: flex;
float: right;
align-self: flex-end;
margin-top: -65px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now this is fine.
We should push back on UX for this in future because:

  • we don't have components for this right now
  • it's a contextual item that appears at the same height as the tabs that set the context below
  • there's no consideration for responsive mobile layout. Right now it overlaps the tabs on mobile.

cc @openshift/team-devconsole-ux

}

@@ -1,23 +1,37 @@
import * as React from 'react';
import * as _ from 'lodash';
import { match as RMatch } from 'react-router-dom';
import { connect } from 'react-redux';
import { Helmet } from 'react-helmet';
import { RootState } from '@console/internal/redux';
import { getURLSearchParams } from '@console/internal/components/utils';
import {
TimespanDropdown,
PollIntervalDropdown,
} from '@console/internal/components/monitoring/dashboards';
import ConnectedMonitoringDashboardGraph from './MonitoringDashboardGraph';
import {
monitoringDashboardQueries,
workloadMetricsQueries,
MonitoringQuery,
topWorkloadMetricsQueries,
} from '../queries';
import './MonitoringDashboard.scss';

interface MonitoringDashboardProps {
type MonitoringDashboardProps = {
match: RMatch<{
ns?: string;
}>;
}
};

type StateProps = {
timespan: number;
pollInterval: number;
};

const MonitoringDashboard: React.FC<MonitoringDashboardProps> = ({ match }) => {
type Props = MonitoringDashboardProps & StateProps;

export const MonitoringDashboard: React.FC<Props> = ({ match, timespan, pollInterval }) => {
const namespace = match.params.ns;
const params = getURLSearchParams();
const { workloadName, workloadType } = params;
Expand All @@ -31,6 +45,10 @@ const MonitoringDashboard: React.FC<MonitoringDashboardProps> = ({ match }) => {
<Helmet>
<title>Dashboard</title>
</Helmet>
<div className="odc-monitoring-dashboard__dropdown-options">
<TimespanDropdown />
<PollIntervalDropdown />
</div>
<div className="co-m-pane__body">
{_.map(queries, (q) => (
<ConnectedMonitoringDashboardGraph
Expand All @@ -41,11 +59,18 @@ const MonitoringDashboard: React.FC<MonitoringDashboardProps> = ({ match }) => {
humanize={q.humanize}
byteDataType={q.byteDataType}
key={q.title}
timespan={timespan}
pollInterval={pollInterval}
/>
))}
</div>
</>
);
};

export default MonitoringDashboard;
const mapStateToProps = (state: RootState): StateProps => ({
timespan: state.UI.getIn(['monitoringDashboards', 'timespan']),
pollInterval: state.UI.getIn(['monitoringDashboards', 'pollInterval']),
});

export default connect<StateProps, MonitoringDashboardProps>(mapStateToProps)(MonitoringDashboard);
Expand Up @@ -23,19 +23,23 @@ type OwnProps = {
graphType?: GraphTypes;
humanize: Humanize;
byteDataType: ByteDataTypes;
timespan?: number;
pollInterval?: number;
};

type MonitoringDashboardGraphProps = OwnProps & DispatchProps;

const defaultTimespan = 30 * 60 * 1000;
const defaultSamples = 30;
const DEFAULT_TIME_SPAN = 30 * 60 * 1000;
const DEFAULT_SAMPLES = 30;

export const MonitoringDashboardGraph: React.FC<MonitoringDashboardGraphProps> = ({
query,
namespace,
title,
patchQuery,
graphType = GraphTypes.area,
timespan,
pollInterval,
}) => {
return (
<div className="odc-monitoring-dashboard-graph">
Expand All @@ -44,11 +48,13 @@ export const MonitoringDashboardGraph: React.FC<MonitoringDashboardGraphProps> =
<div onMouseEnter={() => patchQuery({ query })}>
<QueryBrowser
hideControls
defaultTimespan={defaultTimespan}
defaultSamples={defaultSamples}
defaultTimespan={DEFAULT_TIME_SPAN}
defaultSamples={DEFAULT_SAMPLES}
namespace={namespace}
queries={[query]}
isStack={graphType === GraphTypes.area}
timespan={timespan}
pollInterval={pollInterval}
/>
</div>
</PrometheusGraphLink>
Expand Down
@@ -1,7 +1,11 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import * as link from '@console/internal/components/utils';
import MonitoringDashboard from '../MonitoringDashboard';
import {
TimespanDropdown,
PollIntervalDropdown,
} from '@console/internal/components/monitoring/dashboards';
abhi-kn marked this conversation as resolved.
Show resolved Hide resolved
import { MonitoringDashboard } from '../MonitoringDashboard';
import ConnectedMonitoringDashboardGraph from '../MonitoringDashboardGraph';
import { monitoringDashboardQueries, topWorkloadMetricsQueries } from '../../queries';

Expand All @@ -17,6 +21,8 @@ describe('Monitoring Dashboard Tab', () => {
path: '',
url: '',
},
timespan: 1800000,
pollInterval: 90000,
};

it('should render Monitoring Dashboard tab', () => {
Expand Down Expand Up @@ -55,4 +61,10 @@ describe('Monitoring Dashboard Tab', () => {
.props().query,
).toEqual(dashboardQuery);
});

it('should render Time Range & Refresh Interval dropdowns', () => {
const wrapper = shallow(<MonitoringDashboard {...monitoringDashboardProps} />);
expect(wrapper.find(TimespanDropdown).exists()).toBe(true);
expect(wrapper.find(PollIntervalDropdown).exists()).toBe(true);
});
});
Expand Up @@ -18,6 +18,8 @@ describe('Monitoring Dashboard graph', () => {
humanize: query.humanize,
byteDataType: query.byteDataType,
patchQuery: jest.fn(),
timespan: 1800000,
pollInterval: 30000,
};
});

Expand Down
6 changes: 4 additions & 2 deletions frontend/public/components/monitoring/dashboards/index.tsx
Expand Up @@ -217,7 +217,8 @@ const TimespanDropdown_: React.FC<TimespanDropdownProps> = ({ timespan, setTimes
/>
);
};
const TimespanDropdown = connect(

export const TimespanDropdown = connect(
({ UI }: RootState) => ({
timespan: UI.getIn(['monitoringDashboards', 'timespan']),
}),
Expand Down Expand Up @@ -258,7 +259,8 @@ const PollIntervalDropdown_: React.FC<PollIntervalDropdownProps> = ({
/>
);
};
const PollIntervalDropdown = connect(

export const PollIntervalDropdown = connect(
({ UI }: RootState) => ({
pollInterval: UI.getIn(['monitoringDashboards', 'pollInterval']),
}),
Expand Down