Add dump() for report stats

This commit is contained in:
Bryan Boreham
2018-10-11 15:19:25 +00:00
parent 56c6685e73
commit ae98ab26c1

View File

@@ -16,6 +16,7 @@ import (
"github.com/bluele/gcache"
"github.com/nats-io/nats"
opentracing "github.com/opentracing/opentracing-go"
otlog "github.com/opentracing/opentracing-go/log"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
@@ -324,6 +325,7 @@ func (c *awsCollector) getReports(ctx context.Context, reportKeys []string) ([]r
log.Warningf("Error fetching from cache: %v", err)
}
for key, report := range found {
dump(ctx, report)
if c.maxNodes > 0 {
report = report.DropTopologiesOver(c.maxNodes)
}
@@ -342,6 +344,20 @@ func (c *awsCollector) getReports(ctx context.Context, reportKeys []string) ([]r
return reports, nil
}
func dump(ctx context.Context, r report.Report) {
span := opentracing.SpanFromContext(ctx)
if span == nil {
return
}
var fields []otlog.Field
r.WalkNamedTopologies(func(name string, topology *report.Topology) {
if topology != nil {
fields = append(fields, otlog.Int(name, len(topology.Nodes)))
}
})
span.LogFields(fields...)
}
func (c *awsCollector) Report(ctx context.Context, timestamp time.Time) (report.Report, error) {
span, ctx := opentracing.StartSpanFromContext(ctx, "awsCollector.Report")
defer span.Finish()