Skip to content

Commit

Permalink
fix: [CI-12024]: Fix saving dlc+build cache
Browse files Browse the repository at this point in the history
  • Loading branch information
smjt-h committed Sep 2, 2024
1 parent 85656b6 commit a3b69c9
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions ti/savings/savings.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,12 @@ func ParseAndUploadSavings(ctx context.Context, workspace string, log *logrus.Lo
states := make([]types.IntelligenceExecutionState, 0)
// Cache Savings
start := time.Now()
cacheState, timeTaken, savingsRequest, err := cache.ParseCacheSavings(workspace, log)
if err == nil {
states = append(states, cacheState)
log.Infof("Computed build cache execution details with state %s and time %sms in %0.2f seconds",
cacheState, strconv.Itoa(timeTaken), time.Since(start).Seconds())

tiStart := time.Now()
tiErr := tiConfig.GetClient().WriteSavings(ctx, stepID, types.BUILD_CACHE, cacheState, int64(timeTaken), savingsRequest)
if tiErr == nil {
log.Infof("Successfully uploaded savings for feature %s in %0.2f seconds",
types.BUILD_CACHE, time.Since(tiStart).Seconds())
}
}

// TI Savings
if tiState, err := tiConfig.GetFeatureState(stepID, types.TI); err == nil {
states = append(states, tiState)
log.Infof("Computed test intelligence execution details with state %s and time %dms",
tiState, cmdTimeTaken)

tiStart := time.Now()
tiErr := tiConfig.GetClient().WriteSavings(ctx, stepID, types.TI, tiState, cmdTimeTaken, types.SavingsRequest{})
if tiErr == nil {
log.Infof("Successfully uploaded savings for feature %s in %0.2f seconds",
types.TI, time.Since(tiStart).Seconds())
}
}

// DLC Savings
if cacheMetricsFile, found := envs["PLUGIN_CACHE_METRICS_FILE"]; found {
if opts, ok := envs["PLUGIN_BUILDER_DRIVER_OPTS"]; ok && strings.Contains(opts, "harness/buildkit") {
dlcState, savingsRequest, err := dlc.ParseDlcSavings(cacheMetricsFile, log)
if err == nil {
states = make([]types.IntelligenceExecutionState, 0)
states = append(states, dlcState)
log.Infof("Computed docker layer caching execution details with state %s and time %dms", dlcState, cmdTimeTaken)
tiStart := time.Now()
Expand All @@ -64,6 +36,34 @@ func ParseAndUploadSavings(ctx context.Context, workspace string, log *logrus.Lo
}
}
}
} else {
cacheState, timeTaken, savingsRequest, err := cache.ParseCacheSavings(workspace, log)
if err == nil {
states = append(states, cacheState)
log.Infof("Computed build cache execution details with state %s and time %sms in %0.2f seconds",
cacheState, strconv.Itoa(timeTaken), time.Since(start).Seconds())

tiStart := time.Now()
tiErr := tiConfig.GetClient().WriteSavings(ctx, stepID, types.BUILD_CACHE, cacheState, int64(timeTaken), savingsRequest)
if tiErr == nil {
log.Infof("Successfully uploaded savings for feature %s in %0.2f seconds",
types.BUILD_CACHE, time.Since(tiStart).Seconds())
}
}

// TI Savings
if tiState, err := tiConfig.GetFeatureState(stepID, types.TI); err == nil {
states = append(states, tiState)
log.Infof("Computed test intelligence execution details with state %s and time %dms",
tiState, cmdTimeTaken)

tiStart := time.Now()
tiErr := tiConfig.GetClient().WriteSavings(ctx, stepID, types.TI, tiState, cmdTimeTaken, types.SavingsRequest{})
if tiErr == nil {
log.Infof("Successfully uploaded savings for feature %s in %0.2f seconds",
types.TI, time.Since(tiStart).Seconds())
}
}
}

// No Savings should happen beyond this except for Cache Intel
Expand Down

0 comments on commit a3b69c9

Please sign in to comment.