Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
All monitors own their loggers and set monitorID field
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Fitzpatrick committed Jul 20, 2022
1 parent 37914b1 commit ef730af
Show file tree
Hide file tree
Showing 146 changed files with 789 additions and 616 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ COPY --from=signalfx-agent-dev-cache:stage-agent-builder /go $GOPATH
RUN go install golang.org/x/lint/golint@latest &&\
if [ `uname -m` != "aarch64" ]; then go install github.com/go-delve/delve/cmd/dlv@latest; fi &&\
go install github.com/tebeka/go2xunit@latest &&\
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.8
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.8

COPY ./ ./

Expand Down
3 changes: 2 additions & 1 deletion pkg/core/common/docker/containerlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
dtypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
docker "github.com/docker/docker/client"
"github.com/signalfx/signalfx-agent/pkg/utils/filter"
log "github.com/sirupsen/logrus"

"github.com/signalfx/signalfx-agent/pkg/utils/filter"
)

// ContainerChangeHandler is what gets called when a Docker container is
Expand Down
11 changes: 7 additions & 4 deletions pkg/core/common/kubelet/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
"time"

"github.com/pkg/errors"
"github.com/signalfx/signalfx-agent/pkg/core/common/auth"
log "github.com/sirupsen/logrus"

"github.com/signalfx/signalfx-agent/pkg/core/common/auth"
)

// AuthType to use when connecting to kubelet
Expand Down Expand Up @@ -56,10 +57,11 @@ type APIConfig struct {
type Client struct {
*http.Client
config *APIConfig
logger log.FieldLogger
}

// NewClient creates a new client with the given config
func NewClient(kubeletAPI *APIConfig) (*Client, error) {
func NewClient(kubeletAPI *APIConfig, logger log.FieldLogger) (*Client, error) {
if kubeletAPI.URL == "" {
hostname, err := os.Hostname()
if err != nil {
Expand Down Expand Up @@ -110,7 +112,7 @@ func NewClient(kubeletAPI *APIConfig) (*Client, error) {
Token: string(token),
}

log.Debug("Using service account authentication for Kubelet")
logger.Debug("Using service account authentication for Kubelet")
default:
transport.(*http.Transport).TLSClientConfig = tlsConfig
}
Expand All @@ -121,6 +123,7 @@ func NewClient(kubeletAPI *APIConfig) (*Client, error) {
Transport: transport,
},
config: kubeletAPI,
logger: logger,
}, nil
}

Expand Down Expand Up @@ -157,7 +160,7 @@ func (kc *Client) DoRequestAndSetValue(req *http.Request, value interface{}) err
}

if kc.config.LogResponses {
log.WithField("url", req.URL.String()).WithField("body", string(body)).Info("Raw response from Kubelet url")
kc.logger.WithField("url", req.URL.String()).WithField("body", string(body)).Info("Raw response from Kubelet url")
}

err = json.Unmarshal(body, value)
Expand Down
11 changes: 5 additions & 6 deletions pkg/core/config/sources/vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import (
"sync"
"time"

"github.com/signalfx/signalfx-agent/pkg/core/config/sources/vault/auth"
"github.com/signalfx/signalfx-agent/pkg/core/config/types"
"github.com/sirupsen/logrus"
"github.com/hashicorp/vault/api"
log "github.com/sirupsen/logrus"

"github.com/hashicorp/vault/api"
"github.com/signalfx/signalfx-agent/pkg/core/config/sources/vault/auth"
"github.com/signalfx/signalfx-agent/pkg/core/config/types"
)

type vaultConfigSource struct {
Expand All @@ -32,7 +31,7 @@ type vaultConfigSource struct {
nowProvider func() time.Time
conf *Config
tokenRenewer *api.LifetimeWatcher
logger logrus.FieldLogger
logger log.FieldLogger
}

var _ types.Stoppable = &vaultConfigSource{}
Expand Down Expand Up @@ -110,7 +109,7 @@ func (c *Config) New() (types.ConfigSource, error) {

// New creates a new vault ConfigSource
func New(conf *Config) (types.ConfigSource, error) {
logger := logrus.WithFields(log.Fields{"remoteConfigSource": "vault"})
logger := log.WithFields(log.Fields{"remoteConfigSource": "vault"})

logger.Info("Initializing new Vault remote config instance")

Expand Down
10 changes: 5 additions & 5 deletions pkg/core/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/signalfx/golib/v3/datapoint"
"github.com/signalfx/golib/v3/sfxclient"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"

"github.com/signalfx/signalfx-agent/pkg/core/dpfilters"
"github.com/signalfx/signalfx-agent/pkg/core/writer/tap"
"github.com/signalfx/signalfx-agent/pkg/utils"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)

// VersionLine should be populated by the startup logic to contain version
Expand Down Expand Up @@ -211,13 +211,13 @@ func (a *Agent) datapointTapHandler(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(200)
dpTap := tap.New(filter, rw)

logrus.Infof("Datapoint tap started")
log.Infof("Datapoint tap started")
a.writer.SetTap(dpTap)

dpTap.Run(req.Context())

a.writer.SetTap(nil)
logrus.Infof("Datapoint tap cleared")
log.Infof("Datapoint tap cleared")
}

func streamDatapoints(host string, port uint16, metric string, dims string) (io.ReadCloser, error) {
Expand Down
1 change: 0 additions & 1 deletion pkg/core/services/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ func DoesServiceMatchRule(si Endpoint, ruleText string, doValidation bool) bool
exprVal, ok := ret.(bool)
if !ok {
log.WithFields(log.Fields{

"discoveryRule": ruleText,
"serviceInstance": spew.Sdump(si),
}).Errorf("Discovery rule did not evaluate to a true/false value")
Expand Down
3 changes: 2 additions & 1 deletion pkg/core/writer/dimensions/dedup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"reflect"

lru "github.com/hashicorp/golang-lru"
"github.com/signalfx/signalfx-agent/pkg/monitors/types"
log "github.com/sirupsen/logrus"

"github.com/signalfx/signalfx-agent/pkg/monitors/types"
)

type deduplicator struct {
Expand Down
30 changes: 14 additions & 16 deletions pkg/core/writer/signalfx/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ import (
"github.com/signalfx/golib/v3/sfxclient"
"github.com/signalfx/golib/v3/trace"
sfxwriter "github.com/signalfx/signalfx-go/writer"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"

"github.com/signalfx/signalfx-agent/pkg/apm/correlations"

libtracker "github.com/signalfx/signalfx-agent/pkg/apm/tracetracker"
"github.com/signalfx/signalfx-agent/pkg/core/config"
"github.com/signalfx/signalfx-agent/pkg/core/writer/dimensions"
Expand Down Expand Up @@ -100,7 +98,7 @@ func New(conf *config.WriterConfig, dpChan chan []*datapoint.Datapoint, eventCha
dimensionChan chan *types.Dimension, spanChan chan []*trace.Span,
spanSourceTracker *tracetracker.SpanSourceTracker) (*Writer, error) {

logger := utils.NewThrottledLogger(logrus.WithFields(logrus.Fields{"component": "writer"}), 20*time.Second)
logger := utils.NewThrottledLogger(log.WithFields(log.Fields{"component": "writer"}), 20*time.Second)

ctx, cancel := context.WithCancel(context.Background())

Expand Down Expand Up @@ -179,7 +177,7 @@ func New(conf *config.WriterConfig, dpChan chan []*datapoint.Datapoint, eventCha

dpEndpointURL, err := conf.ParsedIngestURL().Parse("v2/datapoint")
if err != nil {
logger.WithFields(logrus.Fields{
logger.WithFields(log.Fields{
"error": err,
"ingestURL": conf.ParsedIngestURL().String(),
}).Error("Could not construct datapoint ingest URL")
Expand All @@ -192,7 +190,7 @@ func New(conf *config.WriterConfig, dpChan chan []*datapoint.Datapoint, eventCha
var err error
eventEndpointURL, err = conf.ParsedIngestURL().Parse("v2/event")
if err != nil {
logger.WithFields(logrus.Fields{
logger.WithFields(log.Fields{
"error": err,
"ingestURL": conf.ParsedIngestURL().String(),
}).Error("Could not construct event ingest URL")
Expand All @@ -206,7 +204,7 @@ func New(conf *config.WriterConfig, dpChan chan []*datapoint.Datapoint, eventCha
var err error
traceEndpointURL, err = conf.ParsedIngestURL().Parse(conf.DefaultTraceEndpointPath())
if err != nil {
logger.WithFields(logrus.Fields{
logger.WithFields(log.Fields{
"error": err,
"ingestURL": conf.ParsedIngestURL().String(),
}).Error("Could not construct trace ingest URL")
Expand Down Expand Up @@ -267,7 +265,7 @@ func (sw *Writer) processDatapoint(dp *datapoint.Datapoint) bool {
utils.TruncateDimensionValuesInPlace(dp.Dimensions)

if sw.conf.LogDatapoints {
log.Debugf("Sending datapoint:\n%s", utils.DatapointToString(dp))
sw.logger.Debugf("Sending datapoint:\n%s", utils.DatapointToString(dp))
}

return true
Expand All @@ -278,11 +276,11 @@ func (sw *Writer) sendDatapoints(ctx context.Context, dps []*datapoint.Datapoint
err := sw.client.AddDatapoints(ctx, dps)
if err != nil {
if isTransientError(err) {
log.Debugf("retrying datapoint submission after receiving temporary network error: %v\n", err)
sw.logger.Debugf("retrying datapoint submission after receiving temporary network error: %v\n", err)
err = sw.client.AddDatapoints(ctx, dps)
}
if err != nil {
log.WithFields(log.Fields{
sw.logger.WithFields(log.Fields{
"error": utils.SanitizeHTTPError(err),
}).Error("Error shipping datapoints to SignalFx")
// If there is an error sending datapoints then just forget about them.
Expand All @@ -291,7 +289,7 @@ func (sw *Writer) sendDatapoints(ctx context.Context, dps []*datapoint.Datapoint

}

log.Debugf("Sent %d datapoints out of the agent", len(dps))
sw.logger.Debugf("Sent %d datapoints out of the agent", len(dps))

// dpTap.Accept handles the receiver being nil
sw.dpTap.Accept(dps)
Expand Down Expand Up @@ -333,7 +331,7 @@ func (sw *Writer) sendEvents(events []*event.Event) error {
sw.PreprocessEvent(events[i])

if sw.conf.LogEvents {
log.WithFields(log.Fields{
sw.logger.WithFields(log.Fields{
"event": spew.Sdump(events[i]),
}).Debug("Sending event")
}
Expand All @@ -346,7 +344,7 @@ func (sw *Writer) sendEvents(events []*event.Event) error {
}
}
sw.eventsSent += int64(len(events))
log.Debugf("Sent %d events to SignalFx", len(events))
sw.logger.Debugf("Sent %d events to SignalFx", len(events))

return nil
}
Expand All @@ -367,7 +365,7 @@ func (sw *Writer) listenForEventsAndDimensionUpdates() {

case event := <-sw.eventChan:
if len(sw.eventBuffer) > eventBufferCapacity {
log.WithFields(log.Fields{
sw.logger.WithFields(log.Fields{
"eventType": event.EventType,
"eventBufferLength": len(sw.eventBuffer),
}).Error("Dropping event due to overfull buffer")
Expand All @@ -380,14 +378,14 @@ func (sw *Writer) listenForEventsAndDimensionUpdates() {
go func(buf []*event.Event) {
if err := sw.sendEvents(buf); err != nil {

log.WithError(utils.SanitizeHTTPError(err)).Error("Error shipping events to SignalFx")
sw.logger.WithError(utils.SanitizeHTTPError(err)).Error("Error shipping events to SignalFx")
}
}(sw.eventBuffer)
initEventBuffer()
}
case dim := <-sw.dimensionChan:
if err := sw.dimensionClient.AcceptDimension(dim); err != nil {
log.WithFields(log.Fields{
sw.logger.WithFields(log.Fields{
"dimName": dim.Name,
"dimValue": dim.Value,
}).WithError(utils.SanitizeHTTPError(err)).Warn("Dropping dimension update")
Expand All @@ -407,5 +405,5 @@ func (sw *Writer) Shutdown() {
if sw.cancel != nil {
sw.cancel()
}
log.Debug("Stopped datapoint writer")
sw.logger.Debug("Stopped datapoint writer")
}
6 changes: 3 additions & 3 deletions pkg/core/writer/splunk/splunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import (
"strings"
"time"

"github.com/signalfx/golib/v3/trace"

"github.com/signalfx/golib/v3/datapoint"
"github.com/signalfx/golib/v3/event"
"github.com/signalfx/golib/v3/trace"
"github.com/sirupsen/logrus"

"github.com/signalfx/signalfx-agent/pkg/core/common/httpclient"
"github.com/signalfx/signalfx-agent/pkg/core/config"
"github.com/signalfx/signalfx-agent/pkg/core/writer/processor"
"github.com/signalfx/signalfx-agent/pkg/utils"
"github.com/sirupsen/logrus"
)

const (
Expand Down
3 changes: 3 additions & 0 deletions pkg/monitors/aspdotnet/aspdotnet.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package aspdotnet

import (
"github.com/sirupsen/logrus"

"github.com/signalfx/signalfx-agent/pkg/core/config"
"github.com/signalfx/signalfx-agent/pkg/monitors"
"github.com/signalfx/signalfx-agent/pkg/monitors/types"
Expand All @@ -26,6 +28,7 @@ type Config struct {
type Monitor struct {
Output types.Output
cancel func()
logger logrus.FieldLogger // nolint: structcheck,unused
}

// Shutdown stops the metric sync
Expand Down
8 changes: 5 additions & 3 deletions pkg/monitors/aspdotnet/aspdotnet_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ import (
"strings"
"time"

"github.com/sirupsen/logrus"

"github.com/signalfx/signalfx-agent/pkg/monitors/telegraf/common/accumulator"
"github.com/signalfx/signalfx-agent/pkg/monitors/telegraf/common/emitter/baseemitter"
"github.com/signalfx/signalfx-agent/pkg/monitors/telegraf/monitors/winperfcounters"
"github.com/signalfx/signalfx-agent/pkg/utils"
"github.com/sirupsen/logrus"
)

var logger = logrus.WithField("monitorType", monitorType)

// Configure the monitor and kick off metric syncing
func (m *Monitor) Configure(conf *Config) error {
m.logger = logger.WithField("monitorID", conf.MonitorID)
perfcounterConf := &winperfcounters.Config{
CountersRefreshInterval: conf.CountersRefreshInterval,
PrintValid: conf.PrintValid,
Expand Down Expand Up @@ -65,7 +67,7 @@ func (m *Monitor) Configure(conf *Config) error {
}

// create batch emitter
emitter := baseemitter.NewEmitter(m.Output, logger)
emitter := baseemitter.NewEmitter(m.Output, m.logger)

// Hard code the plugin name because the emitter will parse out the
// configured measurement name as plugin and that is confusing.
Expand Down Expand Up @@ -93,7 +95,7 @@ func (m *Monitor) Configure(conf *Config) error {
// gather metrics on the specified interval
utils.RunOnInterval(ctx, func() {
if err := plugin.Gather(ac); err != nil {
logger.WithError(err).Errorf("an error occurred while gathering metrics from the plugin")
m.logger.WithError(err).Errorf("an error occurred while gathering metrics from the plugin")
}
}, time.Duration(conf.IntervalSeconds)*time.Second)

Expand Down
Loading

0 comments on commit ef730af

Please sign in to comment.