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

[DDW-656] Log Daedalus state snapshot #1456

Merged
merged 33 commits into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
322af6c
[DDW-656] Log Daedalus state snapshot
DeeJayElly Jul 10, 2019
59b983c
[DDW-656] Log Daedalus state snapshot
DeeJayElly Jul 10, 2019
e0f8f41
Merge branch 'develop' into chore/ddw-656-log-daedalus-state-snapshot
nikolaglumac Jul 11, 2019
cff9d70
Merge branch 'develop' into chore/ddw-656-log-daedalus-state-snapshot
DeeJayElly Jul 11, 2019
d9648c1
Merge remote-tracking branch 'origin/chore/ddw-656-log-daedalus-state…
DeeJayElly Jul 11, 2019
55d2407
Merge branch 'develop' into chore/ddw-656-log-daedalus-state-snapshot
DeeJayElly Jul 11, 2019
a47349a
[DDW-656] Log Daedalus state snapshot
DeeJayElly Jul 11, 2019
470303a
[DDW-656] Log Daedalus state snapshot
DeeJayElly Jul 11, 2019
4f10301
[DDW-656] Log Daedalus state snapshot
DeeJayElly Jul 11, 2019
565a4de
[DDW-656] Log Daedalus state snapshot
DeeJayElly Jul 12, 2019
2506429
[DDW-656] Log Daedalus state snapshot
DeeJayElly Jul 12, 2019
1dc7741
[DDW-656] Log Daedalus state snapshot
DeeJayElly Jul 12, 2019
3b9826b
[DDW-656] Log Daedalus state snapshot
DeeJayElly Jul 12, 2019
b12524a
Merge branch 'develop' into chore/ddw-656-log-daedalus-state-snapshot
DeeJayElly Jul 12, 2019
6d96fd9
[DDW-656] Log Daedalus state snapshot
DeeJayElly Jul 12, 2019
7eaf46c
[DDW-656] Log Daedalus state snapshot - fixes
DeeJayElly Jul 13, 2019
b9e114a
[DDW-656] Log Daedalus state snapshot - fixes
DeeJayElly Jul 13, 2019
99eaa57
[DDW-656] Log Daedalus state snapshot - fixes
DeeJayElly Jul 13, 2019
d0bf01a
Merge branch 'develop' into chore/ddw-656-log-daedalus-state-snapshot
DeeJayElly Jul 15, 2019
884387b
[DDW-656] Log Daedalus state snapshot - fixes
DeeJayElly Jul 15, 2019
41038c6
[DDW-656] Log Daedalus state snapshot - fixes
DeeJayElly Jul 15, 2019
dfabebf
[DDW-656] Log Daedalus state snapshot - fixes
DeeJayElly Jul 15, 2019
5f2e7a6
[DDW-656] Log Daedalus state snapshot - fixes
DeeJayElly Jul 15, 2019
82fd26f
[DDW-656] Log Daedalus state snapshot - fixes
DeeJayElly Jul 15, 2019
02ee6ca
Merge branch 'develop' into chore/ddw-656-log-daedalus-state-snapshot
DeeJayElly Jul 15, 2019
f5bcd68
[DDW-656] Log Daedalus state snapshot - fixes
DeeJayElly Jul 15, 2019
339a141
[DDW-656] Log Daedalus state snapshot - fixes
DeeJayElly Jul 15, 2019
dd391e2
[DDW-656] Fix logging info
nikolaglumac Jul 16, 2019
fc631b1
[DDW-656] Merge latest develop and fix conflicts
nikolaglumac Jul 16, 2019
eb1bcb6
[DDW-656] Make sure to set the state snapshot log before packing action
nikolaglumac Jul 16, 2019
1794a68
Merge branch 'develop' into chore/ddw-656-log-daedalus-state-snapshot
nikolaglumac Jul 16, 2019
afc30c3
Merge branch 'develop' into chore/ddw-656-log-daedalus-state-snapshot
DeeJayElly Jul 16, 2019
0f7aa27
Merge remote-tracking branch 'origin/chore/ddw-656-log-daedalus-state…
DeeJayElly Jul 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog

### Features

- Added Daedalus state snapshot log file "State-snapshot.json" on Download logs action ([PR 1456](https://github.com/input-output-hk/daedalus/pull/1456))
- Implemented no-wallets case on the Delegation Center screen ([PR 1463](https://github.com/input-output-hk/daedalus/pull/1463))
- Implemented the animated Daedalus logo on the "Loading" screens ([PR 1457](https://github.com/input-output-hk/daedalus/pull/1457))
- Implemented "Delegation Setup wizard" steps 3 & 4 UI ([PR 1439](https://github.com/input-output-hk/daedalus/pull/1439))
Expand Down
8 changes: 8 additions & 0 deletions source/common/ipc/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type { RedemptionTypeChoices } from '../../renderer/app/types/redemptionT
import type { CheckDiskSpaceResponse } from '../types/no-disk-space.types';
import type { LogFiles } from '../../renderer/app/types/LogTypes';
import type { GpuStatus } from '../../renderer/app/types/gpuStatus';
import type { LogStateSnapshotParams } from '../types/logging.types';

/**
* ======================= IPC CHANNELS API =========================
Expand Down Expand Up @@ -77,6 +78,13 @@ export const GET_STATE_DIRECTORY_PATH_CHANNEL = 'GetStateDirectoryPathChannel';
export type GetStateDirectoryPathRendererRequest = string | any;
export type GetStateDirectoryPathMainResponse = any;

/**
* Channel for setting log state snapshot
*/
export const SET_LOG_STATE_SNAPSHOT_CHANNEL = 'SetLogStateSnapshotChannel';
export type SetLogStateSnapshotRendererRequest = LogStateSnapshotParams | any;
export type SetLogStateSnapshotMainResponse = LogStateSnapshotParams | any;

/**
* Channel for loading a base64 encoded asset from within the `source/renderer` folder
*/
Expand Down
4 changes: 4 additions & 0 deletions source/common/ipc/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ export const ERRORS = {
export const NOTIFICATIONS = {
DOWNLOAD_LOGS: 'DOWNLOAD_LOGS_NOTIFICATION',
};

export const STATE_SNAPSHOT = {
LOG: 'LOG',
};
43 changes: 43 additions & 0 deletions source/common/types/logging.types.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// @flow
import type { CardanoNodeState } from './cardano-node.types';

export type FormatMessageContextParams = {
appName: string,
electronProcess: string,
Expand Down Expand Up @@ -48,3 +50,44 @@ export type LogSystemInfoParams = {
ram: string,
startTime: string,
};

export type LogStateSnapshotParams = {
nikolaglumac marked this conversation as resolved.
Show resolved Hide resolved
availableDiskSpace: string,
cardanoAPIPort: number,
cardanoNetwork: string,
cardanoNodeState: CardanoNodeState | any,
cardanoProcessID: number,
cardanoVersion: string,
cpu: string,
current: string,
currentLocale: string,
daedalusVersion: string,
daedalusMainProcessID: string,
daedalusProcessID: string,
daedalusStateDirectoryPath: string,
isConnected: boolean,
isDev: boolean,
isForceCheckingNodeTime: boolean,
isInSafeMode: boolean,
isMainnet: boolean,
isNodeInSync: boolean,
isNodeResponding: boolean,
isNodeSubscribed: boolean,
isNodeSyncing: boolean,
isNodeTimeCorrect: boolean,
isStaging: boolean,
isSynced: boolean,
isSystemTimeCorrect: boolean,
isSystemTimeIgnored: boolean,
isTestnet: boolean,
latestLocalBlockTimestamp: number,
latestNetworkBlockTimestamp: number,
localBlockHeight: number,
localTimeDifference: ?number,
networkBlockHeight: number,
platform: string,
platformVersion: string,
ram: string,
startTime: string,
syncPercentage: number,
};
1 change: 1 addition & 0 deletions source/main/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const ALLOWED_LOGS = [
'Daedalus.json',
'System-info.json',
'Daedalus-versions.json',
'State-snapshot.json',
];
export const ALLOWED_NODE_LOGS = new RegExp(/(node.json-)(\d{14}$)/);
export const ALLOWED_LAUNCHER_LOGS = new RegExp(/(launcher-)(\d{14}$)/);
Expand Down
11 changes: 10 additions & 1 deletion source/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import path from 'path';
import { app, BrowserWindow, shell } from 'electron';
import { client } from 'electron-connect';
import { Logger } from './utils/logging';
import { setupLogging, logSystemInfo } from './utils/setupLogging';
import {
setupLogging,
logSystemInfo,
logStateSnapshot,
} from './utils/setupLogging';
import { getNumberOfEpochsConsolidated } from './utils/getNumberOfEpochsConsolidated';
import { handleDiskSpace } from './utils/handleDiskSpace';
import { createMainWindow } from './windows/main';
Expand All @@ -31,6 +35,7 @@ import { getStateDirectoryPathChannel } from './ipc/getStateDirectoryPathChannel
import { CardanoNodeStates } from '../common/types/cardano-node.types';
import type { CheckDiskSpaceResponse } from '../common/types/no-disk-space.types';
import { logUsedVersion } from './utils/logUsedVersion';
import { setLogStateSnapshotChannel } from './ipc/set-log-state-snapshot';

/* eslint-disable consistent-return */

Expand Down Expand Up @@ -156,6 +161,10 @@ const onAppReady = async () => {

getNumberOfEpochsConsolidated();

setLogStateSnapshotChannel.onReceive(data => {
return Promise.resolve(logStateSnapshot(data));
});

getStateDirectoryPathChannel.onRequest(() =>
Promise.resolve(stateDirectoryPath)
);
Expand Down
14 changes: 14 additions & 0 deletions source/main/ipc/set-log-state-snapshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @flow
import { MainIpcChannel } from './lib/MainIpcChannel';
import { SET_LOG_STATE_SNAPSHOT_CHANNEL } from '../../common/ipc/api';
import type {
SetLogStateSnapshotRendererRequest,
SetLogStateSnapshotMainResponse,
} from '../../common/ipc/api';

// IpcChannel<Incoming, Outgoing>

export const setLogStateSnapshotChannel: MainIpcChannel<
SetLogStateSnapshotMainResponse,
SetLogStateSnapshotRendererRequest
> = new MainIpcChannel(SET_LOG_STATE_SNAPSHOT_CHANNEL);
4 changes: 3 additions & 1 deletion source/main/menus/osx.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import type { MenuActions } from './MenuActions.types';
import { getTranslation } from '../utils/getTranslation';
import { environment } from '../environment';
import { showUiPartChannel } from '../ipc/control-ui-parts';
import { NOTIFICATIONS } from '../../common/ipc/constants';
import { NOTIFICATIONS, STATE_SNAPSHOT } from '../../common/ipc/constants';
import { setLogStateSnapshotChannel } from '../ipc/set-log-state-snapshot';
import type { SupportRequests } from '../../common/types/support-requests.types';

const id = 'menu';
Expand Down Expand Up @@ -180,6 +181,7 @@ export const osxMenu = (
{
label: translation('helpSupport.downloadLogs'),
click() {
setLogStateSnapshotChannel.send(STATE_SNAPSHOT.LOG, window);
showUiPartChannel.send(NOTIFICATIONS.DOWNLOAD_LOGS, window);
},
},
Expand Down
4 changes: 3 additions & 1 deletion source/main/menus/win-linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import type { App, BrowserWindow } from 'electron';
import type { MenuActions } from './MenuActions.types';
import { getTranslation } from '../utils/getTranslation';
import { environment } from '../environment';
import { NOTIFICATIONS } from '../../common/ipc/constants';
import { NOTIFICATIONS, STATE_SNAPSHOT } from '../../common/ipc/constants';
import { showUiPartChannel } from '../ipc/control-ui-parts';
import { setLogStateSnapshotChannel } from '../ipc/set-log-state-snapshot';
import type { SupportRequests } from '../../common/types/support-requests.types';

const id = 'menu';
Expand Down Expand Up @@ -187,6 +188,7 @@ export const winLinuxMenu = (
{
label: translation('helpSupport.downloadLogs'),
click() {
setLogStateSnapshotChannel.send(STATE_SNAPSHOT.LOG, window);
showUiPartChannel.send(NOTIFICATIONS.DOWNLOAD_LOGS, window);
},
},
Expand Down
32 changes: 32 additions & 0 deletions source/main/utils/setupLogging.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
ConstructMessageBodyParams,
MessageBody,
LogSystemInfoParams,
LogStateSnapshotParams,
} from '../../common/types/logging.types';

const isTest = process.env.NODE_ENV === 'test';
Expand Down Expand Up @@ -94,3 +95,34 @@ export const logSystemInfo = (props: LogSystemInfoParams): MessageBody => {
fs.writeFileSync(systemInfoFilePath, JSON.stringify(messageBody));
return messageBody;
};

export const logStateSnapshot = (
props: LogStateSnapshotParams
): MessageBody => {
const { current, ...data } = props;
const {
daedalusVersion,
cardanoVersion,
cardanoNetwork,
platform,
startTime: at,
} = data;
const env = `${cardanoNetwork}:${platform}:${cardanoVersion}:${daedalusVersion}`;
const messageBodyParams: ConstructMessageBodyParams = {
at,
env,
ns: ['daedalus', `v${daedalusVersion}`, `*${current}*`],
data,
msg: 'Updating State-snapshot.json file',
pid: '',
sev: 'info',
thread: '',
};
const messageBody: MessageBody = constructMessageBody(messageBodyParams);
const stateSnapshotFilePath = path.join(
pubLogsFolderPath,
'State-snapshot.json'
);
fs.writeFileSync(stateSnapshotFilePath, JSON.stringify(messageBody));
return messageBody;
};
1 change: 1 addition & 0 deletions source/renderer/app/actions/network-status-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export default class NetworkStatusActions {
isSyncedAndReady: Action<any> = new Action();
tlsConfigIsReady: Action<any> = new Action();
restartNode: Action<any> = new Action();
logStateSnapshot: Action<any> = new Action();
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export default class LoadingSyncingConnectingPage extends Component<Props> {
};

handleDownloadLogs = () => {
const { app } = this.props.actions;
const { app, networkStatus } = this.props.actions;
networkStatus.logStateSnapshot.trigger();
app.downloadLogs.trigger();
app.setNotificationVisibility.trigger(true);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export default class SupportSettingsPage extends Component<InjectedProps> {
};

handleDownloadLogs = () => {
const { app } = this.props.actions;
const { app, networkStatus } = this.props.actions;
networkStatus.logStateSnapshot.trigger();
nikolaglumac marked this conversation as resolved.
Show resolved Hide resolved
app.downloadLogs.trigger();
app.setNotificationVisibility.trigger(true);
};
Expand Down
13 changes: 13 additions & 0 deletions source/renderer/app/ipc/setLogStateSnapshotChannel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @flow
import { RendererIpcChannel } from './lib/RendererIpcChannel';
import { SET_LOG_STATE_SNAPSHOT_CHANNEL } from '../../../common/ipc/api';
import type {
SetLogStateSnapshotRendererRequest,
SetLogStateSnapshotMainResponse,
} from '../../../common/ipc/api';

export const setLogStateSnapshotChannel: // IpcChannel<Incoming, Outgoing>
RendererIpcChannel<
SetLogStateSnapshotMainResponse,
SetLogStateSnapshotRendererRequest
> = new RendererIpcChannel(SET_LOG_STATE_SNAPSHOT_CHANNEL);
82 changes: 82 additions & 0 deletions source/renderer/app/stores/NetworkStatusStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import { CardanoNodeStates } from '../../../common/types/cardano-node.types';
import { getDiskSpaceStatusChannel } from '../ipc/getDiskSpaceChannel.js';
import { getStateDirectoryPathChannel } from '../ipc/getStateDirectoryPathChannel';
import { setLogStateSnapshotChannel } from '../ipc/setLogStateSnapshotChannel';
import type { GetNetworkStatusResponse } from '../api/nodes/types';
import type {
CardanoNodeState,
Expand All @@ -31,6 +32,7 @@ import type {
} from '../../../common/types/cardano-node.types';
import type { NodeInfoQueryParams } from '../api/nodes/requests/getNodeInfo';
import type { CheckDiskSpaceResponse } from '../../../common/types/no-disk-space.types';
import type { LogStateSnapshotParams } from '../../../common/types/logging.types';
import { TlsCertificateNotValidError } from '../api/nodes/errors';
import { openLocalDirectoryChannel } from '../ipc/open-local-directory';
import { rebuildApplicationMenu } from '../ipc/rebuild-application-menu';
Expand Down Expand Up @@ -122,6 +124,8 @@ export default class NetworkStatusStore extends Store {
// Passively receive state changes of the cardano-node
cardanoStateChangeChannel.onReceive(this._handleCardanoNodeStateChange);

setLogStateSnapshotChannel.onReceive(this._handleLogStateSnapshot);
nikolaglumac marked this conversation as resolved.
Show resolved Hide resolved

// ========== MOBX REACTIONS =========== //

this.registerReactions([
Expand All @@ -145,6 +149,8 @@ export default class NetworkStatusStore extends Store {
this._checkDiskSpace();

this._getStateDirectoryPath();

this.actions.networkStatus.logStateSnapshot.listen(this._logStateSnapshot);
nikolaglumac marked this conversation as resolved.
Show resolved Hide resolved
}

// Setup network status polling interval
Expand Down Expand Up @@ -304,6 +310,11 @@ export default class NetworkStatusStore extends Store {
return Promise.resolve();
};

_handleLogStateSnapshot = (): Promise<void> => {
nikolaglumac marked this conversation as resolved.
Show resolved Hide resolved
this._logStateSnapshot();
return Promise.resolve();
};

_extractNodeStatus = (from: Object & CardanoStatus): CardanoStatus => {
const {
isNodeResponding,
Expand Down Expand Up @@ -583,6 +594,17 @@ export default class NetworkStatusStore extends Store {
openLocalDirectoryChannel.send(path);
}

convertBytesToSize = (bytes: number): string => {
nikolaglumac marked this conversation as resolved.
Show resolved Hide resolved
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes === 0) return 'n/a';
const i = parseInt(
Math.floor(Math.log(Math.abs(bytes)) / Math.log(1024)),
10
);
if (i === 0) return `${bytes} ${sizes[i]})`;
return `${(bytes / 1024 ** i).toFixed(1)} ${sizes[i]}`;
};

@action _onCheckDiskSpace = ({
isNotEnoughDiskSpace,
diskSpaceRequired,
Expand Down Expand Up @@ -612,6 +634,66 @@ export default class NetworkStatusStore extends Store {
this.stateDirectoryPath = stateDirectoryPath;
};

@action _logStateSnapshot = () => {
nikolaglumac marked this conversation as resolved.
Show resolved Hide resolved
const {
network,
buildNumber,
cpu,
current,
version,
mainProcessID,
rendererProcessID,
isInSafeMode,
isMainnet,
isStaging,
isTestnet,
os,
platformVersion,
} = this.environment;

const stateSnapshotData: LogStateSnapshotParams = {
availableDiskSpace: this.diskSpaceAvailable,
cardanoAPIPort: this.tlsConfig ? this.tlsConfig.port : 0,
cardanoNetwork: network,
cardanoNodeState: this.cardanoNodeState,
cardanoProcessID: this.cardanoNodeID,
cardanoVersion: buildNumber,
cpu: Array.isArray(cpu) ? cpu[0].model : '',
current,
currentLocale: this.stores.profile.currentLocale,
daedalusVersion: version,
daedalusMainProcessID: mainProcessID,
daedalusProcessID: rendererProcessID,
daedalusStateDirectoryPath: this.stateDirectoryPath,
isConnected: this.isConnected,
isDev: this.isConnected,
isForceCheckingNodeTime: this.forceCheckTimeDifferenceRequest.isExecuting,
isInSafeMode,
isMainnet,
isNodeInSync: this.isNodeInSync,
isNodeResponding: this.isNodeResponding,
isNodeSubscribed: this.isNodeSubscribed,
isNodeSyncing: this.isNodeSyncing,
isNodeTimeCorrect: this.isNodeTimeCorrect,
isStaging,
isSynced: this.isSynced,
isSystemTimeCorrect: this.isSystemTimeCorrect,
isSystemTimeIgnored: this.isSystemTimeIgnored,
isTestnet,
latestLocalBlockTimestamp: this.latestLocalBlockTimestamp,
latestNetworkBlockTimestamp: this.latestNetworkBlockTimestamp,
localBlockHeight: this.localBlockHeight,
localTimeDifference: this.localTimeDifference,
networkBlockHeight: this.networkBlockHeight,
platform: os,
platformVersion,
ram: this.convertBytesToSize(this.environment.ram),
startTime: new Date().toISOString(),
syncPercentage: this.syncPercentage,
};
setLogStateSnapshotChannel.send(stateSnapshotData);
};

// DEFINE COMPUTED VALUES

@computed get isConnected(): boolean {
Expand Down