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
fix: Add struct-wide RWMutex to metrics #3421
Conversation
return | ||
} | ||
m.WorkflowDeleted(key, fromPhase) | ||
m.WorkflowAdded(key, toPhase) | ||
if _, ok := m.workflowsByPhase[fromPhase]; 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.
is this copy-and-paste? maybe make private func which does not lock?
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.
Not quite copy-and-paste, there is some logic that would be redundant if we go with the private func approach; mainly, we will remove and readd the key from the map and perform an additional check unnecessarily. I actually think this is simpler and easier to understand.
However, I don't feel strongly and would gladly go with the private func approach if you think it's necessary.
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.
we should just make sure that if we need to make changes in two places - we are aware of it
it's like in Java when you add |
@@ -77,6 +77,9 @@ func New(metricsConfig, telemetryConfig ServerConfig) *Metrics { | |||
} | |||
|
|||
func (m *Metrics) allMetrics() []prometheus.Metric { | |||
m.mutex.RLock() |
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.
will it handle concurrent read and write on map?
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 is a synchronized map in golang.
https://golang.org/pkg/sync/#Map
Checklist:
"fix(controller): Updates such and such. Fixes #1234"
.