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

release-23.1: ui: make custom chart tool work at store level #122806

Merged
merged 1 commit into from
Apr 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export class CustomMetricState {
downsampler = TimeSeriesQueryAggregator.AVG;
aggregator = TimeSeriesQueryAggregator.SUM;
derivative = TimeSeriesQueryDerivative.NONE;
perNode = false;
source = "";
perSource = false;
nodeSource = "";
}

export class CustomChartState {
Expand Down Expand Up @@ -107,15 +107,15 @@ export class CustomMetricRow extends React.Component<CustomMetricRowProps> {
});
};

changeSource = (selectedOption: DropdownOption) => {
changeNodeSource = (selectedOption: DropdownOption) => {
this.changeState({
source: selectedOption.value,
nodeSource: selectedOption.value,
});
};

changePerNode = (selection: React.FormEvent<HTMLInputElement>) => {
changePerSource = (selection: React.FormEvent<HTMLInputElement>) => {
this.changeState({
perNode: selection.currentTarget.checked,
perSource: selection.currentTarget.checked,
});
};

Expand All @@ -132,8 +132,8 @@ export class CustomMetricRow extends React.Component<CustomMetricRowProps> {
downsampler,
aggregator,
derivative,
source,
perNode,
nodeSource,
perSource,
},
} = this.props;

Expand Down Expand Up @@ -196,17 +196,17 @@ export class CustomMetricRow extends React.Component<CustomMetricRowProps> {
className="metric-table-dropdown__select"
clearable={false}
searchable={false}
value={source}
value={nodeSource}
options={nodeOptions}
onChange={this.changeSource}
onChange={this.changeNodeSource}
/>
</div>
</td>
<td className="metric-table__cell">
<input
type="checkbox"
checked={perNode}
onChange={this.changePerNode}
checked={perSource}
onChange={this.changePerSource}
/>
</td>
<td className="metric-table__cell">
Expand Down Expand Up @@ -291,7 +291,7 @@ export class CustomChartTable extends React.Component<CustomChartTableProps> {
<td className="metric-table__header">Aggregator</td>
<td className="metric-table__header">Rate</td>
<td className="metric-table__header">Source</td>
<td className="metric-table__header">Per Node</td>
<td className="metric-table__header">Per Node/Store</td>
<td className="metric-table__header"></td>
</tr>
</thead>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ import {
} from "src/redux/metricMetadata";
import { INodeStatus } from "src/util/proto";

import { CustomChartState, CustomChartTable } from "./customMetric";
import {
CustomChartState,
CustomChartTable,
CustomMetricState,
} from "./customMetric";
import "./customChart.styl";
import { queryByName } from "src/util/query";
import { PayloadAction } from "src/interfaces/action";
Expand Down Expand Up @@ -197,6 +201,34 @@ export class CustomChart extends React.Component<
);
};

getSources = (
nodesSummary: NodesSummary,
metricState: CustomMetricState,
): string[] => {
if (!(nodesSummary?.nodeStatuses?.length > 0)) {
return [];
}
// If we have no nodeSource, and we're not asking for perSource metrics,
// then the user is asking for cluster-wide metrics. We can return an empty
// source list.
if (metricState.nodeSource === "" && !metricState.perSource) {
return [];
}
if (isStoreMetric(nodesSummary.nodeStatuses[0], metricState.metric)) {
// If a specific node is selected, return the storeIDs associated with that node.
// Otherwise, we're at the cluster level, so we grab each store ID.
return metricState.nodeSource
? nodesSummary.storeIDsByNodeID[metricState.nodeSource]
: Object.values(nodesSummary.storeIDsByNodeID).flatMap(s => s);
} else {
// If it's not a store metric, and a specific nodeSource is chosen, just return that.
// Otherwise, return all known node IDs.
return metricState.nodeSource
? [metricState.nodeSource]
: nodesSummary.nodeIDs;
}
};

// Render a chart of the currently selected metrics.
renderChart = (chart: CustomChartState, index: number) => {
const metrics = chart.metrics;
Expand All @@ -215,23 +247,17 @@ export class CustomChart extends React.Component<
<Axis units={units} label={AxisUnits[units]}>
{metrics.map((m, i) => {
if (m.metric !== "") {
if (m.perNode) {
return _.map(nodesSummary.nodeIDs, nodeID => (
if (m.perSource) {
const sources = this.getSources(nodesSummary, m);
return _.map(sources, source => (
<Metric
key={`${index}${i}${nodeID}`}
title={`${nodeID}: ${m.metric} (${i})`}
key={`${index}${i}${source}`}
title={`${source}: ${m.metric} (${i})`}
name={m.metric}
aggregator={m.aggregator}
downsampler={m.downsampler}
derivative={m.derivative}
sources={
isStoreMetric(nodesSummary.nodeStatuses[0], m.metric)
? _.map(
nodesSummary.storeIDsByNodeID[nodeID] || [],
n => n.toString(),
)
: [nodeID]
}
sources={[source]}
/>
));
} else {
Expand All @@ -243,7 +269,7 @@ export class CustomChart extends React.Component<
aggregator={m.aggregator}
downsampler={m.downsampler}
derivative={m.derivative}
sources={m.source === "" ? [] : [m.source]}
sources={this.getSources(nodesSummary, m)}
/>
);
}
Expand Down Expand Up @@ -344,5 +370,8 @@ export default withRouter(
);

function isStoreMetric(nodeStatus: INodeStatus, metricName: string) {
if (metricName?.startsWith("cr.store")) {
return true;
}
return _.has(nodeStatus.store_statuses[0].metrics, metricName);
}