Skip to content

Commit d4aba06

Browse files
ci(ipa): make IPA metrics collection more efficient (#967)
1 parent d2a5616 commit d4aba06

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*.vscode
2222
*.DS_Store
2323

24+
/tools/spectral/**/outputs/*
2425
*.out
2526
**/*ipa-collector-results-combined.log
2627
**/*metric-collection-results.parquet

tools/spectral/ipa/metrics/utils/metricCollectionUtils.js

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -53,44 +53,43 @@ function getIPAFromIPARule(ipaRule) {
5353
}
5454

5555
export function merge(ownershipData, collectorResults, ruleSeverityMap) {
56-
const results = [];
56+
function mapResults(entry, adoptionStatus) {
57+
let ownerTeam = null;
58+
if (entry.componentId.startsWith('paths')) {
59+
const pathParts = entry.componentId.split('.');
60+
if (pathParts.length === 2) {
61+
const path = pathParts[1];
62+
ownerTeam = ownershipData[path];
63+
}
64+
}
5765

58-
function addEntry(entryType, adoptionStatus) {
59-
for (const entry of collectorResults[entryType]) {
60-
const existing = results.find(
61-
(result) => result.component_id === entry.componentId && result.ipa_rule === entry.ruleName
62-
);
66+
return {
67+
component_id: entry.componentId,
68+
ipa_rule: entry.ruleName,
69+
ipa: getIPAFromIPARule(entry.ruleName),
70+
severity_level: ruleSeverityMap[entry.ruleName],
71+
adoption_status: adoptionStatus,
72+
exception_reason: adoptionStatus === 'exempted' && entry.exceptionReason ? entry.exceptionReason : null,
73+
owner_team: ownerTeam,
74+
timestamp: new Date().toISOString(),
75+
};
76+
}
6377

64-
if (existing) {
65-
console.warn('Duplicate entries found', existing);
66-
continue;
67-
}
78+
const violations = collectorResults[EntryType.VIOLATION] || [];
79+
const adoptions = collectorResults[EntryType.ADOPTION] || [];
80+
const exceptions = collectorResults[EntryType.EXCEPTION] || [];
6881

69-
let ownerTeam = null;
70-
if (entry.componentId.startsWith('paths')) {
71-
const pathParts = entry.componentId.split('.');
72-
if (pathParts.length === 2) {
73-
const path = pathParts[1];
74-
ownerTeam = ownershipData[path];
75-
}
76-
}
82+
console.log('\tMerging violations (total ' + violations.length + ')');
83+
const violationResults = violations.map((entry) => mapResults(entry, 'violated'));
7784

78-
results.push({
79-
component_id: entry.componentId,
80-
ipa_rule: entry.ruleName,
81-
ipa: getIPAFromIPARule(entry.ruleName),
82-
severity_level: ruleSeverityMap[entry.ruleName],
83-
adoption_status: adoptionStatus,
84-
exception_reason: entryType === EntryType.EXCEPTION ? entry.exceptionReason : null,
85-
owner_team: ownerTeam,
86-
timestamp: new Date().toISOString(),
87-
});
88-
}
89-
}
85+
console.log('\tMerging adoptions (total ' + adoptions.length + ')');
86+
const adoptionResults = adoptions.map((entry) => mapResults(entry, 'adopted'));
9087

91-
addEntry(EntryType.VIOLATION, 'violated');
92-
addEntry(EntryType.ADOPTION, 'adopted');
93-
addEntry(EntryType.EXCEPTION, 'exempted');
88+
console.log('\tMerging exceptions (total ' + exceptions.length + ')');
89+
const exceptionResults = exceptions.map((entry) => mapResults(entry, 'exempted'));
9490

95-
return results;
91+
console.log(
92+
'\tMerging complete. Total entries: ' + (violationResults.length + adoptionResults.length + exceptionResults.length)
93+
);
94+
return [...violationResults, ...adoptionResults, ...exceptionResults];
9695
}

0 commit comments

Comments
 (0)