-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[connector/spanmetrics] Fix memory leak #28847
[connector/spanmetrics] Fix memory leak #28847
Conversation
8137649
to
cd81af5
Compare
cd81af5
to
8dc2eac
Compare
8dc2eac
to
2c2baa6
Compare
2c2baa6
to
c64fb77
Compare
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.
LGTM, thanks very much!
@@ -74,3 +74,17 @@ func (c *Cache[K, V]) Purge() { | |||
c.lru.Purge() | |||
c.RemoveEvictedItems() | |||
} | |||
|
|||
// ForEach iterates over all the items within the cache, as well as the evicted items (if any). | |||
func (c *Cache[K, V]) ForEach(fn func(k K, v V)) { |
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.
Nice
c64fb77
to
e929f8b
Compare
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 don't have knowledge to read the code, but this PR seems promises to solve a problem that I have.
need to fix https://github.com/open-telemetry/opentelemetry-collector-contrib/actions/runs/7083411340/job/19275795975#step:8:148: Error: ./connector_test.go:901:146: not enough arguments in call to newConnectorImp
have (*testing.T, consumertest.Consumer, *string, func() HistogramConfig, func() ExemplarsConfig, string, *zap.Logger, nil)
want (*testing.T, consumer.Metrics, *string, func() HistogramConfig, func() ExemplarsConfig, func() EventsConfig, string, *zap.Logger, *clock.Ticker, ...string) (typecheck) |
# Why The `spanmetrics` connector has a memory leak that occurs when the cumulative temporality is used. The `connectorImp#resourceMetrics` map is only ever cleaned up in delta temporality. # What Turn `connectorImp#resourceMetrics` into a LRU cache with a maximum size. To correctly handle metric resets we also introduce a start timestamp per `resourceMetric` instance. # References Fixes open-telemetry#27654 Co-authored-by: Jared Tan <[email protected]>
3eaa2aa
to
7ff7b54
Compare
done @JaredTan95 |
Why
The
spanmetrics
connector has a memory leak that occurs when the cumulative temporality is used. TheconnectorImp#resourceMetrics
map is only ever cleaned up in delta temporality.What
Turn
connectorImp#resourceMetrics
into a LRU cache with a maximum size. To correctly handle metric resets we also introduce a start timestamp perresourceMetric
instance.References
Fixes #27654