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

stats worker as metric producer. #1078

Merged

Conversation

rghetia
Copy link
Contributor

@rghetia rghetia commented Mar 22, 2019

This change provides stats data (view data model) as metric data. Stats worker registers as a metric producer with global producer manager. Read() function is then invoked by Readers.

@rghetia rghetia requested review from rakyll and a team as code owners March 22, 2019 20:34

func rowToTimeseries(row *Row, now time.Time, startTime time.Time) *metricdata.TimeSeries {
return &metricdata.TimeSeries{
Points: []metricdata.Point{row.Data.toPoint(now)},
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to convert metric types here. For example SumData is always converted to Float64 point: https://github.com/census-instrumentation/opencensus-go/pull/1078/files#diff-a282032fe900298505848fd4d08399a2R96. But when measure is of type Int64Measure, metric type will be CumulativeInt64: https://github.com/census-instrumentation/opencensus-go/pull/1078/files#diff-0ac84b9d221fc10ebe99482beb04a4fbR45. This will be an error since the type of point doesn't match with metric type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.
comparing serialized version made the test pass incorrectly. Removed the serialized comparision.

… type.

fixed test. Specifically removed json comparision.
@rghetia
Copy link
Contributor Author

rghetia commented Mar 25, 2019

@songy23 PTAL.

case metricdata.TypeCumulativeInt64:
return metricdata.NewInt64Point(t, a.Value)
case metricdata.TypeCumulativeFloat64:
return metricdata.NewFloat64Point(t, float64(a.Value))
Copy link
Contributor

Choose a reason for hiding this comment

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

Count should always be Int64.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

case "By":
return metricdata.UnitBytes
}
return metricdata.UnitDimensionless
Copy link
Contributor

Choose a reason for hiding this comment

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

Why convert all other units to "1"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll open a new PR to fix this.

stats/view/view_to_metric.go Show resolved Hide resolved
stats/view/view_to_metric.go Show resolved Hide resolved
stats/view/view_to_metric.go Show resolved Hide resolved
stats/view/view_to_metric.go Show resolved Hide resolved
@rghetia
Copy link
Contributor Author

rghetia commented Mar 26, 2019

@songy23 PTAL

Copy link
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 overall

@@ -208,6 +229,26 @@ func (a *DistributionData) equal(other AggregationData) bool {
return a.Count == a2.Count && a.Min == a2.Min && a.Max == a2.Max && math.Pow(a.Mean-a2.Mean, 2) < epsilon && math.Pow(a.variance()-a2.variance(), 2) < epsilon
}

func (a *DistributionData) toPoint(metricType metricdata.Type, t time.Time) metricdata.Point {
buckets := []metricdata.Bucket{}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you can also check metricType here (expect to be cumulative distribution).


gotMetric := viewToMetric(tc.vi, now, startTime)
if !reflect.DeepEqual(gotMetric, tc.wantMetric) {
// JSON format is strictly for checking the content when test fails. Do not use JSON
Copy link
Contributor

Choose a reason for hiding this comment

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

Also replaced reflect.DeepEqual with cmp.Equal
@rghetia rghetia merged commit ec71c97 into census-instrumentation:master Mar 27, 2019
songy23 pushed a commit that referenced this pull request Apr 3, 2019
* stats worker as metric producer.

* fixed the conversion based on measure type in addition to aggregation type.
fixed test. Specifically removed json comparision.

* fixed review comments related to count float64.

* add check for metricType in toPoint func for distribution
Also replaced reflect.DeepEqual with cmp.Equal

(cherry picked from commit ec71c97)
@rghetia rghetia deleted the view_as_metric_producer 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.

2 participants