Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Add support for reader.#1049

Merged
rghetia merged 10 commits intocensus-instrumentation:masterfrom
rghetia:reader
Mar 22, 2019
Merged

Add support for reader.#1049
rghetia merged 10 commits intocensus-instrumentation:masterfrom
rghetia:reader

Conversation

@rghetia
Copy link
Copy Markdown
Contributor

@rghetia rghetia commented Mar 5, 2019

No description provided.

@rghetia rghetia requested a review from rakyll as a code owner March 5, 2019 02:01
@rghetia rghetia requested review from bogdandrutu and songy23 March 5, 2019 06:44
// 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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are "exporter1" and "reader1"? Typo?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when refactored it renamed in reader.go as well. I'll fix it.

Copy link
Copy Markdown
Contributor

@songy23 songy23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rghetia
Copy link
Copy Markdown
Contributor Author

rghetia commented Mar 6, 2019

@bogdandrutu PTAL.

// limitations under the License.
//

package reader
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of log.Panic probably we should return an error. you can file an issue for this.

// External synchronization is required if you want to add gauges to the same
// registry from multiple goroutines.
type Registry struct {
mu sync.RWMutex
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a different issue, can we split it?

@rghetia rghetia requested a review from a team as a code owner March 12, 2019 21:33
@rghetia
Copy link
Copy Markdown
Contributor Author

rghetia commented Mar 12, 2019

@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)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this conflicts with already defined interface used for OC-service.
Should this be changed to ?

  1. Export( ) OR
  2. ExportMetrics() . - It is plural, could be very confusing.

OR should the oc-service change it to

  1. ExportMetricPb(...) - because it exports metric protobuf

@bogdandrutu, @songy23 any thoughts?

Copy link
Copy Markdown
Contributor

@songy23 songy23 Mar 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @odeke-em

@rghetia
Copy link
Copy Markdown
Contributor Author

rghetia commented Mar 15, 2019

@songy23, @bogdandrutu PTAL.
Earlier Reader was actually Interval Reader. So renamed it to IntervalReader. Added Reader. It is similar to java now. Prometheus will just use Reader while Stackdriver will user IntervalReader and Reader.

Copy link
Copy Markdown
Contributor

@songy23 songy23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}

// Options to configure optional parameters for Reader.
type Options struct {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

// with producer manager and exports those metrics using provided
// exporter.
type Reader struct {
Sampler trace.Sampler
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to export this for the moment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

)

// Exporter is an interface that exporters implement to export the metric data.
type Exporter interface {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this in the metric package and not metricexport?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved.

@rghetia
Copy link
Copy Markdown
Contributor Author

rghetia commented Mar 19, 2019

@bogdandrutu PTAL.

}

ctx := context.Background()
_, span := trace.StartSpan(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to record metrics for this. Not now.

// Reader reads metrics from all producers registered
// with producer manager and exports those metrics using provided
// exporter.
type Reader struct {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably for this we should do a WithOption pattern because does not have a start method.

@rghetia
Copy link
Copy Markdown
Contributor Author

rghetia commented Mar 21, 2019

@bogdandrutu PTAL.

@rghetia rghetia merged commit 5ae9166 into census-instrumentation:master Mar 22, 2019
songy23 pushed a commit that referenced this pull request Apr 3, 2019
* 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)
@rghetia rghetia deleted the reader branch April 15, 2019 20:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants