diff --git a/pkg/config/loki.go b/pkg/config/loki.go index 54151359b..737829b05 100644 --- a/pkg/config/loki.go +++ b/pkg/config/loki.go @@ -18,6 +18,7 @@ type Loki struct { TokenPath string `yaml:"tokenPath,omitempty" json:"tokenPath,omitempty"` SkipTLS bool `yaml:"skipTls,omitempty" json:"skipTls,omitempty"` CAPath string `yaml:"caPath,omitempty" json:"caPath,omitempty"` + Status string `yaml:"status,omitempty" json:"status,omitempty"` StatusSkipTLS bool `yaml:"statusSkipTls,omitempty" json:"statusSkipTls,omitempty"` StatusCAPath string `yaml:"statusCaPath,omitempty" json:"statusCaPath,omitempty"` StatusUserCertPath string `yaml:"statusUserCertPath,omitempty" json:"statusUserCertPath,omitempty"` diff --git a/pkg/handler/loki.go b/pkg/handler/loki.go index d36adaca7..0fb4a904a 100644 --- a/pkg/handler/loki.go +++ b/pkg/handler/loki.go @@ -198,6 +198,10 @@ func getLokiNamesForPrefix(cfg *config.Loki, lokiClient httpclient.Caller, filts } func (h *Handlers) getLokiStatus(r *http.Request) ([]byte, int, error) { + // Check if the status was provided by the operator + if h.Cfg.Loki.Status != "" { + return []byte(h.Cfg.Loki.Status), 200, nil + } lokiClient := newLokiClient(&h.Cfg.Loki, r.Header, true) baseURL := strings.TrimRight(h.Cfg.Loki.GetStatusURL(), "/") return executeLokiQuery(fmt.Sprintf("%s/%s", baseURL, "ready"), lokiClient) @@ -231,6 +235,10 @@ func (h *Handlers) LokiMetrics() func(w http.ResponseWriter, r *http.Request) { writeError(w, http.StatusBadRequest, "Loki is disabled") return } + if h.Cfg.Loki.Status != "" { + writeError(w, http.StatusBadRequest, "Status URL endpoints are unavailable when using LokiStack operator. Status is provided via operator conditions.") + return + } lokiClient := newLokiClient(&h.Cfg.Loki, r.Header, true) baseURL := strings.TrimRight(h.Cfg.Loki.GetStatusURL(), "/") @@ -250,6 +258,10 @@ func (h *Handlers) LokiBuildInfos() func(w http.ResponseWriter, r *http.Request) writeError(w, http.StatusBadRequest, "Loki is disabled") return } + if h.Cfg.Loki.Status != "" { + writeError(w, http.StatusBadRequest, "Loki status URL is not usable with Loki operator") + return + } lokiClient := newLokiClient(&h.Cfg.Loki, r.Header, true) baseURL := strings.TrimRight(h.Cfg.Loki.GetStatusURL(), "/") @@ -264,6 +276,10 @@ func (h *Handlers) LokiBuildInfos() func(w http.ResponseWriter, r *http.Request) } func (h *Handlers) fetchLokiConfig(cl httpclient.Caller, output any) error { + if h.Cfg.Loki.Status != "" { + return fmt.Errorf("loki status url is not usable with Loki operator") + } + baseURL := strings.TrimRight(h.Cfg.Loki.GetStatusURL(), "/") resp, _, err := executeLokiQuery(fmt.Sprintf("%s/%s", baseURL, "config"), cl)