` +
`
${commit_data}
` +
@@ -250,9 +251,9 @@ function useStatePerformanceTrend(password: string) {
// With ScanIndexForward being set to true, the trend data are being sorted descending based on the CommitDate.
// Therefore, the first data that has commit date is the latest commit.
const commit_date = performances.at(0)?.CommitDate.N || '';
- const hash_categories = Array.from(new Set(performances.map((p) => p.CommitHash.S.substring(0, 7)))).reverse();
- // Get all the information for the hash categories in order to get the commiter name, the commit message, and the releveant information
- const commits_information = await Promise.all(hash_categories.map((hash) => GetServiceCommitInformation(password, hash)));
+ const hash_categories = Array.from(new Set(performances.map((p: PerformanceTrendData) => p.CommitHash.S.substring(0, 7)))).reverse();
+ // Get all the information for the hash categories in order to get the commiter name, the commit message, and the relevant information
+ const commits_information: ServiceCommitInformation[] = await Promise.all(hash_categories.map((hash) => GetServiceCommitInformation(password, hash)));
/* Generate series of data that has the following format:
data_rate: transaction per minute
@@ -321,7 +322,7 @@ function useStatePerformanceTrend(password: string) {
trend_data: trend_data,
hash_categories: hash_categories,
commits_information: commits_information,
- last_update: moment.unix(Number(commit_date)).format('dddd, MMMM Do, YYYY h:mm:ss A'),
+ last_update: formatUnixTimestamp(commit_date ?? 0),
}));
})();
}, [password, setState]);
@@ -344,3 +345,33 @@ function useStateSelectedMetrics() {
return [state, setState] as const;
}
+
+interface CommitFormatOptions {
+ dateFormat?: boolean; // Whether to format the date
+ fallback?: string;
+ includePrefix?: boolean; // Whether to include "Committed by" prefix
+}
+
+export const formatCommitInfo = (selected_hash_information: ServiceCommitInformation | undefined, options: CommitFormatOptions = {}): string => {
+ const { dateFormat = false, fallback = 'No commit information available', includePrefix = true } = options;
+
+ try {
+ if (!selected_hash_information?.author?.login || !selected_hash_information?.commit?.author?.date) {
+ return fallback;
+ }
+
+ const { login } = selected_hash_information?.author;
+ let { date } = selected_hash_information?.commit?.author;
+
+ // Optional date formatting
+ if (dateFormat) {
+ date = new Date(date).toLocaleDateString();
+ }
+
+ const prefix = includePrefix ? 'Committed by ' : '';
+ return `${prefix}${login} on ${date}`;
+ } catch (error) {
+ console.error('Error formatting commit info:', error);
+ return fallback;
+ }
+};
diff --git a/src/containers/PerformanceTrend/service.ts b/src/containers/PerformanceTrend/service.ts
index aef23d7418..6c09d7a68e 100644
--- a/src/containers/PerformanceTrend/service.ts
+++ b/src/containers/PerformanceTrend/service.ts
@@ -47,21 +47,42 @@ async function GetPerformanceTrend(password: string, params: PerformanceTrendDat
});
}
-export async function GetServiceCommitInformation(password: string, commit_sha: string): Promise
{
- AxiosConfig.defaults.headers['x-api-key'] = password;
- return AxiosConfig.post('/', {
- Action: 'Github',
- URL: 'GET /repos/{owner}/{repo}/commits/{ref}',
- Params: {
- owner: OWNER_REPOSITORY,
- repo: process.env.REACT_APP_GITHUB_REPOSITORY,
- ref: commit_sha,
- },
- })
- .then(function (value: { data: any }) {
- return Promise.resolve(value?.data);
- })
- .catch(function (error: unknown) {
- return Promise.reject(error);
+export async function GetServiceCommitInformation(password: string, commitSha: string): Promise {
+ try {
+ AxiosConfig.defaults.headers['x-api-key'] = password;
+ const response = await AxiosConfig.post('/', {
+ Action: 'Github',
+ URL: 'GET /repos/{owner}/{repo}/commits/{ref}',
+ Params: {
+ owner: OWNER_REPOSITORY,
+ repo: process.env.REACT_APP_GITHUB_REPOSITORY,
+ ref: commitSha,
+ },
});
+
+ // Validate response
+ if (!response?.data?.data) {
+ return createDefaultServiceCommitInformation();
+ }
+
+ return response.data.data;
+ } catch (error) {
+ console.error('Failed to fetch commit information:', error);
+ throw error; // Re-throw the error for handling by the caller
+ }
+}
+
+function createDefaultServiceCommitInformation(): ServiceCommitInformation {
+ return {
+ author: {
+ login: 'default-user',
+ },
+ commit: {
+ message: 'No commit message available',
+ author: {
+ date: new Date().toISOString(),
+ },
+ },
+ sha: 'default-sha',
+ };
}
diff --git a/src/core/table.tsx b/src/core/table.tsx
index 0701207e0e..c3a26ad011 100644
--- a/src/core/table.tsx
+++ b/src/core/table.tsx
@@ -154,21 +154,35 @@ export function PerformanceTable(props: { use_cases: UseCaseData[]; data_rate: s
- {use_cases?.map((use_case) => (
-
- {use_case.name}
- {use_case.instance_type}
- {Number(use_case.data?.[data_rate]?.procstat_cpu_usage).toFixed(2)}
- {(Number(use_case.data?.[data_rate]?.procstat_memory_rss) / Number(use_case.data?.[data_rate]?.mem_total)).toFixed(2)}
- {(Number(use_case.data?.[data_rate]?.procstat_memory_swap) / Number(use_case.data?.[data_rate]?.mem_total)).toFixed(2)}
- {(Number(use_case.data?.[data_rate]?.procstat_memory_data) / Number(use_case.data?.[data_rate]?.mem_total)).toFixed(2)}
- {(Number(use_case.data?.[data_rate]?.procstat_memory_vms) / Number(use_case.data?.[data_rate]?.mem_total)).toFixed(2)}
- {Number(use_case.data?.[data_rate]?.procstat_write_bytes).toFixed(2)}
- {Number(use_case.data?.[data_rate]?.procstat_num_fds).toFixed(2)}
- {Number(use_case.data?.[data_rate]?.net_bytes_sent).toFixed(2)}
- {Number(use_case.data?.[data_rate]?.net_packets_sent).toFixed(2)}
-
- ))}
+ {use_cases
+ ?.filter((use_case) => use_case.data?.[data_rate])
+ .map((use_case: UseCaseData, index) => {
+ const metrics = use_case.data[data_rate];
+ const memTotal = Number(metrics?.mem_total);
+
+ const getFormattedValue = (value: number | undefined, divisor?: number) => {
+ if (!value) {
+ return '0.00';
+ }
+ return (divisor ? value / divisor : value).toFixed(2);
+ };
+
+ return (
+
+ {use_case.name}
+ {use_case.instance_type}
+ {getFormattedValue(Number(metrics?.procstat_cpu_usage))}
+ {getFormattedValue(Number(metrics?.procstat_memory_rss), memTotal)}
+ {getFormattedValue(Number(metrics?.procstat_memory_swap), memTotal)}
+ {getFormattedValue(Number(metrics?.procstat_memory_data), memTotal)}
+ {getFormattedValue(Number(metrics?.procstat_memory_vms), memTotal)}
+ {getFormattedValue(Number(metrics?.procstat_write_bytes))}
+ {getFormattedValue(Number(metrics?.procstat_num_fds))}
+ {getFormattedValue(Number(metrics?.net_bytes_sent))}
+ {getFormattedValue(Number(metrics?.net_packets_sent))}
+
+ );
+ })}