Skip to content

Commit

Permalink
generate one metric data point when generating data
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Feb 17, 2024
1 parent 0e31a69 commit 392cde1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
22 changes: 21 additions & 1 deletion receiver/receivertest/contract_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,28 +507,48 @@ func CreateOneLogWithID(id UniqueIDAttrVal) plog.Logs {
return data
}

func CreateEveryMetricTypeWithID(id UniqueIDAttrVal) pmetric.Metrics {
func CreateGaugeMetricWithID(id UniqueIDAttrVal) pmetric.Metrics {
data := pmetric.NewMetrics()
gauge := data.ResourceMetrics().AppendEmpty().ScopeMetrics().AppendEmpty().Metrics()
gauge.AppendEmpty().SetEmptyGauge().DataPoints().AppendEmpty().Attributes().PutStr(
UniqueIDAttrName,
string(id),
)
return data
}

func CreateSumMetricWithID(id UniqueIDAttrVal) pmetric.Metrics {
data := pmetric.NewMetrics()
sum := data.ResourceMetrics().AppendEmpty().ScopeMetrics().AppendEmpty().Metrics()
sum.AppendEmpty().SetEmptySum().DataPoints().AppendEmpty().Attributes().PutStr(
UniqueIDAttrName,
string(id),
)
return data
}

func CreateSummaryMetricWithID(id UniqueIDAttrVal) pmetric.Metrics {
data := pmetric.NewMetrics()
summary := data.ResourceMetrics().AppendEmpty().ScopeMetrics().AppendEmpty().Metrics()
summary.AppendEmpty().SetEmptySummary().DataPoints().AppendEmpty().Attributes().PutStr(
UniqueIDAttrName,
string(id),
)
return data
}

func CreateHistogramMetricWithID(id UniqueIDAttrVal) pmetric.Metrics {
data := pmetric.NewMetrics()
histogram := data.ResourceMetrics().AppendEmpty().ScopeMetrics().AppendEmpty().Metrics()
histogram.AppendEmpty().SetEmptyHistogram().DataPoints().AppendEmpty().Attributes().PutStr(
UniqueIDAttrName,
string(id),
)
return data
}

func CreateExponentialHistogramMetricWithID(id UniqueIDAttrVal) pmetric.Metrics {
data := pmetric.NewMetrics()
exponentialHistogram := data.ResourceMetrics().AppendEmpty().ScopeMetrics().AppendEmpty().Metrics()
exponentialHistogram.AppendEmpty().SetEmptyExponentialHistogram().DataPoints().AppendEmpty().Attributes().PutStr(
UniqueIDAttrName,
Expand Down
14 changes: 13 additions & 1 deletion receiver/receivertest/contract_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,19 @@ func (g *exampleMetricGenerator) Generate() []UniqueIDAttrVal {
// Make sure the id is atomically incremented. Generate() may be called concurrently.
id := UniqueIDAttrVal(strconv.FormatInt(atomic.AddInt64(&g.sequenceNum, 1), 10))

data := CreateEveryMetricTypeWithID(id)
var data pmetric.Metrics
switch g.sequenceNum % 5 {
case 0:
data = CreateGaugeMetricWithID(id)
case 1:
data = CreateSumMetricWithID(id)
case 2:
data = CreateSummaryMetricWithID(id)
case 3:
data = CreateHistogramMetricWithID(id)
case 4:
data = CreateExponentialHistogramMetricWithID(id)
}

// Send the generated data to the receiver.
g.receiver.ReceiveMetrics(data)
Expand Down

0 comments on commit 392cde1

Please sign in to comment.