Skip to content
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
1 change: 1 addition & 0 deletions x-pack/plugins/infra/common/http_api/snapshot_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const SnapshotRequestRT = rt.intersection([
region: rt.string,
filterQuery: rt.union([rt.string, rt.null]),
overrideCompositeSize: rt.number,
dropPartialBuckets: rt.boolean,
}),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const Tile = ({ type, ...props }: Props) => {
metrics: [{ type }],
groupBy: null,
includeTimeseries: true,
dropPartialBuckets: false,
});

return <KPIChart id={`$metric-${type}`} type={type} nodes={nodes} loading={loading} {...props} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function useSnapshot({
groupBy = null,
sendRequestImmediately = true,
includeTimeseries = true,
dropPartialBuckets = true,
requestTs,
...args
}: UseSnapshotRequest) {
Expand All @@ -56,6 +57,7 @@ export function useSnapshot({
lookbackSize: 5,
},
includeTimeseries,
dropPartialBuckets,
};

const { error, loading, response, makeRequest } = useHTTPRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ import { applyMetadataToLastPath } from './apply_metadata_to_last_path';
const getMetricValue = (row: MetricsAPIRow) => {
if (!isNumber(row.metric_0)) return null;
const value = row.metric_0;
return isFinite(value) ? value : null;
return Number.isFinite(value) ? value : null;
};

const calculateMax = (rows: MetricsAPIRow[]) => {
return max(rows.map(getMetricValue)) || 0;
};

const calculateAvg = (rows: MetricsAPIRow[]): number => {
return sum(rows.map(getMetricValue)) / rows.length || 0;
const values = rows.map(getMetricValue).filter(Number.isFinite);
return sum(values) / Math.max(values.length, 1);
};

const getLastValue = (rows: MetricsAPIRow[]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const transformRequestToMetricsAPIRequest = async ({
? snapshotRequest.overrideCompositeSize
: compositeSize,
alignDataToEnd: true,
dropPartialBuckets: true,
dropPartialBuckets: snapshotRequest.dropPartialBuckets ?? true,
includeTimeseries: snapshotRequest.includeTimeseries,
};

Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/api_integration/apis/metrics_ui/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export default function ({ getService }: FtrProviderContext) {
name: 'cpu',
value: null,
max: 0.47105555555555556,
avg: 0.0672936507936508,
avg: 0.47105555555555556,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is what the query returns:

[{ timestamp: 1562786355035, metric_0: null },
{ timestamp: 1562786415035, metric_0: null },
{ timestamp: 1562786475035, metric_0: null },
{ timestamp: 1562786535035, metric_0: null },
{ timestamp: 1562786595035, metric_0: null },
{ timestamp: 1562786655035, metric_0: 0.47105555555555556 },
{ timestamp: 1562786715035, metric_0: null }]

So, if we're filtering out null values from the average calculation, it makes sense for the expected result to be 0.47105555555555556

};

expect(snapshot).to.have.property('nodes');
Expand Down