Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeWinikates committed Nov 16, 2023
1 parent 2117b1f commit 617079c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 47 deletions.
18 changes: 9 additions & 9 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ linters:
disable-all: true
enable:
- errcheck
- gci
# - goconst
- gocritic
- gocyclo
- gofmt
- goimports
- gosimple
- govet
- gofmt
- gci
- revive
- ineffassign
- staticcheck
- megacheck
- misspell
- gocyclo
- revive
- staticcheck
- typecheck
- megacheck
- goimports
- goconst
- unconvert
- gocritic
issues:
exclude-rules:
- path: example.*_test\.go
Expand Down
2 changes: 1 addition & 1 deletion application/heartbeater.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (hb *heartbeater) beat() {
hb.send(tags)
}

//send customTags heartbeat
// send customTags heartbeat
hb.mux.Lock()
for len(hb.customTags) > 0 {
tags := hb.customTags[0]
Expand Down
8 changes: 4 additions & 4 deletions internal/sdkmetrics/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ func (f *fakeSender) SendDeltaCounter(string, float64, string, map[string]string
func (f *fakeSender) SendMetric(name string, _ float64, _ int64, _ string, tags map[string]string) error {
f.count = f.count + 1
if f.prefix != "" && !strings.HasPrefix(name, f.prefix) {
f.errors = f.errors + 1
f.errors++
}
if f.name != "" && f.prefix != "" && (name != f.prefix+"."+f.name) {
f.errors = f.errors + 1
f.errors++
}
for _, k := range f.tags {
if tags == nil {
f.errors = f.errors + 1
f.errors++
} else {
if _, ok := tags[k]; !ok {
f.errors = f.errors + 1
f.errors++
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions internal/span/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/wavefronthq/wavefront-sdk-go/internal"
)

// Line gets a span line in the Wavefront span data format:
// Line returns a span line in the Wavefront span data format:
// <tracingSpanName> source=<source> [pointTags] <start_millis> <duration_milli_seconds>
// Example:
// "getAllUsers source=localhost traceId=7b3bf470-9456-11e8-9eb6-529269fb1459 spanId=0313bafe-9457-11e8-9eb6-529269fb1459
Expand Down Expand Up @@ -80,6 +80,7 @@ func Line(name string, startMillis, durationMillis int64, source, traceID, spanI
return sb.String(), nil
}

// LogJSON returns Span Logs as a string in JSON format,
func LogJSON(traceID, spanID string, spanLogs []Log, span string) (string, error) {
l := Logs{
TraceID: traceID,
Expand All @@ -91,7 +92,7 @@ func LogJSON(traceID, spanID string, spanLogs []Log, span string) (string, error
if err != nil {
return "", err
}
return string(out[:]) + "\n", nil
return string(out) + "\n", nil
}

func isUUIDFormat(str string) bool {
Expand Down
11 changes: 4 additions & 7 deletions senders/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ import (
)

func tokenServiceForCfg(cfg *configuration) auth.Service {
switch cfg.Authentication.(type) {
switch a := cfg.Authentication.(type) {
case auth.APIToken:
log.Println("The Wavefront SDK will use Direct Ingestion authenticated using an API Token.")
tokenAuth := cfg.Authentication.(auth.APIToken)
return auth.NewWavefrontTokenService(tokenAuth.Token)
return auth.NewWavefrontTokenService(a.Token)
case auth.CSPClientCredentials:
log.Println("The Wavefront SDK will use Direct Ingestion authenticated using CSP client credentials.")
cspAuth := cfg.Authentication.(auth.CSPClientCredentials)
return auth.NewCSPServerToServerService(cspAuth.BaseURL, cspAuth.ClientID, cspAuth.ClientSecret, cspAuth.OrgID)
return auth.NewCSPServerToServerService(a.BaseURL, a.ClientID, a.ClientSecret, a.OrgID)
case auth.CSPAPIToken:
log.Println("The Wavefront SDK will use Direct Ingestion authenticated using CSP API Token.")
cspAuth := cfg.Authentication.(auth.CSPAPIToken)
return auth.NewCSPTokenService(cspAuth.BaseURL, cspAuth.Token)
return auth.NewCSPTokenService(a.BaseURL, a.Token)
}

log.Println("The Wavefront SDK will communicate with a Wavefront Proxy.")
Expand Down
3 changes: 1 addition & 2 deletions senders/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ func CSPBaseURL(baseURL string) CSPOption {
// CSPOrgID sets an explicit orgID for Client Credentials authentication
func CSPOrgID(orgID string) CSPOption {
return func(authentication any) {
switch a := authentication.(type) {
case auth.CSPClientCredentials:
if a, ok := authentication.(auth.CSPClientCredentials); ok {
a.OrgID = &orgID
}
}
Expand Down
40 changes: 18 additions & 22 deletions senders/real_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"strconv"
"strings"

"github.com/wavefronthq/wavefront-sdk-go/event"
"github.com/wavefronthq/wavefront-sdk-go/histogram"
Expand Down Expand Up @@ -197,29 +198,24 @@ func (sender *realSender) Close() {
}

func (sender *realSender) Flush() error {
errStr := ""
err := sender.pointHandler.Flush()
if err != nil {
errStr = errStr + err.Error() + "\n"
}
err = sender.histoHandler.Flush()
if err != nil {
errStr = errStr + err.Error() + "\n"
}
err = sender.spanHandler.Flush()
if err != nil {
errStr = errStr + err.Error()
}
err = sender.spanLogHandler.Flush()
if err != nil {
errStr = errStr + err.Error()
}
err = sender.eventHandler.Flush()
if err != nil {
errStr = errStr + err.Error()
return combineErrorMessages(
sender.pointHandler.Flush(),
sender.histoHandler.Flush(),
sender.spanHandler.Flush(),
sender.spanLogHandler.Flush(),
sender.eventHandler.Flush(),
)
}

func combineErrorMessages(errs ...error) error {
var nonNilErrMessages []string
for _, err := range errs {
if err != nil {
nonNilErrMessages = append(nonNilErrMessages, err.Error())
}
}
if errStr != "" {
return fmt.Errorf(errStr)
if len(nonNilErrMessages) > 0 {
return fmt.Errorf(strings.Join(nonNilErrMessages, "\n"))
}
return nil
}
Expand Down

0 comments on commit 617079c

Please sign in to comment.