Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/gnostic-models v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grafana/loki/operator/apis/loki v0.0.0-20241021105923-5e970e50b166 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
Expand Down Expand Up @@ -63,6 +64,7 @@ require (
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 // indirect
sigs.k8s.io/controller-runtime v0.20.4 // indirect
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/grafana/loki/operator/apis/loki v0.0.0-20241021105923-5e970e50b166 h1:cmG5fwmF+0PsyerLecb7CU4bzNRg5+tDgO3PiNxskKo=
github.com/grafana/loki/operator/apis/loki v0.0.0-20241021105923-5e970e50b166/go.mod h1:QggEReYyQzjnwTlj9hMeRaI2M/w3UPAwrMOXYzIyonc=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
Expand Down Expand Up @@ -233,6 +235,8 @@ k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b h1:MloQ9/bdJyIu9lb1PzujOP
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b/go.mod h1:UZ2yyWbFTpuhSbFhv24aGNOdoRdJZgsIObGBUaYVsts=
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 h1:hwvWFiBzdWw1FhfY1FooPn3kzWuJ8tmbZBHi4zVsl1Y=
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
sigs.k8s.io/controller-runtime v0.20.4 h1:X3c+Odnxz+iPTRobG4tp092+CvBU9UK0t/bRf+n0DGU=
sigs.k8s.io/controller-runtime v0.20.4/go.mod h1:xg2XB0K5ShQzAgsoujxuKN4LNXR2LfwwHsPj7Iaw+XY=
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7npUVDpVXUUOFfW6CgAqE=
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg=
sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU=
Expand Down
34 changes: 18 additions & 16 deletions pkg/config/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@ import (
"fmt"
"strings"

lokiv1 "github.com/grafana/loki/operator/apis/loki/v1"
"github.com/netobserv/network-observability-console-plugin/pkg/utils"
)

type Loki struct {
URL string `yaml:"url" json:"url"`
Labels []string `yaml:"labels" json:"labels"`
FieldsType map[string]string `yaml:"fieldsType" json:"fieldsType"`
FieldsFormat map[string]string `yaml:"fieldsFormat" json:"fieldsFormat"`
StatusURL string `yaml:"statusUrl,omitempty" json:"statusUrl,omitempty"`
Timeout Duration `yaml:"timeout,omitempty" json:"timeout,omitempty"`
TenantID string `yaml:"tenantID,omitempty" json:"tenantID,omitempty"`
TokenPath string `yaml:"tokenPath,omitempty" json:"tokenPath,omitempty"`
SkipTLS bool `yaml:"skipTls,omitempty" json:"skipTls,omitempty"`
CAPath string `yaml:"caPath,omitempty" json:"caPath,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"`
StatusUserKeyPath string `yaml:"statusUserKeyPath,omitempty" json:"statusUserKeyPath,omitempty"`
UseMocks bool `yaml:"useMocks,omitempty" json:"useMocks,omitempty"`
ForwardUserToken bool `yaml:"forwardUserToken,omitempty" json:"forwardUserToken,omitempty"`
URL string `yaml:"url" json:"url"`
Labels []string `yaml:"labels" json:"labels"`
FieldsType map[string]string `yaml:"fieldsType" json:"fieldsType"`
FieldsFormat map[string]string `yaml:"fieldsFormat" json:"fieldsFormat"`
StatusURL string `yaml:"statusUrl,omitempty" json:"statusUrl,omitempty"`
Timeout Duration `yaml:"timeout,omitempty" json:"timeout,omitempty"`
TenantID string `yaml:"tenantID,omitempty" json:"tenantID,omitempty"`
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 *lokiv1.LokiStackStatus `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"`
StatusUserKeyPath string `yaml:"statusUserKeyPath,omitempty" json:"statusUserKeyPath,omitempty"`
UseMocks bool `yaml:"useMocks,omitempty" json:"useMocks,omitempty"`
ForwardUserToken bool `yaml:"forwardUserToken,omitempty" json:"forwardUserToken,omitempty"`
labelsMap map[string]struct{}
}

Expand Down
24 changes: 24 additions & 0 deletions pkg/handler/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ 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 != nil {
for _, conditions := range h.Cfg.Loki.Status.Conditions {
if conditions.Reason == "ReadyComponents" {
if conditions.Status == "True" {
return []byte("ready"), 200, nil
}
break
}
}
return []byte("pending"), 400, 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)
Expand Down Expand Up @@ -231,6 +243,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 != nil {
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(), "/")

Expand All @@ -250,6 +266,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 != nil {
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(), "/")

Expand All @@ -264,6 +284,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 != nil {
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)
Expand Down
Loading