Skip to content

Commit 0da3810

Browse files
authored
Do not return error when selector extraction fails (#579)
1 parent bafc5e2 commit 0da3810

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

authorization/http.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package authorization
22

33
import (
44
"context"
5-
"fmt"
65
"net/http"
76

7+
"github.com/go-kit/log"
8+
"github.com/go-kit/log/level"
89
"github.com/observatorium/api/authentication"
910
"github.com/observatorium/api/httperr"
1011
"github.com/observatorium/api/rbac"
@@ -61,7 +62,7 @@ func WithSelectorsInfo(ctx context.Context, info *SelectorsInfo) context.Context
6162

6263
// WithLogsStreamSelectorsExtractor returns a middleware that, when enabled, tries to extract
6364
// stream selectors from queries, so that they can be used in authorizing the request.
64-
func WithLogsStreamSelectorsExtractor(selectorNames []string) func(http.Handler) http.Handler {
65+
func WithLogsStreamSelectorsExtractor(logger log.Logger, selectorNames []string) func(http.Handler) http.Handler {
6566
enabled := len(selectorNames) > 0
6667

6768
selectorNameMap := make(map[string]bool, len(selectorNames))
@@ -79,9 +80,9 @@ func WithLogsStreamSelectorsExtractor(selectorNames []string) func(http.Handler)
7980

8081
selectorsInfo, err := extractLogStreamSelectors(selectorNameMap, r.URL.Query())
8182
if err != nil {
82-
httperr.PrometheusAPIError(w, fmt.Sprintf("error extracting selectors from query: %s", err), http.StatusInternalServerError)
83-
84-
return
83+
// Don't error out, just warn about error and continue with empty selectorsInfo
84+
level.Warn(logger).Log("msg", err)
85+
selectorsInfo = emptySelectorsInfo
8586
}
8687

8788
next.ServeHTTP(w, r.WithContext(WithSelectorsInfo(r.Context(), selectorsInfo)))

authorization/query.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package authorization
22

33
import (
4+
"fmt"
45
"net/url"
56
"strings"
67

@@ -16,7 +17,7 @@ func extractLogStreamSelectors(selectorNames map[string]bool, values url.Values)
1617

1718
selectors, hasWildcard, err := parseLogStreamSelectors(selectorNames, query)
1819
if err != nil {
19-
return nil, err
20+
return nil, fmt.Errorf("error extracting selectors from query %#q: %w", query, err)
2021
}
2122

2223
return &SelectorsInfo{

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ func main() {
715715
logsv1.WithWriteMiddleware(writePathRedirectProtection),
716716
logsv1.WithGlobalMiddleware(authentication.WithTenantMiddlewares(pm.Middlewares)),
717717
logsv1.WithGlobalMiddleware(authentication.WithTenantHeader(cfg.logs.tenantHeader, tenantIDs)),
718-
logsv1.WithReadMiddleware(authorization.WithLogsStreamSelectorsExtractor(cfg.logs.authExtractSelectors)),
718+
logsv1.WithReadMiddleware(authorization.WithLogsStreamSelectorsExtractor(logger, cfg.logs.authExtractSelectors)),
719719
logsv1.WithReadMiddleware(authorization.WithAuthorizers(authorizers, rbac.Read, "logs")),
720720
logsv1.WithReadMiddleware(logsv1.WithEnforceAuthorizationLabels()),
721721
logsv1.WithWriteMiddleware(authorization.WithAuthorizers(authorizers, rbac.Write, "logs")),

0 commit comments

Comments
 (0)