[v11.0.x] Loki: Remove API restrictions on resource calls (#85201)

Loki: Remove API restrictions on resource calls (#85191)

Loki: Remove API restrictions
(cherry picked from commit c80b31a0d4)

Co-authored-by: Sven Grossmann <sven.grossmann@grafana.com>
This commit is contained in:
grafana-delivery-bot[bot]
2024-04-05 16:00:20 +02:00
committed by GitHub
co-authored by Sven Grossmann
parent 49e74d3237
commit bb5e1e0c5b
+1 -13
View File
@@ -6,7 +6,6 @@ import (
"fmt"
"net/http"
"regexp"
"strings"
"sync"
"time"
@@ -120,18 +119,7 @@ func (s *Service) CallResource(ctx context.Context, req *backend.CallResourceReq
func callResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender, dsInfo *datasourceInfo, plog log.Logger, tracer tracing.Tracer) error {
url := req.URL
// a very basic is-this-url-valid check
if req.Method != "GET" {
plog.Error("Invalid HTTP method", "method", req.Method)
return fmt.Errorf("invalid HTTP method: %s", req.Method)
}
if (!strings.HasPrefix(url, "labels?")) &&
(!strings.HasPrefix(url, "label/")) && // the `/label/$label_name/values` form
(!strings.HasPrefix(url, "series?")) &&
(!strings.HasPrefix(url, "index/stats?")) {
plog.Error("Invalid URL", "url", url)
return fmt.Errorf("invalid URL: %s", url)
}
lokiURL := fmt.Sprintf("/loki/api/v1/%s", url)
ctx, span := tracer.Start(ctx, "datasource.loki.CallResource", trace.WithAttributes(