Skip to content

Commit

Permalink
Improve progress reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyTetrahedron committed Oct 29, 2024
1 parent 3c90f3e commit 929c231
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
13 changes: 0 additions & 13 deletions pkg/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"time"

"github.com/appuio/appuio-reporting/pkg/odoo"
Expand Down Expand Up @@ -105,18 +104,6 @@ func runQuery(ctx context.Context, odooClient OdooClient, prom PromQuerier, args
}
}

// print the records to stdout for preview
for _, record := range records {
m, err := json.Marshal(record)
if err != nil {
// can't use the logger from the context here, since the required context key is in the main package 🙃
// TODO(bastjan) fix the suboptimal and overcomplicated logging setup
fmt.Fprintf(os.Stderr, "warning: failed to marshal record for preview: %+v; error: %s\n", record, err)
continue
}
fmt.Fprintf(os.Stdout, "%s\n", m)
}

return multierr.Append(errs, odooClient.SendData(ctx, records))
}

Expand Down
8 changes: 5 additions & 3 deletions report_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"os"
"time"

"github.com/appuio/appuio-reporting/pkg/odoo"
Expand Down Expand Up @@ -122,8 +121,11 @@ func (cmd *reportCommand) runReportRange(ctx context.Context, odooClient *odoo.O

started := time.Now()
reporter := report.WithProgressReporter(func(p report.Progress) {
fmt.Fprintf(os.Stderr, "Report %d, Current: %s [%s]\n",
p.Count, p.Timestamp.Format(time.RFC3339), time.Since(started).Round(time.Second),
log.Info("Progress report",
"product", cmd.ReportArgs.ProductID,
"reportIndex", p.Count,
"timestamp", p.Timestamp.Format(time.RFC3339),
"timeElapsed", time.Since(started).Round(time.Second),
)
})

Expand Down

0 comments on commit 929c231

Please sign in to comment.