Skip to content

Commit

Permalink
Merge develop to main for release 102 (#119)
Browse files Browse the repository at this point in the history
* Updated get-metrics start time period (#114)

* Improve scanning coverage calculation (#118)

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
rpanman-sonatype and github-actions[bot] authored Feb 3, 2024
1 parent 1b01977 commit e1bfbf9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ public class InsightsAnalysisService {
private MetricsService metricsService;
private PeriodsDataService periodsDataService;
private FileIoService fileIoService;
private DbService dbService;

public InsightsAnalysisService(
MetricsService metricsService,
PeriodsDataService periodsDataService,
FileIoService fileIoService) {
FileIoService fileIoService,
DbService dbService) {
this.metricsService = metricsService;
this.periodsDataService = periodsDataService;
this.fileIoService = fileIoService;
this.dbService = dbService;
}

public void writeInsightsAnalysisData(String timestamp) throws IOException {
Expand Down Expand Up @@ -70,16 +73,25 @@ public Map<String, Object> getInsightsAnalysisData(Map<String, Object> periodsDa
int onboardedBefore =
Integer.parseInt(String.valueOf(p1metrics.get("applicationsOnboarded")));

float scanningCoverageAfter =
this.calculatePct(
Integer.parseInt(
String.valueOf(p2metrics.get("numberOfApplicationsScannedAvg"))),
onboardedAfter);
float scanningCoverageBefore =
this.calculatePct(
Integer.parseInt(
String.valueOf(p1metrics.get("numberOfApplicationsScannedAvg"))),
onboardedBefore);
List<DbRow> p1_scanning_coverage =
dbService.runSql(SqlStatements.METRICP1TABLENAME, SqlStatements.SCANNINGCOVERAGE);
List<DbRow> p2_scanning_coverage =
dbService.runSql(SqlStatements.METRICP2TABLENAME, SqlStatements.SCANNINGCOVERAGE);

double scanningCoverageBefore =
p1_scanning_coverage.stream()
.map(elt -> Double.valueOf(elt.getPointA()) / elt.getPointB())
.mapToDouble(Double::doubleValue)
.average()
.getAsDouble()
* 100.0;
double scanningCoverageAfter =
p2_scanning_coverage.stream()
.map(elt -> Double.valueOf(elt.getPointA()) / elt.getPointB())
.mapToDouble(Double::doubleValue)
.average()
.getAsDouble()
* 100.0;

final String numberOfScansStr = "numberOfScans";
float totalScansAfter = Integer.parseInt(String.valueOf(p2metrics.get(numberOfScansStr)));
Expand Down Expand Up @@ -147,11 +159,11 @@ public Map<String, Object> getInsightsAnalysisData(Map<String, Object> periodsDa
"onboardingRateIncrease",
this.calculateChangeMultiple(onboardingRateBefore, onboardingRateAfter));

model.put("scanningCoverageBefore", this.formatFloat(scanningCoverageBefore));
model.put("scanningCoverageAfter", this.formatFloat(scanningCoverageAfter));
model.put("scanningCoverageBefore", this.formatDouble(scanningCoverageBefore));
model.put("scanningCoverageAfter", this.formatDouble(scanningCoverageAfter));
model.put(
"scanningCoverageDiff",
this.formatFloat(scanningCoverageAfter - scanningCoverageBefore));
this.formatDouble(scanningCoverageAfter - scanningCoverageBefore));
model.put(
"scanningCoverage",
this.calculateChangePctg(scanningCoverageBefore, scanningCoverageAfter));
Expand Down Expand Up @@ -267,6 +279,10 @@ private String formatFloat(float f) {
return String.format("%.2f", f);
}

private String formatDouble(Double d) {
return String.format("%.2f", d);
}

private String calculateChangePctg(float before, float after) {
float result = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ private SqlStatements() {}
+ " sum(OPEN_COUNT_AT_TIME_PERIOD_END_LICENSE_CRITICAL))/count(time_period_start)"
+ " as pointA from <?> group by time_period_start order by 1";

public static final String SCANNINGCOVERAGE =
"SELECT TIME_PERIOD_START, SUM(CASE WHEN EVALUATION_COUNT>0 "
+ "THEN 1 ELSE 0 END) AS pointA, COUNT(*) AS pointB FROM <?> GROUP "
+ "BY TIME_PERIOD_START";

public static final String RISKRATIOCOMPONENTS =
"select time_period_start as label,"
+ " sum(OPEN_COUNT_AT_TIME_PERIOD_END_SECURITY_CRITICAL) as pointA,"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@

<tr style="font-weight:bold">
<td>Scanning Coverage %(apps scanned at least once/period)</td>
<td>71.11</td>
<td>27.34</td>
<td>-43.77</td>
<td>-61.55</td>
<td>98.28</td>
<td>37.06</td>
<td>-61.22</td>
<td>-62.29</td>
<td>0.38</td>
</tr>

Expand Down Expand Up @@ -291,4 +291,4 @@

</div>

</body>
</body>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Measure,Before (2021-01-01 - 2021-03-01),After (2021-04-01 - 2021-05-01),Delta,C
Total Onboarded Apps (# of apps),45,107,62.00,137.78,2.38
Onboarding Rate (apps/period),8.00,31.00,23.00,0.00,3.88
Total Scans,711.0,298.0,-413.00,-58.09,0.42
Scanning Coverage %(apps scanned at least once/period),71.11,37.38,-33.73,-47.43,0.53
Scanning Coverage %(apps scanned at least once/period),98.28,45.44,-52.84,-53.77,0.46
Scanning Rate (total scans per period),237.00,149.00,-88.00,-37.13,0.63
Average Scans per App (scanning rate/apps),5.27,1.39,-3.87,-73.56,0.26
Discovery Rate Criticals (# of discovered Critical violations/period & app),11.52,5.89,-5.63,-48.88,0.51
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Measure,Before (2021-01-01 - 2021-03-01),After (2021-04-01 - 2021-06-01),Delta,C
Total Onboarded Apps (# of apps),45,128,83.00,184.44,2.84
Onboarding Rate (apps/period),8.00,27.67,19.67,0.00,3.46
Total Scans,711.0,445.0,-266.00,-37.41,0.63
Scanning Coverage %(apps scanned at least once/period),71.11,27.34,-43.77,-61.55,0.38
Scanning Coverage %(apps scanned at least once/period),98.28,37.06,-61.22,-62.29,0.38
Scanning Rate (total scans per period),237.00,148.33,-88.67,-37.41,0.63
Average Scans per App (scanning rate/apps),5.27,1.16,-4.11,-78.00,0.22
Discovery Rate Criticals (# of discovered Critical violations/period & app),11.52,3.93,-7.59,-65.88,0.34
Expand Down

0 comments on commit e1bfbf9

Please sign in to comment.