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: added new fields to usage data #6911

Merged
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
64 changes: 32 additions & 32 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1077,37 +1077,37 @@ jobs:
environment:
TEST_SUITE: src/__tests__/plugin.test.ts
CLI_REGION: ap-northeast-1
migration-node-function-amplify_e2e_tests:
schema-iterative-update-locking-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_4
environment:
TEST_SUITE: src/__tests__/migration/node.function.test.ts
TEST_SUITE: src/__tests__/schema-iterative-update-locking.test.ts
CLI_REGION: ap-southeast-1
api_4-amplify_e2e_tests:
migration-node-function-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_4
environment:
TEST_SUITE: src/__tests__/api_4.test.ts
TEST_SUITE: src/__tests__/migration/node.function.test.ts
CLI_REGION: ap-southeast-2
schema-iterative-update-locking-amplify_e2e_tests:
function_5-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_4
environment:
TEST_SUITE: src/__tests__/schema-iterative-update-locking.test.ts
TEST_SUITE: src/__tests__/function_5.test.ts
CLI_REGION: us-east-2
function_5-amplify_e2e_tests:
api_4-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_4
environment:
TEST_SUITE: src/__tests__/function_5.test.ts
TEST_SUITE: src/__tests__/api_4.test.ts
CLI_REGION: us-west-2
schema-iterative-update-4-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
Expand Down Expand Up @@ -1719,44 +1719,44 @@ jobs:
TEST_SUITE: src/__tests__/plugin.test.ts
CLI_REGION: ap-northeast-1
steps: *ref_5
migration-node-function-amplify_e2e_tests_pkg_linux:
schema-iterative-update-locking-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
docker: *ref_1
resource_class: large
environment:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/migration/node.function.test.ts
TEST_SUITE: src/__tests__/schema-iterative-update-locking.test.ts
CLI_REGION: ap-southeast-1
steps: *ref_5
api_4-amplify_e2e_tests_pkg_linux:
migration-node-function-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
docker: *ref_1
resource_class: large
environment:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/api_4.test.ts
TEST_SUITE: src/__tests__/migration/node.function.test.ts
CLI_REGION: ap-southeast-2
steps: *ref_5
schema-iterative-update-locking-amplify_e2e_tests_pkg_linux:
function_5-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
docker: *ref_1
resource_class: large
environment:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/schema-iterative-update-locking.test.ts
TEST_SUITE: src/__tests__/function_5.test.ts
CLI_REGION: us-east-2
steps: *ref_5
function_5-amplify_e2e_tests_pkg_linux:
api_4-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
docker: *ref_1
resource_class: large
environment:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/function_5.test.ts
TEST_SUITE: src/__tests__/api_4.test.ts
CLI_REGION: us-west-2
steps: *ref_5
workflows:
Expand Down Expand Up @@ -1854,11 +1854,11 @@ workflows:
- hostingPROD-amplify_e2e_tests
- amplify-app-amplify_e2e_tests
- init-amplify_e2e_tests
- schema-iterative-update-locking-amplify_e2e_tests
- function_5-amplify_e2e_tests
- predictions-amplify_e2e_tests
- schema-predictions-amplify_e2e_tests
- amplify-configure-amplify_e2e_tests
- function_5-amplify_e2e_tests
- api_4-amplify_e2e_tests
- function_3-amplify_e2e_tests
- containers-api-amplify_e2e_tests
- interactions-amplify_e2e_tests
Expand All @@ -1874,22 +1874,22 @@ workflows:
- schema-key-amplify_e2e_tests
- analytics-amplify_e2e_tests
- notifications-amplify_e2e_tests
- migration-node-function-amplify_e2e_tests
- schema-iterative-update-locking-amplify_e2e_tests
- schema-auth-10-amplify_e2e_tests
- hosting-amplify_e2e_tests
- tags-amplify_e2e_tests
- api_4-amplify_e2e_tests
- migration-node-function-amplify_e2e_tests
- done_with_pkg_linux_e2e_tests:
context: amplify-cli-ecr
requires:
- hostingPROD-amplify_e2e_tests_pkg_linux
- amplify-app-amplify_e2e_tests_pkg_linux
- init-amplify_e2e_tests_pkg_linux
- schema-iterative-update-locking-amplify_e2e_tests_pkg_linux
- function_5-amplify_e2e_tests_pkg_linux
- predictions-amplify_e2e_tests_pkg_linux
- schema-predictions-amplify_e2e_tests_pkg_linux
- amplify-configure-amplify_e2e_tests_pkg_linux
- function_5-amplify_e2e_tests_pkg_linux
- api_4-amplify_e2e_tests_pkg_linux
- function_3-amplify_e2e_tests_pkg_linux
- containers-api-amplify_e2e_tests_pkg_linux
- interactions-amplify_e2e_tests_pkg_linux
Expand All @@ -1905,11 +1905,11 @@ workflows:
- schema-key-amplify_e2e_tests_pkg_linux
- analytics-amplify_e2e_tests_pkg_linux
- notifications-amplify_e2e_tests_pkg_linux
- migration-node-function-amplify_e2e_tests_pkg_linux
- schema-iterative-update-locking-amplify_e2e_tests_pkg_linux
- schema-auth-10-amplify_e2e_tests_pkg_linux
- hosting-amplify_e2e_tests_pkg_linux
- tags-amplify_e2e_tests_pkg_linux
- api_4-amplify_e2e_tests_pkg_linux
- migration-node-function-amplify_e2e_tests_pkg_linux
- amplify_migration_tests_latest:
context: amplify-cli-ecr
filters:
Expand Down Expand Up @@ -2059,7 +2059,7 @@ workflows:
filters: *ref_8
requires:
- schema-auth-7-amplify_e2e_tests
- schema-iterative-update-locking-amplify_e2e_tests:
- function_5-amplify_e2e_tests:
context: amplify-cli-ecr
post-steps: *ref_7
filters: *ref_8
Expand Down Expand Up @@ -2119,7 +2119,7 @@ workflows:
filters: *ref_8
requires:
- auth_4-amplify_e2e_tests
- function_5-amplify_e2e_tests:
- api_4-amplify_e2e_tests:
context: amplify-cli-ecr
post-steps: *ref_7
filters: *ref_8
Expand Down Expand Up @@ -2335,7 +2335,7 @@ workflows:
filters: *ref_8
requires:
- schema-searchable-amplify_e2e_tests
- migration-node-function-amplify_e2e_tests:
- schema-iterative-update-locking-amplify_e2e_tests:
context: amplify-cli-ecr
post-steps: *ref_7
filters: *ref_8
Expand Down Expand Up @@ -2389,7 +2389,7 @@ workflows:
filters: *ref_8
requires:
- schema-auth-8-amplify_e2e_tests
- api_4-amplify_e2e_tests:
- migration-node-function-amplify_e2e_tests:
context: amplify-cli-ecr
post-steps: *ref_7
filters: *ref_8
Expand Down Expand Up @@ -2457,7 +2457,7 @@ workflows:
filters: *ref_10
requires:
- schema-auth-7-amplify_e2e_tests_pkg_linux
- schema-iterative-update-locking-amplify_e2e_tests_pkg_linux:
- function_5-amplify_e2e_tests_pkg_linux:
context: amplify-cli-ecr
post-steps: *ref_9
filters: *ref_10
Expand Down Expand Up @@ -2521,7 +2521,7 @@ workflows:
filters: *ref_10
requires:
- auth_4-amplify_e2e_tests_pkg_linux
- function_5-amplify_e2e_tests_pkg_linux:
- api_4-amplify_e2e_tests_pkg_linux:
context: amplify-cli-ecr
post-steps: *ref_9
filters: *ref_10
Expand Down Expand Up @@ -2753,7 +2753,7 @@ workflows:
filters: *ref_10
requires:
- schema-searchable-amplify_e2e_tests_pkg_linux
- migration-node-function-amplify_e2e_tests_pkg_linux:
- schema-iterative-update-locking-amplify_e2e_tests_pkg_linux:
context: amplify-cli-ecr
post-steps: *ref_9
filters: *ref_10
Expand Down Expand Up @@ -2811,7 +2811,7 @@ workflows:
filters: *ref_10
requires:
- schema-auth-8-amplify_e2e_tests_pkg_linux
- api_4-amplify_e2e_tests_pkg_linux:
- migration-node-function-amplify_e2e_tests_pkg_linux:
context: amplify-cli-ecr
post-steps: *ref_9
filters: *ref_10
Expand Down
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ module.exports = {
'<rootDir>/packages/amplify-cli',
'<rootDir>/packages/amplify-cli-core',
'<rootDir>/packages/amplify-cli-logger',
'<rootDir>/packages/amplify-codegen',
'<rootDir>/packages/amplify-codegen-appsync-model-plugin',
'<rootDir>/packages/amplify-dynamodb-simulator',
'<rootDir>/packages/amplify-frontend-android',
Expand Down
1 change: 1 addition & 0 deletions packages/amplify-cli-core/src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export class AppNotFoundError extends Error {}
export class AppAlreadyDeployedError extends Error {}
export class SchemaDoesNotExistError extends Error {}
export class AngularConfigNotFoundError extends Error {}
export class AppIdMismatchError extends Error {}
34 changes: 25 additions & 9 deletions packages/amplify-cli/src/__tests__/context-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jest.mock('../app-config');

describe('test attachUsageData', () => {
const version = 'latestversion';
const mockContext: Context = jest.genMockFromModule('../domain/context');
const mockContext = jest.genMockFromModule<Context>('../domain/context');

mockContext.input = new Input([
'/Users/userName/.nvm/versions/node/v8.11.4/bin/node',
Expand All @@ -35,10 +35,14 @@ describe('test attachUsageData', () => {
mockContext.pluginPlatform = new PluginPlatform();
mockContext.pluginPlatform.plugins['core'] = [new PluginInfo('', version, '', new PluginManifest('', ''))];

beforeAll(() => {});
afterEach(() => {
beforeEach(() => {
jest.clearAllMocks();
const amplifyToolkit = jest.createMockFromModule<any>('../domain/amplify-toolkit').AmplifyToolkit;
amplifyToolkit['executeProviderUtils'] = jest.fn().mockReturnValue('accountId');
mockContext.amplify = amplifyToolkit;
jest.clearAllMocks();
});
afterEach(() => {});

it('constructContext', () => {
const context = constructContext(mockContext.pluginPlatform, mockContext.input);
Expand All @@ -48,7 +52,7 @@ describe('test attachUsageData', () => {
expect(context.input).toEqual(mockContext.input);
});

it('test with usage data enabled', () => {
it('test with usage data enabled', async () => {
const returnValue = {
usageDataConfig: {
installationUuid: 'uuid',
Expand All @@ -58,11 +62,17 @@ describe('test attachUsageData', () => {
};
const mockedInit = appConfig.init as jest.Mock;
mockedInit.mockReturnValue(returnValue);
attachUsageData(mockContext);
expect(UsageData.UsageData.Instance.init).toBeCalledWith(returnValue.usageDataConfig.installationUuid, version, mockContext.input);
await attachUsageData(mockContext);
expect(UsageData.UsageData.Instance.init).toBeCalledWith(
returnValue.usageDataConfig.installationUuid,
version,
mockContext.input,
'accountId',
{},
);
});

it('test with usage data enabled', () => {
it('test with usage data disabled', async () => {
const returnValue = {
usageDataConfig: {
installationUuid: 'uuid',
Expand All @@ -72,7 +82,13 @@ describe('test attachUsageData', () => {
};
const mockedInit = appConfig.init as jest.Mock;
mockedInit.mockReturnValue(returnValue);
attachUsageData(mockContext);
expect(UsageData.NoUsageData.Instance.init).toBeCalledWith(returnValue.usageDataConfig.installationUuid, version, mockContext.input);
await attachUsageData(mockContext);
expect(UsageData.NoUsageData.Instance.init).toBeCalledWith(
returnValue.usageDataConfig.installationUuid,
version,
mockContext.input,
'accountId',
{},
);
});
});
4 changes: 2 additions & 2 deletions packages/amplify-cli/src/__tests__/usage-data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ describe('test usageData', () => {
it('test instance', () => {
const a = UsageData.Instance;
const b = UsageData.Instance;
a.init(uuid.v4(), '', new Input([]));
b.init(uuid.v4(), '', new Input([]));
a.init(uuid.v4(), '', new Input([]), 'accountId', { editor: 'vscode', framework: 'react', frontend: 'javascript' });
b.init(uuid.v4(), '', new Input([]), 'accountId', { editor: 'vscode', framework: 'react', frontend: 'javascript' });
expect(a).toEqual(b);
});
});
Expand Down
12 changes: 11 additions & 1 deletion packages/amplify-cli/src/__tests__/version-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ describe('test version manager', () => {
});

it('payload version should be the latest', () => {
const payload = new UsageDataPayload('', '', '', new Input([]), new Error(''), '');
const payload = new UsageDataPayload(
'',
'',
'',
new Input([]),
new Error(''),
'',
'12311232',
{ frontend: 'javascript', editor: 'vscode', framework: 'react' },
{},
);
expect(payload.payloadVersion).toEqual(getLatestPayloadVersion());
});
});
2 changes: 1 addition & 1 deletion packages/amplify-cli/src/app-config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Config {
}

class UsageDataConfig {
installationUuid: String;
installationUuid: string;
isUsageTrackingEnabled: boolean;

constructor() {
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-cli/src/commands/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const run = async (context: Context) => {
await providerPlugin.adminLoginFlow(context, appId, envName);
} catch (e) {
context.print.error(`Failed to authenticate: ${e.message || 'Unknown error occurred.'}`);
context.usageData.emitError(e);
await context.usageData.emitError(e);
process.exit(1);
}
return;
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-cli/src/commands/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const run = async context => {
}
} catch (e) {
context.print.error(`An error occurred during the publish operation: ${e.message || 'Unknown error occurred.'}`);
context.usageData.emitError(new FrontendBuildError(e.message));
await context.usageData.emitError(new FrontendBuildError(e.message));
process.exit(1);
}
};
4 changes: 3 additions & 1 deletion packages/amplify-cli/src/commands/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { preDeployPullBackend } from '../pre-deployment-pull';
import { attachBackend } from '../attach-backend';
import { constructInputParams } from '../amplify-service-helper';
import { run as envCheckout } from './env/checkout';
import { $TSContext, stateManager } from 'amplify-cli-core';
import { $TSContext, stateManager, EnvironmentDoesNotExistError, AppIdMismatchError } from 'amplify-cli-core';
import _ from 'lodash';

export const run = async (context: $TSContext) => {
Expand Down Expand Up @@ -31,11 +31,13 @@ export const run = async (context: $TSContext) => {
if (inputAppId && appId && inputAppId !== appId) {
context.print.error('Amplify appId mismatch.');
context.print.info(`You are currently working in the amplify project with Id ${appId}`);
await context.usageData.emitError(new AppIdMismatchError());
process.exit(1);
} else if (!appId) {
context.print.error(`Environment '${envName}' not found.`);
context.print.info(`Try running "amplify env add" to add a new environment.`);
context.print.info(`If this backend already exists, try restoring its definition in your team-provider-info.json file.`);
await context.usageData.emitError(new EnvironmentDoesNotExistError());
process.exit(1);
}

Expand Down
Loading