-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[processor/spanmetrics] Fix getting key from cache error #15687
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
Conversation
pinging @albertteoh as code owner |
@@ -339,8 +339,13 @@ func (p *processorImp) getDimensionsByMetricKey(k metricKey) (*pcommon.Map, erro | |||
} | |||
return nil, fmt.Errorf("type assertion of metricKeyToDimensions attributes failed, the key is %q", k) | |||
} | |||
if item, ok := p.metricKeyToDimensions.EvictedItems[k]; ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought metricKeyToDimensions .Get(...)
already does this?
opentelemetry-collector-contrib/processor/spanmetricsprocessor/internal/cache/cache.go
Line 60 in 0ea5dc4
val, ok := c.evictedItems[key] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it do use the evictedItems
, but still can't not explain why this error occur
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I debug for a while, I catch the point this time that:
opentelemetry-collector-contrib/processor/spanmetricsprocessor/processor.go
Lines 313 to 324 in 9810bb0
for key := range p.callSum { | |
mCalls := ilm.Metrics().AppendEmpty() | |
mCalls.SetName("calls_total") | |
mCalls.SetEmptySum().SetIsMonotonic(true) | |
mCalls.Sum().SetAggregationTemporality(p.config.GetAggregationTemporality()) | |
dpCalls := mCalls.Sum().DataPoints().AppendEmpty() | |
dpCalls.SetStartTimestamp(pcommon.NewTimestampFromTime(p.startTime)) | |
dpCalls.SetTimestamp(pcommon.NewTimestampFromTime(time.Now())) | |
dpCalls.SetIntValue(p.callSum[key]) | |
dimensions, err := p.getDimensionsByMetricKey(key) |
It loops p.callSum
containing all key-values since the collector is started to find a key in the cache, but the cache only has 1000 items by default. If the built different key is large than 1000, then the next loop of p.callSum
will raise an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, I think you're right about the fact that p.callSum
accumulates keys indefinitely since startup, unless if the user has configured delta temporality.
For cumulative temporality, while I think we should still keep all keys since collector startup (so the counts are correct), I don't think we should loop over this entire set of metric keys. Instead we should only loop over those that relate to the current batch of spans received, by somehow marking a key as "dirty" if it relates to a span's set of metric keys.
What do you think?
I can put together some tests locally to test this theory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, we just loop over those keys that relate to the current batch of spans received. Do I need close this PR and wait for your PR or I fix it in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Frapschen FYI #15710 has been merged.
Description:
I get an error in my app when it sent span to a otel collector which configed a spanmetrics processor with
defaultDimensionsCacheSize
:I trick the error to:
opentelemetry-collector-contrib/processor/spanmetricsprocessor/processor.go
Lines 335 to 344 in 92ad54f
I think the error will occur when the added keys are more than
processorImp.defaultDimensionsCacheSize
however theprocessorImp.callSum
doesn't have any limitation, it contains the key and the key's value. I add a patch to get key from themetricKeyToDimensions.EvictedItems
to handle this scene.