Skip to content

Commit

Permalink
chore: eliminate unnecessary use of quoted strings in printf (influxd…
Browse files Browse the repository at this point in the history
  • Loading branch information
Hipska authored Feb 23, 2023
1 parent 245705c commit 6a2f6f3
Show file tree
Hide file tree
Showing 113 changed files with 313 additions and 320 deletions.
2 changes: 1 addition & 1 deletion agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ func (a *Agent) connectOutput(ctx context.Context, output *models.RunningOutput)
err := output.Output.Connect()
if err != nil {
log.Printf("E! [agent] Failed to connect to [%s], retrying in 15s, "+
"error was '%s'", output.LogName(), err)
"error was %q", output.LogName(), err)

err := internal.SleepContext(ctx, 15*time.Second)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/telegraf/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func printConfig(name string, p telegraf.PluginDescriber, op string, commented b
if di.RemovalIn != "" {
removalNote = " and will be removed in " + di.RemovalIn
}
outputBuffer.Write([]byte(fmt.Sprintf("\n%s ## DEPRECATED: The '%s' plugin is deprecated in version %s%s, %s.",
outputBuffer.Write([]byte(fmt.Sprintf("\n%s ## DEPRECATED: The %q plugin is deprecated in version %s%s, %s.",
comment, name, di.Since, removalNote, di.Notice)))
}

Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func getDefaultConfigPath() ([]string, error) {
if _, err := os.Stat(etcfolder); err == nil {
files, err := WalkDirectory(etcfolder)
if err != nil {
log.Printf("W! unable walk '%s': %s", etcfolder, err)
log.Printf("W! unable walk %q: %s", etcfolder, err)
}
for _, file := range files {
log.Printf("I! Using config file: %s", file)
Expand Down
6 changes: 3 additions & 3 deletions internal/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ var tests = []SnakeTest{

func TestSnakeCase(t *testing.T) {
for _, test := range tests {
if SnakeCase(test.input) != test.output {
t.Errorf(`SnakeCase("%s"), wanted "%s", got \%s"`, test.input, test.output, SnakeCase(test.input))
}
t.Run(test.input, func(t *testing.T) {
require.Equal(t, test.output, SnakeCase(test.input))
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/rotate/file_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (w *FileWriter) rotateIfNeeded() error {
(w.maxSizeInBytes > 0 && w.bytesWritten >= w.maxSizeInBytes) {
if err := w.rotate(); err != nil {
//Ignore rotation errors and keep the log open
fmt.Printf("unable to rotate the file '%s', %s", w.filename, err.Error())
fmt.Printf("unable to rotate the file %q, %s", w.filename, err.Error())
}
return w.openCurrent()
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/aggregators/histogram/histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,5 +526,5 @@ func assertContainsTaggedField(t *testing.T, acc *testutil.Accumulator, metricNa
return
}

require.Fail(t, fmt.Sprintf("unknown measurement '%s' with tags: %v, fields: %v", metricName, tags, fields))
require.Fail(t, fmt.Sprintf("unknown measurement %q with tags: %v, fields: %v", metricName, tags, fields))
}
4 changes: 2 additions & 2 deletions plugins/common/jolokia2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (c *Client) read(requests []ReadRequest) ([]ReadResponse, error) {
req, err := http.NewRequest("POST", requestURL, bytes.NewBuffer(requestBody))
if err != nil {
//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)
return nil, fmt.Errorf("unable to create new request for: %q", c.URL)
}

req.Header.Add("Content-type", "application/json")
Expand All @@ -149,7 +149,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 %q has status code %d (%s), expected %d (%s)",
c.URL, resp.StatusCode, http.StatusText(resp.StatusCode), http.StatusOK, http.StatusText(http.StatusOK))
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/common/opcua/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ func (o *OpcUAClientConfig) validateEndpoint() error {
switch o.SecurityPolicy {
case "None", "Basic128Rsa15", "Basic256", "Basic256Sha256", "auto":
default:
return fmt.Errorf("invalid security type '%s' in '%s'", o.SecurityPolicy, o.Endpoint)
return fmt.Errorf("invalid security type %q in %q", o.SecurityPolicy, o.Endpoint)
}

switch o.SecurityMode {
case "None", "Sign", "SignAndEncrypt", "auto":
default:
return fmt.Errorf("invalid security type '%s' in '%s'", o.SecurityMode, o.Endpoint)
return fmt.Errorf("invalid security type %q in %q", o.SecurityMode, o.Endpoint)
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions plugins/common/opcua/input/input_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func tagsSliceToMap(tags [][]string) (map[string]string, error) {

func validateNodeToAdd(existing map[metricParts]struct{}, nmm *NodeMetricMapping) error {
if nmm.Tag.FieldName == "" {
return fmt.Errorf("empty name in '%s'", nmm.Tag.FieldName)
return fmt.Errorf("empty name in %q", nmm.Tag.FieldName)
}

if len(nmm.Tag.Namespace) == 0 {
Expand All @@ -249,19 +249,19 @@ func validateNodeToAdd(existing map[metricParts]struct{}, nmm *NodeMetricMapping

mp := newMP(nmm)
if _, exists := existing[mp]; exists {
return fmt.Errorf("name '%s' is duplicated (metric name '%s', tags '%s')",
return fmt.Errorf("name %q is duplicated (metric name %q, tags %q)",
mp.fieldName, mp.metricName, mp.tags)
}

switch nmm.Tag.IdentifierType {
case "i":
if _, err := strconv.Atoi(nmm.Tag.Identifier); err != nil {
return fmt.Errorf("identifier type '%s' does not match the type of identifier '%s'", nmm.Tag.IdentifierType, nmm.Tag.Identifier)
return fmt.Errorf("identifier type %q does not match the type of identifier %q", nmm.Tag.IdentifierType, nmm.Tag.Identifier)
}
case "s", "g", "b":
// Valid identifier type - do nothing.
default:
return fmt.Errorf("invalid identifier type '%s' in '%s'", nmm.Tag.IdentifierType, nmm.Tag.FieldName)
return fmt.Errorf("invalid identifier type %q in %q", nmm.Tag.IdentifierType, nmm.Tag.FieldName)
}

existing[mp] = struct{}{}
Expand Down Expand Up @@ -382,7 +382,7 @@ func (o *OpcUAInputClient) MetricForNode(nodeIdx int) telegraf.Metric {
fields["Quality"] = strings.TrimSpace(fmt.Sprint(o.LastReceivedData[nodeIdx].Quality))
if !o.StatusCodeOK(o.LastReceivedData[nodeIdx].Quality) {
mp := newMP(nmm)
o.Log.Debugf("status not OK for node '%s'(metric name '%s', tags '%s')",
o.Log.Debugf("status not OK for node %q(metric name %q, tags %q)",
mp.fieldName, mp.metricName, mp.tags)
}

Expand Down
18 changes: 10 additions & 8 deletions plugins/common/opcua/input/input_client_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package input

import (
"errors"
"fmt"
"testing"
"time"

"github.com/gopcua/opcua/ua"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/metric"
"github.com/influxdata/telegraf/plugins/common/opcua"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"
"testing"
"time"
)

func TestTagsSliceToMap(t *testing.T) {
Expand Down Expand Up @@ -74,7 +76,7 @@ func TestValidateOPCTags(t *testing.T) {
},
},
},
fmt.Errorf("name 'fn' is duplicated (metric name 'mn', tags 't1=v1, t2=v2')"),
errors.New(`name "fn" is duplicated (metric name "mn", tags "t1=v1, t2=v2")`),
},
{
"empty tag value not allowed",
Expand Down Expand Up @@ -352,7 +354,7 @@ func TestValidateNodeToAdd(t *testing.T) {
}, map[string]string{})
return nmm
}(),
err: fmt.Errorf("empty name in ''"),
err: errors.New(`empty name in ""`),
},
{
name: "empty namespace not allowed",
Expand Down Expand Up @@ -382,7 +384,7 @@ func TestValidateNodeToAdd(t *testing.T) {
}, map[string]string{})
return nmm
}(),
err: fmt.Errorf("invalid identifier type '' in 'f'"),
err: errors.New(`invalid identifier type "" in "f"`),
},
{
name: "invalid identifier type not allowed",
Expand All @@ -397,7 +399,7 @@ func TestValidateNodeToAdd(t *testing.T) {
}, map[string]string{})
return nmm
}(),
err: fmt.Errorf("invalid identifier type 'j' in 'f'"),
err: errors.New(`invalid identifier type "j" in "f"`),
},
{
name: "duplicate metric not allowed",
Expand All @@ -414,7 +416,7 @@ func TestValidateNodeToAdd(t *testing.T) {
}, map[string]string{})
return nmm
}(),
err: fmt.Errorf("name 'f' is duplicated (metric name 'testmetric', tags 't1=v1, t2=v2')"),
err: errors.New(`name "f" is duplicated (metric name "testmetric", tags "t1=v1, t2=v2")`),
},
{
name: "identifier type mismatch",
Expand All @@ -429,7 +431,7 @@ func TestValidateNodeToAdd(t *testing.T) {
}, map[string]string{})
return nmm
}(),
err: fmt.Errorf("identifier type 'i' does not match the type of identifier 'hf'"),
err: errors.New(`identifier type "i" does not match the type of identifier "hf"`),
},
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/common/shim/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *Shim) RunInput(pollInterval time.Duration) error {
go func() {
err := s.writeProcessedMetrics()
if err != nil {
s.log.Warnf("%s", err)
s.log.Warn(err.Error())
}
wg.Done()
}()
Expand Down
2 changes: 1 addition & 1 deletion plugins/common/shim/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *Shim) RunProcessor() error {
go func() {
err := s.writeProcessedMetrics()
if err != nil {
s.log.Warnf("%s", err)
s.log.Warn(err.Error())
}
wg.Done()
}()
Expand Down
2 changes: 1 addition & 1 deletion plugins/common/starlark/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type builtinMethod func(b *starlark.Builtin, args starlark.Tuple, kwargs []starl
func builtinAttr(recv starlark.Value, name string, methods map[string]builtinMethod) (starlark.Value, error) {
method := methods[name]
if method == nil {
return starlark.None, fmt.Errorf("no such method '%s'", name)
return starlark.None, fmt.Errorf("no such method %q", name)
}

// Allocate a closure over 'method'.
Expand Down
2 changes: 1 addition & 1 deletion plugins/common/starlark/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (m *Metric) SetField(name string, value starlark.Value) error {
return errors.New("cannot set fields")
default:
return starlark.NoSuchAttrError(
fmt.Sprintf("cannot assign to field '%s'", name))
fmt.Sprintf("cannot assign to field %q", name))
}
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/common/tls/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (c *ClientConfig) TLSConfig() (*tls.Config, error) {
case "freely":
renegotiationMethod = tls.RenegotiateFreelyAsClient
default:
return nil, fmt.Errorf("unrecognized renegotation method '%s', choose from: 'never', 'once', 'freely'", c.RenegotiationMethod)
return nil, fmt.Errorf("unrecognized renegotation method %q, choose from: 'never', 'once', 'freely'", c.RenegotiationMethod)
}

tlsConfig := &tls.Config{
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/azure_storage_queue/azure_storage_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (a *AzureStorageQueue) Gather(acc telegraf.Accumulator) error {
ctx := context.TODO()

for marker := (azqueue.Marker{}); marker.NotDone(); {
a.Log.Debugf("Listing queues of storage account '%s'", a.StorageAccountName)
a.Log.Debugf("Listing queues of storage account %q", a.StorageAccountName)
queuesSegment, err := serviceURL.ListQueuesSegment(ctx, marker,
azqueue.ListQueuesSegmentOptions{
Detail: azqueue.ListQueuesSegmentDetails{Metadata: false},
Expand All @@ -99,7 +99,7 @@ func (a *AzureStorageQueue) Gather(acc telegraf.Accumulator) error {
marker = queuesSegment.NextMarker

for _, queueItem := range queuesSegment.QueueItems {
a.Log.Debugf("Processing queue '%s' of storage account '%s'", queueItem.Name, a.StorageAccountName)
a.Log.Debugf("Processing queue %q of storage account %q", queueItem.Name, a.StorageAccountName)
queueURL := serviceURL.NewQueueURL(queueItem.Name)
properties, err := queueURL.GetProperties(ctx)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/bond/bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (bond *Bond) gatherBondPart(bondName string, rawFile string, acc telegraf.A
if err := scanner.Err(); err != nil {
return err
}
return fmt.Errorf("Couldn't find status info for '%s' ", bondName)
return fmt.Errorf("Couldn't find status info for %q", bondName)
}

func (bond *Bond) readSysFiles(bondDir string) (sysFiles, error) {
Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/cassandra/cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (j javaMetric) addTagsFields(out map[string]interface{}) {
}
j.acc.AddFields(tokens["class"]+tokens["type"], fields, tags)
} else {
j.acc.AddError(fmt.Errorf("missing key 'value' in '%s' output response: %v", j.metric, out))
j.acc.AddError(fmt.Errorf("missing key 'value' in %q output response: %v", j.metric, out))
}
}

Expand All @@ -154,7 +154,7 @@ func (c cassandraMetric) addTagsFields(out map[string]interface{}) {
tokens["scope"] == "*") {
valuesMap, ok := out["value"]
if !ok {
c.acc.AddError(fmt.Errorf("missing key 'value' in '%s' output response: %v", c.metric, out))
c.acc.AddError(fmt.Errorf("missing key 'value' in %q output response: %v", c.metric, out))
return
}
for k, v := range valuesMap.(map[string]interface{}) {
Expand All @@ -163,7 +163,7 @@ func (c cassandraMetric) addTagsFields(out map[string]interface{}) {
} else {
values, ok := out["value"]
if !ok {
c.acc.AddError(fmt.Errorf("missing key 'value' in '%s' output response: %v", c.metric, out))
c.acc.AddError(fmt.Errorf("missing key 'value' in %q output response: %v", c.metric, out))
return
}
addCassandraMetric(r.(map[string]interface{})["mbean"].(string), c, values.(map[string]interface{}))
Expand All @@ -185,7 +185,7 @@ func (c *Cassandra) getAttr(requestURL *url.URL) (map[string]interface{}, error)

// Process response
if resp.StatusCode != http.StatusOK {
err = fmt.Errorf("response from url \"%s\" has status code %d (%s), expected %d (%s)",
err = fmt.Errorf("response from url %q has status code %d (%s), expected %d (%s)",
requestURL,
resp.StatusCode,
http.StatusText(resp.StatusCode),
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/ceph/ceph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func assertFoundSocket(t *testing.T, dir, sockType string, i int, sockets []*soc
require.NoError(t, err)
if s.socket == expected {
found = true
require.Equal(t, s.sockType, sockType, "Unexpected socket type for '%s'", s)
require.Equal(t, s.sockType, sockType, "Unexpected socket type for %q", s)
require.Equal(t, s.sockID, strconv.Itoa(i))
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/conntrack/conntrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (c *Conntrack) Gather(acc telegraf.Accumulator) error {
fields[metricKey], err = strconv.ParseFloat(v, 64)
if err != nil {
acc.AddError(fmt.Errorf("failed to parse metric, expected number but "+
" found '%s': %v", v, err))
" found %q: %w", v, err))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/cpu/cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ func assertContainsTaggedFloat(
return
}
} else {
require.Fail(t, fmt.Sprintf("Measurement \"%s\" does not have type float64", measurement))
require.Fail(t, fmt.Sprintf("Measurement %q does not have type float64", measurement))
}
}
}
}
}
msg := fmt.Sprintf(
"Could not find measurement \"%s\" with requested tags within %f of %f, Actual: %f",
"Could not find measurement %q with requested tags within %f of %f, Actual: %f",
measurement, delta, expectedValue, actualValue)
require.Fail(t, msg)
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/disque/disque.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (d *Disque) gatherServer(addr *url.URL, acc telegraf.Accumulator) error {
return err
}
if line[0] != '+' {
return fmt.Errorf("%s", strings.TrimSpace(line)[1:])
return errors.New(strings.TrimSpace(line)[1:])
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/elasticsearch_query/aggregation_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ func recurseResponse(acc telegraf.Accumulator, aggNameFunction map[string]string
for _, aggName := range aggNames {
aggFunction, found := aggNameFunction[aggName]
if !found {
return m, fmt.Errorf("child aggregation function '%s' not found %v", aggName, aggNameFunction)
return m, fmt.Errorf("child aggregation function %q not found %v", aggName, aggNameFunction)
}

resp := getResponseAggregation(aggFunction, aggName, bucketResponse)
if resp == nil {
return m, fmt.Errorf("child aggregation '%s' not found", aggName)
return m, fmt.Errorf("child aggregation %q not found", aggName)
}

switch resp := resp.(type) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/elasticsearch_query/aggregation_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func getFunctionAggregation(function string, aggfield string) (elastic5.Aggregat
case "max":
agg = elastic5.NewMaxAggregation().Field(aggfield)
default:
return nil, fmt.Errorf("aggregation function '%s' not supported", function)
return nil, fmt.Errorf("aggregation function %q not supported", function)
}

return agg, nil
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/elasticsearch_query/elasticsearch_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (e *ElasticsearchQuery) Init() error {
}
err = e.initAggregation(ctx, agg, i)
if err != nil {
e.Log.Errorf("%s", err)
e.Log.Error(err.Error())
return nil
}
}
Expand All @@ -100,7 +100,7 @@ func (e *ElasticsearchQuery) initAggregation(ctx context.Context, agg esAggregat

for _, metricField := range agg.MetricFields {
if _, ok := agg.mapMetricFields[metricField]; !ok {
return fmt.Errorf("metric field '%s' not found on index '%s'", metricField, agg.Index)
return fmt.Errorf("metric field %q not found on index %q", metricField, agg.Index)
}
}

Expand Down
Loading

0 comments on commit 6a2f6f3

Please sign in to comment.