Skip to content

Commit

Permalink
Implement Conversion Between OC and OTel Summary Metric (#2048)
Browse files Browse the repository at this point in the history
_Note:_ This PR is based off the Summary datapoint proto (that has not been merged upstream) in this [PR](https:/open-telemetry/opentelemetry-proto/pull/227/files).

**Description:** 

This PR has two main parts: 

* Implement the [Summary datapoint proto](https:/open-telemetry/opentelemetry-proto/pull/227/files) in the OTel Collector. Changes were made to _metrics_struct.go_ to create the generated Summary structs (using the `make genproto` and `make genpdata` commands).
* Add in the conversion between OpenCensus summary metrics and OTel Summary datapoints. This conversion directly adds compatibility for the Prometheus Summary metric in the PrometheusReceiver. 

**Link to tracking Issue:** [opentelemetry-specification/issues/1146](open-telemetry/opentelemetry-specification#1146) and [opentelemetry-collector/issues/1638](#1638)

A lot of the code in this PR is auto-generated from creating the structs and protos. The following files are were auto-generated:
* generated_metrics.go
* generated_metrics_test.go
* trace_config.pb.go 
* metrics.pg.go

**Testing:**

* Updated unit tests in _oc_to_metrics.go_ for conversion between OC summary metrics to OTel summary metrics
* Created end-to-end tests for the Summary metric in PrometheusReceiver
  • Loading branch information
Jason Liu authored Nov 6, 2020
1 parent 2ab1de6 commit 0c44bc2
Show file tree
Hide file tree
Showing 16 changed files with 2,369 additions and 157 deletions.
64 changes: 64 additions & 0 deletions cmd/pdatagen/internal/metrics_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var metricsFile = &File{
doubleSum,
intHistogram,
doubleHistogram,
doubleSummary,
intDataPointSlice,
intDataPoint,
doubleDataPointSlice,
Expand All @@ -47,6 +48,10 @@ var metricsFile = &File{
intHistogramDataPoint,
doubleHistogramDataPointSlice,
doubleHistogramDataPoint,
doubleSummaryDataPointSlice,
doubleSummaryDataPoint,
quantileValuesSlice,
quantileValues,
intExemplarSlice,
intExemplar,
doubleExemplarSlice,
Expand Down Expand Up @@ -206,6 +211,19 @@ var doubleHistogram = &messageStruct{
},
}

var doubleSummary = &messageStruct{
structName: "DoubleSummary",
description: "// DoubleSummary represents the type of a metric that is calculated by aggregating as a Summary of all reported double measurements over a time interval.",
originFullName: "otlpmetrics.DoubleSummary",
fields: []baseField{
&sliceField{
fieldName: "DataPoints",
originFieldName: "DataPoints",
returnSlice: doubleSummaryDataPointSlice,
},
},
}

var intDataPointSlice = &sliceStruct{
structName: "IntDataPointSlice",
element: intDataPoint,
Expand Down Expand Up @@ -284,6 +302,44 @@ var doubleHistogramDataPoint = &messageStruct{
},
}

var doubleSummaryDataPointSlice = &sliceStruct{
structName: "DoubleSummaryDataPointSlice",
element: doubleSummaryDataPoint,
}

var doubleSummaryDataPoint = &messageStruct{
structName: "DoubleSummaryDataPoint",
description: "// DoubleSummaryDataPoint is a single data point in a timeseries that describes the time-varying values of a Summary of double values.",
originFullName: "otlpmetrics.DoubleSummaryDataPoint",
fields: []baseField{
labelsField,
startTimeField,
timeField,
countField,
doubleSumField,
&sliceField{
fieldName: "QuantileValues",
originFieldName: "QuantileValues",
returnSlice: quantileValuesSlice,
},
},
}

var quantileValuesSlice = &sliceStruct{
structName: "ValueAtQuantileSlice",
element: quantileValues,
}

var quantileValues = &messageStruct{
structName: "ValueAtQuantile",
description: "// ValueAtQuantile is a quantile value within a Summary data point",
originFullName: "otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile",
fields: []baseField{
quantileField,
valueFloat64Field,
},
}

var intExemplarSlice = &sliceStruct{
structName: "IntExemplarSlice",
element: intExemplar,
Expand Down Expand Up @@ -404,6 +460,14 @@ var explicitBoundsField = &primitiveField{
testVal: "[]float64{1, 2, 3}",
}

var quantileField = &primitiveField{
fieldName: "Quantile",
originFieldName: "Quantile",
returnType: "float64",
defaultVal: "float64(0.0)",
testVal: "float64(17.13)",
}

var isMonotonicField = &primitiveField{
fieldName: "IsMonotonic",
originFieldName: "IsMonotonic",
Expand Down
Loading

0 comments on commit 0c44bc2

Please sign in to comment.