Skip to content

Commit 036ca22

Browse files
authored
fix: fill the missing data in the metrics response (#5479)
1 parent c882a25 commit 036ca22

11 files changed

Lines changed: 69 additions & 187 deletions

File tree

static/js/publisher/components/PublisherMetrics/PublisherMetrics.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ function PublisherMetrics({ snaps }: { snaps: ISnap[] }): React.JSX.Element {
1616
}
1717
}, [metricsData]);
1818

19-
const daysWithoutDataExist =
20-
metricsData && metricsData.daysWithoutData.length > 0;
2119
return (
2220
<Strip
2321
className="u-no-padding--top"
@@ -30,12 +28,6 @@ function PublisherMetrics({ snaps }: { snaps: ISnap[] }): React.JSX.Element {
3028
size={12}
3129
className="snap-installs-container snapcraft-metrics__graph snapcraft-metrics__active-devices"
3230
>
33-
{daysWithoutDataExist && (
34-
<Notification severity="caution">
35-
Metrics for the most recent days may be incomplete or missing.
36-
They will be updated and accurate within a few hours.
37-
</Notification>
38-
)}
3931
<svg width="100%" height="240"></svg>
4032
{metricsData && metricsData.buckets.length === 0 && (
4133
<div className="p-snap-list__metrics-empty-message">

static/js/publisher/hooks/__tests__/useActiveDeviceMetrics.test.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ describe("useActiveDeviceMetrics", () => {
5555
},
5656
],
5757
},
58-
days_without_data: [],
5958
latest_active_devices: 4,
6059
total_page_num: 1,
6160
}),
@@ -89,7 +88,6 @@ describe("useActiveDeviceMetrics", () => {
8988
],
9089
series: [{ name: "1.0", values: [5, 5, 0, 4, 4] }],
9190
},
92-
daysWithoutData: [],
9391
});
9492
(global.fetch as Mock).mockRestore();
9593
});
@@ -115,7 +113,6 @@ describe("useActiveDeviceMetrics", () => {
115113
},
116114
],
117115
},
118-
days_without_data: [],
119116
latest_active_devices: 4,
120117
total_page_num: 1,
121118
}),

static/js/publisher/hooks/useActiveDeviceMetrics.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ function useActiveDeviceMetrics({
7777
const buckets = [];
7878
const series = new Map();
7979

80-
const daysWithoutData = [];
81-
8280
let seriesThatAreAddedBefore = 0;
8381

8482
for (const result of results.reverse()) {
@@ -112,10 +110,6 @@ function useActiveDeviceMetrics({
112110
}
113111

114112
seriesThatAreAddedBefore += activeDeviceBuckets.length;
115-
116-
if (data.days_without_data) {
117-
daysWithoutData.push(...data.days_without_data);
118-
}
119113
}
120114

121115
const resultArray = Array.from(series.entries()).map(([key, value]) => ({
@@ -128,7 +122,6 @@ function useActiveDeviceMetrics({
128122
buckets,
129123
series: resultArray,
130124
},
131-
daysWithoutData,
132125
};
133126
};
134127

static/js/publisher/hooks/useFetchPublishedSnapMetrics.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ type Series = {
99
type SnapMetrics = {
1010
series: Array<Series>;
1111
buckets: Array<string>;
12-
daysWithoutData: Array<string>;
1312
};
1413

1514
function useFetchPublishedSnapMetrics(snaps: ISnap[]) {
@@ -41,7 +40,6 @@ function useFetchPublishedSnapMetrics(snaps: ISnap[]) {
4140
const metrics: SnapMetrics = {
4241
series: [],
4342
buckets: data.buckets,
44-
daysWithoutData: data.days_without_data,
4543
};
4644

4745
data.snaps.forEach((snap: { series: Array<Series>; name: string }) => {

static/js/publisher/pages/Metrics/ActiveDeviceMetrics.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { useParams, useSearchParams } from "react-router-dom";
2-
import {
3-
Row,
4-
Col,
5-
Spinner,
6-
CodeSnippet,
7-
Notification,
8-
} from "@canonical/react-components";
2+
import { Row, Col, Spinner, CodeSnippet } from "@canonical/react-components";
93

104
import { useEffect } from "react";
115
import { renderActiveDevicesMetrics } from "./metrics/metrics";
@@ -61,17 +55,10 @@ function ActiveDeviceMetrics({
6155
return searchParams;
6256
});
6357
};
64-
const daysWithoutDataExist = data && data.daysWithoutData.length > 0;
6558

6659
return (
6760
<section className={`p-strip is-shallow ${isEmpty ? "is-empty" : ""}`}>
6861
<Row>
69-
{daysWithoutDataExist && (
70-
<Notification severity="caution">
71-
Metrics for the most recent days may be incomplete or missing. They
72-
will be updated and accurate within a few hours.
73-
</Notification>
74-
)}
7562
<Col size={12} key="activeServices">
7663
<h4 className="u-float-left">Weekly active devices</h4>
7764
<div className="p-heading--4 u-float-right u-no-margin--top">

static/js/publisher/pages/Metrics/__tests__/ActiveDeviceMetrics.test.tsx

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ describe("ActiveDeviceMetrics", () => {
6262
}
6363
return {
6464
status: "success",
65-
data: {
66-
daysWithoutData: [],
67-
},
65+
data: {},
6866
};
6967
});
7068

@@ -75,11 +73,6 @@ describe("ActiveDeviceMetrics", () => {
7573
expect(screen.getByText("5")).toBeInTheDocument();
7674
expect(screen.getByText("Past 30 days")).toBeInTheDocument();
7775
expect(screen.getByText("By version")).toBeInTheDocument();
78-
expect(
79-
screen.queryByText(
80-
"Metrics for the most recent days may be incomplete or missing. They will be updated and accurate within a few hours.",
81-
),
82-
).toBeNull();
8376
});
8477
});
8578

@@ -104,16 +97,13 @@ describe("ActiveDeviceMetrics", () => {
10497
buckets: [],
10598
name: "annotations",
10699
series: [],
107-
daysWithoutData: [],
108100
},
109101
};
110102
}
111103
}
112104
return {
113105
status: "success",
114-
data: {
115-
daysWithoutData: [],
116-
},
106+
data: {},
117107
};
118108
});
119109

@@ -147,16 +137,13 @@ describe("ActiveDeviceMetrics", () => {
147137
buckets: [],
148138
name: "annotations",
149139
series: [],
150-
daysWithoutData: [],
151140
},
152141
};
153142
}
154143
}
155144
return {
156145
status: "success",
157-
data: {
158-
daysWithoutData: [],
159-
},
146+
data: {},
160147
};
161148
});
162149

@@ -204,51 +191,4 @@ describe("ActiveDeviceMetrics", () => {
204191
expect(screen.getByText("No data found.")).toBeInTheDocument();
205192
});
206193
});
207-
208-
test("renders the warning", async () => {
209-
// @ts-expect-error mocks
210-
useQuery.mockImplementation((params) => {
211-
if (params) {
212-
if (params.queryKey[0] === "activeDeviceMetrics") {
213-
const mock = {
214-
...mockActiveDeviceMetrics,
215-
daysWithoutData: ["2024-08-27"],
216-
};
217-
return {
218-
status: "success",
219-
data: mock,
220-
};
221-
} else if (params.queryKey[0] === "latestActiveDevicesMetric") {
222-
return {
223-
status: "success",
224-
data: 5,
225-
};
226-
} else {
227-
return {
228-
status: "success",
229-
data: {
230-
buckets: [],
231-
name: "annotations",
232-
series: [],
233-
daysWithoutData: [],
234-
},
235-
};
236-
}
237-
}
238-
return {
239-
status: "success",
240-
data: {},
241-
};
242-
});
243-
244-
renderComponent(false);
245-
246-
await waitFor(() => {
247-
expect(
248-
screen.getByText(
249-
"Metrics for the most recent days may be incomplete or missing. They will be updated and accurate within a few hours.",
250-
),
251-
).toBeInTheDocument();
252-
});
253-
});
254194
});

static/js/publisher/pages/Metrics/__tests__/Metrics.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ const handlers = [
6060
name: "weekly_installed_base_by_version",
6161
series: [],
6262
},
63-
days_without_data: [],
6463
latest_archive_devices: 0,
6564
total_page_num: 1,
6665
});

static/js/publisher/test-utils/mockActiveDeviceMetrics.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,5 @@ export const mockActiveDeviceMetrics = {
4444
},
4545
],
4646
},
47-
daysWithoutData: [],
4847
latest_active_devices: 5,
4948
};

tests/publisher/tests_account_snaps_metrics.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def test_metrics(self):
5858

5959
expected_response = {
6060
"buckets": ["2018-04-13", "2018-04-20"],
61-
"days_without_data": [],
6261
"snaps": [
6362
{
6463
"id": "1",
@@ -114,50 +113,3 @@ def test_metrics_bad_id_payload(self):
114113

115114
self.assertEqual(500, response.status_code)
116115
self.assertEqual(expected_response, response.json)
117-
118-
@responses.activate
119-
def test_metrics_with_empty_data(self):
120-
metrics_payload = {
121-
"metrics": [
122-
{
123-
"snap_id": "1",
124-
"status": "OK",
125-
"series": [
126-
{"values": [0, 3, None], "name": "new"},
127-
{"values": [2, 3, None], "name": "lost"},
128-
{"values": [9, 6, None], "name": "continued"},
129-
],
130-
"buckets": ["2018-04-13", "2018-04-20", "2018-04-21"],
131-
},
132-
]
133-
}
134-
135-
responses.add(
136-
responses.POST, self.api_url, json=metrics_payload, status=200
137-
)
138-
139-
payload = {"1": "test1"}
140-
headers = {"content-type": "application/json"}
141-
response = self.client.post(
142-
self.endpoint_url, data=json.dumps(payload), headers=headers
143-
)
144-
145-
expected_response = {
146-
"buckets": ["2018-04-13", "2018-04-20", "2018-04-21"],
147-
"days_without_data": ["2018-04-21"],
148-
"snaps": [
149-
{
150-
"id": "1",
151-
"name": None,
152-
"series": [
153-
{"name": "new", "values": [0, 3, None]},
154-
{"name": "lost", "values": [2, 3, None]},
155-
{"name": "continued", "values": [9, 6, None]},
156-
],
157-
}
158-
],
159-
}
160-
161-
self.assertEqual(200, response.status_code)
162-
self.assertEqual(expected_response, response.json)
163-
self.assertEqual(1, len(responses.calls))

0 commit comments

Comments
 (0)