@@ -82,31 +82,42 @@ func (client *LokiConnector) IsReady() bool {
82
82
return err == nil && response .StatusCode == 200
83
83
}
84
84
85
- //ConnectLoki creates a new loki connector
86
- func ConnectLoki (cfg config.Config , logger * logging.Logger ) (* LokiConnector , error ) {
85
+ func CreateLokiConnector (logger * logging.Logger , address string , maxWaitTime time.Duration , batchSize int64 ) (* LokiConnector , error ) {
87
86
client := LokiConnector {
88
- quit : make (chan struct {}),
89
- streams : make (chan * LokiStream ),
90
- logger : logger ,
91
- endpoints : endpoints {
87
+ url : address ,
88
+ maxBatch : batchSize ,
89
+ maxWaitTime : maxWaitTime ,
90
+ quit : make (chan struct {}),
91
+ streams : make (chan * LokiStream ),
92
+ logger : logger ,
93
+ endpoints : endpoints {
92
94
push : "/loki/api/v1/push" ,
93
95
query : "/loki/api/v1/query_range" ,
94
96
ready : "/ready" ,
95
97
},
96
98
}
99
+ err := client .Connect ()
100
+ return & client , err
101
+ }
97
102
103
+ //ConnectLoki creates a new loki connector
104
+ func ConnectLoki (cfg config.Config , logger * logging.Logger ) (* LokiConnector , error ) {
98
105
var err error
106
+ var url string
107
+ var maxBatch int64
108
+ var maxWaitTime time.Duration
109
+
99
110
var addr * config.Option
100
111
switch conf := cfg .(type ) {
101
112
case * config.INIConfig :
102
113
addr , err = conf .GetOption ("loki/connection" )
103
114
case * config.JSONConfig :
104
115
addr , err = conf .GetOption ("Loki.Connection.Address" )
105
116
default :
106
- return & client , fmt .Errorf ("Unknown Config type" )
117
+ return nil , fmt .Errorf ("Unknown Config type" )
107
118
}
108
119
if err == nil && addr != nil {
109
- client . url = addr .GetString ()
120
+ url = addr .GetString ()
110
121
} else {
111
122
return nil , fmt .Errorf ("Failed to get connection URL from configuration file" )
112
123
}
@@ -119,7 +130,7 @@ func ConnectLoki(cfg config.Config, logger *logging.Logger) (*LokiConnector, err
119
130
batchSize , err = conf .GetOption ("Loki.Connection.BatchSize" )
120
131
}
121
132
if err == nil && batchSize != nil {
122
- client . maxBatch = batchSize .GetInt ()
133
+ maxBatch = batchSize .GetInt ()
123
134
} else {
124
135
return nil , fmt .Errorf ("Failed to get connection max batch size from configuration file" )
125
136
}
@@ -132,13 +143,12 @@ func ConnectLoki(cfg config.Config, logger *logging.Logger) (*LokiConnector, err
132
143
waitTime , err = conf .GetOption ("Loki.Connection.MaxWaitTime" )
133
144
}
134
145
if err == nil && waitTime != nil {
135
- client . maxWaitTime = time .Duration (waitTime .GetInt ()) * time .Millisecond
146
+ maxWaitTime = time .Duration (waitTime .GetInt ()) * time .Millisecond
136
147
} else {
137
148
return nil , fmt .Errorf ("Failed to get connection max wait time from configuration file" )
138
149
}
139
150
140
- err = client .Connect ()
141
- return & client , err
151
+ return CreateLokiConnector (logger , url , maxWaitTime , maxBatch )
142
152
}
143
153
144
154
//Connect just checks the Loki availability
0 commit comments