Skip to content

Commit

Permalink
fix showing logs
Browse files Browse the repository at this point in the history
  • Loading branch information
simonoff committed Jul 25, 2022
1 parent 4cda1c1 commit b5c999d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

//nolint:gochecknoinits // cobra is initialized in init()
func init() {
rootCmd.Flags().String("log-level", "INFO", "Logging level")
rootCmd.Flags().String("log-level", "info", "Logging level")
rootCmd.Flags().String("log-fmt", "logfmt", "Logging output format: logfmt|json")
rootCmd.Flags().Int("port", 9191, "address the HTTP server will be listening to")
rootCmd.Flags().Duration("timeout", 30*time.Second, "log request timeout")
Expand Down
4 changes: 2 additions & 2 deletions pkg/faas/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ func (l *lokiRequester) buildRequest(logReq logs.Request) (req logproto.QueryReq
}

if logReq.Instance != "" {
req.Selector = fmt.Sprintf("{faas_function=\"%s\",instance=\"%s\"}", logReq.Name, logReq.Instance)
req.Selector = fmt.Sprintf("{app=\"%s\",instance=\"%s\"}", logReq.Name, logReq.Instance)
} else {
req.Selector = fmt.Sprintf("{faas_function=\"%s\"}", logReq.Name)
req.Selector = fmt.Sprintf("{app=\"%s\"}", logReq.Name)
}
log.Debug().Str("method", "buildRequest").Msgf("%v => %v", logReq, req)
return req
Expand Down
7 changes: 4 additions & 3 deletions pkg/loki/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ func (c *httpClient) doRequest(ctx context.Context, path string, out interface{}
}
req = req.WithContext(ctx)

logger.Debug().Msg(req.URL.String())
logger.Debug().Msgf("URL: %s", req.URL.String())

resp, err := c.parent.Do(req)
if err != nil {
logger.Debug().Err(err).Msgf("Error with request")
return errors.Wrap(err, "failed request")
}
defer func() {
Expand All @@ -74,15 +75,15 @@ func (c *httpClient) doRequest(ctx context.Context, path string, out interface{}
}
}()

logger.Debug().Msgf("Response: %v", resp.Status)
if !isOK(resp.StatusCode) {
return errors.Wrap(err, "error response from server")
}

return json.NewDecoder(resp.Body).Decode(out)
}

func isOK(s int) bool {
return s/100 == 2
return s == 200 || s == 201
}

func requestAsQueryParms(req logproto.QueryRequest) (params url.Values) {
Expand Down

0 comments on commit b5c999d

Please sign in to comment.