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

chore: enable revive linter and resolve linter warnings #166

Merged
merged 1 commit into from
Sep 27, 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
5 changes: 3 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ linters:
- govet
- gofmt
- gci
# - revive
- revive
- ineffassign
# - staticcheck
- staticcheck
issues:
exclude-rules:
- path: example.*_test\.go
linters:
- ineffassign
- revive
2 changes: 1 addition & 1 deletion internal/auth/csp/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type Client interface {
}

type AuthorizeResponse struct {
IdToken string `json:"id_token"`
IDToken string `json:"id_token"`
TokenType string `json:"token_type"`
ExpiresIn int64 `json:"expires_in"`
Scope string `json:"scope"`
Expand Down
12 changes: 6 additions & 6 deletions internal/auth/csp_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ type CSPService struct {

// NewCSPServerToServerService returns a Service instance that gets access tokens via CSP client credentials
func NewCSPServerToServerService(
CSPBaseUrl string,
ClientId string,
CSPBaseURL string,
ClientID string,
ClientSecret string,
OrgID *string,
) Service {
return newService(&csp.ClientCredentialsClient{
BaseURL: CSPBaseUrl,
ClientID: ClientId,
BaseURL: CSPBaseURL,
ClientID: ClientID,
ClientSecret: ClientSecret,
OrgID: OrgID,
})
}

func NewCSPTokenService(CSPBaseUrl, apiToken string) Service {
func NewCSPTokenService(CSPBaseURL, apiToken string) Service {
return newService(&csp.APITokenClient{
BaseURL: CSPBaseUrl,
BaseURL: CSPBaseURL,
APIToken: apiToken,
})
}
Expand Down
4 changes: 2 additions & 2 deletions internal/histogram/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"github.com/wavefronthq/wavefront-sdk-go/internal"
)

// Gets a histogram line in the Wavefront histogram data format:
// Line returns a histogram line in the Wavefront histogram data format:
// {!M | !H | !D} [<timestamp>] #<count> <mean> [centroids] <histogramName> source=<source> [pointTags]
// Example: "!M 1533531013 #20 30.0 #10 5.1 request.latency source=appServer1 region=us-west"
func HistogramLine(name string, centroids histogram.Centroids, hgs map[histogram.Granularity]bool, ts int64, source string, tags map[string]string, defaultSource string) (string, error) {
func Line(name string, centroids histogram.Centroids, hgs map[histogram.Granularity]bool, ts int64, source string, tags map[string]string, defaultSource string) (string, error) {
if name == "" {
return "", errors.New("empty distribution name")
}
Expand Down
14 changes: 7 additions & 7 deletions internal/histogram/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func BenchmarkHistogramLine(b *testing.B) {

var r string
for n := 0; n < b.N; n++ {
r, _ = HistogramLine(name, centroids, hgs, ts, src, tags, "")
r, _ = Line(name, centroids, hgs, ts, src, tags, "")
}
benchmarkLine = r
}
Expand All @@ -34,7 +34,7 @@ func TestHistogramLineCentroidsFormat(t *testing.T) {
{Value: 30.0, Count: 20},
}

line, err := HistogramLine("request.latency", centroids, map[histogram.Granularity]bool{histogram.MINUTE: true},
line, err := Line("request.latency", centroids, map[histogram.Granularity]bool{histogram.MINUTE: true},
1533529977, "test_source", map[string]string{"env": "test"}, "")

assert.Nil(t, err)
Expand All @@ -57,31 +57,31 @@ func TestHistogramLineCentroidsFormat(t *testing.T) {
func TestHistogramLine(t *testing.T) {
centroids := makeCentroids()

line, err := HistogramLine("request.latency", centroids, map[histogram.Granularity]bool{histogram.MINUTE: true},
line, err := Line("request.latency", centroids, map[histogram.Granularity]bool{histogram.MINUTE: true},
1533529977, "test_source", map[string]string{"env": "test"}, "")
expected := "!M 1533529977 #20 30 \"request.latency\" source=\"test_source\" \"env\"=\"test\"\n"
assert.NoError(t, err)
assert.Equal(t, expected, line)

line, err = HistogramLine("request.latency", centroids, map[histogram.Granularity]bool{histogram.MINUTE: true, histogram.HOUR: false},
line, err = Line("request.latency", centroids, map[histogram.Granularity]bool{histogram.MINUTE: true, histogram.HOUR: false},
1533529977, "", map[string]string{"env": "test"}, "default")
expected = "!M 1533529977 #20 30 \"request.latency\" source=\"default\" \"env\"=\"test\"\n"
assert.NoError(t, err)
assert.Equal(t, expected, line)

line, err = HistogramLine("request.latency", centroids, map[histogram.Granularity]bool{histogram.HOUR: true, histogram.MINUTE: false},
line, err = Line("request.latency", centroids, map[histogram.Granularity]bool{histogram.HOUR: true, histogram.MINUTE: false},
1533529977, "", map[string]string{"env": "test"}, "default")
expected = "!H 1533529977 #20 30 \"request.latency\" source=\"default\" \"env\"=\"test\"\n"
assert.NoError(t, err)
assert.Equal(t, expected, line)

line, err = HistogramLine("request.latency", centroids, map[histogram.Granularity]bool{histogram.DAY: true},
line, err = Line("request.latency", centroids, map[histogram.Granularity]bool{histogram.DAY: true},
1533529977, "", map[string]string{"env": "test"}, "default")
expected = "!D 1533529977 #20 30 \"request.latency\" source=\"default\" \"env\"=\"test\"\n"
assert.NoError(t, err)
assert.Equal(t, expected, line)

line, err = HistogramLine("request.latency", centroids, map[histogram.Granularity]bool{histogram.MINUTE: true, histogram.HOUR: true, histogram.DAY: false},
line, err = Line("request.latency", centroids, map[histogram.Granularity]bool{histogram.MINUTE: true, histogram.HOUR: true, histogram.DAY: false},
1533529977, "test_source", map[string]string{"env": "test"}, "")

assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion internal/sanitize.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Sanitize(str string) string {
if (strings.HasPrefix(str, DeltaPrefix) || strings.HasPrefix(str, AltDeltaPrefix)) &&
str[skipHead] == 126 {
sb.WriteString(string(str[skipHead]))
skipHead += 1
skipHead++
}
if str[0] == 126 {
sb.WriteString(string(str[0]))
Expand Down
4 changes: 2 additions & 2 deletions internal/sdkmetrics/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ type fakeSender struct {
tags []string
}

func (f *fakeSender) SendDeltaCounter(name string, value float64, source string, tags map[string]string) error {
func (f *fakeSender) SendDeltaCounter(string, float64, string, map[string]string) error {
return nil
}

func (f *fakeSender) SendMetric(name string, value float64, ts int64, source string, tags map[string]string) error {
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
Expand Down
24 changes: 12 additions & 12 deletions internal/span/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// "getAllUsers source=localhost traceId=7b3bf470-9456-11e8-9eb6-529269fb1459 spanId=0313bafe-9457-11e8-9eb6-529269fb1459
//
// parent=2f64e538-9457-11e8-9eb6-529269fb1459 application=Wavefront http.method=GET 1533531013 343500"
func Line(name string, startMillis, durationMillis int64, source, traceId, spanId string, parents, followsFrom []string, tags []Tag, spanLogs []Log, defaultSource string) (string, error) {
func Line(name string, startMillis, durationMillis int64, source, traceID, spanID string, parents, followsFrom []string, tags []Tag, spanLogs []Log, defaultSource string) (string, error) {
if name == "" {
return "", errors.New("span name cannot be empty")
}
Expand All @@ -24,11 +24,11 @@ func Line(name string, startMillis, durationMillis int64, source, traceId, spanI
source = defaultSource
}

if !isUUIDFormat(traceId) {
return "", fmt.Errorf("traceId is not in UUID format: span=%s traceId=%s", name, traceId)
if !isUUIDFormat(traceID) {
return "", fmt.Errorf("traceId is not in UUID format: span=%s traceId=%s", name, traceID)
}
if !isUUIDFormat(spanId) {
return "", fmt.Errorf("spanId is not in UUID format: span=%s spanId=%s", name, spanId)
if !isUUIDFormat(spanID) {
return "", fmt.Errorf("spanId is not in UUID format: span=%s spanId=%s", name, spanID)
}

sb := internal.GetBuffer()
Expand All @@ -38,9 +38,9 @@ func Line(name string, startMillis, durationMillis int64, source, traceId, spanI
sb.WriteString(" source=")
sb.WriteString(internal.SanitizeValue(source))
sb.WriteString(" traceId=")
sb.WriteString(traceId)
sb.WriteString(traceID)
sb.WriteString(" spanId=")
sb.WriteString(spanId)
sb.WriteString(spanID)

for _, parent := range parents {
sb.WriteString(" parent=")
Expand Down Expand Up @@ -80,10 +80,10 @@ func Line(name string, startMillis, durationMillis int64, source, traceId, spanI
return sb.String(), nil
}

func LogJSON(traceId, spanId string, spanLogs []Log, span string) (string, error) {
func LogJSON(traceID, spanID string, spanLogs []Log, span string) (string, error) {
l := Logs{
TraceId: traceId,
SpanId: spanId,
TraceID: traceID,
SpanID: spanID,
Logs: spanLogs,
Span: span,
}
Expand Down Expand Up @@ -123,8 +123,8 @@ type Log struct {
}

type Logs struct {
TraceId string `json:"traceId"`
SpanId string `json:"spanId"`
TraceID string `json:"traceId"`
SpanID string `json:"spanId"`
Logs []Log `json:"logs"`
Span string `json:"span"`
}
4 changes: 2 additions & 2 deletions internal/span/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ func BenchmarkSpanLine(b *testing.B) {
start := int64(1533531013)
dur := int64(343500)
src := "test_source"
traceId := "7b3bf470-9456-11e8-9eb6-529269fb1459"
traceID := "7b3bf470-9456-11e8-9eb6-529269fb1459"

var r string
for n := 0; n < b.N; n++ {
r, _ = Line(name, start, dur, src, traceId, traceId, []string{traceId}, nil, nil, nil, "")
r, _ = Line(name, start, dur, src, traceID, traceID, []string{traceID}, nil, nil, nil, "")
}
line = r
}
Expand Down
2 changes: 1 addition & 1 deletion senders/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

const (
defaultCSPBaseUrl = "https://console.cloud.vmware.com/"
defaultCSPBaseURL = "https://console.cloud.vmware.com/"
defaultTracesPort = 30001
defaultMetricsPort = 2878
defaultBatchSize = 10_000
Expand Down
4 changes: 2 additions & 2 deletions senders/multi_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ func (ms *multiSender) SendDistribution(name string, centroids []histogram.Centr
return errors.get()
}

func (ms *multiSender) SendSpan(name string, startMillis, durationMillis int64, source, traceId, spanId string, parents, followsFrom []string, tags []SpanTag, spanLogs []SpanLog) error {
func (ms *multiSender) SendSpan(name string, startMillis, durationMillis int64, source, traceID, spanID string, parents, followsFrom []string, tags []SpanTag, spanLogs []SpanLog) error {
var errors multiError
for _, sender := range ms.senders {
err := sender.SendSpan(name, startMillis, durationMillis, source, traceId, spanId, parents, followsFrom, tags, spanLogs)
err := sender.SendSpan(name, startMillis, durationMillis, source, traceID, spanID, parents, followsFrom, tags, spanLogs)
if err != nil {
errors.add(err)
}
Expand Down
12 changes: 5 additions & 7 deletions senders/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,23 @@ func (sender *noOpSender) Start() {
// no-op
}

func (sender *noOpSender) SendMetric(name string, value float64, ts int64, source string, tags map[string]string) error {
func (sender *noOpSender) SendMetric(string, float64, int64, string, map[string]string) error {
return nil
}

func (sender *noOpSender) SendDeltaCounter(name string, value float64, source string, tags map[string]string) error {
func (sender *noOpSender) SendDeltaCounter(string, float64, string, map[string]string) error {
return nil
}

func (sender *noOpSender) SendDistribution(name string, centroids []histogram.Centroid,
hgs map[histogram.Granularity]bool, ts int64, source string, tags map[string]string) error {
func (sender *noOpSender) SendDistribution(string, []histogram.Centroid, map[histogram.Granularity]bool, int64, string, map[string]string) error {
return nil
}

func (sender *noOpSender) SendSpan(name string, startMillis, durationMillis int64, source, traceId, spanId string,
parents, followsFrom []string, tags []SpanTag, spanLogs []SpanLog) error {
func (sender *noOpSender) SendSpan(string, int64, int64, string, string, string, []string, []string, []SpanTag, []SpanLog) error {
return nil
}

func (sender *noOpSender) SendEvent(name string, startMillis, endMillis int64, source string, tags map[string]string, setters ...event.Option) error {
func (sender *noOpSender) SendEvent(string, int64, int64, string, map[string]string, ...event.Option) error {
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions senders/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func CSPAPIToken(cspAPIToken string, options ...CSPOption) Option {
return func(c *configuration) {
cspTokenAuth := auth.CSPAPIToken{
Token: cspAPIToken,
BaseURL: defaultCSPBaseUrl,
BaseURL: defaultCSPBaseURL,
}
for _, option := range options {
option(&cspTokenAuth)
Expand All @@ -59,12 +59,12 @@ func CSPAPIToken(cspAPIToken string, options ...CSPOption) Option {
}

// CSPClientCredentials configures the sender to use a CSP Client Credentials for authentication
func CSPClientCredentials(clientId string, clientSecret string, options ...CSPOption) Option {
func CSPClientCredentials(clientID string, clientSecret string, options ...CSPOption) Option {
return func(c *configuration) {
clientCredentials := &auth.CSPClientCredentials{
ClientID: clientId,
ClientID: clientID,
ClientSecret: clientSecret,
BaseURL: defaultCSPBaseUrl,
BaseURL: defaultCSPBaseURL,
}
for _, option := range options {
option(clientCredentials)
Expand Down
14 changes: 7 additions & 7 deletions senders/real_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (sender *realSender) SendDistribution(
source string,
tags map[string]string,
) error {
line, err := histogramInternal.HistogramLine(name, centroids, hgs, ts, source, tags, sender.defaultSource)
line, err := histogramInternal.Line(name, centroids, hgs, ts, source, tags, sender.defaultSource)
return trySendWith(
line,
err,
Expand All @@ -107,9 +107,9 @@ func trySendWith(line string, err error, handler internal.LineHandler, tracker s
if err != nil {
tracker.IncInvalid()
return err
} else {
tracker.IncValid()
}

tracker.IncValid()
err = handler.HandleLine(line)
if err != nil {
tracker.IncDropped()
Expand All @@ -120,7 +120,7 @@ func trySendWith(line string, err error, handler internal.LineHandler, tracker s
func (sender *realSender) SendSpan(
name string,
startMillis, durationMillis int64,
source, traceId, spanId string,
source, traceID, spanID string,
parents, followsFrom []string,
tags []SpanTag,
spanLogs []SpanLog,
Expand All @@ -132,8 +132,8 @@ func (sender *realSender) SendSpan(
startMillis,
durationMillis,
source,
traceId,
spanId,
traceID,
spanID,
parents,
followsFrom,
makeSpanTags(tags),
Expand All @@ -150,7 +150,7 @@ func (sender *realSender) SendSpan(
}

if len(spanLogs) > 0 {
logJSON, logJSONErr := span.LogJSON(traceId, spanId, logs, line)
logJSON, logJSONErr := span.LogJSON(traceID, spanID, logs, line)
return trySendWith(
logJSON,
logJSONErr,
Expand Down
12 changes: 6 additions & 6 deletions senders/real_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ func TestSendDirect(t *testing.T) {
token := "direct-send-api-token"
directServer := startTestServer(false)
defer directServer.Close()
updatedUrl, err := url.Parse(directServer.URL)
updatedURL, err := url.Parse(directServer.URL)
assert.NoError(t, err)
updatedUrl.User = url.User(token)
wf, err := NewSender(updatedUrl.String())
updatedURL.User = url.User(token)
wf, err := NewSender(updatedURL.String())

require.NoError(t, err)
testSender(t, wf, directServer)
Expand All @@ -36,11 +36,11 @@ func TestSendDirectWithTags(t *testing.T) {
directServer := startTestServer(false)
defer directServer.Close()

updatedUrl, err := url.Parse(directServer.URL)
updatedURL, err := url.Parse(directServer.URL)
assert.NoError(t, err)
updatedUrl.User = url.User(token)
updatedURL.User = url.User(token)
tags := map[string]string{"foo": "bar"}
wf, err := NewSender(updatedUrl.String(), SDKMetricsTags(tags))
wf, err := NewSender(updatedURL.String(), SDKMetricsTags(tags))
require.NoError(t, err)
testSender(t, wf, directServer)

Expand Down
4 changes: 2 additions & 2 deletions senders/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ type DistributionSender interface {
// SpanSender Interface for sending tracing spans to Wavefront
type SpanSender interface {
// SendSpan sends a tracing span to Wavefront.
// traceId, spanId, parentIds and preceding spanIds are expected to be UUID strings.
// traceID, spanId, parentIds and preceding spanIds are expected to be UUID strings.
// parents and preceding spans can be empty for a root span.
// span tag keys can be repeated (example: "user"="foo" and "user"="bar")
// span logs are currently omitted
SendSpan(name string, startMillis, durationMillis int64, source, traceId, spanId string, parents, followsFrom []string, tags []SpanTag, spanLogs []SpanLog) error
SendSpan(name string, startMillis, durationMillis int64, source, traceID, spanID string, parents, followsFrom []string, tags []SpanTag, spanLogs []SpanLog) error
}

// EventSender Interface for sending events to Wavefront. NOT yet supported.
Expand Down
Loading
Loading