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

feat: Introduce debug info button #9895

Merged
merged 13 commits into from
Jul 3, 2024
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
4 changes: 4 additions & 0 deletions packages/cli/src/License.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ export class License {
);
}

getConsumerId() {
return this.manager?.getConsumerId() ?? 'unknown';
}

// Helper functions for computed data
getUsersLimit() {
return this.getFeatureValue(LICENSE_QUOTAS.USERS_LIMIT) ?? UNLIMITED_LICENSE_QUOTA;
Expand Down
34 changes: 34 additions & 0 deletions packages/cli/src/services/frontend.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'node:fs';
import { Container, Service } from 'typedi';
import uniq from 'lodash/uniq';
import { createWriteStream } from 'fs';
Expand Down Expand Up @@ -83,6 +84,8 @@ export class FrontendService {
}

this.settings = {
isDocker: this.isDocker(),
databaseType: config.getEnv('database.type'),
previewMode: process.env.N8N_PREVIEW_MODE === 'true',
endpointForm: config.getEnv('endpoints.form'),
endpointFormTest: config.getEnv('endpoints.formTest'),
Expand All @@ -92,14 +95,17 @@ export class FrontendService {
saveDataErrorExecution: config.getEnv('executions.saveDataOnError'),
saveDataSuccessExecution: config.getEnv('executions.saveDataOnSuccess'),
saveManualExecutions: config.getEnv('executions.saveDataManualExecutions'),
saveExecutionProgress: config.getEnv('executions.saveExecutionProgress'),
executionTimeout: config.getEnv('executions.timeout'),
maxExecutionTimeout: config.getEnv('executions.maxTimeout'),
workflowCallerPolicyDefaultOption: config.getEnv('workflows.callerPolicyDefaultOption'),
timezone: config.getEnv('generic.timezone'),
urlBaseWebhook: this.urlService.getWebhookBaseUrl(),
urlBaseEditor: instanceBaseUrl,
binaryDataMode: config.getEnv('binaryDataManager.mode'),
nodeJsVersion: process.version.replace(/^v/, ''),
versionCli: '',
concurrency: config.getEnv('executions.concurrency.productionLimit'),
authCookie: {
secure: config.getEnv('secure_cookie'),
},
Expand Down Expand Up @@ -196,6 +202,7 @@ export class FrontendService {
},
hideUsagePage: config.getEnv('hideUsagePage'),
license: {
consumerId: 'unknown',
environment: config.getEnv('license.tenantId') === 1 ? 'production' : 'staging',
},
variables: {
Expand All @@ -218,6 +225,14 @@ export class FrontendService {
pruneTime: -1,
licensePruneTime: -1,
},
pruning: {
isEnabled: config.getEnv('executions.pruneData'),
maxAge: config.getEnv('executions.pruneDataMaxAge'),
maxCount: config.getEnv('executions.pruneDataMaxCount'),
},
security: {
blockFileAccessToN8nFiles: config.getEnv('security.blockFileAccessToN8nFiles'),
},
};
}

Expand Down Expand Up @@ -269,6 +284,9 @@ export class FrontendService {
const isS3Available = config.getEnv('binaryDataManager.availableModes').includes('s3');
const isS3Licensed = this.license.isBinaryDataS3Licensed();

this.settings.license.planName = this.license.getPlanName();
this.settings.license.consumerId = this.license.getConsumerId();

// refresh enterprise status
Object.assign(this.settings.enterprise, {
sharing: this.license.isSharingEnabled(),
Expand Down Expand Up @@ -368,4 +386,20 @@ export class FrontendService {
}
}
}

/**
* Whether this instance is running inside a Docker container.
*
* Based on: https://github.com/sindresorhus/is-docker
*/
private isDocker() {
try {
return (
fs.existsSync('/.dockerenv') ||
fs.readFileSync('/proc/self/cgroup', 'utf8').includes('docker')
);
} catch {
return false;
}
}
}
7 changes: 4 additions & 3 deletions packages/editor-ui/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ export interface RootState {
urlBaseEditor: string;
instanceId: string;
isNpmAvailable: boolean;
binaryDataMode: string;
binaryDataMode: 'default' | 'filesystem' | 's3';
}

export interface NodeMetadataMap {
Expand Down Expand Up @@ -1380,9 +1380,10 @@ export interface ISettingsState {
enabled: boolean;
};
onboardingCallPromptEnabled: boolean;
saveDataErrorExecution: string;
saveDataSuccessExecution: string;
saveDataErrorExecution: WorkflowSettings.SaveDataExecution;
saveDataSuccessExecution: WorkflowSettings.SaveDataExecution;
saveManualExecutions: boolean;
saveDataProgressExecution: boolean;
}

export type NodeTypesByTypeNameAndVersion = {
Expand Down
15 changes: 14 additions & 1 deletion packages/editor-ui/src/__tests__/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import type { IN8nUISettings } from 'n8n-workflow';

export const defaultSettings: IN8nUISettings = {
databaseType: 'sqlite',
isDocker: false,
pruning: {
isEnabled: false,
maxAge: 0,
maxCount: 0,
},
allowedModules: {},
communityNodesEnabled: false,
defaultLocale: '',
Expand Down Expand Up @@ -40,7 +47,7 @@ export const defaultSettings: IN8nUISettings = {
hiringBannerEnabled: false,
instanceId: '',
isNpmAvailable: false,
license: { environment: 'development' },
license: { environment: 'development', consumerId: 'unknown' },
logLevel: 'info',
maxExecutionTimeout: 0,
oauthCallbackUrls: { oauth1: '', oauth2: '' },
Expand All @@ -60,6 +67,7 @@ export const defaultSettings: IN8nUISettings = {
saveDataErrorExecution: 'DEFAULT',
saveDataSuccessExecution: 'DEFAULT',
saveManualExecutions: false,
saveExecutionProgress: false,
sso: {
ldap: { loginEnabled: false, loginLabel: '' },
saml: { loginEnabled: false, loginLabel: '' },
Expand All @@ -81,6 +89,8 @@ export const defaultSettings: IN8nUISettings = {
quota: 10,
},
versionCli: '',
nodeJsVersion: '',
concurrency: -1,
versionNotifications: {
enabled: true,
endpoint: '',
Expand Down Expand Up @@ -113,4 +123,7 @@ export const defaultSettings: IN8nUISettings = {
pruneTime: 0,
licensePruneTime: 0,
},
security: {
blockFileAccessToN8nFiles: false,
},
};
1 change: 1 addition & 0 deletions packages/editor-ui/src/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const SETTINGS_STORE_DEFAULT_STATE: ISettingsState = {
onboardingCallPromptEnabled: false,
saveDataErrorExecution: 'all',
saveDataSuccessExecution: 'all',
saveDataProgressExecution: false,
saveManualExecutions: false,
};

Expand Down
22 changes: 22 additions & 0 deletions packages/editor-ui/src/components/AboutModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
<n8n-text>{{ rootStore.instanceId }}</n8n-text>
</el-col>
</el-row>
<el-row>
<el-col :span="8" class="info-name">
<n8n-text>{{ $locale.baseText('about.debug.title') }}</n8n-text>
</el-col>
<el-col :span="16">
<div :class="$style.debugInfo" @click="copyDebugInfoToClipboard">
<n8n-link>{{ $locale.baseText('about.debug.message') }}</n8n-link>
</div>
</el-col>
</el-row>
</div>
</template>

Expand All @@ -66,6 +76,9 @@ import Modal from './Modal.vue';
import { ABOUT_MODAL_KEY } from '../constants';
import { useSettingsStore } from '@/stores/settings.store';
import { useRootStore } from '@/stores/root.store';
import { useToast } from '@/composables/useToast';
import { useClipboard } from '@/composables/useClipboard';
import { useDebugInfo } from '@/composables/useDebugInfo';

export default defineComponent({
name: 'About',
Expand All @@ -85,6 +98,15 @@ export default defineComponent({
closeDialog() {
this.modalBus.emit('close');
},
async copyDebugInfoToClipboard() {
useToast().showToast({
title: this.$locale.baseText('about.debug.toast.title'),
message: this.$locale.baseText('about.debug.toast.message'),
type: 'info',
duration: 5000,
});
await useClipboard().copy(useDebugInfo().generateDebugInfo());
},
},
});
</script>
Expand Down
148 changes: 148 additions & 0 deletions packages/editor-ui/src/composables/useDebugInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { useSettingsStore } from '@/stores/settings.store';
import type { WorkflowSettings } from 'n8n-workflow';

type DebugInfo = {
core: {
n8nVersion: string;
platform: 'docker (cloud)' | 'docker (self-hosted)' | 'npm';
nodeJsVersion: string;
database: 'sqlite' | 'mysql' | 'mariadb' | 'postgres';
executionMode: 'regular' | 'scaling';
license: 'community' | 'enterprise (production)' | 'enterprise (sandbox)';
consumerId: string;
concurrency: number;
};
storage: {
success: WorkflowSettings.SaveDataExecution;
error: WorkflowSettings.SaveDataExecution;
progress: boolean;
manual: boolean;
binaryMode: 'memory' | 'filesystem' | 's3';
};
pruning:
| {
enabled: false;
}
| {
enabled: true;
maxAge: `${number} hours`;
maxCount: `${number} executions`;
};
/**
* Reported only if insecure settings are found.
*/
security?: {
secureCookie?: boolean;
blockFileAccessToN8nFiles?: boolean;
};
};

export function useDebugInfo() {
const store = useSettingsStore();

const coreInfo = () => {
return {
n8nVersion: store.versionCli,
platform:
store.isDocker && store.deploymentType === 'cloud'
? 'docker (cloud)'
: store.isDocker
? 'docker (self-hosted)'
: 'npm',
nodeJsVersion: store.nodeJsVersion,
database:
store.databaseType === 'postgresdb'
? 'postgres'
: store.databaseType === 'mysqldb'
? 'mysql'
: store.databaseType,
executionMode: store.isQueueModeEnabled ? 'scaling' : 'regular',
concurrency: store.settings.concurrency,
license:
store.planName === 'Community'
? (store.planName.toLowerCase() as 'community')
: store.settings.license.environment === 'production'
? 'enterprise (production)'
: 'enterprise (sandbox)',
consumerId: store.consumerId,
} as const;
};

const storageInfo = (): DebugInfo['storage'] => {
return {
success: store.saveDataSuccessExecution,
error: store.saveDataErrorExecution,
progress: store.saveDataProgressExecution,
manual: store.saveManualExecutions,
binaryMode: store.binaryDataMode === 'default' ? 'memory' : store.binaryDataMode,
};
};

const pruningInfo = () => {
if (!store.pruning.isEnabled) return { enabled: false } as const;

return {
enabled: true,
maxAge: `${store.pruning.maxAge} hours`,
maxCount: `${store.pruning.maxCount} executions`,
} as const;
};

const securityInfo = () => {
const info: DebugInfo['security'] = {};

if (!store.security.blockFileAccessToN8nFiles) info.blockFileAccessToN8nFiles = false;
if (!store.security.secureCookie) info.secureCookie = false;

if (Object.keys(info).length === 0) return;

return info;
};

const gatherDebugInfo = () => {
const debugInfo: DebugInfo = {
core: coreInfo(),
storage: storageInfo(),
pruning: pruningInfo(),
};

const security = securityInfo();

if (security) debugInfo.security = security;

return debugInfo;
};

const toMarkdown = (debugInfo: DebugInfo): string => {
let markdown = '# Debug info\n\n';

for (const sectionKey in debugInfo) {
markdown += `## ${sectionKey}\n\n`;

const section = debugInfo[sectionKey as keyof DebugInfo];

if (!section) continue;

for (const itemKey in section) {
const itemValue = section[itemKey as keyof typeof section];
markdown += `- ${itemKey}: ${itemValue}\n`;
}

markdown += '\n';
}

return markdown;
};

const appendTimestamp = (markdown: string) => {
return `${markdown}Generated at: ${new Date().toISOString()}`;
};

const generateDebugInfo = () => {
return appendTimestamp(toMarkdown(gatherDebugInfo()));
};

return {
generateDebugInfo,
};
}
4 changes: 4 additions & 0 deletions packages/editor-ui/src/plugins/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
"about.n8nVersion": "n8n Version",
"about.sourceCode": "Source Code",
"about.instanceID": "Instance ID",
"about.debug.title": "Debug",
"about.debug.message": "Copy debug information",
"about.debug.toast.title": "Debug info",
"about.debug.toast.message": "Copied debug info to clipboard",
"askAi.dialog.title": "'Ask AI' is almost ready",
"askAi.dialog.body": "We’re still applying the finishing touches. Soon, you will be able to <strong>automatically generate code from simple text prompts</strong>. Join the waitlist to get early access to this feature.",
"askAi.dialog.signup": "Join Waitlist",
Expand Down
Loading
Loading