Skip to content

Commit

Permalink
chore: add telemetry for psuedo types
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Feb 10, 2025
1 parent 89a53fb commit ab23e36
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/collections/componentSetBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
*/

import * as path from 'node:path';
import { AuthInfo, Connection, Logger, Messages, SfError, StateAggregator, trimTo15 } from '@salesforce/core';
import {
AuthInfo,
Connection,
Lifecycle,
Logger,
Messages,
SfError,
StateAggregator,
trimTo15,
} from '@salesforce/core';
import fs from 'graceful-fs';
import { minimatch } from 'minimatch';
import { MetadataComponent } from '../resolve/types';
Expand Down Expand Up @@ -399,6 +408,11 @@ const replacePseudoTypes = async (mdEntries: string[], connection: Connection):
});

if (pseudoEntries.length) {
void Lifecycle.getInstance().emitTelemetry({
library: 'SDR',
eventName: 'PseudoTypesConverted',
types: pseudoEntries.map((p) => p[0]).join(),
});
await Promise.all(
pseudoEntries.map(async (pseudoEntry) => {
const pseudoType = pseudoEntry[0];
Expand Down
25 changes: 24 additions & 1 deletion test/collections/componentSetBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { join } from 'node:path';
import fs from 'graceful-fs';
import * as sinon from 'sinon';
import { assert, expect, config } from 'chai';
import { Connection, SfError } from '@salesforce/core';
import { Connection, Lifecycle, SfError } from '@salesforce/core';
import { instantiateContext, MockTestOrgData, restoreContext, stubContext } from '@salesforce/core/testSetup';
import { RegistryAccess } from '../../src/registry/registryAccess';
import { ComponentSetBuilder, entryToTypeAndName } from '../../src/collections/componentSetBuilder';
Expand Down Expand Up @@ -61,13 +61,15 @@ describe('ComponentSetBuilder', () => {
let fromSourceStub: sinon.SinonStub;
let fromManifestStub: sinon.SinonStub;
let fromConnectionStub: sinon.SinonStub;
let emitTelemetrySpy: sinon.SinonStub;

beforeEach(() => {
fileExistsSyncStub = sandbox.stub(fs, 'existsSync');
fromSourceStub = sandbox.stub(ComponentSet, 'fromSource');
fromManifestStub = sandbox.stub(ComponentSet, 'fromManifest');
fromConnectionStub = sandbox.stub(ComponentSet, 'fromConnection');
componentSet = new ComponentSet();
emitTelemetrySpy = sandbox.stub(Lifecycle.prototype, 'emitTelemetry');
});

it('should create ComponentSet from single sourcepath', async () => {
Expand All @@ -89,6 +91,7 @@ describe('ComponentSetBuilder', () => {
expect(argWithoutRegistry).to.deep.equal(expectedArg);
expect(compSet.size).to.equal(1);
expect(compSet.has(apexClassComponent)).to.equal(true);
expect(emitTelemetrySpy.called).to.be.false;
});

it('should create ComponentSet from multiple sourcepaths', async () => {
Expand Down Expand Up @@ -132,6 +135,7 @@ describe('ComponentSetBuilder', () => {
expect(argWithoutRegistry).to.deep.equal(expectedArg);
expect(compSet.size).to.equal(0);
expect(compSet.apiVersion).to.equal(options.apiversion);
expect(emitTelemetrySpy.called).to.be.false;
});

it('should create ComponentSet with sourceApiVersion', async () => {
Expand Down Expand Up @@ -208,6 +212,7 @@ describe('ComponentSetBuilder', () => {
expect(compSet.size).to.equal(2);
expect(compSet.has(apexClassComponent)).to.equal(true);
expect(compSet.has({ type: 'ApexClass', fullName: '*' })).to.equal(true);
expect(emitTelemetrySpy.called).to.be.false;
});

it('should create ComponentSet from metadata with spaces between : (ApexClass: MyApexClass)', async () => {
Expand Down Expand Up @@ -276,6 +281,7 @@ describe('ComponentSetBuilder', () => {
expect(fromSourceArgs.include.getSourceComponents()).to.deep.equal(filter.getSourceComponents());
expect(compSet.size).to.equal(1);
expect(compSet.has(apexClassComponent)).to.equal(true);
expect(emitTelemetrySpy.called).to.be.false;
});

it('should create ComponentSet from multiple metadata (ApexClass:MyClass,CustomObject)', async () => {
Expand Down Expand Up @@ -513,6 +519,7 @@ describe('ComponentSetBuilder', () => {
expect(fromConnectionArgs['componentFilter'].call()).equal(true);
expect(compSet.size).to.equal(1);
expect(compSet.has(apexClassComponent)).to.equal(true);
expect(emitTelemetrySpy.args.flat()).to.not.include('PseudoTypesConverted');
});

it('should create ComponentSet from org connection and metadata', async () => {
Expand Down Expand Up @@ -599,6 +606,14 @@ describe('ComponentSetBuilder', () => {
const expectedMdTypes = ['Bot', 'BotVersion', 'GenAiPlanner', 'GenAiPlugin'];
expect(fromConnectionArgs).to.have.deep.property('metadataTypes', expectedMdTypes);
expect(compSet.getSourceComponents()).to.deep.equal(mdCompSet.getSourceComponents());
expect(emitTelemetrySpy.calledOnce).to.be.true;
expect(emitTelemetrySpy.args[0]).to.deep.equal([
{
eventName: 'PseudoTypesConverted',
library: 'SDR',
types: 'Agent',
},
]);
});

it('should create ComponentSet from org connection and Agent developer name', async () => {
Expand Down Expand Up @@ -633,6 +648,14 @@ describe('ComponentSetBuilder', () => {
const expectedMdTypes = ['Bot', 'BotVersion', 'GenAiPlanner', 'GenAiPlugin'];
expect(fromConnectionArgs).to.have.deep.property('metadataTypes', expectedMdTypes);
expect(compSet.getSourceComponents()).to.deep.equal(mdCompSet.getSourceComponents());
expect(emitTelemetrySpy.calledOnce).to.be.true;
expect(emitTelemetrySpy.args[0]).to.deep.equal([
{
eventName: 'PseudoTypesConverted',
library: 'SDR',
types: 'Agent',
},
]);
});
});
});
Expand Down

2 comments on commit ab23e36

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: ab23e36 Previous: 2e6f1dc Ratio
eda-componentSetCreate-linux 221 ms 234 ms 0.94
eda-sourceToMdapi-linux 2068 ms 2173 ms 0.95
eda-sourceToZip-linux 1870 ms 2042 ms 0.92
eda-mdapiToSource-linux 2730 ms 2843 ms 0.96
lotsOfClasses-componentSetCreate-linux 465 ms 496 ms 0.94
lotsOfClasses-sourceToMdapi-linux 3599 ms 3810 ms 0.94
lotsOfClasses-sourceToZip-linux 2939 ms 3316 ms 0.89
lotsOfClasses-mdapiToSource-linux 3542 ms 3686 ms 0.96
lotsOfClassesOneDir-componentSetCreate-linux 821 ms 883 ms 0.93
lotsOfClassesOneDir-sourceToMdapi-linux 6278 ms 6674 ms 0.94
lotsOfClassesOneDir-sourceToZip-linux 5309 ms 5633 ms 0.94
lotsOfClassesOneDir-mdapiToSource-linux 6312 ms 6707 ms 0.94

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: ab23e36 Previous: 2e6f1dc Ratio
eda-componentSetCreate-win32 716 ms 638 ms 1.12
eda-sourceToMdapi-win32 4105 ms 3862 ms 1.06
eda-sourceToZip-win32 3267 ms 3091 ms 1.06
eda-mdapiToSource-win32 5899 ms 5608 ms 1.05
lotsOfClasses-componentSetCreate-win32 1422 ms 1335 ms 1.07
lotsOfClasses-sourceToMdapi-win32 8156 ms 7616 ms 1.07
lotsOfClasses-sourceToZip-win32 5142 ms 4867 ms 1.06
lotsOfClasses-mdapiToSource-win32 8158 ms 7578 ms 1.08
lotsOfClassesOneDir-componentSetCreate-win32 2294 ms 2284 ms 1.00
lotsOfClassesOneDir-sourceToMdapi-win32 13730 ms 13570 ms 1.01
lotsOfClassesOneDir-sourceToZip-win32 8623 ms 8485 ms 1.02
lotsOfClassesOneDir-mdapiToSource-win32 14137 ms 13831 ms 1.02

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.