fix: concurrent map writes to temporalityMap (#5432)

This commit is contained in:
Srikanth Chekuri 2024-07-10 11:00:28 +05:30 committed by GitHub
parent 3b2a811f7b
commit 831de18464
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -83,6 +83,7 @@ type APIHandler struct {
// querying the v4 table on low cardinal temporality column // querying the v4 table on low cardinal temporality column
// should be fast but we can still avoid the query if we have the data in memory // should be fast but we can still avoid the query if we have the data in memory
temporalityMap map[string]map[v3.Temporality]bool temporalityMap map[string]map[v3.Temporality]bool
temporalityMux sync.Mutex
maxIdleConns int maxIdleConns int
maxOpenConns int maxOpenConns int
@ -455,6 +456,9 @@ func (aH *APIHandler) getRule(w http.ResponseWriter, r *http.Request) {
// populateTemporality adds the temporality to the query if it is not present // populateTemporality adds the temporality to the query if it is not present
func (aH *APIHandler) populateTemporality(ctx context.Context, qp *v3.QueryRangeParamsV3) error { func (aH *APIHandler) populateTemporality(ctx context.Context, qp *v3.QueryRangeParamsV3) error {
aH.temporalityMux.Lock()
defer aH.temporalityMux.Unlock()
missingTemporality := make([]string, 0) missingTemporality := make([]string, 0)
metricNameToTemporality := make(map[string]map[v3.Temporality]bool) metricNameToTemporality := make(map[string]map[v3.Temporality]bool)
if qp.CompositeQuery != nil && len(qp.CompositeQuery.BuilderQueries) > 0 { if qp.CompositeQuery != nil && len(qp.CompositeQuery.BuilderQueries) > 0 {