Add support for reader.#1049
Conversation
metric/reader/reader.go
Outdated
| // Reader periodically reads metrics from all producers registered | ||
| // with producer manager and exports those metrics using provided | ||
| // exporter. Call Reader.Stop() to stop the reader. | ||
| // exporter1. Call Reader.Stop() to stop the reader1. |
There was a problem hiding this comment.
What are "exporter1" and "reader1"? Typo?
There was a problem hiding this comment.
when refactored it renamed in reader.go as well. I'll fix it.
|
@bogdandrutu PTAL. |
metric/reader/reader.go
Outdated
| // limitations under the License. | ||
| // | ||
|
|
||
| package reader |
There was a problem hiding this comment.
Why is this not in metricexport? Also generic names are not good for go packages (so this should be metricreader), I forgot to mention this for producer that should be metricproducer (please fix that).
| r.mu.Lock() | ||
| defer r.mu.Unlock() | ||
| existing, ok := r.gauges[name] | ||
| if ok { |
There was a problem hiding this comment.
Instead of log.Panic probably we should return an error. you can file an issue for this.
metric/registry.go
Outdated
| // External synchronization is required if you want to add gauges to the same | ||
| // registry from multiple goroutines. | ||
| type Registry struct { | ||
| mu sync.RWMutex |
There was a problem hiding this comment.
This is a different issue, can we split it?
|
@bogdandrutu PTAL. |
metric/export.go
Outdated
|
|
||
| // Exporter is an interface that exporters implement to export the metric data. | ||
| type Exporter interface { | ||
| ExportMetric(data []*metricdata.Metric) |
There was a problem hiding this comment.
this conflicts with already defined interface used for OC-service.
Should this be changed to ?
- Export( ) OR
- ExportMetrics() . - It is plural, could be very confusing.
OR should the oc-service change it to
- ExportMetricPb(...) - because it exports metric protobuf
@bogdandrutu, @songy23 any thoughts?
There was a problem hiding this comment.
should the oc-service change it to
ExportMetricPb(...) - because it exports metric protobuf
I would suggest to go with this approach. I think we should stick to "Metric" when we're referring to the native Go metrics data model and "MetricPb" when referring to the proto-generated files.
|
@songy23, @bogdandrutu PTAL. |
metric/metricexport/reader.go
Outdated
| } | ||
|
|
||
| // Options to configure optional parameters for Reader. | ||
| type Options struct { |
There was a problem hiding this comment.
Options is very generic name to have in this package. Consider to use the same pattern as https://golang.org/src/net/http/server.go?s=76578:79938#L2468
So you have a IntervalReader struct with exported properties like ReportingInterval, users will have to set this before calling "Start"
intervalReader := NewIntervalReader(reader, exporter)
intervalReader.ReportingInterval = 30 * time.Second
intervalReader.Start()You can check the reporting interval at the beginning of Start and save it in a local variable.
metric/metricexport/reader.go
Outdated
| // with producer manager and exports those metrics using provided | ||
| // exporter. | ||
| type Reader struct { | ||
| Sampler trace.Sampler |
There was a problem hiding this comment.
No need to export this for the moment.
| ) | ||
|
|
||
| // Exporter is an interface that exporters implement to export the metric data. | ||
| type Exporter interface { |
There was a problem hiding this comment.
Why is this in the metric package and not metricexport?
|
@bogdandrutu PTAL. |
metric/metricexport/reader.go
Outdated
| } | ||
|
|
||
| ctx := context.Background() | ||
| _, span := trace.StartSpan( |
There was a problem hiding this comment.
This probably should be:
ctx, span := trace.StartSpan(context.Background(), spanName, trace.WithSampler(...))
| data = append(data, producer.Read()...) | ||
| } | ||
| // TODO: [rghetia] what to do with errors? log them? | ||
| exporter.ExportMetrics(ctx, data) |
There was a problem hiding this comment.
We need to record metrics for this. Not now.
metric/metricexport/reader.go
Outdated
| // Reader reads metrics from all producers registered | ||
| // with producer manager and exports those metrics using provided | ||
| // exporter. | ||
| type Reader struct { |
There was a problem hiding this comment.
Probably for this we should do a WithOption pattern because does not have a start method.
Also include ctx in ExportMetric api.
|
@bogdandrutu PTAL. |
* Add support for reader. * handle multiple call to reader.Stop and test for producer while reader is stopped. * fix typo. * fix review comment and refactor reader to metricexport package. * change Reader to IntervalReader and add Reader. Also include ctx in ExportMetric api. * modify export interface to return error and make it plural. * remove option and provide Start function. * move exporter.go to metricexport package. * added option for reader. * make constants private. (cherry picked from commit 5ae9166)
No description provided.