From 3c90f3e36b6c70abf857ef34948a55404ed3f722 Mon Sep 17 00:00:00 2001 From: Sebastian Widmer Date: Fri, 2 Feb 2024 17:01:14 +0100 Subject: [PATCH] Print records sent to Odoo (#26) --- pkg/report/report.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/report/report.go b/pkg/report/report.go index 31a1d99..ec8784b 100644 --- a/pkg/report/report.go +++ b/pkg/report/report.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "os" "time" "github.com/appuio/appuio-reporting/pkg/odoo" @@ -104,6 +105,18 @@ 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)) }