Skip to content

Commit 0452f4e

Browse files
committed
Add LokiStack operator status integration
Integrate with LokiStack operator to use its status conditions instead of querying the Loki status endpoint. This adds support for detecting Loki readiness through the operator's status API when available. Changes: - Add github.com/grafana/loki/operator/apis/loki dependency - Add LokiStackStatus field to Loki config - Check operator status in getLokiStatus before querying status URL - Prevent status URL usage when using Loki operator
1 parent a2cf608 commit 0452f4e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pkg/config/loki.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Loki struct {
1818
TokenPath string `yaml:"tokenPath,omitempty" json:"tokenPath,omitempty"`
1919
SkipTLS bool `yaml:"skipTls,omitempty" json:"skipTls,omitempty"`
2020
CAPath string `yaml:"caPath,omitempty" json:"caPath,omitempty"`
21+
Status string `yaml:"status,omitempty" json:"status,omitempty"`
2122
StatusSkipTLS bool `yaml:"statusSkipTls,omitempty" json:"statusSkipTls,omitempty"`
2223
StatusCAPath string `yaml:"statusCaPath,omitempty" json:"statusCaPath,omitempty"`
2324
StatusUserCertPath string `yaml:"statusUserCertPath,omitempty" json:"statusUserCertPath,omitempty"`

pkg/handler/loki.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ func getLokiNamesForPrefix(cfg *config.Loki, lokiClient httpclient.Caller, filts
198198
}
199199

200200
func (h *Handlers) getLokiStatus(r *http.Request) ([]byte, int, error) {
201+
// Check if the status was provided by the operator
202+
if h.Cfg.Loki.Status != "" {
203+
return []byte(h.Cfg.Loki.Status), 200, nil
204+
}
201205
lokiClient := newLokiClient(&h.Cfg.Loki, r.Header, true)
202206
baseURL := strings.TrimRight(h.Cfg.Loki.GetStatusURL(), "/")
203207
return executeLokiQuery(fmt.Sprintf("%s/%s", baseURL, "ready"), lokiClient)
@@ -231,6 +235,10 @@ func (h *Handlers) LokiMetrics() func(w http.ResponseWriter, r *http.Request) {
231235
writeError(w, http.StatusBadRequest, "Loki is disabled")
232236
return
233237
}
238+
if h.Cfg.Loki.Status != nil {
239+
writeError(w, http.StatusBadRequest, "Loki status URL is not usable with Loki operator")
240+
return
241+
}
234242
lokiClient := newLokiClient(&h.Cfg.Loki, r.Header, true)
235243
baseURL := strings.TrimRight(h.Cfg.Loki.GetStatusURL(), "/")
236244

@@ -250,6 +258,10 @@ func (h *Handlers) LokiBuildInfos() func(w http.ResponseWriter, r *http.Request)
250258
writeError(w, http.StatusBadRequest, "Loki is disabled")
251259
return
252260
}
261+
if h.Cfg.Loki.Status != nil {
262+
writeError(w, http.StatusBadRequest, "Loki status URL is not usable with Loki operator")
263+
return
264+
}
253265
lokiClient := newLokiClient(&h.Cfg.Loki, r.Header, true)
254266
baseURL := strings.TrimRight(h.Cfg.Loki.GetStatusURL(), "/")
255267

@@ -264,6 +276,10 @@ func (h *Handlers) LokiBuildInfos() func(w http.ResponseWriter, r *http.Request)
264276
}
265277

266278
func (h *Handlers) fetchLokiConfig(cl httpclient.Caller, output any) error {
279+
if h.Cfg.Loki.Status != nil {
280+
return fmt.Errorf("loki status url is not usable with Loki operator")
281+
}
282+
267283
baseURL := strings.TrimRight(h.Cfg.Loki.GetStatusURL(), "/")
268284

269285
resp, _, err := executeLokiQuery(fmt.Sprintf("%s/%s", baseURL, "config"), cl)

0 commit comments

Comments
 (0)