Skip to content

Commit

Permalink
Clearing LGTM alerts and warnings (influxdata#8923)
Browse files Browse the repository at this point in the history
  • Loading branch information
zak-pawel authored Mar 3, 2021
1 parent 5e3d7b8 commit 17efd17
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .lgtm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
queries:
- exclude: go/disabled-certificate-check
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Telegraf [![Circle CI](https://circleci.com/gh/influxdata/telegraf.svg?style=svg)](https://circleci.com/gh/influxdata/telegraf) [![Docker pulls](https://img.shields.io/docker/pulls/library/telegraf.svg)](https://hub.docker.com/_/telegraf/)
# Telegraf [![Circle CI](https://circleci.com/gh/influxdata/telegraf.svg?style=svg)](https://circleci.com/gh/influxdata/telegraf) [![Docker pulls](https://img.shields.io/docker/pulls/library/telegraf.svg)](https://hub.docker.com/_/telegraf/) [![Total alerts](https://img.shields.io/lgtm/alerts/g/influxdata/telegraf.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/influxdata/telegraf/alerts/)
[![Slack Status](https://img.shields.io/badge/slack-join_chat-white.svg?logo=slack&style=social)](https://www.influxdata.com/slack)

Telegraf is an agent for collecting, processing, aggregating, and writing metrics.
Expand Down
10 changes: 5 additions & 5 deletions plugins/inputs/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,22 @@ func (g *GitHub) Gather(acc telegraf.Accumulator) error {
fields := getFields(repositoryInfo)

for _, field := range g.AdditionalFields {
addFields := make(map[string]interface{})
switch field {
case "pull-requests":
// Pull request properties
addFields, err = g.getPullRequestFields(ctx, owner, repository)
addFields, err := g.getPullRequestFields(ctx, owner, repository)
if err != nil {
acc.AddError(err)
continue
}

for k, v := range addFields {
fields[k] = v
}
default:
acc.AddError(fmt.Errorf("unknown additional field %q", field))
continue
}
for k, v := range addFields {
fields[k] = v
}
}

acc.AddFields("github_repository", fields, tags, now)
Expand Down
17 changes: 9 additions & 8 deletions plugins/inputs/jolokia2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ func NewClient(url string, config *ClientConfig) (*Client, error) {
}

func (c *Client) read(requests []ReadRequest) ([]ReadResponse, error) {
jrequests := makeJolokiaRequests(requests, c.config.ProxyConfig)
requestBody, err := json.Marshal(jrequests)
jRequests := makeJolokiaRequests(requests, c.config.ProxyConfig)
requestBody, err := json.Marshal(jRequests)
if err != nil {
return nil, err
}
Expand All @@ -132,7 +132,8 @@ func (c *Client) read(requests []ReadRequest) ([]ReadResponse, error) {

req, err := http.NewRequest("POST", requestURL, bytes.NewBuffer(requestBody))
if err != nil {
return nil, fmt.Errorf("unable to create new request '%s': %s", requestURL, err)
//err is not contained in returned error - it may contain sensitive data (password) which should not be logged
return nil, fmt.Errorf("unable to create new request for: '%s'", c.URL)
}

req.Header.Add("Content-type", "application/json")
Expand All @@ -144,7 +145,7 @@ func (c *Client) read(requests []ReadRequest) ([]ReadResponse, error) {
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("Response from url \"%s\" has status code %d (%s), expected %d (%s)",
return nil, fmt.Errorf("response from url \"%s\" has status code %d (%s), expected %d (%s)",
c.URL, resp.StatusCode, http.StatusText(resp.StatusCode), http.StatusOK, http.StatusText(http.StatusOK))
}

Expand All @@ -153,12 +154,12 @@ func (c *Client) read(requests []ReadRequest) ([]ReadResponse, error) {
return nil, err
}

var jresponses []jolokiaResponse
if err = json.Unmarshal([]byte(responseBody), &jresponses); err != nil {
return nil, fmt.Errorf("Error decoding JSON response: %s: %s", err, responseBody)
var jResponses []jolokiaResponse
if err = json.Unmarshal(responseBody, &jResponses); err != nil {
return nil, fmt.Errorf("decoding JSON response: %s: %s", err, responseBody)
}

return makeReadResponses(jresponses), nil
return makeReadResponses(jResponses), nil
}

func makeJolokiaRequests(rrequests []ReadRequest, proxyConfig *ProxyConfig) []jolokiaRequest {
Expand Down
3 changes: 1 addition & 2 deletions plugins/inputs/riemann_listener/riemann_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ func (rsl *riemannListener) read(conn net.Conn) {

for {
if rsl.ReadTimeout != nil && rsl.ReadTimeout.Duration > 0 {

err = conn.SetDeadline(time.Now().Add(rsl.ReadTimeout.Duration))
conn.SetDeadline(time.Now().Add(rsl.ReadTimeout.Duration))
}

messagePb := &riemangoProto.Msg{}
Expand Down
3 changes: 3 additions & 0 deletions plugins/outputs/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ func (h *HTTP) write(reqBody []byte) error {
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("when writing to [%s] received status code: %d", h.URL, resp.StatusCode)
}
if err != nil {
return fmt.Errorf("when writing to [%s] received error: %v", h.URL, err)
}

return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ func (a *YandexCloudMonitoring) Write(metrics []telegraf.Metric) error {
if err != nil {
return err
}
body = append(body, jsonBytes...)
body = append(jsonBytes, '\n')
return a.send(body)
}
Expand Down
3 changes: 1 addition & 2 deletions plugins/parsers/prometheus/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ func (p *Parser) Parse(buf []byte) ([]telegraf.Metric, error) {
} else {
// standard metric
// reading fields
fields := make(map[string]interface{})
fields = getNameAndValue(m, metricName)
fields := getNameAndValue(m, metricName)
// converting to telegraf metric
if len(fields) > 0 {
t := getTimestamp(m, now)
Expand Down

0 comments on commit 17efd17

Please sign in to comment.