Skip to content

PostgreSQL backup tool with Point-In-Time-Recovery and restore verification

FIX (logging): Add login to VictoriaLogs logger

Rostislav Duginb0510d7c2171
diff --git a/backend/internal/util/logger/logger.go b/backend/internal/util/logger/logger.go
index 873748b6..e98093c0 100644
--- a/backend/internal/util/logger/logger.go
+++ b/backend/internal/util/logger/logger.go
@@ -71,6 +71,7 @@ func tryInitVictoriaLogs() *VictoriaLogsWriter {
// Try to get config - this may fail early in startup
url := getVictoriaLogsURL()
+ username := getVictoriaLogsUsername()
password := getVictoriaLogsPassword()
if url == "" {
@@ -78,7 +79,7 @@ func tryInitVictoriaLogs() *VictoriaLogsWriter {
return nil
}
- return NewVictoriaLogsWriter(url, password)
+ return NewVictoriaLogsWriter(url, username, password)
}
func ensureEnvLoaded() {
@@ -126,6 +127,10 @@ func getVictoriaLogsURL() string {
return os.Getenv("VICTORIA_LOGS_URL")
}
+func getVictoriaLogsUsername() string {
+ return os.Getenv("VICTORIA_LOGS_USERNAME")
+}
+
func getVictoriaLogsPassword() string {
return os.Getenv("VICTORIA_LOGS_PASSWORD")
}
diff --git a/backend/internal/util/logger/victorialogs_writer.go b/backend/internal/util/logger/victorialogs_writer.go
index 0ca13e22..48190a84 100644
--- a/backend/internal/util/logger/victorialogs_writer.go
+++ b/backend/internal/util/logger/victorialogs_writer.go
@@ -23,6 +23,7 @@ type logEntry struct {
type VictoriaLogsWriter struct {
url string
+ username string
password string
httpClient *http.Client
logChannel chan logEntry
@@ -33,11 +34,12 @@ type VictoriaLogsWriter struct {
logger *slog.Logger
}
-func NewVictoriaLogsWriter(url, password string) *VictoriaLogsWriter {
+func NewVictoriaLogsWriter(url, username, password string) *VictoriaLogsWriter {
ctx, cancel := context.WithCancel(context.Background())
writer := &VictoriaLogsWriter{
url: url,
+ username: username,
password: password,
httpClient: &http.Client{
Timeout: 10 * time.Second,
@@ -149,9 +151,9 @@ func (w *VictoriaLogsWriter) sendHTTP(entries []logEntry) error {
// Set headers
req.Header.Set("Content-Type", "application/x-ndjson")
- // Set Basic Auth (password as username, empty password)
+ // Set Basic Auth (username:password)
if w.password != "" {
- auth := base64.StdEncoding.EncodeToString([]byte(w.password + ":"))
+ auth := base64.StdEncoding.EncodeToString([]byte(w.username + ":" + w.password))
req.Header.Set("Authorization", "Basic "+auth)
}