Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: appuio/appuio-reporting
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 172819093df0395d961a4993617a00d7830ade4a
Choose a base ref
..
head repository: appuio/appuio-reporting
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 80621dd442b9d719def2dbd1bdcb97a984e573eb
Choose a head ref
Showing with 20 additions and 3 deletions.
  1. +1 −1 go.mod
  2. +2 −2 go.sum
  3. +17 −0 pkg/report/report.go
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ module github.com/appuio/appuio-reporting
go 1.19

require (
github.com/go-logr/logr v1.4.1
github.com/go-logr/logr v1.4.2
github.com/go-logr/zapr v1.3.0
github.com/google/go-jsonnet v0.20.0
github.com/prometheus/client_golang v1.17.0
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ=
github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
17 changes: 17 additions & 0 deletions pkg/report/report.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"time"

"github.com/appuio/appuio-reporting/pkg/odoo"
@@ -89,6 +90,10 @@ func runQuery(ctx context.Context, odooClient OdooClient, prom PromQuerier, args
return fmt.Errorf("expected prometheus query to return a model.Vector, got %T", res)
}

if samples.Len() == 0 {
return nil
}

var errs error
records := make([]odoo.OdooMeteredBillingRecord, 0, len(samples))
for _, sample := range samples {
@@ -100,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))
}