This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
@@ -13,6 +14,7 @@ type LokiWriter struct {
|
||||
url string
|
||||
labels map[string]string
|
||||
httpClient *http.Client
|
||||
disabled bool
|
||||
|
||||
// Circuit breaker fields
|
||||
mu sync.RWMutex
|
||||
@@ -38,15 +40,29 @@ const (
|
||||
warningInterval = 1 * time.Minute // Minimum time between warning messages
|
||||
)
|
||||
|
||||
func NewLokiWriter(url string, labels map[string]string) *LokiWriter {
|
||||
func NewLokiWriter(rawURL string, labels map[string]string) *LokiWriter {
|
||||
disabled := false
|
||||
if rawURL == "" {
|
||||
disabled = true
|
||||
} else {
|
||||
u, err := url.ParseRequestURI(rawURL)
|
||||
if err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" {
|
||||
disabled = true
|
||||
}
|
||||
}
|
||||
return &LokiWriter{
|
||||
url: url,
|
||||
url: rawURL,
|
||||
labels: labels,
|
||||
httpClient: &http.Client{},
|
||||
disabled: disabled,
|
||||
}
|
||||
}
|
||||
|
||||
func (w *LokiWriter) Write(p []byte) (n int, err error) {
|
||||
if w.disabled {
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
// Check circuit breaker status
|
||||
w.mu.RLock()
|
||||
if w.circuitOpen {
|
||||
|
||||
Reference in New Issue
Block a user