Skip to content

Commit 55ee5f4

Browse files
authored
Modify graphs to ignore missing data and to retrieve commit data (#1453)
Co-authored-by: Travis Stark <[email protected]>
1 parent b267fe8 commit 55ee5f4

File tree

5 files changed

+52
-33
lines changed

5 files changed

+52
-33
lines changed

src/common/Constant.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
export const USE_CASE: string[] = ['statsd', 'logs', 'disk'];
55
export const REPORTED_METRICS: string[] = [
6+
'cpu_usage',
67
'procstat_cpu_usage',
78
'procstat_memory_rss',
89
'procstat_memory_swap',
@@ -17,7 +18,8 @@ export const TRANSACTION_PER_MINUTE: number[] = [100, 1000, 5000];
1718
export const OWNER_REPOSITORY: string = 'aws';
1819
export const SERVICE_NAME: string = 'AmazonCloudWatchAgent';
1920
export const CONVERT_REPORTED_METRICS_NAME: { [metric_name: string]: string } = {
20-
procstat_cpu_usage: 'CPU Usage',
21+
cpu_usage: 'CPU Usage',
22+
procstat_cpu_usage: 'Procstat CPU Usage',
2123
procstat_memory_rss: 'Memory Resource',
2224
procstat_memory_swap: 'Memory Swap',
2325
procstat_memory_vms: 'Virtual Memory',

src/containers/PerformanceReport/data.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface PerformanceMetricReport {
4747

4848
// PerformanceMetric shows all collected metrics when running performance metrics
4949
export interface PerformanceMetric {
50+
cpu_usage?: { M: PerformanceMetricStatistic };
5051
procstat_cpu_usage?: { M: PerformanceMetricStatistic };
5152
procstat_memory_rss?: { M: PerformanceMetricStatistic };
5253
procstat_memory_swap?: { M: PerformanceMetricStatistic };
@@ -86,6 +87,7 @@ export interface UseCaseData {
8687
instance_type?: string;
8788
data: {
8889
[data_rate: string]: {
90+
cpu_usage?: string;
8991
procstat_cpu_usage?: string;
9092
procstat_memory_rss?: string;
9193
procstat_memory_swap?: string;

src/containers/PerformanceReport/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ function useStatePerformanceReport(password: string) {
170170
(accu, tpm) => ({
171171
...accu,
172172
[tpm]: {
173+
cpu_usage: pReport?.Results.M[tpm]?.M?.cpu_usage?.M?.Average?.N,
173174
procstat_cpu_usage: pReport?.Results.M[tpm]?.M?.procstat_cpu_usage?.M?.Average?.N,
174175
procstat_memory_rss: pReport?.Results.M[tpm]?.M?.procstat_memory_rss?.M?.Average?.N,
175176
procstat_memory_swap: pReport?.Results.M[tpm]?.M?.procstat_memory_swap?.M?.Average?.N,

src/containers/PerformanceTrend/data.d.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export interface PerformanceTrendData {
3434
CommitHash: { S: string };
3535

3636
DataType: { S: string };
37+
Service: { S: string };
38+
UniqueID: { S: string };
3739

3840
InstanceAMI: { S: string };
3941
InstanceType: { S: string };
@@ -55,7 +57,10 @@ export interface TrendData {
5557
data_tpm: number;
5658
data_series: {
5759
name: string;
58-
data: number[];
60+
data: {
61+
y: number;
62+
x: string;
63+
}[];
5964
}[];
6065
}
6166

@@ -70,8 +75,11 @@ export interface PerformanceMetricStatistic {
7075

7176
export interface ServiceCommitInformation {
7277
// Release version for the service
73-
author: { login: string };
74-
commit: { message: string; committer: { date: string } };
78+
author: {
79+
login: string;
80+
date: string;
81+
};
82+
commit: { message: string };
7583
sha: string;
7684
}
7785

src/containers/PerformanceTrend/index.tsx

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import * as React from 'react';
99
import Chart from 'react-apexcharts';
1010
import { CONVERT_REPORTED_METRICS_NAME, REPORTED_METRICS, TRANSACTION_PER_MINUTE, USE_CASE } from '../../common/Constant';
1111
import { usePageEffect } from '../../core/page';
12-
import { CommitInformation, PerformanceTrendData, ServiceCommitInformation, TrendData } from './data';
13-
import { GetPerformanceTrendData } from './service';
12+
import { PerformanceTrendData, ServiceCommitInformation, TrendData } from './data';
13+
import { GetPerformanceTrendData, GetServiceCommitInformation } from './service';
1414
import { PasswordDialog } from '../../common/Dialog';
1515
import { BasedOptionChart } from './styles';
1616

@@ -188,10 +188,11 @@ export default function PerformanceTrend(props: { password: string; password_is_
188188
const use_case = ctx.opts.series.at(seriesIndex)?.name;
189189
const selected_data = series[seriesIndex][dataPointIndex];
190190
const selected_hash = w.globals.categoryLabels[dataPointIndex];
191-
const selected_hash_information = commits_information.filter((c: CommitInformation) => c.sha === selected_hash).at(0);
192-
193-
const commit_history = selected_hash_information?.commit_message.replace(/\n\r*\n*/g, '<br />');
194-
const commited_by = selected_hash_information?.commit_date + ' commited by @' + selected_hash_information?.commiter_name;
191+
const selected_hash_information: ServiceCommitInformation | undefined = commits_information
192+
.filter((c: ServiceCommitInformation) => c.sha === selected_hash)
193+
.at(0);
194+
const commit_history = selected_hash_information?.commit.message.replace(/\n\r*\n*/g, '<br />');
195+
const commited_by = `Committed by ${selected_hash_information?.author.login} on ${selected_hash_information?.author.date}`;
195196
const commit_data = `<b>${use_case}</b>: ${selected_data}`;
196197

197198
return (
@@ -231,7 +232,7 @@ function useStatePerformanceTrend(password: string) {
231232
last_update: undefined as string | undefined,
232233
hash_categories: [] as number[],
233234
trend_data: [] as TrendData[],
234-
commits_information: [] as CommitInformation[],
235+
commits_information: [] as ServiceCommitInformation[],
235236
});
236237

237238
React.useEffect(() => {
@@ -249,50 +250,55 @@ function useStatePerformanceTrend(password: string) {
249250
// With ScanIndexForward being set to true, the trend data are being sorted descending based on the CommitDate.
250251
// Therefore, the first data that has commit date is the latest commit.
251252
const commit_date = performances.at(0)?.CommitDate.N || '';
252-
const hash_categories = Array.from(new Set(performances.map((p) => p.CommitHash.S.substring(0, 6)))).reverse();
253+
const hash_categories = Array.from(new Set(performances.map((p) => p.CommitHash.S.substring(0, 7)))).reverse();
253254
// Get all the information for the hash categories in order to get the commiter name, the commit message, and the releveant information
254-
// const commits_information = await Promise.all(hash_categories.map((hash) => GetServiceCommitInformation(hash)));
255-
const commits_information: ServiceCommitInformation[] = hash_categories.map((hash) => {
256-
return {
257-
author: { login: 'Login' },
258-
commit: { message: 'Message', committer: { date: '1/1/99' } },
259-
sha: hash,
260-
};
261-
});
262-
const final_commits_information: CommitInformation[] = commits_information.map((c) => {
263-
return {
264-
commiter_name: c.author.login,
265-
commit_message: c.commit.message,
266-
commit_date: c.commit.committer.date,
267-
sha: c.sha.substring(0, 7),
268-
};
269-
});
255+
const commits_information = await Promise.all(hash_categories.map((hash) => GetServiceCommitInformation(password, hash)));
270256

271257
/* Generate series of data that has the following format:
272258
data_rate: transaction per minute
273259
data_series: [{…}]
274260
data_type: metrics or traces or logs
275261
name: metric_name
276262
*/
263+
277264
for (const metric of REPORTED_METRICS) {
278265
for (const tpm of TRANSACTION_PER_MINUTE) {
279266
for (const data_type of ['metrics', 'traces', 'logs']) {
280267
const typeGrouping = performances.filter((p) => p.DataType.S === data_type);
281268
if (typeGrouping.length === 0) {
282269
continue;
283270
}
284-
const data_series: { name: string; data: number[] }[] = [];
271+
const data_series: {
272+
name: string;
273+
data: {
274+
y: number;
275+
x: string;
276+
}[];
277+
}[] = [];
278+
285279
for (const use_case of USE_CASE) {
286-
const data = typeGrouping
280+
const rawData = typeGrouping
287281
.reverse()
288282
.filter((d) => d.UseCase.S === use_case)
289283
.map((p) => {
290284
try {
291-
return Number(Number(p.Results.M[tpm].M[metric].M.Average?.N).toFixed(2));
285+
return {
286+
y: Number(Number(p.Results.M[tpm].M[metric].M.Average?.N).toFixed(2)),
287+
x: p.CommitHash.S.substring(0, 7),
288+
};
292289
} catch (e) {
293-
return -1;
290+
return {
291+
y: -1,
292+
x: p.CommitHash.S.substring(0, 7),
293+
};
294294
}
295295
});
296+
297+
const data: {
298+
y: number;
299+
x: string;
300+
}[] = rawData.filter((a) => a?.y !== -1 && a?.y !== undefined);
301+
296302
if (data.length === 0) {
297303
continue;
298304
}
@@ -314,7 +320,7 @@ function useStatePerformanceTrend(password: string) {
314320
...prev,
315321
trend_data: trend_data,
316322
hash_categories: hash_categories,
317-
commits_information: final_commits_information,
323+
commits_information: commits_information,
318324
last_update: moment.unix(Number(commit_date)).format('dddd, MMMM Do, YYYY h:mm:ss A'),
319325
}));
320326
})();

0 commit comments

Comments
 (0)