Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nil checks in summarizer.go #36

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading