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

[exporter/loadbalancing] allow metrics routing #26378

Merged
merged 20 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
split metrics in batches
  • Loading branch information
claudiobastos committed Sep 1, 2023
commit 4ee2e3b7e0dc187883476499c2f568f135f8ede0
12 changes: 6 additions & 6 deletions pkg/batchpersignal/batchpersignal.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,28 +115,28 @@ func SplitMetrics(batch pmetric.Metrics) []pmetric.Metrics {

for j := 0; j < rs.ScopeMetrics().Len(); j++ {
// the batches for this ILS
batches := map[pcommon.ByteSlice]pmetric.ResourceMetrics{}
batches := map[string]pmetric.ResourceMetrics{}

ils := rs.ScopeMetrics().At(j)
for k := 0; k < ils.Metrics().Len(); k++ {
metric := ils.Metrics().At(k)

key := pcommon.NewByteSlice()
key.FromRaw([]byte(metric.Name()))
// key := pcommon.NewByteSlice()
// key.FromRaw([]byte(metric.Name()))
key := metric.Name()

// for the first metric in the ILS, initialize the map entry
// and add the singleMetricBatch to the result list
if _, ok := batches[key]; !ok {
// qual deve ser aqui: Gauge, Histogram, Exemplar, ExponentialHistogram, ???
metric := pmetric.NewMetrics()
newRS := metric.ResourceMetrics().AppendEmpty()
// currently, the ResourceMetrics implementation has only a Resource and an ILS. We'll copy the Resource
// and set our own ILS
rs.Resource().CopyTo(newRS.Resource())
newRS.SetSchemaUrl(rs.SchemaUrl())
newILS := newRS.ScopeMetrics().AppendEmpty()
// currently, the ILS implementation has only an InstrumentationLibrary and spans. We'll copy the library
// and set our own spans
// currently, the ILS implementation has only an InstrumentationLibrary and metrics. We'll copy the library
// and set our own metrics
ils.Scope().CopyTo(newILS.Scope())
newILS.SetSchemaUrl(ils.SchemaUrl())
batches[key] = newRS
Expand Down
22 changes: 12 additions & 10 deletions pkg/batchpersignal/batchpersignal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,14 @@ func TestSplitMetricsWithNilName(t *testing.T) {
assert.Equal(t, ils.SchemaUrl(), batches[0].ResourceMetrics().At(0).ScopeMetrics().At(0).SchemaUrl())
}

func NeedsReviewingTestSplitSameMetricIntoDifferentBatches(t *testing.T) {
func TestSplitSameMetricIntoDifferentBatches(t *testing.T) {
// prepare
inBatch := pmetric.NewMetrics()
rs := inBatch.ResourceMetrics().AppendEmpty()
rs.SetSchemaUrl(schemaUrl)

// we have 1 ResourceMetrics with 2 ILS, resulting in two batches
rs.ScopeMetrics().EnsureCapacity(2)
rs.ScopeMetrics().EnsureCapacity(1) //2 ou 1??

// the first ILS has two metrics
firstILS := rs.ScopeMetrics().AppendEmpty()
Expand Down Expand Up @@ -367,21 +367,23 @@ func NeedsReviewingTestSplitSameMetricIntoDifferentBatches(t *testing.T) {
batches := SplitMetrics(inBatch)

// verify
assert.Len(t, batches, 2)
assert.Len(t, batches, 3)

// first batch
assert.Equal(t, rs.SchemaUrl(), batches[0].ResourceMetrics().At(0).SchemaUrl())
assert.Equal(t, firstILS.SchemaUrl(), batches[0].ResourceMetrics().At(0).ScopeMetrics().At(0).SchemaUrl())
assert.Equal(t, signalName1, batches[0].ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Name())

assert.Equal(t, firstLibrary.Name(), batches[0].ResourceMetrics().At(0).ScopeMetrics().At(0).Scope().Name())
assert.Equal(t, firstMetric.Name(), batches[0].ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Name())
assert.Equal(t, secondMetric.Name(), batches[0].ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(1).Name())

// second batch
assert.Equal(t, rs.SchemaUrl(), batches[1].ResourceMetrics().At(0).SchemaUrl())
assert.Equal(t, secondILS.SchemaUrl(), batches[1].ResourceMetrics().At(0).ScopeMetrics().At(0).SchemaUrl())
assert.Equal(t, signalName1, batches[1].ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Name())
assert.Equal(t, secondLibrary.Name(), batches[1].ResourceMetrics().At(0).ScopeMetrics().At(0).Scope().Name())
assert.Equal(t, thirdMetric.Name(), batches[1].ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Name())
assert.Equal(t, firstILS.SchemaUrl(), batches[1].ResourceMetrics().At(0).ScopeMetrics().At(0).SchemaUrl())
assert.Equal(t, firstLibrary.Name(), batches[1].ResourceMetrics().At(0).ScopeMetrics().At(0).Scope().Name())
assert.Equal(t, secondMetric.Name(), batches[1].ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Name())

// third batch
assert.Equal(t, rs.SchemaUrl(), batches[2].ResourceMetrics().At(0).SchemaUrl())
assert.Equal(t, secondILS.SchemaUrl(), batches[2].ResourceMetrics().At(0).ScopeMetrics().At(0).SchemaUrl())
assert.Equal(t, secondLibrary.Name(), batches[2].ResourceMetrics().At(0).ScopeMetrics().At(0).Scope().Name())
assert.Equal(t, thirdMetric.Name(), batches[2].ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Name())
}