Skip to content

Commit

Permalink
feat: variants instrumentation (#1272)
Browse files Browse the repository at this point in the history
* feat: telemetry on registryVariants

* chore: todo cleanup for types
  • Loading branch information
mshanemc authored Apr 3, 2024
1 parent be3735e commit 1261096
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
20 changes: 11 additions & 9 deletions src/registry/variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import * as fs from 'node:fs';
import * as path from 'node:path';
import { Logger, SfProject, SfProjectJson } from '@salesforce/core';
import { Logger, SfProject, SfProjectJson, Lifecycle } from '@salesforce/core';
import { deepFreeze } from '../utils/collections';
import { MetadataRegistry } from './types';
import * as registryData from './metadataRegistry.json';
Expand All @@ -16,7 +16,6 @@ export type RegistryLoadInput = {
* will default to the current working directory
* if no project file is found, the standard registry will be returned without modifications
*/
// TODO: this might be a string instead of an object if no other props are needed
projectDir?: string;
};

Expand Down Expand Up @@ -49,6 +48,16 @@ const loadVariants = ({ projectDir }: RegistryLoadInput = {}): MetadataRegistry
(prev, curr) => firstLevelMerge(prev, loadPreset(curr)),
emptyRegistry
);
if (presets.length > 0 || Object.keys(customizations.types).length > 0) {
void Lifecycle.getInstance().emitTelemetry({
library: 'SDR',
eventName: 'RegistryVariants',
presetCount: presets.length,
presets: presets.join(','),
customizationsCount: Object.keys(customizations.types).length,
customizationsTypes: Object.keys(customizations.types).join(','),
});
}
return firstLevelMerge(registryFromPresets, customizations);
};

Expand All @@ -60,13 +69,6 @@ const maybeGetProject = (projectDir?: string): SfProjectJson | undefined => {
}
};

// TODO: this type should maybe live somewhere else and be part of the sfdx-project schema
// but we don't want circular dependency from sfdx-core to SDR
// type CustomRegistry = {
// registryCustomizations: MetadataRegistry;
// registryPresets: string[];
// };

const loadPreset = (preset: string): MetadataRegistry => {
const pathToCheck = path.join(__dirname, 'presets', `${preset}.json`);

Expand Down
13 changes: 5 additions & 8 deletions test/nuts/scale/perfUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ export const recordPerf = async (testName: string, performance: Performance): Pr
fileTarget,
JSON.stringify(
existing.concat(
performance
.getEntriesByType('measure')
// TODO: remove this when we upgrade to node16 and get its types
.map((m: { name: string; duration: number }) => ({
name: `${testName}-${m.name}-${os.platform()}`,
value: Math.trunc(m.duration),
unit: 'ms',
}))
performance.getEntriesByType('measure').map((m) => ({
name: `${testName}-${m.name}-${os.platform()}`,
value: Math.trunc(m.duration),
unit: 'ms',
}))
),
null,
2
Expand Down

0 comments on commit 1261096

Please sign in to comment.