Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Change ExportMetric api to ExportMetricProto (#106)
Browse files Browse the repository at this point in the history
* Change ExportMetric api to ExportMetricProto

* restrict to name change.

* accept slice of metric
Change the api to ExportMetricsProto to reflect that it accepts more
than one metric.

* fix review comment.
  • Loading branch information
rghetia committed Mar 16, 2019
1 parent e9b8671 commit ed9eca6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 1 addition & 3 deletions equivalence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ func TestEquivalenceStatsVsMetricsUploads(t *testing.T) {
oce.Flush()

ma.forEachRequest(func(emr *agentmetricspb.ExportMetricsServiceRequest) {
for _, metric := range emr.Metrics {
_ = se.ExportMetric(context.Background(), emr.Node, emr.Resource, metric)
}
_ = se.ExportMetricsProto(context.Background(), emr.Node, emr.Resource, emr.Metrics)
})
se.Flush()

Expand Down
18 changes: 10 additions & 8 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,20 @@ type metricPayload struct {
metric *metricspb.Metric
}

// ExportMetric exports OpenCensus Metrics to Stackdriver Monitoring.
func (se *statsExporter) ExportMetric(ctx context.Context, node *commonpb.Node, rsc *resourcepb.Resource, metric *metricspb.Metric) error {
if metric == nil {
// ExportMetricsProto exports OpenCensus Metrics Proto to Stackdriver Monitoring.
func (se *statsExporter) ExportMetricsProto(ctx context.Context, node *commonpb.Node, rsc *resourcepb.Resource, metrics []*metricspb.Metric) error {
if len(metrics) == 0 {
return errNilMetric
}

payload := &metricPayload{
metric: metric,
resource: rsc,
node: node,
for _, metric := range metrics {
payload := &metricPayload{
metric: metric,
resource: rsc,
node: node,
}
se.protoMetricsBundler.Add(payload, 1)
}
se.protoMetricsBundler.Add(payload, 1)

return nil
}
Expand Down
6 changes: 3 additions & 3 deletions stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ func (e *Exporter) ExportView(vd *view.Data) {
e.statsExporter.ExportView(vd)
}

// ExportMetric exports OpenCensus Metrics to Stackdriver Monitoring.
func (e *Exporter) ExportMetric(ctx context.Context, node *commonpb.Node, rsc *resourcepb.Resource, metric *metricspb.Metric) error {
return e.statsExporter.ExportMetric(ctx, node, rsc, metric)
// ExportMetricsProto exports OpenCensus Metrics Proto to Stackdriver Monitoring.
func (e *Exporter) ExportMetricsProto(ctx context.Context, node *commonpb.Node, rsc *resourcepb.Resource, metrics []*metricspb.Metric) error {
return e.statsExporter.ExportMetricsProto(ctx, node, rsc, metrics)
}

// ExportSpan exports a SpanData to Stackdriver Trace.
Expand Down

0 comments on commit ed9eca6

Please sign in to comment.