فهرست منبع

fix: Add https to dsn

Louis PERDEREAU 2 سال پیش
والد
کامیت
2017e6b113
2فایلهای تغییر یافته به همراه23 افزوده شده و 6 حذف شده
  1. 9 5
      pkg/acquisition/modules/loki/loki.go
  2. 14 1
      pkg/acquisition/modules/loki/loki_test.go

+ 9 - 5
pkg/acquisition/modules/loki/loki.go

@@ -152,12 +152,10 @@ func (l *LokiSource) ConfigureByDSN(dsn string, labels map[string]string, logger
 	}
 	scheme := "http"
 
-	l.Config.URL = fmt.Sprintf("%s://%s", scheme, u.Host)
-	if u.User != nil {
-		l.Config.Auth.Username = u.User.Username()
-		l.Config.Auth.Password, _ = u.User.Password()
-	}
 	params := u.Query()
+	if q := params.Get("ssl"); q != "" {
+		scheme = "https"
+	}
 	if q := params.Get("query"); q != "" {
 		l.Config.Query = q
 	}
@@ -202,6 +200,12 @@ func (l *LokiSource) ConfigureByDSN(dsn string, labels map[string]string, logger
 		l.logger.Logger.SetLevel(level)
 	}
 
+	l.Config.URL = fmt.Sprintf("%s://%s", scheme, u.Host)
+	if u.User != nil {
+		l.Config.Auth.Username = u.User.Username()
+		l.Config.Auth.Password, _ = u.User.Password()
+	}
+
 	clientConfig := lokiclient.Config{
 		LokiURL:  l.Config.URL,
 		Headers:  l.Config.Headers,

+ 14 - 1
pkg/acquisition/modules/loki/loki_test.go

@@ -6,6 +6,7 @@ import (
 	"fmt"
 	"io/ioutil"
 	"net/http"
+	"net/url"
 	"os"
 	"strings"
 	"testing"
@@ -82,7 +83,7 @@ query: >
 			config: `
 mode: tail
 source: loki
-url: http://@localhost:3100/
+url: http://localhost:3100/
 auth:
   username: foo
   password: bar
@@ -125,6 +126,7 @@ func TestConfigureDSN(t *testing.T) {
 		expectedErr  string
 		since        time.Time
 		password     string
+		scheme       string
 		waitForReady time.Duration
 	}{
 		{
@@ -163,6 +165,11 @@ func TestConfigureDSN(t *testing.T) {
 			expectedErr:  "",
 			waitForReady: 5 * time.Second,
 		},
+		{
+			name:   "SSL DSN",
+			dsn:    `loki://localhost:3100/?ssl=true`,
+			scheme: "https",
+		},
 	}
 
 	for _, test := range tests {
@@ -186,6 +193,12 @@ func TestConfigureDSN(t *testing.T) {
 				t.Fatalf("Password mismatch : %s != %s", test.password, p)
 			}
 		}
+		if test.scheme != "" {
+			url, _ := url.Parse(lokiSource.Config.URL)
+			if test.scheme != url.Scheme {
+				t.Fatalf("Schema mismatch : %s != %s", test.scheme, url.Scheme)
+			}
+		}
 		if test.waitForReady != 0 {
 			if lokiSource.Config.WaitForReady != test.waitForReady {
 				t.Fatalf("Wrong WaitForReady %v != %v", lokiSource.Config.WaitForReady, test.waitForReady)