Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple lint fixes to help support newer version of github.com/golangci/golangci-lint in /internal/tools #3843

Merged
merged 3 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package httpclient
import (
"crypto/tls"
"crypto/x509"
"errors"
"io/ioutil"
"net"
"net/http"
Expand Down Expand Up @@ -152,7 +151,7 @@ func TestHttpTimeout(t *testing.T) {
}
req.Error(err)
var uerr *url.Error
req.True(errors.As(err, &uerr))
req.ErrorAs(err, &uerr)
req.True(uerr.Timeout())
})
}
Expand Down
8 changes: 4 additions & 4 deletions internal/signalfx-agent/pkg/core/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ func TestWriterOutputValidation(t *testing.T) {
{ProcPath: "/proc"},
},
}
require.Nil(t, defaults.Set(c))
require.NoError(t, defaults.Set(c))

err := c.validate()
require.NotNil(t, err)
require.Error(t, err)
require.Contains(t, err.Error(), "output are disabled")
})

Expand All @@ -37,9 +37,9 @@ func TestWriterOutputValidation(t *testing.T) {
{ProcPath: "/proc"},
},
}
require.Nil(t, defaults.Set(c))
require.NoError(t, defaults.Set(c))

err := c.validate()
require.Nil(t, err)
require.NoError(t, err)
})
}
2 changes: 1 addition & 1 deletion internal/signalfx-agent/pkg/core/config/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func TestNewFilters(t *testing.T) {
},
},
})
assert.Nil(t, err)
assert.NoError(t, err)

assert.True(t, f.Matches(&datapoint.Datapoint{Metric: "disk.utilization"}))
assert.True(t, f.Matches(&datapoint.Datapoint{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package auth

import (
"fmt"
"strconv"

gcpauth "github.com/hashicorp/vault-plugin-auth-gcp/plugin"
"github.com/hashicorp/vault/api"
Expand Down Expand Up @@ -61,7 +61,7 @@ func (ic *GCPConfig) GetToken(client *api.Client) (*api.Secret, error) {
data["credentials"] = *ic.Credentials
}
if ic.JWTExp != nil {
data["jwt_exp"] = fmt.Sprintf("%d", *ic.JWTExp)
data["jwt_exp"] = strconv.Itoa(*ic.JWTExp)
}
if ic.ServiceAccount != nil {
data["service_account"] = *ic.ServiceAccount
Expand Down
2 changes: 1 addition & 1 deletion internal/signalfx-agent/pkg/core/dpfilters/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
type DatapointFilter interface {
// Matches takes a datapoint and returns whether it is matched by the
// filter
Matches(*datapoint.Datapoint) bool
Matches(dp *datapoint.Datapoint) bool
}

// BasicDatapointFilter is designed to filter SignalFx datapoint objects. It
Expand Down
28 changes: 14 additions & 14 deletions internal/signalfx-agent/pkg/core/propfilters/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestFilters(t *testing.T) {
filteredProperties := f.FilterProperties(properties)

expectedProperties := map[string]string{"replicaSet": "abc"}
assert.Equal(t, filteredProperties, expectedProperties)
assert.Equal(t, expectedProperties, filteredProperties)
})

t.Run("Filter a regex property name", func(t *testing.T) {
Expand All @@ -27,7 +27,7 @@ func TestFilters(t *testing.T) {
filteredProperties := f.FilterProperties(properties)

expectedProperties := map[string]string{"replicaSet": "abc"}
assert.Equal(t, filteredProperties, expectedProperties)
assert.Equal(t, expectedProperties, filteredProperties)
})

t.Run("Filter a globbed property name", func(t *testing.T) {
Expand All @@ -38,7 +38,7 @@ func TestFilters(t *testing.T) {
filteredProperties := f.FilterProperties(properties)

expectedProperties := map[string]string{"replicaSet": "abc"}
assert.Equal(t, filteredProperties, expectedProperties)
assert.Equal(t, expectedProperties, filteredProperties)
})

t.Run("Filter a single property value", func(t *testing.T) {
Expand All @@ -49,7 +49,7 @@ func TestFilters(t *testing.T) {
filteredProperties := f.FilterProperties(properties)

expectedProperties := map[string]string{"replicaSet": "abc"}
assert.Equal(t, filteredProperties, expectedProperties)
assert.Equal(t, expectedProperties, filteredProperties)
})

t.Run("Filter a regex property value", func(t *testing.T) {
Expand All @@ -60,7 +60,7 @@ func TestFilters(t *testing.T) {
filteredProperties := f.FilterProperties(properties)

expectedProperties := map[string]string{"replicaSet": "abc"}
assert.Equal(t, filteredProperties, expectedProperties)
assert.Equal(t, expectedProperties, filteredProperties)
})

t.Run("Filter a globbed property value", func(t *testing.T) {
Expand All @@ -71,7 +71,7 @@ func TestFilters(t *testing.T) {
filteredProperties := f.FilterProperties(properties)

expectedProperties := map[string]string{"replicaSet": "abc"}
assert.Equal(t, filteredProperties, expectedProperties)
assert.Equal(t, expectedProperties, filteredProperties)
})

t.Run("Filter a property name and value", func(t *testing.T) {
Expand All @@ -82,7 +82,7 @@ func TestFilters(t *testing.T) {
filteredProperties := f.FilterProperties(properties)

expectedProperties := map[string]string{"replicaSet": "abc"}
assert.Equal(t, filteredProperties, expectedProperties)
assert.Equal(t, expectedProperties, filteredProperties)
})

t.Run("Filter a single dimension name", func(t *testing.T) {
Expand Down Expand Up @@ -171,7 +171,7 @@ func TestFilters(t *testing.T) {
filteredDimension := f.FilterDimension(dim)

expectedProperties := map[string]string{"replicaSet": "abc"}
assert.Equal(t, filteredDimension.Properties, expectedProperties)
assert.Equal(t, expectedProperties, filteredDimension.Properties)
})

t.Run("Filter a dimension object given property value", func(t *testing.T) {
Expand All @@ -189,7 +189,7 @@ func TestFilters(t *testing.T) {
filteredDimension := f.FilterDimension(dim)

expectedProperties := map[string]string{"replicaSet": "abc"}
assert.Equal(t, filteredDimension.Properties, expectedProperties)
assert.Equal(t, expectedProperties, filteredDimension.Properties)
})

t.Run("Filter a dimension object given property name and value", func(t *testing.T) {
Expand All @@ -205,7 +205,7 @@ func TestFilters(t *testing.T) {
}
filteredDimension := f.FilterDimension(dim)
expectedProperties := map[string]string{"replicaSet": "abc", "service_uid": "123"}
assert.Equal(t, filteredDimension.Properties, expectedProperties)
assert.Equal(t, expectedProperties, filteredDimension.Properties)
})

t.Run("Filter a dimension object given dimension value", func(t *testing.T) {
Expand Down Expand Up @@ -245,8 +245,8 @@ func TestFilters(t *testing.T) {
filteredDimension := f.FilterDimension(dim)
nodeFilteredDimension := f.FilterDimension(dimNode)
expectedProperties := map[string]string{"replicaSet": "abc", "service_uid": "123"}
assert.Equal(t, filteredDimension.Properties, expectedProperties)
assert.Equal(t, nodeFilteredDimension.Properties, properties)
assert.Equal(t, expectedProperties, filteredDimension.Properties)
assert.Equal(t, properties, nodeFilteredDimension.Properties)
jvoravong marked this conversation as resolved.
Show resolved Hide resolved
})

// negation tests
Expand All @@ -258,7 +258,7 @@ func TestFilters(t *testing.T) {
filteredProperties := f.FilterProperties(properties)

expectedProperties := map[string]string{"pod-template-hash": "123"}
assert.Equal(t, filteredProperties, expectedProperties)
assert.Equal(t, expectedProperties, filteredProperties)
})

t.Run("Filter a single negated property value", func(t *testing.T) {
Expand All @@ -269,7 +269,7 @@ func TestFilters(t *testing.T) {
filteredProperties := f.FilterProperties(properties)

expectedProperties := map[string]string{"pod-template-hash": "123"}
assert.Equal(t, filteredProperties, expectedProperties)
assert.Equal(t, expectedProperties, filteredProperties)
})

t.Run("Match a negated dimension name", func(t *testing.T) {
Expand Down
22 changes: 11 additions & 11 deletions internal/signalfx-agent/pkg/monitors/cloudfoundry/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,36 @@ func envelopeToDatapoints(env *loggregator_v2.Envelope) ([]*datapoint.Datapoint,
// We intentionally modify the Tags map on the envelope, assuming that the
// loggregator code that generated it is not going to reuse envelope
// instances or tag maps.
dims := env.Tags
dims := env.GetTags()

prefix := ""

if env.SourceId != "" {
dims["source_id"] = env.SourceId
if hexIDRegexp.MatchString(env.SourceId) {
prefix = env.Tags["origin"] + "."
if env.GetSourceId() != "" {
dims["source_id"] = env.GetSourceId()
if hexIDRegexp.MatchString(env.GetSourceId()) {
prefix = env.GetTags()["origin"] + "."
} else {
prefix = env.SourceId + "."
prefix = env.GetSourceId() + "."
}
}

if env.InstanceId != "" {
dims["instance_id"] = env.InstanceId
if env.GetInstanceId() != "" {
dims["instance_id"] = env.GetInstanceId()
}

var metricType datapoint.MetricType

namesToValues := make(map[string]float64)

switch m := env.Message.(type) {
switch m := env.GetMessage().(type) {
case *loggregator_v2.Envelope_Log:
case *loggregator_v2.Envelope_Counter:
metricType = datapoint.Counter
namesToValues[m.Counter.GetName()] = float64(m.Counter.GetTotal())
case *loggregator_v2.Envelope_Gauge:
metricType = datapoint.Gauge
for name, gauge := range m.Gauge.GetMetrics() {
namesToValues[name] = gauge.Value
namesToValues[name] = gauge.GetValue()
}
case *loggregator_v2.Envelope_Timer:
case *loggregator_v2.Envelope_Event:
Expand All @@ -56,7 +56,7 @@ func envelopeToDatapoints(env *loggregator_v2.Envelope) ([]*datapoint.Datapoint,

var dps []*datapoint.Datapoint
for name, val := range namesToValues {
dps = append(dps, datapoint.New(prefix+cleanupName(name), dims, datapoint.NewFloatValue(val), metricType, time.Unix(0, env.Timestamp)))
dps = append(dps, datapoint.New(prefix+cleanupName(name), dims, datapoint.NewFloatValue(val), metricType, time.Unix(0, env.GetTimestamp())))
}

return dps, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/signalfx-agent/pkg/monitors/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type DynamicConfig struct {
}

type MockMonitor interface {
SetConfigHook(func(types.MonitorID, MockMonitor))
SetConfigHook(configHook func(types.MonitorID, MockMonitor))
AddShutdownHook(fn func())
Type() string
MyVar() string
Expand Down
8 changes: 5 additions & 3 deletions internal/signalfx-agent/pkg/monitors/postgresql/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ type Monitor struct {
logger logrus.FieldLogger
}

const dbNamePrefix = " dbname="

// Configure the monitor and kick off metric collection
func (m *Monitor) Configure(conf *Config) error {
m.conf = conf
Expand All @@ -118,7 +120,7 @@ func (m *Monitor) Configure(conf *Config) error {
m.connectionString = connStr
m.Output.AddExtraDimension("postgres_port", port)

connectionStringWithMasterDB := m.connectionString + " dbname=" + m.conf.MasterDBName
connectionStringWithMasterDB := m.connectionString + dbNamePrefix + m.conf.MasterDBName

var dbFilter filter.StringFilter
if len(conf.Databases) > 0 {
Expand Down Expand Up @@ -235,7 +237,7 @@ func (m *Monitor) startMonitoringDatabase(name string) (*sql.Monitor, error) {

return sqlMon, sqlMon.Configure(&sql.Config{
MonitorConfig: m.conf.MonitorConfig,
ConnectionString: m.connectionString + " dbname=" + name,
ConnectionString: m.connectionString + dbNamePrefix + name,
DBDriver: "postgres",
Queries: makeDefaultDBQueries(name),
LogQueries: m.conf.LogQueries,
Expand Down Expand Up @@ -338,7 +340,7 @@ func (m *Monitor) monitorReplication() (*sql.Monitor, error) {

return sqlMon, sqlMon.Configure(&sql.Config{
MonitorConfig: m.conf.MonitorConfig,
ConnectionString: connStr + " dbname=" + m.conf.MasterDBName,
ConnectionString: connStr + dbNamePrefix + m.conf.MasterDBName,
DBDriver: "postgres",
Queries: defaultReplicationQueries,
LogQueries: m.conf.LogQueries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ func TestProcessListLinux(t *testing.T) {
cache := initOSCache()

tps, err := ProcessList(&Config{}, cache, nil)
require.Nil(t, err)
require.Greater(t, len(tps), 0)
require.NoError(t, err)
require.NotEmpty(t, len(tps))

selfPID := os.Getpid()
for _, proc := range tps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ func convertMetricFamily(mf *dto.MetricFamily) []*datapoint.Datapoint {
}
switch *mf.Type {
case dto.MetricType_GAUGE:
return makeSimpleDatapoints(*mf.Name, mf.Metric, sfxclient.GaugeF, gaugeExtractor)
return makeSimpleDatapoints(mf.GetName(), mf.GetMetric(), sfxclient.GaugeF, gaugeExtractor)
case dto.MetricType_COUNTER:
return makeSimpleDatapoints(*mf.Name, mf.Metric, sfxclient.CumulativeF, counterExtractor)
return makeSimpleDatapoints(mf.GetName(), mf.GetMetric(), sfxclient.CumulativeF, counterExtractor)
case dto.MetricType_UNTYPED:
return makeSimpleDatapoints(*mf.Name, mf.Metric, sfxclient.GaugeF, untypedExtractor)
return makeSimpleDatapoints(mf.GetName(), mf.GetMetric(), sfxclient.GaugeF, untypedExtractor)
case dto.MetricType_SUMMARY:
return makeSummaryDatapoints(*mf.Name, mf.Metric)
return makeSummaryDatapoints(mf.GetName(), mf.GetMetric())
// TODO: figure out how to best convert histograms, in particular the
// upper bound value
case dto.MetricType_HISTOGRAM:
return makeHistogramDatapoints(*mf.Name, mf.Metric)
return makeHistogramDatapoints(mf.GetName(), mf.GetMetric())
default:
return nil
}
Expand All @@ -49,15 +49,15 @@ func convertMetricFamily(mf *dto.MetricFamily) []*datapoint.Datapoint {
func makeSimpleDatapoints(name string, ms []*dto.Metric, dpf dpFactory, e extractor) []*datapoint.Datapoint {
dps := make([]*datapoint.Datapoint, len(ms))
for i, m := range ms {
dps[i] = dpf(name, labelsToDims(m.Label), e(m))
dps[i] = dpf(name, labelsToDims(m.GetLabel()), e(m))
}
return dps
}

func makeSummaryDatapoints(name string, ms []*dto.Metric) []*datapoint.Datapoint {
var dps []*datapoint.Datapoint
for _, m := range ms {
dims := labelsToDims(m.Label)
dims := labelsToDims(m.GetLabel())
s := m.GetSummary()
if s == nil {
continue
Expand Down Expand Up @@ -85,7 +85,7 @@ func makeSummaryDatapoints(name string, ms []*dto.Metric) []*datapoint.Datapoint
func makeHistogramDatapoints(name string, ms []*dto.Metric) []*datapoint.Datapoint {
var dps []*datapoint.Datapoint
for _, m := range ms {
dims := labelsToDims(m.Label)
dims := labelsToDims(m.GetLabel())
h := m.GetHistogram()
if h == nil {
continue
Expand Down
4 changes: 2 additions & 2 deletions internal/signalfx-agent/pkg/monitors/subproc/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ func makePipes() (*messageReadWriter, io.ReadCloser, io.WriteCloser, error) {
// subprocess. MontiorCore.ConfigureInSubproc handles configuring the
// subprocess monitor and collecting the result.
type MessageHandler interface {
ProcessMessages(context.Context, MessageReceiver)
HandleLogMessage(io.Reader) error
ProcessMessages(ctx context.Context, messageReceiver MessageReceiver)
HandleLogMessage(r io.Reader) error
}

// ConfigureInSubproc sends the given config to the subproc and returns whether
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
// Emitter interface to telegraf accumulator for processing metrics from
// telegraf
type Emitter interface {
// Add is a function used by the telegraf accumulator to emit events
// through the agent. Pleaes note that if the emitter is a BatchEmitter
// AddMetric Add is a function used by the telegraf accumulator to emit events
// through the agent. Please note that if the emitter is a BatchEmitter
// you will have to invoke the Send() function to send the batch of
// datapoints and events collected by the Emit function
AddMetric(telegraf.Metric)
AddMetric(m telegraf.Metric)
// AddTag adds a key/value pair to all measurement tags. If a key conflicts
// the key value pair in AddTag will override the original key on the
// measurement
Expand Down
Loading
Loading