Drop progress reporting from banner tracker reset

The ResetProgressFunc callback streamed per-phase messages from inside
the reset transaction, so a rollback could leave already-printed
progress describing work that never committed. Remove the callback
entirely; the final result summary printed by proboctl still conveys
the outcome without the misleading intermediate output.

Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-06-10 18:28:21 +02:00
parent ed9831a734
commit 2db063bc60
3 changed files with 4 additions and 40 deletions

View File

@@ -33,21 +33,6 @@ type ResetTrackersResult struct {
AnalysisRequested bool
}
// ResetProgressFunc receives human-readable progress messages emitted as
// a banner reset advances through its phases. It is optional: pass nil to
// run silently. Messages are emitted inside the reset transaction, so a
// later failure that rolls the transaction back may leave already-printed
// progress describing work that did not commit.
type ResetProgressFunc func(message string)
func (p ResetProgressFunc) report(format string, args ...any) {
if p == nil {
return
}
p(fmt.Sprintf(format, args...))
}
// ResetBannerTrackers re-arms the tracker pipeline for a banner's
// uncategorised, non-excluded patterns. It is an operator action
// (proboctl), tenant-scoped via the provided Scoper.
@@ -70,9 +55,6 @@ func (p ResetProgressFunc) report(format string, args ...any) {
// whose pattern or display name contains it (case-insensitive): only
// matching globs are decomposed and only matching patterns are re-armed
// for mapping. The banner-wide pattern-analysis re-arm is unaffected.
//
// progress receives human-readable phase updates as the reset runs; pass
// nil to run silently.
func ResetBannerTrackers(
ctx context.Context,
pgClient *pg.Client,
@@ -80,28 +62,23 @@ func ResetBannerTrackers(
bannerID gid.GID,
mappingOnly bool,
keyword *string,
progress ResetProgressFunc,
) (ResetTrackersResult, error) {
var result ResetTrackersResult
err := pgClient.WithTx(
ctx,
func(ctx context.Context, tx pg.Tx) error {
progress.report("Loading uncategorised category for banner %s...", bannerID)
var uncategorised coredata.CookieCategory
if err := uncategorised.LoadUncategorisedByCookieBannerID(ctx, tx, scope, bannerID); err != nil {
return fmt.Errorf("cannot load uncategorised category: %w", err)
}
if !mappingOnly {
if err := decomposeGlobs(ctx, tx, scope, bannerID, uncategorised.ID, keyword, &result, progress); err != nil {
if err := decomposeGlobs(ctx, tx, scope, bannerID, uncategorised.ID, keyword, &result); err != nil {
return err
}
}
progress.report("Resetting links and re-arming mapping on matching patterns...")
var patterns coredata.TrackerPatterns
reset, err := patterns.ResetAndRequestMappingByCookieCategoryID(ctx, tx, scope, uncategorised.ID, keyword)
@@ -111,11 +88,7 @@ func ResetBannerTrackers(
result.PatternsReset = reset
progress.report("Reset %d pattern(s) and re-armed mapping.", reset)
if !mappingOnly {
progress.report("Re-arming pattern analysis on banner %s...", bannerID)
banner := coredata.CookieBanner{ID: bannerID}
if err := banner.SetPatternAnalysisRequested(ctx, tx); err != nil {
return fmt.Errorf("cannot request pattern analysis: %w", err)
@@ -145,7 +118,6 @@ func decomposeGlobs(
uncategorisedID gid.GID,
keyword *string,
result *ResetTrackersResult,
progress ResetProgressFunc,
) error {
globMatchType := coredata.TrackerPatternMatchTypeGlob
notExcluded := false
@@ -162,16 +134,12 @@ func decomposeGlobs(
return fmt.Errorf("cannot load glob patterns: %w", err)
}
progress.report("Decomposing %d glob pattern(s) into exact patterns...", len(globs))
for i, glob := range globs {
for _, glob := range globs {
var detections coredata.DetectedTrackers
if err := detections.LoadAllByTrackerPatternID(ctx, tx, scope, glob.ID); err != nil {
return fmt.Errorf("cannot load detections for glob %q: %w", glob.Pattern, err)
}
progress.report("[%d/%d] Decomposing glob %q (%d detection(s))...", i+1, len(globs), glob.Pattern, len(detections))
for _, detection := range detections {
exactID, created, err := ensureExactPattern(ctx, tx, scope, glob, uncategorisedID, detection)
if err != nil {

View File

@@ -85,7 +85,7 @@ func TestResetBannerTrackers_FullRebuild(t *testing.T) {
return nil
}))
result, err := ResetBannerTrackers(ctx, client, fx.scope, fx.banner.ID, false, nil, nil)
result, err := ResetBannerTrackers(ctx, client, fx.scope, fx.banner.ID, false, nil)
require.NoError(t, err)
require.Equal(t, 1, result.GlobsDecomposed)

View File

@@ -89,11 +89,7 @@ func newCmdResetTrackers(f *cmdutil.Factory) *cobra.Command {
_, _ = fmt.Fprintf(out, "Running %s on banner %s.\n", mode, bannerID.String())
progress := func(message string) {
_, _ = fmt.Fprintf(out, " %s\n", message)
}
result, err := cookiebanner.ResetBannerTrackers(ctx, pgClient, scope, bannerID, flagMappingOnly, keyword, progress)
result, err := cookiebanner.ResetBannerTrackers(ctx, pgClient, scope, bannerID, flagMappingOnly, keyword)
if err != nil {
return fmt.Errorf("cannot reset banner %s: %w", bannerID, err)
}