Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
- Remove empty lines
- If multiple tenant matchers are found in the original query, we only
  replace the first one with the header provided tenant, and remove any
  subsequent ones.

Signed-off-by: Jacob Baungard Hansen <[email protected]>
  • Loading branch information
jacobbaungard committed Oct 17, 2023
1 parent c253e40 commit 329677a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/api/query/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,6 @@ func (qapi *QueryAPI) query(r *http.Request) (interface{}, []error, *api.ApiErro
ctx = context.WithValue(ctx, tenancy.TenantKey, tenant)

queryStr := r.FormValue("query")

if qapi.enforceTenancy {
queryStr, err = tenancy.EnforceQueryTenancy(qapi.tenantLabel, tenant, queryStr)
if err != nil {
Expand Down Expand Up @@ -970,7 +969,6 @@ func (qapi *QueryAPI) queryRange(r *http.Request) (interface{}, []error, *api.Ap
qapi.queryRangeHist.Observe(end.Sub(start).Seconds())

queryStr := r.FormValue("query")

if qapi.enforceTenancy {
queryStr, err = tenancy.EnforceQueryTenancy(qapi.tenantLabel, tenant, queryStr)
if err != nil {
Expand Down Expand Up @@ -1337,12 +1335,17 @@ func (qapi *QueryAPI) getLabelMatchers(matchers []string, tenant string) ([][]*l
}
if qapi.enforceTenancy {
// first check if there's a tenant matcher already, in which case we overwrite it
// if there are multiple tenant matchers, we overwrite all of them
// if there are multiple tenant matchers, we remove the subsequent ones
found := false
for idx, matchValue := range matchers {
if matchValue.Name == qapi.tenantLabel {
matchers[idx] = tenantLabelMatcher
found = true
if found {
// remove any additional tenant matchers.
matchers = append(matchers[:idx], matchers[idx+1:]...)
} else {
matchers[idx] = tenantLabelMatcher
found = true
}
}
}
// if there are no pre-existing tenant matchers, add it.
Expand Down

0 comments on commit 329677a

Please sign in to comment.