-
Notifications
You must be signed in to change notification settings - Fork 229
Support Application Signals .NET runtime metrics exporting #1471
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
plugins/processors/awsapplicationsignals/internal/metrichandlers/aggregation_mutator.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package metrichandlers | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
) | ||
|
||
type aggregationType int | ||
|
||
const ( | ||
defaultAggregation aggregationType = iota | ||
lastValueAggregation | ||
) | ||
|
||
// AggregationMutator is used to convert predefined ObservableUpDownCounter metrics to use LastValue metrichandlers. This | ||
// is necessary for cases where metrics are instrumented as cumulative, yet reported with snapshot values. | ||
// | ||
// For example, metrics like DotNetGCGen0HeapSize may report values such as 1000, 2000, 1000, with cumulative temporality | ||
// When exporters, such as the EMF exporter, detect these as cumulative, they convert the values to deltas, | ||
// resulting in outputs like -, 1000, -1000, which misrepresent the data. | ||
// | ||
// Normally, this issue could be resolved by configuring a view with LastValue metrichandlers within the SDK. | ||
// However, since the view feature is not fully supported in .NET, this workaround implements the required | ||
// conversion to LastValue metrichandlers to ensure accurate metric reporting. | ||
// See https://github.com/open-telemetry/opentelemetry-dotnet/issues/2618. | ||
type AggregationMutator struct { | ||
includes map[string]aggregationType | ||
} | ||
|
||
func NewAggregationMutator() AggregationMutator { | ||
return newAggregationMutatorWithConfig(map[string]aggregationType{ | ||
"DotNetGCGen0HeapSize": lastValueAggregation, | ||
sky333999 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"DotNetGCGen1HeapSize": lastValueAggregation, | ||
"DotNetGCGen2HeapSize": lastValueAggregation, | ||
"DotNetGCLOHHeapSize": lastValueAggregation, | ||
"DotNetGCPOHHeapSize": lastValueAggregation, | ||
"DotNetThreadCount": lastValueAggregation, | ||
"DotNetThreadQueueLength": lastValueAggregation, | ||
}) | ||
} | ||
|
||
func newAggregationMutatorWithConfig(includes map[string]aggregationType) AggregationMutator { | ||
return AggregationMutator{ | ||
includes, | ||
} | ||
} | ||
|
||
func (t *AggregationMutator) ProcessMetrics(_ context.Context, m pmetric.Metric, _ pcommon.Map) { | ||
aggType, exists := t.includes[m.Name()] | ||
if !exists || aggType == defaultAggregation { | ||
return | ||
} | ||
switch m.Type() { | ||
case pmetric.MetricTypeSum: | ||
switch aggType { | ||
case lastValueAggregation: | ||
m.Sum().SetAggregationTemporality(pmetric.AggregationTemporalityDelta) | ||
default: | ||
} | ||
default: | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
plugins/processors/awsapplicationsignals/internal/metrichandlers/aggregation_mutator_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package metrichandlers | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
) | ||
|
||
func TestAggregationMutator_ProcessMetrics(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
config map[string]aggregationType | ||
metrics []pmetric.Metric | ||
expectedTemporality map[string]pmetric.AggregationTemporality | ||
}{ | ||
{ | ||
"testCumulativeToDelta", | ||
map[string]aggregationType{ | ||
"test0": lastValueAggregation, | ||
}, | ||
|
||
[]pmetric.Metric{ | ||
generateMetricWithSumAggregation("test0", pmetric.AggregationTemporalityCumulative), | ||
}, | ||
map[string]pmetric.AggregationTemporality{ | ||
"test0": pmetric.AggregationTemporalityDelta, | ||
}, | ||
}, | ||
{ | ||
"testNoChange", | ||
map[string]aggregationType{ | ||
"test0": lastValueAggregation, | ||
"test1": defaultAggregation, | ||
}, | ||
[]pmetric.Metric{ | ||
generateMetricWithSumAggregation("test0", pmetric.AggregationTemporalityDelta), | ||
generateMetricWithSumAggregation("test1", pmetric.AggregationTemporalityCumulative), | ||
generateMetricWithSumAggregation("test2", pmetric.AggregationTemporalityCumulative), | ||
}, | ||
map[string]pmetric.AggregationTemporality{ | ||
"test0": pmetric.AggregationTemporalityDelta, | ||
"test1": pmetric.AggregationTemporalityCumulative, | ||
"test2": pmetric.AggregationTemporalityCumulative, | ||
}, | ||
}, | ||
} | ||
|
||
ctx := context.Background() | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t1 *testing.T) { | ||
mutator := newAggregationMutatorWithConfig(tt.config) | ||
|
||
for _, m := range tt.metrics { | ||
mutator.ProcessMetrics(ctx, m, pcommon.NewMap()) | ||
assert.Equal(t1, tt.expectedTemporality[m.Name()], m.Sum().AggregationTemporality()) | ||
} | ||
}) | ||
} | ||
|
||
mutator := NewAggregationMutator() | ||
|
||
m := generateMetricWithSumAggregation("DotNetGCGen0HeapSize", pmetric.AggregationTemporalityCumulative) | ||
mutator.ProcessMetrics(ctx, m, pcommon.NewMap()) | ||
assert.Equal(t, pmetric.MetricTypeSum, m.Type()) | ||
assert.Equal(t, pmetric.AggregationTemporalityDelta, m.Sum().AggregationTemporality()) | ||
|
||
m.SetEmptyHistogram() | ||
m.Histogram().SetAggregationTemporality(pmetric.AggregationTemporalityCumulative) | ||
mutator.ProcessMetrics(ctx, m, pcommon.NewMap()) | ||
assert.Equal(t, pmetric.MetricTypeHistogram, m.Type()) | ||
assert.Equal(t, pmetric.AggregationTemporalityCumulative, m.Histogram().AggregationTemporality()) | ||
|
||
} | ||
|
||
func generateMetricWithSumAggregation(metricName string, temporality pmetric.AggregationTemporality) pmetric.Metric { | ||
m := pmetric.NewMetrics().ResourceMetrics().AppendEmpty().ScopeMetrics().AppendEmpty().Metrics().AppendEmpty() | ||
m.SetName(metricName) | ||
m.SetEmptySum() | ||
m.Sum().SetAggregationTemporality(temporality) | ||
return m | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.