-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3882 from snyk/chore/send-integrated-iac-test-ana…
- Loading branch information
Showing
2 changed files
with
40 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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,46 +1,49 @@ | ||
import * as createDebugLogger from 'debug'; | ||
|
||
import { policyEngineReleaseVersion } from '../local-cache/policy-engine/constants'; | ||
import { ResourceKind, TestOutput } from '../scan/results'; | ||
import * as analytics from '../../../../../lib/analytics'; | ||
import { getIacType, IacType } from './iac-type'; | ||
|
||
const debugLog = createDebugLogger('snyk-iac'); | ||
|
||
export interface IacAnalytics { | ||
iacType: IacType; | ||
packageManager: ResourceKind[]; | ||
'iac-type': IacType; | ||
'iac-issues-count': number; | ||
'iac-ignored-issues-count': number; | ||
'iac-files-count': number; | ||
'iac-resources-count': number; | ||
'iac-test-binary-version': string; | ||
'iac-error-codes': number[]; | ||
// 'iac-rules-bundle-version': string; // TODO: Add when we have the rules bundle version | ||
iacIssuesCount: number; | ||
iacIgnoredIssuesCount: number; | ||
iacFilesCount: number; | ||
iacResourcesCount: number; | ||
iacErrorCodes: number[]; | ||
iacTestBinaryVersion: string; | ||
// iacRulesBundleVersion: string; // TODO: Add when we have the rules bundle version | ||
} | ||
|
||
export function addIacAnalytics(testOutput: TestOutput): void { | ||
const iacAnalytics = computeIacAnalytics(testOutput); | ||
|
||
debugLog(iacAnalytics); | ||
analytics.add('iac-type', iacAnalytics.iacType); | ||
analytics.add('packageManager', iacAnalytics.packageManager); | ||
analytics.add('iac-issues-count', iacAnalytics.iacIssuesCount); | ||
analytics.add('iac-ignored-issues-count', iacAnalytics.iacIgnoredIssuesCount); | ||
analytics.add('iac-files-count', iacAnalytics.iacFilesCount); | ||
analytics.add('iac-resources-count', iacAnalytics.iacResourcesCount); | ||
analytics.add('iac-error-codes', iacAnalytics.iacErrorCodes); | ||
analytics.add('iac-test-binary-version', iacAnalytics.iacTestBinaryVersion); | ||
} | ||
|
||
export function computeIacAnalytics(testOutput: TestOutput): IacAnalytics { | ||
function computeIacAnalytics(testOutput: TestOutput): IacAnalytics { | ||
const iacType = getIacType(testOutput); | ||
|
||
return { | ||
'iac-type': iacType, | ||
iacType, | ||
packageManager: Object.keys(iacType) as ResourceKind[], | ||
'iac-issues-count': testOutput.results?.vulnerabilities?.length || 0, | ||
'iac-ignored-issues-count': | ||
testOutput.results?.scanAnalytics.ignoredCount || 0, | ||
'iac-files-count': Object.values(iacType).reduce( | ||
iacIssuesCount: testOutput.results?.vulnerabilities?.length || 0, | ||
iacIgnoredIssuesCount: testOutput.results?.scanAnalytics.ignoredCount || 0, | ||
iacFilesCount: Object.values(iacType).reduce( | ||
(acc, packageManagerAnalytics) => acc + packageManagerAnalytics!.count, | ||
0, | ||
), | ||
'iac-resources-count': testOutput.results?.resources?.length || 0, | ||
'iac-error-codes': | ||
iacResourcesCount: testOutput.results?.resources?.length || 0, | ||
iacErrorCodes: | ||
[...new Set(testOutput.errors?.map((error) => error.code!))] || [], | ||
'iac-test-binary-version': policyEngineReleaseVersion, | ||
// iacAnalytics['iac-rules-bundle-version'] = ''; // TODO: Add when we have the rules bundle version | ||
iacTestBinaryVersion: policyEngineReleaseVersion, | ||
// iacRulesBundleVersion = ''; // TODO: Add when we have the rules bundle version | ||
}; | ||
} |
This file contains 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