Skip to content

Commit

Permalink
Merge pull request #130 from rancher/cluster-names
Browse files Browse the repository at this point in the history
Updated to the areas of the app that display cluster id to now make use of cluster name when available
  • Loading branch information
codyrancher authored Mar 29, 2023
2 parents 4ba4406 + 62adba2 commit 31b9504
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 55 deletions.
13 changes: 7 additions & 6 deletions public/components/Breakdowns/Breakdowns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Pod from './components/Pod';
import Namespace from './components/Namesapce';
import Rancher from './components/Rancher';
import Longhorn from './components/Longhorn';
import { BasicBreakdown, getControlPlaneBreakdown, getLogTypes, getNamespaceBreakdown, getPodBreakdown, getRancherBreakdown, getLonghornBreakdown } from '../../utils/requests';
import { BasicBreakdown, getControlPlaneBreakdown, getLogTypes, getNamespaceBreakdown, getPodBreakdown, getRancherBreakdown, getLonghornBreakdown, getClusterMetadataById } from '../../utils/requests';
import Loading from '../Loading/Loading';
import { Granularity, isSameRange, Range } from '../../utils/time';

Expand Down Expand Up @@ -70,11 +70,12 @@ export default class Breakdowns extends Component<BreakdownsProps, BreakdownStat
}

load = async () => {
const controlPlaneBreakdownRequest = getControlPlaneBreakdown(this.props.range, this.props.clusterId, this.props.keywords);
const podBreakdownRequest = getPodBreakdown(this.props.range, this.props.clusterId, this.props.keywords);
const namespaceBreakdownRequest = getNamespaceBreakdown(this.props.range, this.props.clusterId, this.props.keywords);
const rancherBreakdownRequest = getRancherBreakdown(this.props.range, this.props.clusterId, this.props.keywords);
const longhornBreakdownRequest = getLonghornBreakdown(this.props.range, this.props.clusterId, this.props.keywords);
const clusterById = await getClusterMetadataById();
const controlPlaneBreakdownRequest = getControlPlaneBreakdown(this.props.range, this.props.clusterId, this.props.keywords, clusterById);
const podBreakdownRequest = getPodBreakdown(this.props.range, this.props.clusterId, this.props.keywords, clusterById);
const namespaceBreakdownRequest = getNamespaceBreakdown(this.props.range, this.props.clusterId, this.props.keywords, clusterById);
const rancherBreakdownRequest = getRancherBreakdown(this.props.range, this.props.clusterId, this.props.keywords, clusterById);
const longhornBreakdownRequest = getLonghornBreakdown(this.props.range, this.props.clusterId, this.props.keywords, clusterById);
const logTypesRequest = getLogTypes();

this.setState({
Expand Down
1 change: 0 additions & 1 deletion public/components/EventsTable/EventsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export default class EventsTable extends Component<EventsTableProps, EventsTable
const getPagedEvents = () => {
const start = this.state.pagination.pageIndex * this.state.pagination.pageSize;
const end = start + this.state.pagination.pageSize;
console.log(this.state.events.slice(this.state.pagination.pageIndex * this.state.pagination.pageSize, this.state.pagination.pageSize))
return this.state.events.slice(start, end);
};

Expand Down
5 changes: 3 additions & 2 deletions public/components/Filters/EventsFilter/EventsFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
EuiSuperDatePicker
} from '@elastic/eui';
import { Settings } from '@elastic/charts';
import { ClusterMetadata } from '../../../utils/requests';

export interface Settings {
range: {
Expand All @@ -20,7 +21,7 @@ export interface Settings {
}
export interface SelectorProps {
settings: Settings;
clusterIds: string[];
clusters: ClusterMetadata[];
onChange: (Settings) => void;
onRefresh: () => void;
};
Expand Down Expand Up @@ -56,7 +57,7 @@ export default class Selector extends Component<SelectorProps> {

render() {
const { range, cluster } = this.props.settings;
const clusterOptions = [...CLUSTER_OPTIONS, ...this.props.clusterIds.map(id => ({ value: id, text: id}))];
const clusterOptions = [...CLUSTER_OPTIONS, ...this.props.clusters.map(c => ({ value: c.id, text: c.name}))];
const onTimeChange = (newRange) => {
this.onChange('range')({start: newRange.start, end: (newRange.end.includes('now') ? 'now' : newRange.end) });
setTimeout(() => this.props.onRefresh());
Expand Down
5 changes: 3 additions & 2 deletions public/components/Selector/Selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Settings } from '@elastic/charts';
import { Granularity } from '../../utils/time';
import Keywords from '../Keywords';
import { CoreConsumer } from '../../utils/CoreContext';
import { ClusterMetadata } from '../../utils/requests';

export interface Settings {
range: {
Expand All @@ -25,7 +26,7 @@ export interface Settings {
}
export interface SelectorProps {
settings: Settings;
clusterIds: string[];
clusters: ClusterMetadata[];
onChange: (Settings) => void;
onRefresh: () => void;
};
Expand Down Expand Up @@ -92,7 +93,7 @@ export default class Selector extends Component<SelectorProps, SelectorState> {

render() {
const { range, granularity, cluster, keywords } = this.props.settings;
const clusterOptions = [...CLUSTER_OPTIONS, ...this.props.clusterIds.map(id => ({ value: id, text: id}))];
const clusterOptions = [...CLUSTER_OPTIONS, ...this.props.clusters.map(c => ({ value: c.id, text: c.name}))];
const onTimeChange = (newRange) => {
this.onChange('range')({start: newRange.start, end: (newRange.end.includes('now') ? 'now' : newRange.end)});
setTimeout(() => this.props.onRefresh());
Expand Down
11 changes: 6 additions & 5 deletions public/pages/Events/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import React, { Component } from 'react';
import EventsFilter from '../../components/Filters/EventsFilter';
import { DEFAULT_SETTINGS, Settings } from '../../components/Filters/EventsFilter';
import { Range } from '../../utils/time';
import { getClusterIds } from '../../utils/requests';
import { ClusterMetadata, getClusterMetadata } from '../../utils/requests';
import dateMath from '@elastic/datemath';
import PrimaryLayout from '../../components/Layout/PrimaryLayout';
import EventsTable from '../../components/EventsTable/EventsTable';
import { Moment } from 'moment';

interface EventsState {
settings: Settings,
clustersRequest: Promise<string[]>;
clusters: string[];
clustersRequest: Promise<ClusterMetadata[]>;
clusters: ClusterMetadata[];
range: Range;
cluster: string;
};
Expand Down Expand Up @@ -53,21 +53,22 @@ export default class Events extends Component<any, EventsState> {
};

load = async () => {
const clustersRequest = getClusterIds();
const clustersRequest = getClusterMetadata();
this.setState({
clustersRequest
});

this.setState({
clusters: await clustersRequest
});

};


render() {
return (
<PrimaryLayout loadingPromise={this.state.clustersRequest}>
<EventsFilter settings={this.state.settings} onChange={this.onSettingsChange} clusterIds={this.state.clusters} onRefresh={this.onRefresh}/>
<EventsFilter settings={this.state.settings} onChange={this.onSettingsChange} clusters={this.state.clusters} onRefresh={this.onRefresh}/>
<EventsTable range={this.state.range} clusterId={this.state.cluster} />
</PrimaryLayout>
);
Expand Down
11 changes: 5 additions & 6 deletions public/pages/Insights/Insights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import Selector from '../../components/Selector';
import Breakdowns from '../../components/Breakdowns';
import { DEFAULT_SETTINGS, Settings } from '../../components/Selector/Selector';
import { Range, Granularity } from '../../utils/time';
import AnomalyChart from '../../components/AnomalyChart';
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { getClusterIds, getInsights, getK8sEvents } from '../../utils/requests';
import { ClusterMetadata, getClusterMetadata, getInsights, getK8sEvents } from '../../utils/requests';
import dateMath from '@elastic/datemath';
import Cookies from 'js-cookie';
import PrimaryLayout from '../../components/Layout/PrimaryLayout';
import { Moment } from 'moment';

interface MainState {
settings: Settings,
clustersRequest: Promise<string[]>;
clusters: string[];
clustersRequest: Promise<ClusterMetadata[]>;
clusters: ClusterMetadata[];
range: Range;
granularity: Granularity,
cluster: string;
Expand Down Expand Up @@ -69,7 +68,7 @@ class Main extends Component<any, MainState> {
};

load = async () => {
const clustersRequest = getClusterIds();
const clustersRequest = getClusterMetadata();
this.setState({
clustersRequest
});
Expand All @@ -82,7 +81,7 @@ class Main extends Component<any, MainState> {
render() {
return (
<PrimaryLayout loadingPromise={this.state.clustersRequest}>
<Selector settings={this.state.settings} onChange={this.onSettingsChange} clusterIds={this.state.clusters} onRefresh={this.onRefresh}/>
<Selector settings={this.state.settings} onChange={this.onSettingsChange} clusters={this.state.clusters} onRefresh={this.onRefresh}/>
<EuiFlexGroup style={{ padding: '0 15px' }} className="selector">
<EuiFlexItem><InsightsChart range={this.state.range} granularity={this.state.granularity} clusterId={this.state.cluster} insightsProvider={getInsights} eventsProvider={(range, clusterId) => getK8sEvents(range, clusterId, 'Warning')} keywords={this.state.keywords} showTitle={true} /></EuiFlexItem>
</EuiFlexGroup>
Expand Down
10 changes: 5 additions & 5 deletions public/pages/Templates/Templates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import React, { Component } from 'react';
import EventsFilter from '../../components/Filters/EventsFilter';
import { DEFAULT_SETTINGS, Settings } from '../../components/Filters/EventsFilter';
import { Range } from '../../utils/time';
import { getClusterIds } from '../../utils/requests';
import { ClusterMetadata, getClusterMetadata } from '../../utils/requests';
import dateMath from '@elastic/datemath';
import PrimaryLayout from '../../components/Layout/PrimaryLayout';
import TemplatesTable from '../../components/TemplatesTable';
import { Moment } from 'moment';

interface EventsState {
settings: Settings,
clustersRequest: Promise<string[]>;
clusters: string[];
clustersRequest: Promise<ClusterMetadata[]>;
clusters: ClusterMetadata[];
range: Range;
cluster: string;
};
Expand Down Expand Up @@ -53,7 +53,7 @@ export default class Events extends Component<any, EventsState> {
};

load = async () => {
const clustersRequest = getClusterIds();
const clustersRequest = getClusterMetadata();
this.setState({
clustersRequest
});
Expand All @@ -66,7 +66,7 @@ export default class Events extends Component<any, EventsState> {
render() {
return (
<PrimaryLayout loadingPromise={this.state.clustersRequest}>
<EventsFilter settings={this.state.settings} onChange={this.onSettingsChange} clusterIds={this.state.clusters} onRefresh={this.onRefresh}/>
<EventsFilter settings={this.state.settings} onChange={this.onSettingsChange} clusters={this.state.clusters} onRefresh={this.onRefresh}/>
<TemplatesTable range={this.state.range} clusterId={this.state.cluster} />
</PrimaryLayout>
);
Expand Down
6 changes: 3 additions & 3 deletions public/utils/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import { BasicBreakdown } from "./requests";
export function getGroupBreakdown(breakdown: BasicBreakdown[]): Item[] {
const grouping = {};
breakdown.forEach(b => {
grouping[b.clusterId] = grouping[b.clusterId] || [];
grouping[b.clusterId].push(b);
grouping[b.clusterName] = grouping[b.clusterName] || [];
grouping[b.clusterName].push(b);
});

Object.keys(grouping).forEach(groupKey => {
grouping[groupKey] = sortBy(grouping[groupKey], [(group) => (group.anomaly || 0), (group) => (group.normal || 0)]).reverse()
});

const groupingArray = Object.entries(grouping)
.map(([clusterId, values]) => [{ group: true, name: `Cluster: ${clusterId}` }, ...(values as any)]);
.map(([clusterName, values]) => [{ group: true, name: `Cluster: ${clusterName}` }, ...(values as any)]);

const sortedGroupingArray = sortBy(groupingArray, (group) => (group[1].anomaly || 0), (group) => (group[1].keywords || 0), (group) => (group[1].normal || 0)).reverse();

Expand Down
Loading

0 comments on commit 31b9504

Please sign in to comment.