Skip to content

Commit

Permalink
Move MetricsData to internaldata
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu committed Feb 25, 2021
1 parent e6319ac commit 0ad48eb
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 78 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## 🛑 Breaking changes 🛑

- Remove `consumerdata.TraceData` (#2551)
- Move `consumerdata.MetricsData` to `internaldata.MetricsData` (#2512)

## v0.21.0 Beta

Expand Down
5 changes: 2 additions & 3 deletions exporter/prometheusexporter/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer/consumerdata"
"go.opentelemetry.io/collector/translator/internaldata"
)

Expand Down Expand Up @@ -101,7 +100,7 @@ func TestPrometheusExporter_endToEnd(t *testing.T) {
assert.NotNil(t, exp)

for delta := 0; delta <= 20; delta += 10 {
md := internaldata.OCToMetrics(consumerdata.MetricsData{Metrics: metricBuilder(int64(delta))})
md := internaldata.OCToMetrics(internaldata.MetricsData{Metrics: metricBuilder(int64(delta))})
assert.NoError(t, exp.ConsumeMetrics(context.Background(), md))

res, err := http.Get("http://localhost:7777/metrics")
Expand Down Expand Up @@ -152,7 +151,7 @@ func TestPrometheusExporter_endToEndWithTimestamps(t *testing.T) {
assert.NotNil(t, exp)

for delta := 0; delta <= 20; delta += 10 {
md := internaldata.OCToMetrics(consumerdata.MetricsData{Metrics: metricBuilder(int64(delta))})
md := internaldata.OCToMetrics(internaldata.MetricsData{Metrics: metricBuilder(int64(delta))})
assert.NoError(t, exp.ConsumeMetrics(context.Background(), md))

res, err := http.Get("http://localhost:7777/metrics")
Expand Down
5 changes: 2 additions & 3 deletions processor/filterprocessor/filter_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/consumer/consumerdata"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/internal/goldendataset"
Expand Down Expand Up @@ -333,9 +332,9 @@ func TestFilterMetricProcessor(t *testing.T) {
ctx := context.Background()
assert.NoError(t, fmp.Start(ctx, nil))

mds := make([]consumerdata.MetricsData, len(test.inMN))
mds := make([]internaldata.MetricsData, len(test.inMN))
for i, metrics := range test.inMN {
mds[i] = consumerdata.MetricsData{
mds[i] = internaldata.MetricsData{
Metrics: metrics,
}
}
Expand Down
5 changes: 2 additions & 3 deletions receiver/opencensusreceiver/ocmetrics/opencensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/consumer/consumerdata"
"go.opentelemetry.io/collector/obsreport"
"go.opentelemetry.io/collector/translator/internaldata"
)
Expand Down Expand Up @@ -117,7 +116,7 @@ func (ocr *Receiver) processReceivedMsg(
resource = recv.Resource
}

md := consumerdata.MetricsData{
md := internaldata.MetricsData{
Node: lastNonNilNode,
Resource: resource,
Metrics: recv.Metrics,
Expand All @@ -127,7 +126,7 @@ func (ocr *Receiver) processReceivedMsg(
return lastNonNilNode, resource, err
}

func (ocr *Receiver) sendToNextConsumer(longLivedRPCCtx context.Context, md consumerdata.MetricsData) error {
func (ocr *Receiver) sendToNextConsumer(longLivedRPCCtx context.Context, md internaldata.MetricsData) error {
ctx := obsreport.StartMetricsReceiveOp(
longLivedRPCCtx,
ocr.instanceName,
Expand Down
3 changes: 1 addition & 2 deletions receiver/prometheusreceiver/internal/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"

"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/consumer/consumerdata"
"go.opentelemetry.io/collector/obsreport"
"go.opentelemetry.io/collector/translator/internaldata"
)
Expand Down Expand Up @@ -176,7 +175,7 @@ func (tr *transaction) Commit() error {

numPoints := 0
if len(metrics) > 0 {
md := internaldata.OCToMetrics(consumerdata.MetricsData{
md := internaldata.OCToMetrics(internaldata.MetricsData{
Node: tr.node,
Resource: tr.resource,
Metrics: metrics,
Expand Down
33 changes: 16 additions & 17 deletions receiver/prometheusreceiver/metrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
"gopkg.in/yaml.v2"

"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumerdata"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/translator/internaldata"
)
Expand Down Expand Up @@ -111,7 +110,7 @@ type testData struct {
pages []mockPrometheusResponse
node *commonpb.Node
resource *resourcepb.Resource
validateFunc func(t *testing.T, td *testData, result []consumerdata.MetricsData)
validateFunc func(t *testing.T, td *testData, result []internaldata.MetricsData)
}

// setupMockPrometheus to create a mocked prometheus based on targets, returning the server and a prometheus exporting
Expand Down Expand Up @@ -167,7 +166,7 @@ func setupMockPrometheus(tds ...*testData) (*mockPrometheus, *promcfg.Config, er
return mp, pCfg, err
}

func verifyNumScrapeResults(t *testing.T, td *testData, mds []consumerdata.MetricsData) {
func verifyNumScrapeResults(t *testing.T, td *testData, mds []internaldata.MetricsData) {
want := 0
for _, p := range td.pages {
if p.code == 200 {
Expand Down Expand Up @@ -248,7 +247,7 @@ rpc_duration_seconds_sum 5002
rpc_duration_seconds_count 1001
`

func verifyTarget1(t *testing.T, td *testData, mds []consumerdata.MetricsData) {
func verifyTarget1(t *testing.T, td *testData, mds []internaldata.MetricsData) {
verifyNumScrapeResults(t, td, mds)
m1 := mds[0]
// m1 shall only have a gauge
Expand Down Expand Up @@ -282,7 +281,7 @@ func verifyTarget1(t *testing.T, td *testData, mds []consumerdata.MetricsData) {
m2 := mds[1]
ts2 := m2.Metrics[0].Timeseries[0].Points[0].Timestamp

want2 := &consumerdata.MetricsData{
want2 := &internaldata.MetricsData{
Node: td.node,
Resource: td.resource,
Metrics: []*metricspb.Metric{
Expand Down Expand Up @@ -475,7 +474,7 @@ http_requests_total{method="post",code="400"} 59
http_requests_total{method="post",code="500"} 5
`

func verifyTarget2(t *testing.T, td *testData, mds []consumerdata.MetricsData) {
func verifyTarget2(t *testing.T, td *testData, mds []internaldata.MetricsData) {
verifyNumScrapeResults(t, td, mds)
m1 := mds[0]
// m1 shall only have a gauge
Expand Down Expand Up @@ -508,7 +507,7 @@ func verifyTarget2(t *testing.T, td *testData, mds []consumerdata.MetricsData) {
m2 := mds[1]
ts2 := m2.Metrics[0].Timeseries[0].Points[0].Timestamp

want2 := &consumerdata.MetricsData{
want2 := &internaldata.MetricsData{
Node: td.node,
Resource: td.resource,
Metrics: []*metricspb.Metric{
Expand Down Expand Up @@ -565,7 +564,7 @@ func verifyTarget2(t *testing.T, td *testData, mds []consumerdata.MetricsData) {
// its start timestamp shall be from the 2nd run
ts3 := m3.Metrics[0].Timeseries[0].Points[0].Timestamp

want3 := &consumerdata.MetricsData{
want3 := &internaldata.MetricsData{
Node: td.node,
Resource: td.resource,
Metrics: []*metricspb.Metric{
Expand Down Expand Up @@ -631,7 +630,7 @@ func verifyTarget2(t *testing.T, td *testData, mds []consumerdata.MetricsData) {
m4 := mds[3]
ts4 := m4.Metrics[0].Timeseries[0].Points[0].Timestamp

want4 := &consumerdata.MetricsData{
want4 := &internaldata.MetricsData{
Node: td.node,
Resource: td.resource,
Metrics: []*metricspb.Metric{
Expand All @@ -658,7 +657,7 @@ func verifyTarget2(t *testing.T, td *testData, mds []consumerdata.MetricsData) {
// its start timestamp shall be from the 3rd run
ts5 := m5.Metrics[0].Timeseries[0].Points[0].Timestamp

want5 := &consumerdata.MetricsData{
want5 := &internaldata.MetricsData{
Node: td.node,
Resource: td.resource,
Metrics: []*metricspb.Metric{
Expand Down Expand Up @@ -793,7 +792,7 @@ rpc_duration_seconds_sum{foo="no_quantile"} 101
rpc_duration_seconds_count{foo="no_quantile"} 55
`

func verifyTarget3(t *testing.T, td *testData, mds []consumerdata.MetricsData) {
func verifyTarget3(t *testing.T, td *testData, mds []internaldata.MetricsData) {
verifyNumScrapeResults(t, td, mds)
m1 := mds[0]
// m1 shall only have a gauge
Expand Down Expand Up @@ -825,7 +824,7 @@ func verifyTarget3(t *testing.T, td *testData, mds []consumerdata.MetricsData) {
m2 := mds[1]
ts2 := m2.Metrics[0].Timeseries[0].Points[0].Timestamp

want2 := &consumerdata.MetricsData{
want2 := &internaldata.MetricsData{
Node: td.node,
Resource: td.resource,
Metrics: []*metricspb.Metric{
Expand Down Expand Up @@ -1025,7 +1024,7 @@ var startTimeMetricPageStartTimestamp = &timestamppb.Timestamp{Seconds: 400, Nan

const numStartTimeMetricPageTimeseries = 6

func verifyStartTimeMetricPage(t *testing.T, _ *testData, mds []consumerdata.MetricsData) {
func verifyStartTimeMetricPage(t *testing.T, _ *testData, mds []internaldata.MetricsData) {
numTimeseries := 0
for _, cmd := range mds {
for _, metric := range cmd.Metrics {
Expand Down Expand Up @@ -1074,13 +1073,13 @@ func testEndToEnd(t *testing.T, targets []*testData, useStartTimeMetric bool) {
metrics := cms.AllMetrics()

// split and store results by target name
results := make(map[string][]consumerdata.MetricsData)
results := make(map[string][]internaldata.MetricsData)
for _, m := range metrics {
ocmds := internaldata.MetricsToOC(m)
for _, ocmd := range ocmds {
result, ok := results[ocmd.Node.ServiceInfo.Name]
if !ok {
result = make([]consumerdata.MetricsData, 0)
result = make([]internaldata.MetricsData, 0)
}
results[ocmd.Node.ServiceInfo.Name] = append(result, ocmd)
}
Expand Down Expand Up @@ -1161,13 +1160,13 @@ func testEndToEndRegex(t *testing.T, targets []*testData, useStartTimeMetric boo
metrics := cms.AllMetrics()

// split and store results by target name
results := make(map[string][]consumerdata.MetricsData)
results := make(map[string][]internaldata.MetricsData)
for _, m := range metrics {
ocmds := internaldata.MetricsToOC(m)
for _, ocmd := range ocmds {
result, ok := results[ocmd.Node.ServiceInfo.Name]
if !ok {
result = make([]consumerdata.MetricsData, 0)
result = make([]internaldata.MetricsData, 0)
}
results[ocmd.Node.ServiceInfo.Name] = append(result, ocmd)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package consumerdata contains data structures that holds proto metrics/spans, node and resource.
package consumerdata
package internaldata

import (
commonpb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1"
Expand Down
9 changes: 4 additions & 5 deletions translator/internaldata/metrics_to_oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
ocmetrics "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1"
"github.com/golang/protobuf/ptypes/wrappers"

"go.opentelemetry.io/collector/consumer/consumerdata"
"go.opentelemetry.io/collector/consumer/pdata"
)

Expand All @@ -34,23 +33,23 @@ type labelKeys struct {

// MetricsToOC may be used only by OpenCensus receiver and exporter implementations.
// TODO: move this function to OpenCensus package.
func MetricsToOC(md pdata.Metrics) []consumerdata.MetricsData {
func MetricsToOC(md pdata.Metrics) []MetricsData {
resourceMetrics := md.ResourceMetrics()

if resourceMetrics.Len() == 0 {
return nil
}

ocResourceMetricsList := make([]consumerdata.MetricsData, 0, resourceMetrics.Len())
ocResourceMetricsList := make([]MetricsData, 0, resourceMetrics.Len())
for i := 0; i < resourceMetrics.Len(); i++ {
ocResourceMetricsList = append(ocResourceMetricsList, resourceMetricsToOC(resourceMetrics.At(i)))
}

return ocResourceMetricsList
}

func resourceMetricsToOC(rm pdata.ResourceMetrics) consumerdata.MetricsData {
ocMetricsData := consumerdata.MetricsData{}
func resourceMetricsToOC(rm pdata.ResourceMetrics) MetricsData {
ocMetricsData := MetricsData{}
ocMetricsData.Node, ocMetricsData.Resource = internalResourceToOC(rm.Resource())
ilms := rm.InstrumentationLibraryMetrics()
if ilms.Len() == 0 {
Expand Down
Loading

0 comments on commit 0ad48eb

Please sign in to comment.