Skip to content

Commit

Permalink
Add nil checks in summarizer.go
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenmj committed Oct 16, 2024
1 parent f00ea18 commit 8834352
Showing 1 changed file with 47 additions and 15 deletions.
62 changes: 47 additions & 15 deletions pkg/summary/summarizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,10 @@ func readSystemNetworkStats(systemNetworkStatsData *bes.BuildMetrics_NetworkMetr

// readCumulativeMetrics
func readCumulativeMetrics(cumulativeMetricsData *bes.BuildMetrics_CumulativeMetrics) CumulativeMetrics {
if cumulativeMetricsData == nil {
return CumulativeMetrics{}
}

cumulativeMetrics := CumulativeMetrics{
NumAnalyses: cumulativeMetricsData.NumAnalyses,
NumBuilds: cumulativeMetricsData.NumBuilds,
Expand All @@ -512,24 +516,32 @@ func readCumulativeMetrics(cumulativeMetricsData *bes.BuildMetrics_CumulativeMet

// readArtifactMetrics
func readArtifactMetrics(artifactMetricsData *bes.BuildMetrics_ArtifactMetrics) ArtifactMetrics {
sourceArtifactsRead := FilesMetric{
SizeInBytes: artifactMetricsData.SourceArtifactsRead.SizeInBytes,
Count: artifactMetricsData.SourceArtifactsRead.Count,
if artifactMetricsData == nil {
return ArtifactMetrics{}
}

sourceArtifactsRead := FilesMetric{}
if artifactMetricsData.SourceArtifactsRead != nil {
sourceArtifactsRead.SizeInBytes = artifactMetricsData.SourceArtifactsRead.SizeInBytes
sourceArtifactsRead.Count = artifactMetricsData.SourceArtifactsRead.Count
}

outputArtifactsSeen := FilesMetric{
SizeInBytes: artifactMetricsData.OutputArtifactsSeen.SizeInBytes,
Count: artifactMetricsData.OutputArtifactsSeen.Count,
outputArtifactsSeen := FilesMetric{}
if artifactMetricsData.OutputArtifactsSeen != nil {
outputArtifactsSeen.SizeInBytes = artifactMetricsData.OutputArtifactsSeen.SizeInBytes
outputArtifactsSeen.Count = artifactMetricsData.OutputArtifactsSeen.Count
}

outputArtifactsFromActionCache := FilesMetric{
SizeInBytes: artifactMetricsData.OutputArtifactsFromActionCache.SizeInBytes,
Count: artifactMetricsData.OutputArtifactsFromActionCache.Count,
outputArtifactsFromActionCache := FilesMetric{}
if artifactMetricsData.OutputArtifactsFromActionCache != nil {
outputArtifactsFromActionCache.SizeInBytes = artifactMetricsData.OutputArtifactsFromActionCache.SizeInBytes
outputArtifactsFromActionCache.Count = artifactMetricsData.OutputArtifactsFromActionCache.Count
}

topLevelArtifacts := FilesMetric{
SizeInBytes: artifactMetricsData.TopLevelArtifacts.SizeInBytes,
Count: artifactMetricsData.TopLevelArtifacts.Count,
topLevelArtifacts := FilesMetric{}
if artifactMetricsData.TopLevelArtifacts != nil {
topLevelArtifacts.SizeInBytes = artifactMetricsData.TopLevelArtifacts.SizeInBytes
topLevelArtifacts.Count = artifactMetricsData.TopLevelArtifacts.Count
}

artifactMetrics := ArtifactMetrics{
Expand All @@ -543,6 +555,10 @@ func readArtifactMetrics(artifactMetricsData *bes.BuildMetrics_ArtifactMetrics)

// readTimingMetrics
func readTimingMetrics(timingMetricsData *bes.BuildMetrics_TimingMetrics) TimingMetrics {
if timingMetricsData == nil {
return TimingMetrics{}
}

timingMetrics := TimingMetrics{
CPUTimeInMs: timingMetricsData.CpuTimeInMs,
WallTimeInMs: timingMetricsData.WallTimeInMs,
Expand All @@ -553,18 +569,26 @@ func readTimingMetrics(timingMetricsData *bes.BuildMetrics_TimingMetrics) Timing
}

// readPackageMetrics
func readPackageMetrics(packagMetricsData *bes.BuildMetrics_PackageMetrics) PackageMetrics {
packageLoadMetrics := readPackageLoadMetrics(packagMetricsData.PackageLoadMetrics)
func readPackageMetrics(packageMetricsData *bes.BuildMetrics_PackageMetrics) PackageMetrics {
if packageMetricsData == nil {
return PackageMetrics{}
}

packageLoadMetrics := readPackageLoadMetrics(packageMetricsData.PackageLoadMetrics)

packageMetrics := PackageMetrics{
PackagesLoaded: packagMetricsData.PackagesLoaded,
PackagesLoaded: packageMetricsData.PackagesLoaded,
PackageLoadMetrics: packageLoadMetrics,
}
return packageMetrics
}

// readTargetMetrics
func readTargetMetrics(targetMetricsData *bes.BuildMetrics_TargetMetrics) TargetMetrics {
if targetMetricsData == nil {
return TargetMetrics{}
}

targetMetrics := TargetMetrics{
TargetsConfigured: targetMetricsData.TargetsConfigured,
TargetsConfiguredNotIncludingAspects: targetMetricsData.TargetsConfiguredNotIncludingAspects,
Expand All @@ -575,6 +599,10 @@ func readTargetMetrics(targetMetricsData *bes.BuildMetrics_TargetMetrics) Target

// readMemoryMetrics
func readMemoryMetrics(memoryMetricsData *bes.BuildMetrics_MemoryMetrics) MemoryMetrics {
if memoryMetricsData == nil {
return MemoryMetrics{}
}

garbageMetrics := readGarbageMetrics(memoryMetricsData.GarbageMetrics)

memoryMetrics := MemoryMetrics{
Expand All @@ -588,6 +616,10 @@ func readMemoryMetrics(memoryMetricsData *bes.BuildMetrics_MemoryMetrics) Memory

// readActionSummary
func readActionSummary(actionSummaryData *bes.BuildMetrics_ActionSummary) ActionSummary {
if actionSummaryData == nil {
return ActionSummary{}
}

actionCacheStatistics := readActionCacheStatistics(actionSummaryData.ActionCacheStatistics)

runnerCounts := readRunnerCounts(actionSummaryData.RunnerCount)
Expand Down

0 comments on commit 8834352

Please sign in to comment.