-
Notifications
You must be signed in to change notification settings - Fork 53
NEW @W-17915999@ Added telemetry collection for run action #1778
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
29eb583
@W-17915999@ Added telemetry collection for run action
jfeingold35 cb5b38d
@W-17915999@ Feedback from code review
jfeingold35 aad9d84
@W-17915999@ Void-ing dangling promises
jfeingold35 14f3df4
@W-17915999@ Feedback from code review
jfeingold35 5853c8a
@W-17915999@ Fixed silly oversight.
jfeingold35 0ba14f8
@W-17915999@ Updated to latest SFGE
jfeingold35 9f0ba88
@W-17915999@ Removing unnecessary conditional
jfeingold35 9c23689
@W-17915999@ Splitting events
jfeingold35 d5460b2
@W-17915999@ Feedback from code review
jfeingold35 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import {TelemetryData} from '@salesforce/code-analyzer-core'; | ||
| import {Lifecycle} from "@salesforce/core"; | ||
|
|
||
| export interface TelemetryEmitter { | ||
| emitTelemetry(source: string, eventName: string, data: TelemetryData): void; | ||
| } | ||
|
|
||
| export class SfCliTelemetryEmitter implements TelemetryEmitter { | ||
| // istanbul ignore next - No sense in covering SF-CLI core code. | ||
| public emitTelemetry(source: string, eventName: string, data: TelemetryData): void { | ||
| return void Lifecycle.getInstance().emitTelemetry({ | ||
| ...data, | ||
| source, | ||
| eventName | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { | ||
| CodeAnalyzer, | ||
| EngineTelemetryEvent, | ||
| EventType, | ||
| TelemetryEvent | ||
| } from "@salesforce/code-analyzer-core"; | ||
| import {TelemetryEmitter} from '../Telemetry'; | ||
| import * as constants from '../../Constants'; | ||
|
|
||
| export class TelemetryEventListener { | ||
| private telemetryEmitter: TelemetryEmitter; | ||
|
|
||
| public constructor(telemetryEmitter: TelemetryEmitter) { | ||
| this.telemetryEmitter = telemetryEmitter; | ||
| } | ||
|
|
||
| public listen(codeAnalyzer: CodeAnalyzer): void { | ||
| // Set up listeners. | ||
| codeAnalyzer.onEvent(EventType.TelemetryEvent, (e: TelemetryEvent) => this.handleEvent('Core', e)); | ||
| codeAnalyzer.onEvent(EventType.EngineTelemetryEvent, (e: EngineTelemetryEvent) => this.handleEvent(e.engineName, e)); | ||
| } | ||
|
|
||
| public stopListening(): void { | ||
| // Intentional no-op, because no cleanup is required. | ||
| } | ||
|
|
||
| private handleEvent(source: string, event: TelemetryEvent|EngineTelemetryEvent): void { | ||
| return this.telemetryEmitter.emitTelemetry(source, constants.TelemetryEventName, { | ||
| ...event.data, | ||
| sfcaEvent: event.eventName, | ||
| timestamp: event.timestamp.getTime(), | ||
| uuid: event.uuid | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,23 @@ | ||
| import {stubSfCommandUx} from '@salesforce/sf-plugins-core'; | ||
| import {TelemetryData} from '@salesforce/code-analyzer-core'; | ||
| import {TestContext} from '@salesforce/core/lib/testSetup'; | ||
| import RunCommand from '../../../src/commands/code-analyzer/run'; | ||
| import {RunAction, RunDependencies, RunInput} from '../../../src/lib/actions/RunAction'; | ||
| import {CompositeResultsWriter} from '../../../src/lib/writers/ResultsWriter'; | ||
| import {SfCliTelemetryEmitter} from "../../../src/lib/Telemetry"; | ||
|
|
||
| type TelemetryEmission = { | ||
| source: string, | ||
| eventName: string, | ||
| data: TelemetryData | ||
| }; | ||
|
|
||
| describe('`code-analyzer run` tests', () => { | ||
| const $$ = new TestContext(); | ||
|
|
||
| let executeSpy: jest.SpyInstance; | ||
| let createActionSpy: jest.SpyInstance; | ||
| let receivedTelemetryEmissions: TelemetryEmission[]; | ||
| let receivedActionInput: RunInput; | ||
| let receivedActionDependencies: RunDependencies; | ||
| let fromFilesSpy: jest.SpyInstance; | ||
|
|
@@ -19,6 +28,11 @@ describe('`code-analyzer run` tests', () => { | |
| receivedActionInput = input; | ||
| return Promise.resolve(); | ||
| }); | ||
| receivedTelemetryEmissions = []; | ||
| jest.spyOn(SfCliTelemetryEmitter.prototype, 'emitTelemetry').mockImplementation((source, eventName, data) => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this isn't the preferred way of doing this sort of test, but it was the best option available. |
||
| receivedTelemetryEmissions.push({source, eventName, data}); | ||
| return Promise.resolve(); | ||
| }); | ||
| const originalCreateAction = RunAction.createAction; | ||
| createActionSpy = jest.spyOn(RunAction, 'createAction').mockImplementation((dependencies) => { | ||
| receivedActionDependencies = dependencies; | ||
|
|
@@ -325,6 +339,14 @@ describe('`code-analyzer run` tests', () => { | |
| }); | ||
| }); | ||
|
|
||
| describe('Telemetry emission', () => { | ||
| it('Passes telemetry emitter through into Action layer', async () => { | ||
| await RunCommand.run([]); | ||
| expect(createActionSpy).toHaveBeenCalled(); | ||
| expect(receivedActionDependencies.telemetryEmitter!.constructor.name).toEqual('SfCliTelemetryEmitter'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Flag interactions', () => { | ||
| describe('--output-file and --view', () => { | ||
| it('When --output-file and --view are both present, both are used', async () => { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import {TelemetryData} from '@salesforce/code-analyzer-core'; | ||
| import {TelemetryEmitter} from '../../src/lib/Telemetry'; | ||
|
|
||
| export type CapturedTelemetryEmission = { | ||
| source: string, | ||
| eventName: string, | ||
| data: TelemetryData | ||
| }; | ||
|
|
||
| export class SpyTelemetryEmitter implements TelemetryEmitter { | ||
| private capturedTelemetry: CapturedTelemetryEmission[] = []; | ||
|
|
||
| public emitTelemetry(source: string, eventName: string, data: TelemetryData): void { | ||
| this.capturedTelemetry.push({source, eventName, data}); | ||
| } | ||
|
|
||
| public getCapturedTelemetry(): CapturedTelemetryEmission[] { | ||
| return this.capturedTelemetry; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really need to pass in coreEngineNames. Let's just loop over selectedEngineNames. Then back on line 81... we don't need to get the engine names from the plugins.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to use
coreEngineNamesin order to limit ourselves to the plugins that we ourselves ship. Otherwise, we're collecting telemetry on possibly-user-created engines, which is apparently a no-no.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh you are saying that enginePlugins which you get from the this.dependencies.pluginsFactory.create(); doesn't include the dynamic engines. OK makes sense.