Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tune testdata, and update testdataold to use same names #1667

Merged
merged 1 commit into from
Aug 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/orijtech/prometheus-go-metrics-exporter v0.0.5
github.com/ory/go-acc v0.2.5
github.com/pavius/impi v0.0.3
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.7.1
github.com/prometheus/common v0.11.1
github.com/prometheus/prometheus v1.8.2-0.20200626085723-c448ada63d83
Expand Down
97 changes: 87 additions & 10 deletions internal/data/testdata/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,15 @@ func GenerateMetricsOneMetricNoLabels() data.MetricData {
md := GenerateMetricsOneMetric()
dps := md.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0).IntSumData().DataPoints()
dps.At(0).LabelsMap().InitFromMap(map[string]string{})
dps.At(1).LabelsMap().InitFromMap(map[string]string{})
return md
}

func generateMetricsOtlpOneMetricNoLabels() []*otlpmetrics.ResourceMetrics {
md := generateMetricsOtlpOneMetric()
mis := md[0].InstrumentationLibraryMetrics[0].Metrics[0].Data.(*otlpmetrics.Metric_IntSum).IntSum
mis.DataPoints[0].Labels = nil
mis.DataPoints[1].Labels = nil
return md
}

Expand Down Expand Up @@ -326,7 +328,7 @@ func GenerateMetricsMetricTypeInvalid() data.MetricData {
ms := ilm0.Metrics()
ms.Resize(1)

initMetric(ms.At(0), TestGaugeDoubleMetricName, pdata.MetricDataNone)
initMetric(ms.At(0), TestCounterIntMetricName, pdata.MetricDataNone)
return md
}

Expand All @@ -350,26 +352,26 @@ func generateMetricsOtlpAllTypesNoDataPoints() []*otlpmetrics.ResourceMetrics {
}
}

func GenerateMetricsWithCountersHistogram() data.MetricData {
func GenerateMetricsWithCountersHistograms() data.MetricData {
metricData := data.NewMetricData()
metricData.ResourceMetrics().Resize(1)

rms := metricData.ResourceMetrics()

rms.At(0).InstrumentationLibraryMetrics().Resize(1)
initResource1(rms.At(0).Resource())
rms.At(0).InstrumentationLibraryMetrics().Resize(1)

ilms := rms.At(0).InstrumentationLibraryMetrics()
ilms.At(0).Metrics().Resize(3)
ilms.At(0).Metrics().Resize(4)
ms := ilms.At(0).Metrics()
initCounterIntMetric(ms.At(0))
initSumDoubleMetric(ms.At(1))
initDoubleHistogramMetric(ms.At(2))
initIntHistogramMetric(ms.At(3))

return metricData
}

func generateMetricsOtlpWithCountersHistogram() []*otlpmetrics.ResourceMetrics {
func generateMetricsOtlpWithCountersHistograms() []*otlpmetrics.ResourceMetrics {
return []*otlpmetrics.ResourceMetrics{
{
Resource: generateOtlpResource1(),
Expand All @@ -379,6 +381,7 @@ func generateMetricsOtlpWithCountersHistogram() []*otlpmetrics.ResourceMetrics {
generateOtlpCounterIntMetric(),
generateOtlpSumDoubleMetric(),
generateOtlpDoubleHistogramMetric(),
generateOtlpIntHistogramMetric(),
},
},
},
Expand Down Expand Up @@ -531,6 +534,64 @@ func generateOtlpDoubleHistogramMetric() *otlpmetrics.Metric {
return m
}

func initIntHistogramMetric(hm pdata.Metric) {
initMetric(hm, TestIntHistogramMetricName, pdata.MetricDataIntHistogram)

hdps := hm.IntHistogramData().DataPoints()
hdps.Resize(2)
hdp0 := hdps.At(0)
initMetricLabels13(hdp0.LabelsMap())
hdp0.SetStartTime(TestMetricStartTimestamp)
hdp0.SetTimestamp(TestMetricTimestamp)
hdp0.SetCount(1)
hdp0.SetSum(15)
hdp1 := hdps.At(1)
initMetricLabels2(hdp1.LabelsMap())
hdp1.SetStartTime(TestMetricStartTimestamp)
hdp1.SetTimestamp(TestMetricTimestamp)
hdp1.SetCount(1)
hdp1.SetSum(15)
hdp1.SetBucketCounts([]uint64{0, 1})
exemplars := hdp1.Exemplars()
exemplars.Resize(1)
exemplar := exemplars.At(0)
exemplar.SetTimestamp(TestMetricExemplarTimestamp)
exemplar.SetValue(15)
initMetricAttachment(exemplar.FilteredLabels())
hdp1.SetExplicitBounds([]float64{1})
}

func generateOtlpIntHistogramMetric() *otlpmetrics.Metric {
m := generateOtlpMetric(TestIntHistogramMetricName, pdata.MetricDataIntHistogram)
m.Data.(*otlpmetrics.Metric_IntHistogram).IntHistogram.DataPoints =
[]*otlpmetrics.IntHistogramDataPoint{
{
Labels: generateOtlpMetricLabels13(),
StartTimeUnixNano: uint64(TestMetricStartTimestamp),
TimeUnixNano: uint64(TestMetricTimestamp),
Count: 1,
Sum: 15,
},
{
Labels: generateOtlpMetricLabels2(),
StartTimeUnixNano: uint64(TestMetricStartTimestamp),
TimeUnixNano: uint64(TestMetricTimestamp),
Count: 1,
Sum: 15,
BucketCounts: []uint64{0, 1},
ExplicitBounds: []float64{1},
Exemplars: []*otlpmetrics.IntExemplar{
{
FilteredLabels: generateOtlpMetricAttachment(),
TimeUnixNano: uint64(TestMetricExemplarTimestamp),
Value: 15,
},
},
},
}
return m
}

func initMetric(m pdata.Metric, name string, ty pdata.MetricDataType) {
m.InitEmpty()
m.SetName(name)
Expand All @@ -548,18 +609,24 @@ func initMetric(m pdata.Metric, name string, ty pdata.MetricDataType) {
case pdata.MetricDataIntSum:
md := pdata.NewIntSum()
md.InitEmpty()
md.SetIsMonotonic(true)
md.SetAggregationTemporality(pdata.AggregationTemporalityCumulative)
m.SetIntSumData(md)
case pdata.MetricDataDoubleSum:
md := pdata.NewDoubleSum()
md.InitEmpty()
md.SetIsMonotonic(true)
md.SetAggregationTemporality(pdata.AggregationTemporalityCumulative)
m.SetDoubleSumData(md)
case pdata.MetricDataIntHistogram:
md := pdata.NewIntHistogram()
md.InitEmpty()
md.SetAggregationTemporality(pdata.AggregationTemporalityCumulative)
m.SetIntHistogramData(md)
case pdata.MetricDataDoubleHistogram:
md := pdata.NewDoubleHistogram()
md.InitEmpty()
md.SetAggregationTemporality(pdata.AggregationTemporalityCumulative)
m.SetDoubleHistogramData(md)
}
}
Expand All @@ -576,13 +643,23 @@ func generateOtlpMetric(name string, ty pdata.MetricDataType) *otlpmetrics.Metri
case pdata.MetricDataDoubleGauge:
m.Data = &otlpmetrics.Metric_DoubleGauge{DoubleGauge: &otlpmetrics.DoubleGauge{}}
case pdata.MetricDataIntSum:
m.Data = &otlpmetrics.Metric_IntSum{IntSum: &otlpmetrics.IntSum{}}
m.Data = &otlpmetrics.Metric_IntSum{IntSum: &otlpmetrics.IntSum{
IsMonotonic: true,
AggregationTemporality: otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
}}
case pdata.MetricDataDoubleSum:
m.Data = &otlpmetrics.Metric_DoubleSum{DoubleSum: &otlpmetrics.DoubleSum{}}
m.Data = &otlpmetrics.Metric_DoubleSum{DoubleSum: &otlpmetrics.DoubleSum{
IsMonotonic: true,
AggregationTemporality: otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
}}
case pdata.MetricDataIntHistogram:
m.Data = &otlpmetrics.Metric_IntHistogram{IntHistogram: &otlpmetrics.IntHistogram{}}
m.Data = &otlpmetrics.Metric_IntHistogram{IntHistogram: &otlpmetrics.IntHistogram{
AggregationTemporality: otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
}}
case pdata.MetricDataDoubleHistogram:
m.Data = &otlpmetrics.Metric_DoubleHistogram{DoubleHistogram: &otlpmetrics.DoubleHistogram{}}
m.Data = &otlpmetrics.Metric_DoubleHistogram{DoubleHistogram: &otlpmetrics.DoubleHistogram{
AggregationTemporality: otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
}}
}
return m
}
Expand Down
4 changes: 2 additions & 2 deletions internal/data/testdata/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func generateAllMetricsTestCases() []traceMetricsCase {
},
{
name: "counters-histogram",
td: GenerateMetricsWithCountersHistogram(),
otlp: generateMetricsOtlpWithCountersHistogram(),
td: GenerateMetricsWithCountersHistograms(),
otlp: generateMetricsOtlpWithCountersHistograms(),
},
}
}
Expand Down
66 changes: 31 additions & 35 deletions internal/dataold/testdataold/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"go.opentelemetry.io/collector/consumer/pdata"
otlpmetrics "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/metrics/v1old"
"go.opentelemetry.io/collector/internal/data/testdata"
"go.opentelemetry.io/collector/internal/dataold"
)

Expand All @@ -34,13 +35,8 @@ var (
)

const (
TestGaugeDoubleMetricName = "gauge-double"
TestGaugeIntMetricName = "gauge-int"
TestCounterDoubleMetricName = "counter-double"
TestCounterIntMetricName = "counter-int"
TestCumulativeHistogramMetricName = "cumulative-histogram"
TestSummaryMetricName = "summary"
NumMetricTests = 14
TestSummaryMetricName = "summary"
NumMetricTests = 14
)

func GenerateMetricDataEmpty() dataold.MetricData {
Expand Down Expand Up @@ -257,15 +253,15 @@ func GenerateMetricDataAllTypesNoDataPoints() dataold.MetricData {
ms := ilm0.Metrics()
ms.Resize(6)
initMetricDescriptor(
ms.At(0).MetricDescriptor(), TestGaugeDoubleMetricName, dataold.MetricTypeDouble)
ms.At(0).MetricDescriptor(), testdata.TestGaugeDoubleMetricName, dataold.MetricTypeDouble)
initMetricDescriptor(
ms.At(1).MetricDescriptor(), TestGaugeIntMetricName, dataold.MetricTypeInt64)
ms.At(1).MetricDescriptor(), testdata.TestGaugeIntMetricName, dataold.MetricTypeInt64)
initMetricDescriptor(
ms.At(2).MetricDescriptor(), TestCounterDoubleMetricName, dataold.MetricTypeMonotonicDouble)
ms.At(2).MetricDescriptor(), testdata.TestCounterDoubleMetricName, dataold.MetricTypeMonotonicDouble)
initMetricDescriptor(
ms.At(3).MetricDescriptor(), TestCounterIntMetricName, dataold.MetricTypeMonotonicInt64)
ms.At(3).MetricDescriptor(), testdata.TestCounterIntMetricName, dataold.MetricTypeMonotonicInt64)
initMetricDescriptor(
ms.At(4).MetricDescriptor(), TestCumulativeHistogramMetricName, dataold.MetricTypeHistogram)
ms.At(4).MetricDescriptor(), testdata.TestDoubleHistogramMetricName, dataold.MetricTypeHistogram)
initMetricDescriptor(
ms.At(5).MetricDescriptor(), TestSummaryMetricName, dataold.MetricTypeSummary)
return md
Expand All @@ -283,19 +279,19 @@ func GenerateMetricDataAllTypesNilDataPoint() dataold.MetricData {
nilSummary := dataold.NewSummaryDataPoint()

initMetricDescriptor(
ms.At(0).MetricDescriptor(), TestGaugeDoubleMetricName, dataold.MetricTypeDouble)
ms.At(0).MetricDescriptor(), testdata.TestGaugeDoubleMetricName, dataold.MetricTypeDouble)
ms.At(0).DoubleDataPoints().Append(&nilDouble)
initMetricDescriptor(
ms.At(1).MetricDescriptor(), TestGaugeIntMetricName, dataold.MetricTypeInt64)
ms.At(1).MetricDescriptor(), testdata.TestGaugeIntMetricName, dataold.MetricTypeInt64)
ms.At(1).Int64DataPoints().Append(&nilInt64)
initMetricDescriptor(
ms.At(2).MetricDescriptor(), TestCounterDoubleMetricName, dataold.MetricTypeMonotonicDouble)
ms.At(2).MetricDescriptor(), testdata.TestCounterDoubleMetricName, dataold.MetricTypeMonotonicDouble)
ms.At(2).DoubleDataPoints().Append(&nilDouble)
initMetricDescriptor(
ms.At(3).MetricDescriptor(), TestCounterIntMetricName, dataold.MetricTypeMonotonicInt64)
ms.At(3).MetricDescriptor(), testdata.TestCounterIntMetricName, dataold.MetricTypeMonotonicInt64)
ms.At(3).Int64DataPoints().Append(&nilInt64)
initMetricDescriptor(
ms.At(4).MetricDescriptor(), TestCumulativeHistogramMetricName, dataold.MetricTypeHistogram)
ms.At(4).MetricDescriptor(), testdata.TestDoubleHistogramMetricName, dataold.MetricTypeHistogram)
ms.At(4).HistogramDataPoints().Append(&nilHistogram)
initMetricDescriptor(
ms.At(5).MetricDescriptor(), TestSummaryMetricName, dataold.MetricTypeSummary)
Expand All @@ -319,19 +315,19 @@ func GenerateMetricDataAllTypesEmptyDataPoint() dataold.MetricData {
emptySummary.InitEmpty()

initMetricDescriptor(
ms.At(0).MetricDescriptor(), TestGaugeDoubleMetricName, dataold.MetricTypeDouble)
ms.At(0).MetricDescriptor(), testdata.TestGaugeDoubleMetricName, dataold.MetricTypeDouble)
ms.At(0).DoubleDataPoints().Append(&emptyDouble)
initMetricDescriptor(
ms.At(1).MetricDescriptor(), TestGaugeIntMetricName, dataold.MetricTypeInt64)
ms.At(1).MetricDescriptor(), testdata.TestGaugeIntMetricName, dataold.MetricTypeInt64)
ms.At(1).Int64DataPoints().Append(&emptyInt64)
initMetricDescriptor(
ms.At(2).MetricDescriptor(), TestCounterDoubleMetricName, dataold.MetricTypeMonotonicDouble)
ms.At(2).MetricDescriptor(), testdata.TestCounterDoubleMetricName, dataold.MetricTypeMonotonicDouble)
ms.At(2).DoubleDataPoints().Append(&emptyDouble)
initMetricDescriptor(
ms.At(3).MetricDescriptor(), TestCounterIntMetricName, dataold.MetricTypeMonotonicInt64)
ms.At(3).MetricDescriptor(), testdata.TestCounterIntMetricName, dataold.MetricTypeMonotonicInt64)
ms.At(3).Int64DataPoints().Append(&emptyInt64)
initMetricDescriptor(
ms.At(4).MetricDescriptor(), TestCumulativeHistogramMetricName, dataold.MetricTypeHistogram)
ms.At(4).MetricDescriptor(), testdata.TestDoubleHistogramMetricName, dataold.MetricTypeHistogram)
ms.At(4).HistogramDataPoints().Append(&emptyHistogram)
initMetricDescriptor(
ms.At(5).MetricDescriptor(), TestSummaryMetricName, dataold.MetricTypeSummary)
Expand All @@ -354,7 +350,7 @@ func GenerateMetricDataMetricTypeInvalid() dataold.MetricData {
ms.Resize(1)

initMetricDescriptor(
ms.At(0).MetricDescriptor(), TestGaugeDoubleMetricName, dataold.MetricTypeInvalid)
ms.At(0).MetricDescriptor(), testdata.TestGaugeDoubleMetricName, dataold.MetricTypeInvalid)
return md
}

Expand All @@ -366,19 +362,19 @@ func generateMetricOtlpAllTypesNoDataPoints() []*otlpmetrics.ResourceMetrics {
{
Metrics: []*otlpmetrics.Metric{
{
MetricDescriptor: generateOtlpMetricDescriptor(TestGaugeDoubleMetricName, dataold.MetricTypeDouble),
MetricDescriptor: generateOtlpMetricDescriptor(testdata.TestGaugeDoubleMetricName, dataold.MetricTypeDouble),
},
{
MetricDescriptor: generateOtlpMetricDescriptor(TestGaugeIntMetricName, dataold.MetricTypeInt64),
MetricDescriptor: generateOtlpMetricDescriptor(testdata.TestGaugeIntMetricName, dataold.MetricTypeInt64),
},
{
MetricDescriptor: generateOtlpMetricDescriptor(TestCounterDoubleMetricName, dataold.MetricTypeMonotonicDouble),
MetricDescriptor: generateOtlpMetricDescriptor(testdata.TestCounterDoubleMetricName, dataold.MetricTypeMonotonicDouble),
},
{
MetricDescriptor: generateOtlpMetricDescriptor(TestCounterIntMetricName, dataold.MetricTypeMonotonicInt64),
MetricDescriptor: generateOtlpMetricDescriptor(testdata.TestCounterIntMetricName, dataold.MetricTypeMonotonicInt64),
},
{
MetricDescriptor: generateOtlpMetricDescriptor(TestCumulativeHistogramMetricName, dataold.MetricTypeHistogram),
MetricDescriptor: generateOtlpMetricDescriptor(testdata.TestDoubleHistogramMetricName, dataold.MetricTypeHistogram),
},
{
MetricDescriptor: generateOtlpMetricDescriptor(TestSummaryMetricName, dataold.MetricTypeSummary),
Expand Down Expand Up @@ -429,7 +425,7 @@ func generateMetricOtlpWithCountersHistogramAndSummary() []*otlpmetrics.Resource
}

func initCounterIntMetric(im dataold.Metric) {
initMetricDescriptor(im.MetricDescriptor(), TestCounterIntMetricName, dataold.MetricTypeMonotonicInt64)
initMetricDescriptor(im.MetricDescriptor(), testdata.TestCounterIntMetricName, dataold.MetricTypeMonotonicInt64)

idps := im.Int64DataPoints()
idps.Resize(2)
Expand All @@ -446,7 +442,7 @@ func initCounterIntMetric(im dataold.Metric) {
}

func initGaugeIntMetricOneDataPoint(im dataold.Metric) {
initMetricDescriptor(im.MetricDescriptor(), TestCounterIntMetricName, dataold.MetricTypeInt64)
initMetricDescriptor(im.MetricDescriptor(), testdata.TestCounterIntMetricName, dataold.MetricTypeInt64)
idps := im.Int64DataPoints()
idps.Resize(1)
idp0 := idps.At(0)
Expand All @@ -458,7 +454,7 @@ func initGaugeIntMetricOneDataPoint(im dataold.Metric) {

func generateOtlpCounterIntMetric() *otlpmetrics.Metric {
return &otlpmetrics.Metric{
MetricDescriptor: generateOtlpMetricDescriptor(TestCounterIntMetricName, dataold.MetricTypeMonotonicInt64),
MetricDescriptor: generateOtlpMetricDescriptor(testdata.TestCounterIntMetricName, dataold.MetricTypeMonotonicInt64),
Int64DataPoints: []*otlpmetrics.Int64DataPoint{
{
Labels: generateOtlpMetricLabels1(),
Expand All @@ -477,7 +473,7 @@ func generateOtlpCounterIntMetric() *otlpmetrics.Metric {
}

func initCounterDoubleMetric(dm dataold.Metric) {
initMetricDescriptor(dm.MetricDescriptor(), TestCounterDoubleMetricName, dataold.MetricTypeMonotonicDouble)
initMetricDescriptor(dm.MetricDescriptor(), testdata.TestCounterDoubleMetricName, dataold.MetricTypeMonotonicDouble)

ddps := dm.DoubleDataPoints()
ddps.Resize(2)
Expand All @@ -497,7 +493,7 @@ func initCounterDoubleMetric(dm dataold.Metric) {

func generateOtlpCounterDoubleMetric() *otlpmetrics.Metric {
return &otlpmetrics.Metric{
MetricDescriptor: generateOtlpMetricDescriptor(TestCounterDoubleMetricName, dataold.MetricTypeMonotonicDouble),
MetricDescriptor: generateOtlpMetricDescriptor(testdata.TestCounterDoubleMetricName, dataold.MetricTypeMonotonicDouble),
DoubleDataPoints: []*otlpmetrics.DoubleDataPoint{
{
Labels: generateOtlpMetricLabels12(),
Expand All @@ -516,7 +512,7 @@ func generateOtlpCounterDoubleMetric() *otlpmetrics.Metric {
}

func initCumulativeHistogramMetric(hm dataold.Metric) {
initMetricDescriptor(hm.MetricDescriptor(), TestCumulativeHistogramMetricName, dataold.MetricTypeHistogram)
initMetricDescriptor(hm.MetricDescriptor(), testdata.TestDoubleHistogramMetricName, dataold.MetricTypeHistogram)

hdps := hm.HistogramDataPoints()
hdps.Resize(2)
Expand Down Expand Up @@ -545,7 +541,7 @@ func initCumulativeHistogramMetric(hm dataold.Metric) {

func generateOtlpCumulativeHistogramMetric() *otlpmetrics.Metric {
return &otlpmetrics.Metric{
MetricDescriptor: generateOtlpMetricDescriptor(TestCumulativeHistogramMetricName, dataold.MetricTypeHistogram),
MetricDescriptor: generateOtlpMetricDescriptor(testdata.TestDoubleHistogramMetricName, dataold.MetricTypeHistogram),
HistogramDataPoints: []*otlpmetrics.HistogramDataPoint{
{
Labels: generateOtlpMetricLabels13(),
Expand Down
Loading