Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

refactor ReadAll to Read and fix concurrency issue. #1056

Merged
merged 2 commits into from
Mar 12, 2019

Conversation

rghetia
Copy link
Contributor

@rghetia rghetia commented Mar 11, 2019

No description provided.

@rghetia rghetia requested review from rakyll and a team as code owners March 11, 2019 22:50
)

// Registry creates and manages a set of gauges.
// External synchronization is required if you want to add gauges to the same
// registry from multiple goroutines.
type Registry struct {
mu sync.RWMutex
gauges map[string]*gauge
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe consider to use sync.Map? Please let me know if that matches your requirements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sync.Map would work.

if ok {
existing := val.(*gauge)
if existing.isFloat != g.isFloat {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed we need to return an error if it exists not only if it has a different type. But happy to see that in a different PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will create a different PR for this.

ms := make([]*metricdata.Metric, 0, len(r.gauges))
for _, g := range r.gauges {
// Read reads all gauges in this registry and returns their values as metrics.
func (r *Registry) Read() []*metricdata.Metric {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this name? I don't feel strongly about it but was curios.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Producer interface is Read(). Since there is only going to be one Read there is no point in naming ReadAll. (short is better as long as it is clear).
If ReadAll is preferable I can change the producer interface.

@bogdandrutu bogdandrutu merged commit d1aebdc into census-instrumentation:master Mar 12, 2019
@rghetia rghetia deleted the registry_race branch April 15, 2019 20:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants