|
6 | 6 | "fmt"
|
7 | 7 | "io"
|
8 | 8 | "net/http"
|
| 9 | + "net/http/httputil" |
9 | 10 | "net/url"
|
10 | 11 | "path"
|
11 | 12 | "strconv"
|
@@ -168,12 +169,34 @@ func (s *LogPluginServer) getLokiLogs(writer *logs.BufferedLog, parent string, r
|
168 | 169 | req.Header.Set("Authorization", "Bearer "+token.AccessToken)
|
169 | 170 | resp, err := s.client.Do(req)
|
170 | 171 | if err != nil {
|
| 172 | + dump, err := httputil.DumpRequest(req, true) |
| 173 | + if err == nil { |
| 174 | + s.logger.Debugf("Request Dump***:\n %q\n", dump) |
| 175 | + } |
171 | 176 | s.logger.Errorf("request to loki failed, err: %s, req: %v", err.Error(), req)
|
172 | 177 | return status.Error(codes.Internal, "Error streaming log")
|
173 | 178 | }
|
174 | 179 |
|
| 180 | + if resp == nil { |
| 181 | + dump, err := httputil.DumpRequest(req, true) |
| 182 | + if err == nil { |
| 183 | + s.logger.Debugf("Request Dump***:\n %q\n", dump) |
| 184 | + } |
| 185 | + s.logger.Errorf("request to loki failed, received nil response") |
| 186 | + s.logger.Debugf("loki request url:%s", URL.String()) |
| 187 | + return status.Error(codes.Internal, "Error streaming log") |
| 188 | + } |
| 189 | + |
175 | 190 | if resp.StatusCode != http.StatusOK {
|
176 | 191 | s.logger.Errorf("Loki API request failed with HTTP status code: %d", resp.StatusCode)
|
| 192 | + dump, err := httputil.DumpRequest(req, true) |
| 193 | + if err == nil { |
| 194 | + s.logger.Debugf("Request Dump***:\n %q\n", dump) |
| 195 | + } |
| 196 | + dump, err = httputil.DumpResponse(resp, true) |
| 197 | + if err == nil { |
| 198 | + s.logger.Debugf("Response Dump***:\n %q\n", dump) |
| 199 | + } |
177 | 200 | return status.Error(codes.Internal, "Error fetching log data")
|
178 | 201 | }
|
179 | 202 |
|
|
0 commit comments