-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spring cleaning. #115
Spring cleaning. #115
Conversation
details.dataOutputCount += len(nrMetrics) | ||
batch.Metrics = append(batch.Metrics, nrMetrics...) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you reorganized it as follows, we'd be able to independently test the preparation of the payload from the measurement / sending of the http request (and all the code would be indented one fewer tab):
func (e exporter) pushMetricData(ctx context.Context, md pdata.Metrics) (outputErr error) {
details := newMetricMetadata(ctx)
_, details.dataInputCount = md.MetricAndDataPointCount()
bb := func () (telemetry.PayloadEntry, error) {
return e.buildMetricPayload(details, ctx, md)
}
return e.export(&details, ctx, bb);
}
func (e exporter) buildMetricPayload(details exportMetadata, ctx context.Context, md pdata.Metrics) (telemetry.PayloadEntry, error) {
var (
errs []error
batch telemetry.MetricBatch
)
rms := md.ResourceMetrics()
_, dpCount := md.MetricAndDataPointCount()
batch.Metrics = make([]telemetry.Metric, 0, dpCount)
for i := 0; i < rms.Len(); i++ {
rm := rms.At(i)
ilms := rm.InstrumentationLibraryMetrics()
for j := 0; j < ilms.Len(); j++ {
ilm := ilms.At(j)
ms := ilm.Metrics()
transform := newTransformer(rm.Resource(), ilm.InstrumentationLibrary())
for k := 0; k < ms.Len(); k++ {
m := ms.At(k)
nrMetrics, err := transform.Metric(m)
if err != nil {
e.logger.Debug("Transform of metric failed.", zap.Error(err))
errs = append(errs, err)
continue
}
details.dataOutputCount += len(nrMetrics)
batch.Metrics = append(batch.Metrics, nrMetrics...)
}
}
}
return &batch, consumererror.CombineErrors(errs)
}
895ec28
to
3208027
Compare
1959352
to
b2e7590
Compare
b2e7590
to
2254f52
Compare
2d2941c
to
c445064
Compare
2254f52
to
6bf8cf1
Compare
e.logger.Error("An error occurred recording metrics.", zap.Error(err)) | ||
} | ||
}() | ||
func (e exporter) buildTracePayload(details *exportMetadata, td pdata.Traces) (telemetry.PayloadEntry, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woops gotta change *exportMetadata
to exportMetadata
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't that mean we wouldn't be able to modify attributes in the details
? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, maybe not. export
has to have a pointer for exportMetadata
because it needs to change its values.
I think that suggests we should use pointers to *exportMetadata
throughout for consistency, including in metrics.go
.
return nil, fmt.Errorf("invalid config: %#v", c) | ||
} | ||
|
||
func newExporter(l *zap.Logger, nrConfig endpointConfig, createFactory factoryBuilder) (*exporter, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to return a pointer or value here? If pointer, should we make all the methods attached to type exporter
work off pointers as well? Or does that not matter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we change to a value type, that means we can no longer return nil
. Is that preferable? 🤔
Some spring cleaning 😄