-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Refactor Pipeline #3233
Refactor Pipeline #3233
Conversation
Redundant maps tracking readers to views and readers to pipelines exist in the pipelineRegistry. Unify these maps by tracing views in pipelines.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #3233 +/- ##
=====================================
Coverage 77.3% 77.3%
=====================================
Files 159 159
Lines 11167 11184 +17
=====================================
+ Hits 8637 8653 +16
Misses 2333 2333
- Partials 197 198 +1
|
I like where this has landed. At a high level, I think it is much cleaner than what I fabrocobbled together. I do wonder how this will solve the problem raised in #3229. In particular, the case when I do something like:
Do you think there will be any problem adding something like a caching layer? |
Yeah, it should be pretty easy: MrAlias#660 |
💯 |
pipeline
typeThe
pipeline
type is declared with a mapping of instrument aggregations and other data needed to export measurements:opentelemetry-go/sdk/metric/pipeline.go
Lines 56 to 67 in d7bfe66
However, as the documentation states, a "pipeline connects all of the instruments created by a meter provider to a Reader", it not only serves as the "sync point" for instruments, but also the "pull point" for a
Reader
. There is a one-to-one mapping between aReader
and the views it was registered with and thepipeline
.This strongly indicates there are fields that are missing from the type. Namely, the
Reader
and[]view.View
it corresponds to. By adding these fields, they will no longer need to be tracked elsewhere. E.g.pipelineRegistry
typeThe
pipelineRegistry
is declared as astruct
containing twomap
s:opentelemetry-go/sdk/metric/pipeline.go
Lines 158 to 163 in d7bfe66
After its creation, the
pipelineRegistry
fields do not change (a by-product of aMeterProvider
only allowingReader
registration during initialization). There is never a need to look-up existingReader
s to ensure a unique insert.The only iteration of these fields is done in parallel:
opentelemetry-go/sdk/metric/pipeline.go
Lines 192 to 193 in d7bfe66
This strongly indicates that these fields can be unified into a single field. When the
Reader
and[]view.View
data are moved into thepipeline
(see above), both fields and the type itself are flattened into a slice ofpipeline
s. E.g.This new type still provides the iteration like before, but now over a slice type instead of by linking two
map
s:Facilitators
There are three "create" functions currently associated with the creation of
internal.Aggreagtor
s for an instrument:opentelemetry-go/sdk/metric/pipeline.go
Line 188 in d7bfe66
opentelemetry-go/sdk/metric/pipeline.go
Line 236 in d7bfe66
opentelemetry-go/sdk/metric/pipeline.go
Line 286 in d7bfe66
Multiple of these create
func
s were declared to help break apart a long set of logic and to interface with the genericinternal.Aggreagtor
type.The use and purpose of each function is not immediately clear to a developer. It requires cognitive load to understand the complexity these introduce.
Furthermore, both
createAggregators
andcreateAggregatorsForReader
are closer in function to methods on apipelineRegistry
andReader
/[]view.View
pair respectively. With theReader
/[]view.View
pair being moved into thepipeline
type (see above), it makes sense to define each one as a method. However, methods cannot be declared with generics. The receiver itself needs to be defined with a generic which is problematic.Instead, use the facilitator pattern to accomplish this. Not only will this allow the interface with generic and non-generic types, it will help name things for the purpose they serve.
inserter
Create an
inserter
type that acts as a facilitator of apipeline
(see above) to return[]internal.Aggregator
for a new instrument from aresolver
(see below).The
inserter.Instrument
method replaces use of thecreateAggregatorsForReader
function, andinserter.aggregator
replaces use of thecreateAggregator
function.resolver
Create a
resolver
type that acts as a facilitator ofinserter
(see above) to return[]internal.Aggregator
for a new instrument from an instrument provider.The
resolver.Aggregators
replaces the use of thecreateAggregators
function.