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: webclient version and installation method #321

Merged
Merged
Show file tree
Hide file tree
Changes from 7 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
20 changes: 19 additions & 1 deletion .github/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,22 @@ then
aws s3api put-object --bucket $bucket --key "content/$patchUpdate/cwr.js.map" --body build/assets/cwr.js.map --cache-control max-age=7200
aws s3api put-object --bucket $bucket --key "content/$patchUpdate/LICENSE-THIRD-PARTY" --body LICENSE-THIRD-PARTY --cache-control max-age=7200
aws s3api put-object --bucket $bucket --key "content/$patchUpdate/LICENSE" --body LICENSE --cache-control max-age=7200
fi

# update versions.csv file
fileName="versions.csv"

# if file not found, returns NoSuchKey error
aws s3api get-object --bucket $bucket --key "content/$fileName" $fileName

versionsFileDir="./$fileName";
scriptVersion="arw-script,$version"
moduleVersion="arw-module,$version"

echo $scriptVersion >> $versionsFileDir
echo $moduleVersion >> $versionsFileDir

updatedVersions=$(<$versionsFileDir)
echo "$updatedVersions" | aws s3 cp - s3://$bucket/content/versions.csv

rm -f $versionsFileDir
fi
50 changes: 50 additions & 0 deletions .github/scripts/validate_versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
bucket=$1

# exit when any command fails
set -e

delete_local_file() {
rm -f $versionsFileDir
}

fileName="versions.csv"

# if file not found, throws NoSuchKey error
aws s3api get-object --bucket $bucket --key "content/versions.csv" $fileName

versionsFileDir="./$fileName";
versions=$(<$versionsFileDir)

allPairsArr=(${versions});

# verify current versions in versions.csv file contain valid client,version pairs
scriptString="arw-script"
moduleString="arw-module"

for singlePair in "${allPairsArr[@]}";
do
IFS=',' read -ra singlePairArr <<< "$singlePair"

if [ ${singlePairArr[0]} != $scriptString ] && [ ${singlePairArr[0]} != $moduleString ]
then
delete_local_file

echo ERROR: INVALID CLIENT
echo ${singlePairArr[0]}
exit 1
fi

if ! [[ ${singlePairArr[1]} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]
then
delete_local_file


echo ERROR: INVALID VERSION
echo ${singlePairArr[1]}
exit 1
fi

done

delete_local_file
5 changes: 5 additions & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ jobs:
chmod u+x .github/scripts/deploy.sh
.github/scripts/deploy.sh ${{ secrets.BUCKET }}

- name: Validate versions.csv file
run: |
chmod u+x .github/scripts/validate_versions.sh
.github/scripts/validate_versions.sh ${{ secrets.BUCKET }}

- name: Fetch AWS Credentials for Smoke Test
run: |
export AWS_ROLE_ARN=${{ secrets.SMOKE_TEST_ROLE }}
Expand Down
7 changes: 6 additions & 1 deletion .testcaferc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@
{
"name": "spec"
}
]
],
"compilerOptions": {
"typescript": {
"configPath": "./tsconfig.testcafe.json"
}
}
}
17 changes: 15 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"build:dist:es": "tsc --project ./tsconfig.es.json",
"build:dist:cjs": "tsc --project ./tsconfig.cjs.json",
"build:assets": "npm-run-all -p build:dist:* build:webpack:prod",
"build": "npm-run-all -s build:schemas build:assets",
"build": "npm-run-all -s build:schemas update:version build:assets",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: If we run any of the targets independently, like npm run build:dist:es, then the correct version may not be used.

This is fine for the deployment script in this repository, because it runs build, but there is are scenarios where this step could be missed. For example, a third party runs their own web client build, but runs only the subset they need: build:schemas && build:dist:es.

One way to help mitigate this would be to omit version.json from version control (by adding it to .gitignore). This way, like the schemas, build:version would need to run before the other build steps, helping ensure the file is up to date.

Copy link
Contributor Author

@limhjgrace limhjgrace Jan 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to .gitignore and removed files from changes

"build:dev": "npm-run-all -s build build:webpack:dev",
"release": "npm run build",
"version": "standard-version",
Expand Down Expand Up @@ -57,7 +57,8 @@
"smoke:local": "cross-env URL=$URL MONITOR_ID=$MONITOR ENDPOINT=$ENDPOINT NAME=$NAME VERSION=$npm_package_version npx playwright test --config=playwright.local.config.ts --headed",
"smoke": "cross-env URL=$URL MONITOR_ID=$MONITOR ENDPOINT=$ENDPOINT NAME=$NAME VERSION=$npm_package_version npx playwright test --config=playwright.config.ts --headed",
"smoke:headless": "cross-env URL=$URL MONITOR_ID=$MONITOR ENDPOINT=$ENDPOINT NAME=$NAME VERSION=$npm_package_version npx playwright test --config=playwright.config.ts",
"prepare": "husky install"
"prepare": "husky install",
"update:version": "bash update-version.sh"
limhjgrace marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@aws-sdk/client-rum": "^3.76.0",
Expand All @@ -83,6 +84,7 @@
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-react": "^7.31.8",
"http-server": "^14.1.1",
"generate-json-webpack-plugin": "^2.0.0",
"husky": "^8.0.1",
"jest": "^29.3.1",
"jest-date-mock": "^1.0.8",
Expand Down
7 changes: 7 additions & 0 deletions src/CommandQueue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CredentialProvider, Credentials } from '@aws-sdk/types';
import { Plugin } from 'plugins/Plugin';
import { INSTALL_SCRIPT } from './utils/constants';
import { PartialConfig, Orchestration } from './orchestration/Orchestration';
import { getRemoteConfig } from './remote-config/remote-config';

Expand Down Expand Up @@ -134,6 +135,12 @@ export class CommandQueue {
}

private initCwr(awsRum: AwsRumClientInit) {
if (awsRum.c) {
awsRum.c.client = INSTALL_SCRIPT;
} else {
awsRum.c = { client: INSTALL_SCRIPT };
}

this.orchestration = new Orchestration(
awsRum.i,
awsRum.v,
Expand Down
17 changes: 16 additions & 1 deletion src/__tests__/CommandQueue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '../test-utils/mock-remote-config';
import { Response } from 'node-fetch';
import * as RemoteConfig from '../remote-config/remote-config';
import { INSTALL_SCRIPT } from '../utils/constants';

const mockFetch = jest.fn();

Expand Down Expand Up @@ -340,7 +341,7 @@ describe('CommandQueue tests', () => {
'application_id',
'1.0',
'us-west-2',
undefined
{ client: INSTALL_SCRIPT }
]);
});

Expand Down Expand Up @@ -414,4 +415,18 @@ describe('CommandQueue tests', () => {
})
).rejects.toEqual(new Error('IncorrectParametersException'));
});

test('when Orchestration is initialized then indicate installation method was script', async () => {
const commandQueue: CommandQueue = getCommandQueue();
await commandQueue.init({ ...initArgsWithAppName });
expect(Orchestration).toHaveBeenCalled();
expect((Orchestration as any).mock.calls[0]).toEqual([
'application_id',
'1.0',
'us-west-2',
{
client: INSTALL_SCRIPT
}
]);
});
});
9 changes: 8 additions & 1 deletion src/event-cache/EventCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
RumEvent
} from '../dispatch/dataplane';

import packageInfo from '../../version.json';
const webClientVersion = packageInfo.version;

/**
* A cache which stores events generated by telemetry plugins.
*
Expand All @@ -26,6 +29,7 @@ export class EventCache {
private pageManager: PageManager;

private enabled: boolean;
private installationMethod: string;

/**
* @param applicationDetails Application identity and version.
Expand All @@ -45,6 +49,7 @@ export class EventCache {
this.recordSessionInitEvent,
this.pageManager
);
this.installationMethod = config.client;
}

/**
Expand Down Expand Up @@ -211,7 +216,9 @@ export class EventCache {
const metaData: MetaData = {
...this.sessionManager.getAttributes(),
...this.pageManager.getAttributes(),
version: '1.0.0'
version: '1.0.0',
'aws:client': this.installationMethod,
'aws:clientVersion': webClientVersion
};

this.events.push({
Expand Down
11 changes: 11 additions & 0 deletions src/event-cache/__tests__/EventCache.integ.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import * as Utils from '../../test-utils/test-utils';
import { RumEvent } from '../../dispatch/dataplane';
import { DEFAULT_CONFIG, mockFetch } from '../../test-utils/test-utils';
import { SESSION_START_EVENT_TYPE } from '../../sessions/SessionManager';
import { INSTALL_MODULE } from '../../utils/constants';

jest.mock('../../../version.json', () => ({
version: '2.0.0' // WEB_CLIENT_VERSION
}));

const WEB_CLIENT_VERSION = '2.0.0';

global.fetch = mockFetch;
describe('EventCache tests', () => {
Expand Down Expand Up @@ -51,6 +58,8 @@ describe('EventCache tests', () => {
const eventCache: EventCache = Utils.createEventCache(config);
const expectedMetaData = {
version: '1.0.0',
'aws:client': INSTALL_MODULE,
'aws:clientVersion': WEB_CLIENT_VERSION,
domain: 'us-east-1.console.aws.amazon.com',
browserLanguage: 'en-US',
browserName: 'WebKit',
Expand Down Expand Up @@ -91,6 +100,8 @@ describe('EventCache tests', () => {
const eventCache: EventCache = Utils.createEventCache(config);
const expectedMetaData = {
version: '1.0.0',
'aws:client': INSTALL_MODULE,
'aws:clientVersion': WEB_CLIENT_VERSION,
domain: 'us-east-1.console.aws.amazon.com',
browserLanguage: 'en-US',
browserName: 'WebKit',
Expand Down
Loading